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.

Pin documents system

Smaug67396af7a22e2b87
diff --git a/backend/controllers/documents.controller.go b/backend/controllers/documents.controller.go
index 73d2a5d2..48edb862 100644
--- a/backend/controllers/documents.controller.go
+++ b/backend/controllers/documents.controller.go
@@ -92,6 +92,7 @@ func (ctr *Controller) CreateDocument(c *gin.Context) (int, any) {
Name: document.Name,
Description: document.Description,
Tags: document.Tags,
+ Pinned: document.Pinned,
Category: document.Category,
ParentId: document.ParentId,
Accessibility: document.Accessibility,
@@ -140,6 +141,7 @@ func (ctr *Controller) UpdateDocument(c *gin.Context) (int, any) {
Name: document.Name,
Description: document.Description,
Tags: document.Tags,
+ Pinned: document.Pinned,
Category: document.Category,
ParentId: document.ParentId,
Accessibility: document.Accessibility,
diff --git a/backend/models/document.model.go b/backend/models/document.model.go
index 47931db5..a70ae08e 100644
--- a/backend/models/document.model.go
+++ b/backend/models/document.model.go
@@ -7,6 +7,7 @@ type Document struct {
Name string `json:"name" form:"name" binding:"required,max=50"`
Description *string `json:"description" form:"description" binding:"omitempty,max=250"`
Tags *string `json:"tags" form:"tags" binding:"omitempty,max=250"`
+ Pinned int `json:"pinned" form:"pinned" binding:"omitempty"` // 0: Not pinned; 1: Pinned; 2: Pinned to top
Category *types.Snowflake `json:"category" form:"category" binding:"omitempty"`
ParentId *types.Snowflake `json:"parent_id" form:"parent_id" binding:"omitempty"`
Accessibility int `json:"accessibility" form:"accessibility" binding:"required"` // 0: Public; 1: Private; 2: Unlisted;
diff --git a/backend/services/document.service.go b/backend/services/document.service.go
index 5f1267d8..48867f5d 100644
--- a/backend/services/document.service.go
+++ b/backend/services/document.service.go
@@ -21,7 +21,7 @@ func NewDocumentService(db *sql.DB) DocumentService {
func (s *Service) GetAllDocuments(userId types.Snowflake) ([]*models.Document, error) {
var documents = make([]*models.Document, 0)
- rows, err := s.db.Query("SELECT id, name, description, tags, category, parent_id, accessibility, author_id, created_timestamp, updated_timestamp FROM documents WHERE author_id = ? ORDER BY name", userId)
+ rows, err := s.db.Query("SELECT id, name, description, tags, pinned, category, parent_id, accessibility, author_id, created_timestamp, updated_timestamp FROM documents WHERE author_id = ? ORDER BY name", userId)
if err != nil {
return nil, err
}
@@ -34,6 +34,7 @@ func (s *Service) GetAllDocuments(userId types.Snowflake) ([]*models.Document, e
&document.Name,
&document.Description,
&document.Tags,
+ &document.Pinned,
&document.Category,
&document.ParentId,
&document.Accessibility,
@@ -49,7 +50,7 @@ func (s *Service) GetAllDocuments(userId types.Snowflake) ([]*models.Document, e
func (s *Service) GetAllDocumentBackup(author_id types.Snowflake) ([]*models.Document, error) {
var documents = make([]*models.Document, 0)
- rows, err := s.db.Query("SELECT id, name, description, tags, category, parent_id, accessibility, content_markdown, content_html, author_id, created_timestamp, updated_timestamp FROM documents WHERE author_id = ?", author_id)
+ rows, err := s.db.Query("SELECT id, name, description, tags, pinned, category, parent_id, accessibility, content_markdown, content_html, author_id, created_timestamp, updated_timestamp FROM documents WHERE author_id = ?", author_id)
if err != nil {
return nil, err
}
@@ -60,6 +61,7 @@ func (s *Service) GetAllDocumentBackup(author_id types.Snowflake) ([]*models.Doc
&document.Name,
&document.Description,
&document.Tags,
+ &document.Pinned,
&document.Category,
&document.ParentId,
&document.Accessibility,
@@ -77,11 +79,12 @@ func (s *Service) GetAllDocumentBackup(author_id types.Snowflake) ([]*models.Doc
func (s *Service) GetDocument(documentId types.Snowflake) (*models.Document, error) {
var document models.Document
- err := s.db.QueryRow("SELECT id, name, description, tags, category, parent_id, accessibility, content_markdown, content_html, author_id, created_timestamp, updated_timestamp FROM documents WHERE id = ?", documentId).Scan(
+ err := s.db.QueryRow("SELECT id, name, description, tags, pinned, category, parent_id, accessibility, content_markdown, content_html, author_id, created_timestamp, updated_timestamp FROM documents WHERE id = ?", documentId).Scan(
&document.Id,
&document.Name,
&document.Description,
&document.Tags,
+ &document.Pinned,
&document.Category,
&document.ParentId,
&document.Accessibility,
@@ -97,11 +100,12 @@ func (s *Service) GetDocument(documentId types.Snowflake) (*models.Document, err
}
func (s *Service) CreateDocument(document *models.Document) error {
- _, err := s.db.Exec("INSERT INTO documents (id, name, description, tags, category, parent_id, accessibility, content_markdown, content_html, author_id, created_timestamp, updated_timestamp) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
+ _, err := s.db.Exec("INSERT INTO documents (id, name, description, tags, pinned, category, parent_id, accessibility, content_markdown, content_html, author_id, created_timestamp, updated_timestamp) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
document.Id,
document.Name,
document.Description,
document.Tags,
+ document.Pinned,
document.Category,
document.ParentId,
document.Accessibility,
@@ -114,10 +118,11 @@ func (s *Service) CreateDocument(document *models.Document) error {
}
func (s *Service) UpdateDocument(document *models.Document) error {
- _, err := s.db.Exec("UPDATE documents SET name = ?, description = ?, tags = ?, category = ?, parent_id = ?, accessibility = ?, content_markdown = ?, content_html = ? WHERE id = ?",
+ _, err := s.db.Exec("UPDATE documents SET name = ?, description = ?, tags = ?, pinned = ?, category = ?, parent_id = ?, accessibility = ?, content_markdown = ?, content_html = ? WHERE id = ?",
document.Name,
document.Description,
document.Tags,
+ document.Pinned,
document.Category,
document.ParentId,
document.Accessibility,
diff --git a/frontend/app/components/AppDotMenu.vue b/frontend/app/components/AppDotMenu.vue
index 716edf08..bd910480 100644
--- a/frontend/app/components/AppDotMenu.vue
+++ b/frontend/app/components/AppDotMenu.vue
@@ -15,20 +15,21 @@
<script setup lang="ts">
const open = ref(false);
+const emit = defineEmits(['open', 'close']);
const menuRoot: Ref<HTMLDivElement | undefined> = ref();
-const toggleMenu = () => (open.value = !open.value);
+const toggleMenu = () => {
+ open.value = !open.value;
+ emit(open.value ? 'open' : 'close');
+};
function handleClickOutside(e: MouseEvent) {
- if (menuRoot.value && !menuRoot.value.contains(e.target as Node)) {
- open.value = false;
- }
+ open.value = false;
+ emit('close');
}
const close = () => (open.value = false);
-defineExpose({ close });
+defineExpose({ close, opened: open });
-onMounted(() => {
- document.addEventListener('mousedown', handleClickOutside);
-});
+onMounted(() => document.addEventListener('mousedown', handleClickOutside));
onBeforeUnmount(() => document.removeEventListener('mousedown', handleClickOutside));
</script>
diff --git a/frontend/app/components/DocumentDotMenu.vue b/frontend/app/components/DocumentDotMenu.vue
index 46225780..207bb7a6 100644
--- a/frontend/app/components/DocumentDotMenu.vue
+++ b/frontend/app/components/DocumentDotMenu.vue
@@ -1,8 +1,10 @@
<template>
- <AppDotMenu ref="dotMenu">
+ <AppDotMenu ref="dotMenu" @open="() => emit('open')" @close="() => emit('close')">
<button @click="open"><Icon name="file_open" /> Open</button>
<button @click="edit"><Icon name="edit_page" /> Edit</button>
<button @click="copyLink"><Icon name="link" /> Copy link</button>
+ <button @click="pin"><Icon :name="document.pinned ? 'pin_off' : 'pin'" /> {{ document.pinned ? '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">
@@ -19,6 +21,7 @@ const dotMenu = ref();
const props = defineProps<{ document: Document; user?: User }>();
const emit = defineEmits<{
(e: 'open'): void;
+ (e: 'close'): void;
(e: 'edit'): void;
(e: 'rename'): void;
(e: 'delete'): void;
@@ -44,6 +47,11 @@ const emitDelete = () => {
dotMenu.value?.close();
emit('delete');
};
+const pin = () => {
+ dotMenu.value?.close();
+ props.document.pinned = props.document.pinned === 1 ? 0 : 1; // Toggle pin state
+ useDocumentsStore().update(props.document);
+};
</script>
<style scoped lang="scss">
diff --git a/frontend/app/components/Sidebar/SidebarItem.vue b/frontend/app/components/Sidebar/SidebarItem.vue
index e44177f6..872c7eab 100644
--- a/frontend/app/components/Sidebar/SidebarItem.vue
+++ b/frontend/app/components/Sidebar/SidebarItem.vue
@@ -1,10 +1,12 @@
<template>
- <span class="item" @click="onClick" :draggable="true" @dragstart="dragStart" @dragover.prevent="dragOver" @drop="drop" @dragleave="dragLeave" :class="{ 'drag-over': isDragOver }" @mouseleave="closeDotMenu">
+ <span class="item" @click="onClick" :draggable="true" @dragstart="dragStart" @dragover.prevent="dragOver" @drop="drop" @dragleave="dragLeave" :class="{ 'drag-over': isDragOver }">
<Icon :name="icon" :class="customClass" />&nbsp;
- <NuxtLink :to="item.route" style="width: 100%" class="close">{{ item.label }} </NuxtLink>
- <DocumentDotMenu v-if="item.data.type === 'document'" ref="dotMenu" class="nav close" :document="item.data" :user="user" :mouse-leave="true" @delete="deleteDoc" />
+
+ <NuxtLink :to="item.route" style="width: 100%" class="close">{{ item.label }}</NuxtLink>
+ <DocumentDotMenu v-if="item.data.type === 'document'" ref="dotMenu" class="nav close" :class="{ active: isActive }" :document="item.data" :user="user" @open="() => (isActive = true)" @close="() => (isActive = false)" @delete="deleteDoc" />
<NuxtLink v-if="item.data.type === 'category'" :to="`/dashboard/categories/${item.id}/edit`" class="nav close"> <Icon name="settings" fill="var(--font-color)" /> </NuxtLink>
<NuxtLink v-if="item.data.type === 'category'" :to="`/dashboard/docs/new?cat=${item.id}`" class="nav close"> <Icon name="plus" fill="var(--font-color)" /> </NuxtLink>
+ <Icon name="pin" fill="var(--font-color-light)" v-if="item.data.type === 'document' && item.data.pinned" class="ni" />
<slot></slot>
</span>
</template>
@@ -21,9 +23,7 @@ const dotMenu = ref();
const customClass = computed(() => {
if ('color' in props.item.data && props.item.data.color) return `item-icon ${getAppColor(props.item.data.color as number)}`;
});
-const closeDotMenu = () => {
- if (dotMenu.value) dotMenu.value.close();
-};
+const isActive = ref(false);
const icon = computed(() => {
if ('icon' in props.item.data && props.item.data.icon) return props.item.data.icon;
return props.item.icon || '';
@@ -133,11 +133,13 @@ const drop = async (event: DragEvent) => {
}
.nav {
display: none;
- &:deep(svg) {
- fill: inherit !important;
- }
}
-.item:hover .nav {
+.nav:deep(svg),
+.ni:deep(svg) {
+ fill: inherit !important;
+}
+.item:hover .nav,
+.active {
display: block;
}
</style>
diff --git a/frontend/app/helpers/icons.ts b/frontend/app/helpers/icons.ts
index 9fbf5877..17f59e17 100644
--- a/frontend/app/helpers/icons.ts
+++ b/frontend/app/helpers/icons.ts
@@ -30,6 +30,8 @@ const icons = {
logout: `<svg xmlns="http://www.w3.org/2000/svg" style="fill:var(--font-color);" viewBox="0 -960 960 960"><path d="M200-120q-33 0-56.5-23.5T120-200v-560q0-33 23.5-56.5T200-840h280v80H200v560h280v80H200Zm440-160-55-58 102-102H360v-80h327L585-622l55-58 200 200-200 200Z"/></svg>`,
markdown: `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 -960 960 960"><path d="m640-360 120-120-42-43-48 48v-125h-60v125l-48-48-42 43 120 120ZM160-160q-33 0-56.5-23.5T80-240v-480q0-33 23.5-56.5T160-800h640q33 0 56.5 23.5T880-720v480q0 33-23.5 56.5T800-160H160Zm0-80h640v-480H160v480Zm0 0v-480 480Zm60-120h60v-180h40v120h60v-120h40v180h60v-200q0-17-11.5-28.5T440-600H260q-17 0-28.5 11.5T220-560v200Z"/></svg>`,
pdf: `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 -960 960 960"><path style="fill:var(--green);" d="M280-280h280v-80H280v80Zm0-160h400v-80H280v80Zm0-160h400v-80H280v80Zm-80 480q-33 0-56.5-23.5T120-200v-560q0-33 23.5-56.5T200-840h560q33 0 56.5 23.5T840-760v560q0 33-23.5 56.5T760-120H200Zm0-80h560v-560H200v560Zm0-560v560-560Z"/></svg>`,
+ pin: `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 -960 960 960"><path d="m640-480 80 80v80H520v240l-40 40-40-40v-240H240v-80l80-80v-280h-40v-80h400v80h-40v280Zm-286 80h252l-46-46v-314H400v314l-46 46Zm126 0Z"/></svg>`,
+ pin_off: `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 -960 960 960"><path d="M680-840v80h-40v327l-80-80v-247H400v87l-87-87-33-33v-47h400ZM480-40l-40-40v-240H240v-80l80-80v-46L56-792l56-56 736 736-58 56-264-264h-6v240l-40 40ZM354-400h92l-44-44-2-2-46 46Zm126-193Zm-78 149Z"/></svg>`,
plus: `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 -960 960 960"><path d="M440-440H200v-80h240v-240h80v240h240v80H520v240h-80v-240Z"/></svg>`,
profil: `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 -960 960 960"><path d="M234-276q51-39 114-61.5T480-360q69 0 132 22.5T726-276q35-41 54.5-93T800-480q0-133-93.5-226.5T480-800q-133 0-226.5 93.5T160-480q0 59 19.5 111t54.5 93Zm246-164q-59 0-99.5-40.5T340-580q0-59 40.5-99.5T480-720q59 0 99.5 40.5T620-580q0 59-40.5 99.5T480-440Zm0 360q-83 0-156-31.5T197-197q-54-54-85.5-127T80-480q0-83 31.5-156T197-763q54-54 127-85.5T480-880q83 0 156 31.5T763-763q54 54 85.5 127T880-480q0 83-31.5 156T763-197q-54 54-127 85.5T480-80Zm0-80q53 0 100-15.5t86-44.5q-39-29-86-44.5T480-280q-53 0-100 15.5T294-220q39 29 86 44.5T480-160Zm0-360q26 0 43-17t17-43q0-26-17-43t-43-17q-26 0-43 17t-17 43q0 26 17 43t43 17Zm0-60Zm0 360Z"/></svg>`,
search: `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 -960 960 960"><path d="M784-120 532-372q-30 24-69 38t-83 14q-109 0-184.5-75.5T120-580q0-109 75.5-184.5T380-840q109 0 184.5 75.5T640-580q0 44-14 83t-38 69l252 252-56 56ZM380-400q75 0 127.5-52.5T560-580q0-75-52.5-127.5T380-760q-75 0-127.5 52.5T200-580q0 75 52.5 127.5T380-400Z"/></svg>`,
@@ -41,7 +43,7 @@ const icons = {
users: `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 -960 960 960"><path d="M40-160v-112q0-34 17.5-62.5T104-378q62-31 126-46.5T360-440q66 0 130 15.5T616-378q29 15 46.5 43.5T680-272v112H40Zm720 0v-120q0-44-24.5-84.5T666-434q51 6 96 20.5t84 35.5q36 20 55 44.5t19 53.5v120H760ZM360-480q-66 0-113-47t-47-113q0-66 47-113t113-47q66 0 113 47t47 113q0 66-47 113t-113 47Zm400-160q0 66-47 113t-113 47q-11 0-28-2.5t-28-5.5q27-32 41.5-71t14.5-81q0-42-14.5-81T544-792q14-5 28-6.5t28-1.5q66 0 113 47t47 113ZM120-240h480v-32q0-11-5.5-20T580-306q-54-27-109-40.5T360-360q-56 0-111 13.5T140-306q-9 5-14.5 14t-5.5 20v32Zm240-320q33 0 56.5-23.5T440-640q0-33-23.5-56.5T360-720q-33 0-56.5 23.5T280-640q0 33 23.5 56.5T360-560Zm0 320Zm0-400Z"/></svg>`,
user_settings: `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 -960 960 960"><path d="M400-480q-66 0-113-47t-47-113q0-66 47-113t113-47q66 0 113 47t47 113q0 66-47 113t-113 47ZM80-160v-112q0-33 17-62t47-44q51-26 115-44t141-18h14q6 0 12 2-8 18-13.5 37.5T404-360h-4q-71 0-127.5 18T180-306q-9 5-14.5 14t-5.5 20v32h252q6 21 16 41.5t22 38.5H80Zm560 40-12-60q-12-5-22.5-10.5T584-204l-58 18-40-68 46-40q-2-14-2-26t2-26l-46-40 40-68 58 18q11-8 21.5-13.5T628-460l12-60h80l12 60q12 5 22.5 11t21.5 15l58-20 40 70-46 40q2 12 2 25t-2 25l46 40-40 68-58-18q-11 8-21.5 13.5T732-180l-12 60h-80Zm40-120q33 0 56.5-23.5T760-320q0-33-23.5-56.5T680-400q-33 0-56.5 23.5T600-320q0 33 23.5 56.5T680-240ZM400-560q33 0 56.5-23.5T480-640q0-33-23.5-56.5T400-720q-33 0-56.5 23.5T320-640q0 33 23.5 56.5T400-560Zm0-80Zm12 400Z"/></svg>`,
view: `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 -960 960 960" fill="var(--font-color)"><path d="M480-320q75 0 127.5-52.5T660-500q0-75-52.5-127.5T480-680q-75 0-127.5 52.5T300-500q0 75 52.5 127.5T480-320Zm0-72q-45 0-76.5-31.5T372-500q0-45 31.5-76.5T480-608q45 0 76.5 31.5T588-500q0 45-31.5 76.5T480-392Zm0 192q-146 0-266-81.5T40-500q54-137 174-218.5T480-800q146 0 266 81.5T920-500q-54 137-174 218.5T480-200Zm0-300Zm0 220q113 0 207.5-59.5T832-500q-50-101-144.5-160.5T480-720q-113 0-207.5 59.5T128-500q50 101 144.5 160.5T480-280Z"/></svg>`,
- workspace: `<svg xmlns="http://www.w3.org/2000/svg" height="24px" viewBox="0 -960 960 960" width="24px" fill="#1f1f1f"><path d="M440-183v-274L200-596v274l240 139Zm80 0 240-139v-274L520-457v274Zm-40-343 237-137-237-137-237 137 237 137ZM160-252q-19-11-29.5-29T120-321v-318q0-22 10.5-40t29.5-29l280-161q19-11 40-11t40 11l280 161q19 11 29.5 29t10.5 40v318q0 22-10.5 40T800-252L520-91q-19 11-40 11t-40-11L160-252Zm320-228Z"/></svg>`,
+ workspace: `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 -960 960 960"><path d="M440-183v-274L200-596v274l240 139Zm80 0 240-139v-274L520-457v274Zm-40-343 237-137-237-137-237 137 237 137ZM160-252q-19-11-29.5-29T120-321v-318q0-22 10.5-40t29.5-29l280-161q19-11 40-11t40 11l280 161q19 11 29.5 29t10.5 40v318q0 22-10.5 40T800-252L520-91q-19 11-40 11t-40-11L160-252Zm320-228Z"/></svg>`,
};
export type IconName = keyof typeof icons;
diff --git a/frontend/app/stores/db_strustures.d.ts b/frontend/app/stores/db_strustures.d.ts
index b14a343b..85f9053c 100644
--- a/frontend/app/stores/db_strustures.d.ts
+++ b/frontend/app/stores/db_strustures.d.ts
@@ -3,6 +3,7 @@ export interface DB_Document {
name: string;
description?: string;
tags?: string;
+ pinned: number; // 0: Not pinned; 1: Pinned; 2: Favorite;
category?: string;
parent_id?: string | null;
accessibility: number; // 1 Visible; 2 Draft; 3 Archived;