Skip to content

πŸ“š The open-source, offline-first Notion, Obsidian & Confluence alternative. Advanced Markdown, multi-tenant teams, OIDC/SSO, and local S3 backups. Deploy in one command.

New context menus management: - Default options are the same between context menu and dot menu - Export utils date format - Remove code duplication & fix bugs

Smaug67398ca444a506ad
diff --git a/frontend/app/components/DocumentCard.vue b/frontend/app/components/DocumentCard.vue
index 80844e06..decf8d87 100644
--- a/frontend/app/components/DocumentCard.vue
+++ b/frontend/app/components/DocumentCard.vue
@@ -6,7 +6,7 @@
<Icon :name="category?.icon || 'files'" display="xl" :class="`category-icon ${getAppColor(document.color || category?.color as number, true)}`" />
<NuxtLink :to="`/dashboard/docs/${document.id}`" class="document-title">{{ document.name }}</NuxtLink>
</span>
- <DocumentDotMenu :document="document" :user="user" @delete="deleteDoc" />
+ <NodeDotMenu :node="document" :user="user" @delete="deleteDoc" />
</div>
<div class="body">
<div class="category">{{ category?.name }}</div>
diff --git a/frontend/app/components/DocumentDotMenu.vue b/frontend/app/components/DocumentDotMenu.vue
deleted file mode 100644
index d857886b..00000000
--- a/frontend/app/components/DocumentDotMenu.vue
+++ /dev/null
@@ -1,87 +0,0 @@
-<template>
- <AppDotMenu ref="dotMenu" @open="() => emit('open')" @close="() => emit('close')">
- <button @click="open"><Icon name="file_open" /> Open</button>
- <NuxtLink :to="`/dashboard/docs/${props.document.id}`" target="_blank"
- ><button><Icon name="new_tab" />Open in new tab</button></NuxtLink
- >
- <button @click="edit"><Icon name="edit_page" /> Edit</button>
- <button @click="copyLink"><Icon name="link" /> Copy link</button>
- <button @click="pin"><Icon :name="document.order === -1 ? 'pin_off' : 'pin'" /> {{ document.order === -1 ? 'Unpin' : 'Pin' }}</button>
- <hr style="margin: 2px 0" />
- <button @click="emitDelete"><Icon name="delete" fill="red" /> Delete</button>
- <hr style="margin: 2px 0" />
- <div class="foot-menu">
- <p style="display: flex; align-items: center; gap: 8px">
- <img :src="useAvatar(user)" alt="Avatar" style="width: 20px; height: 20px; margin: 0; border-radius: 50%" />{{ user?.username }}
- </p>
- <p>Updated on {{ numericDate(document.updated_timestamp) }}</p>
- </div>
- </AppDotMenu>
-</template>
-
-<script setup lang="ts">
-import type { Node, PublicUser } from '~/stores';
-
-const dotMenu = ref();
-const props = defineProps<{ document: Node; user?: PublicUser }>();
-const emit = defineEmits<{
- (e: 'open' | 'close' | 'edit' | 'rename' | 'delete'): void;
-}>();
-defineExpose({ close: () => dotMenu.value?.close() });
-
-const numericDate = (timestamp: number): string => {
- const date = new Date(timestamp);
- return date.toLocaleDateString('en-US', {
- year: 'numeric',
- month: '2-digit',
- day: '2-digit',
- });
-};
-
-const open = () => useRouter().push(`/dashboard/docs/${props.document.id}`);
-const edit = () => useRouter().push(`/dashboard/docs/edit/${props.document.id}`);
-const copyLink = () => {
- const link = `${window.location.origin}/dashboard/docs/${props.document.id}`;
- navigator.clipboard.writeText(link).then(() => {});
-};
-const emitDelete = () => {
- dotMenu.value?.close();
- emit('delete');
-};
-const pin = async () => {
- await useNodesStore().update({ ...props.document, order: props.document.order === -1 ? 0 : -1 });
-};
-</script>
-
-<style scoped lang="scss">
-button {
- display: flex;
- width: 100%;
- padding: 6px 8px;
- border: none;
- font-family: ui-sans-serif, sans-serif;
- font-size: 14px;
- color: var(--font-color);
- background: none;
- align-items: center;
- cursor: pointer;
- gap: 8px;
-
- &:hover {
- background-color: var(--bg-contrast);
- }
-}
-
-.foot-menu {
- display: flex;
- padding: 4px 8px;
- font-size: 0.85rem;
- color: var(--font-color-light);
- flex-direction: column;
- gap: 5px;
-
- p {
- margin: 0;
- }
-}
-</style>
diff --git a/frontend/app/components/DocumentLine.vue b/frontend/app/components/DocumentLine.vue
index 9b4378d4..a98dde32 100644
--- a/frontend/app/components/DocumentLine.vue
+++ b/frontend/app/components/DocumentLine.vue
@@ -9,7 +9,7 @@
/>
<NuxtLink :to="`/dashboard/docs/${document.id}`" class="document-title">{{ document.name }}</NuxtLink>
</div>
- <DocumentDotMenu :document="document" :user="user" @delete="deleteDoc" />
+ <NodeDotMenu :node="document" :user="user" @delete="deleteDoc" />
</header>
<div v-if="document.tags" class="tags">
<tag v-for="tag in document.tags?.split(', ')" :key="tag" class="primary">{{ tag }}</tag>
diff --git a/frontend/app/components/Node/NodeContextMenu.vue b/frontend/app/components/Node/NodeContextMenu.vue
index eb54fdb3..f2dbe068 100644
--- a/frontend/app/components/Node/NodeContextMenu.vue
+++ b/frontend/app/components/Node/NodeContextMenu.vue
@@ -1,69 +1,58 @@
<template>
- <div>
- <button @click="action('open')"><Icon name="file_open" /> Open</button>
- <NuxtLink :to="`/dashboard/docs/${props.node.id}`" target="_blank"
- ><button><Icon name="new_tab" />Open in new tab</button></NuxtLink
- >
- <template v-if="nodesStore.hasPermissions(node, 2)">
- <button @click="action('edit')"><Icon name="edit_page" /> Edit</button>
- <button @click="action('pin')"><Icon :name="node.order === -1 ? 'pin_off' : 'pin'" /> {{ node.order === -1 ? 'Unpin' : 'Pin' }}</button>
- <button @click="action('duplicate')"><Icon name="duplicate" /> Duplicate</button>
- </template>
- <button @click="action('copyLink')"><Icon name="link" /> Copy link</button>
- <button v-if="preferences.get('developerMode').value" @click="action('copyId')"><Icon name="snippets" /> Copy ID</button>
- <template v-if="nodesStore.hasPermissions(node, 2)">
- <hr style="margin: 2px 0" />
- <button @click="action('delete')"><Icon name="delete" fill="red" /> Delete</button>
- </template>
- <hr style="margin: 2px 0" />
- <div class="foot-menu">
- <p style="display: flex; align-items: center; gap: 8px">
- <img :src="useAvatar(user)" alt="Avatar" style="width: 20px; height: 20px; margin: 0; border-radius: 50%" />{{ user?.username }}
- </p>
- <p>Updated on {{ numericDate(node.updated_timestamp) }}</p>
- </div>
+ <button @click="action('open')"><Icon name="file_open" /> Open</button>
+ <button @click="action('edit')"><Icon name="edit_page" /> Edit</button>
+ <button><Icon name="duplicate" /> Duplicate</button>
+ <button @click="action('copyLink')"><Icon name="link" /> Copy link</button>
+ <button @click="action('pin')"><Icon :name="node.order === -1 ? 'pin_off' : 'pin'" /> {{ node.order === -1 ? 'Unpin' : 'Pin' }}</button>
+ <button v-if="nodeStore.hasPermissions(node, 4)" @click="action('manageAccess')"><Icon name="manage_access" />Manage Access</button>
+ <hr />
+ <button @click="action('delete')"><Icon name="delete" fill="red" /> Delete</button>
+ <button v-if="preferences.get('developerMode').value"><Icon name="snippets" /> Copy ID</button>
+ <hr />
+ <div class="footer">
+ <p style="display: flex; align-items: center; gap: 8px">
+ <img :src="useAvatar(user)" alt="Avatar" style="width: 20px; height: 20px; margin: 0; border-radius: 50%" />{{ user?.username }}
+ </p>
+ <p>Updated on {{ numericDate(node.updated_timestamp) }}</p>
</div>
</template>
<script setup lang="ts">
-import type { Node, PublicUser } from '~/stores';
-import DeleteDocumentModal from '~/components/Node/DeleteNodeModal.vue';
-const props = defineProps<{ node: Node }>();
-const emit = defineEmits(['close']);
-const user = ref<PublicUser | null>(null);
+import NodePermissions from './NodePermissions.modal.vue';
+import NodeDeleteModal from './DeleteNodeModal.vue';
+import type { Node } from '~/stores';
-const userStore = useUserStore();
-const nodesStore = useNodesStore();
+const nodeStore = useNodesStore();
const preferences = usePreferences();
+const emit = defineEmits(['close']);
+const dotMenu = ref();
+const props = defineProps<{ node: Node }>();
-watchEffect(async () => {
- if (props.node) user.value = await userStore.fetchPublicUser(props.node.user_id);
-});
-
-const numericDate = (timestamp: number): string => {
- const date = new Date(timestamp);
- return date.toLocaleDateString('en-US', {
- year: 'numeric',
- month: '2-digit',
- day: '2-digit',
- });
-};
+useUserStore().fetchPublicUser(props.node.user_id);
+const user = computed(() => useUserStore().getById(props.node.user_id || ''));
+defineExpose({ close: () => dotMenu.value?.close() });
-function action(actionName: string) {
- if (actionName === 'open') useRouter().push(`/dashboard/docs/${props.node.id}`);
- else if (actionName === 'edit') useRouter().push(`/dashboard/docs/edit/${props.node.id}`);
- else if (actionName === 'copyLink') {
- const link = `${window.location.origin}/dashboard/docs/${props.node.id}`;
- navigator.clipboard.writeText(link);
- } else if (actionName === 'copyId') {
- navigator.clipboard.writeText(props.node.id);
- } else if (actionName === 'duplicate') {
- nodesStore.duplicate(props.node);
- } else if (actionName === 'delete') {
- useModal().add(new Modal(shallowRef(DeleteDocumentModal), { props: { documentId: props.node.id } }));
- emit('close');
- } else if (actionName === 'pin') {
- nodesStore.update({ ...props.node, order: props.node.order === -1 ? 0 : -1 });
+async function action(name: string) {
+ switch (name) {
+ case 'open':
+ useRouter().push(`/dashboard/docs/${props.node.id}`);
+ break;
+ case 'edit':
+ useRouter().push(`/dashboard/docs/edit/${props.node.id}`);
+ break;
+ case 'delete':
+ dotMenu.value?.close();
+ useModal().add(new Modal(shallowRef(NodeDeleteModal), { props: { documentId: props.node.id }, size: 'small' }));
+ break;
+ case 'copyLink':
+ navigator.clipboard.writeText(`${window.location.origin}/dashboard/docs/${props.node.id}`);
+ break;
+ case 'pin':
+ await useNodesStore().update({ ...props.node, order: props.node.order === -1 ? 0 : -1 });
+ break;
+ case 'manageAccess':
+ useModal().add(new Modal(shallowRef(NodePermissions), { props: { node: props.node }, size: 'small' }));
+ break;
}
emit('close');
}
@@ -73,7 +62,7 @@ function action(actionName: string) {
button {
display: flex;
width: 100%;
- padding: 6px 8px;
+ padding: 4px;
border: none;
font-family: ui-sans-serif, sans-serif;
font-size: 14px;
@@ -88,8 +77,9 @@ button {
}
}
-.foot-menu {
+.footer {
display: flex;
+ margin-top: 4px;
padding: 4px 8px;
font-size: 0.85rem;
color: var(--font-color-light);
diff --git a/frontend/app/components/NodeDotMenu.vue b/frontend/app/components/NodeDotMenu.vue
new file mode 100644
index 00000000..cabd0623
--- /dev/null
+++ b/frontend/app/components/NodeDotMenu.vue
@@ -0,0 +1,12 @@
+<template>
+ <AppDotMenu ref="dotMenu">
+ <NodeContextMenu :node="node" />
+ </AppDotMenu>
+</template>
+
+<script setup lang="ts">
+import NodeContextMenu from '~/components/Node/NodeContextMenu.vue';
+import type { Node } from '~/stores';
+
+defineProps<{ node: Node }>();
+</script>
diff --git a/frontend/app/composables/utils.ts b/frontend/app/composables/utils.ts
index 0b287a78..f6186109 100644
--- a/frontend/app/composables/utils.ts
+++ b/frontend/app/composables/utils.ts
@@ -28,6 +28,15 @@ export function formatDate(timestamp: number | undefined): string {
return `${date.getDate()} ${date.toLocaleString('default', { month: 'short' })} ${date.getFullYear()}`;
}
+export function numericDate(timestamp: number): string {
+ const date = new Date(timestamp);
+ return date.toLocaleDateString('en-US', {
+ year: 'numeric',
+ month: '2-digit',
+ day: '2-digit',
+ });
+}
+
export function setAppColor(color: string | number) {
if (typeof color === 'number') {
color = getAppColor(color);