diff --git a/AGENTS.md b/AGENTS.md index 54e95785..8125d8cd 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -136,8 +136,8 @@ User ──< Campaign ──< Note ──?> Folder ──?> Folder (parentFolder |---|---|---| | `User` | `models/User.js` | `name*`, `username*` (unique), `email*` (unique), `password` (bcrypt hash, 10 salt rounds), `date`, `admin` (bool, default false), `image`, `setupCode`, `settings` (Object) | | `Campaign` | `models/Campaign.js` | `name*`, `description`, `color`, `createdBy*` → User, `date`, `settings` (Object) | -| `Note` | `models/Note.js` | `title`, `content` (markdown source string), `campaign*` → Campaign, `folder` → Folder (null = root), `date` | -| `Folder` | `models/Folder.js` | `name*`, `campaign*` → Campaign, `parentFolder` → Folder (null = root), `date` | +| `Note` | `models/Note.js` | `title`, `content` (markdown source string), `campaign*` → Campaign, `folder` → Folder (null = root), `color` (hex string, sidebar entry background), `date` | +| `Folder` | `models/Folder.js` | `name*`, `campaign*` → Campaign, `parentFolder` → Folder (null = root), `color` (hex string, sidebar entry background), `date` | `*` = required. Notes and folders are ordered by `date: -1` everywhere. @@ -171,12 +171,13 @@ Fetch the file from `/api/public/`. `GET /api/note/list?campaign=` → `{status:'ok', folders, notes}` — notes with `folder: null` (roots) `GET /api/note/subfolder/list?campaign=&folder=` → `{status:'ok', subfolders, notes}` `POST /api/note/create` — `{title*,content,campaign*,folder?}` (folder validated against campaign) -`POST /api/note/update` — `{id*, title?, content?, folder?}` — partial, ownership checked +`POST /api/note/update` — `{id*, title?, content?, folder?, color?}` — partial, ownership checked `POST /api/note/delete` — `{id}` — **no ownership check** (§9) `GET /api/folder/list?campaign=` → `{status:'ok',folders}` `POST /api/folder/create` — `{name*,campaign*}` `POST /api/folder/rename` — `{id*,name*}` +`POST /api/folder/update` — `{id*, name?, color?}` — partial, ownership checked `POST /api/folder/delete` — `{id}` — recursive: notes inside are moved to root (`folder: null`), subfolders re-parented to null then deleted. diff --git a/backend/src/models/Folder.js b/backend/src/models/Folder.js index d25810e1..533dd613 100644 --- a/backend/src/models/Folder.js +++ b/backend/src/models/Folder.js @@ -12,6 +12,7 @@ const FolderSchema = new Schema({ type: Schema.Types.ObjectId, ref: 'Folder' }, + color: { type: String }, date: { type: Date, default: Date.now } }); diff --git a/backend/src/models/Note.js b/backend/src/models/Note.js index df82478a..ae357062 100644 --- a/backend/src/models/Note.js +++ b/backend/src/models/Note.js @@ -13,6 +13,7 @@ const NoteSchema = new Schema({ type: Schema.Types.ObjectId, ref: 'Folder' }, + color: { type: String }, date: { type: Date, default: Date.now } }); diff --git a/backend/src/routes/folder.js b/backend/src/routes/folder.js index f1790cb8..c0251250 100644 --- a/backend/src/routes/folder.js +++ b/backend/src/routes/folder.js @@ -19,7 +19,7 @@ router.get('/list', async (req, res) => { if (!hasAccess) return res.json({ status: 'error', msg: 'unauthorized' }); const folders = await Folder.find({ campaign }) - .select('_id name date') + .select('_id name date color') .sort({ date: -1 }) .lean(); @@ -50,6 +50,28 @@ router.post('/create', async (req, res) => { } }); +router.post('/update', async (req, res) => { + try { + const { id, name, color } = req.body; + if (!id) return res.json({ status: 'error', msg: 'errors.missing-data' }); + + const folder = await Folder.findById(id); + if (!folder) return res.json({ status: 'error', msg: 'errors.notfound' }); + + const hasAccess = await userOwnsCampaign(folder.campaign, req.user.id); + if (!hasAccess) return res.json({ status: 'error', msg: 'unauthorized' }); + + if (name !== undefined) folder.name = String(name).trim(); + if (color !== undefined) folder.color = color; + await folder.save(); + + res.json({ status: 'ok', folder }); + } catch (err) { + console.error(err); + res.json({ status: 'error', msg: 'errors.internal' }); + } +}); + router.post('/delete', async (req, res) => { try { const { id } = req.body; diff --git a/backend/src/routes/note.js b/backend/src/routes/note.js index a078e541..5bfd6e4b 100644 --- a/backend/src/routes/note.js +++ b/backend/src/routes/note.js @@ -19,12 +19,12 @@ router.get('/list', async (req, res) => { if (!hasAccess) return res.json({ status: 'error', msg: 'unauthorized' }); const folders = await Folder.find({ campaign }) - .select('_id name date') + .select('_id name date color') .sort({ date: -1 }) .lean(); const rootNotes = await Note.find({ campaign, folder: null }) - .select('_id title content date') + .select('_id title content date color') .sort({ date: -1 }) .lean(); @@ -48,12 +48,12 @@ router.get('/subfolder/list', async (req, res) => { if (!folderDoc) return res.json({ status: 'error', msg: 'errors.notfound' }); const subfolders = await Folder.find({ campaign, parentFolder: folder }) - .select('_id name date') + .select('_id name date color') .sort({ date: -1 }) .lean(); const notes = await Note.find({ campaign, folder: folder }) - .select('_id title content date') + .select('_id title content date color') .sort({ date: -1 }) .lean(); @@ -90,7 +90,7 @@ router.post('/create', async (req, res) => { router.post('/update', async (req, res) => { try { - const { id, title, content, folder } = req.body; + const { id, title, content, folder, color } = req.body; if (!id) return res.json({ status: 'error', msg: 'errors.missing-data' }); const note = await Note.findById(id); @@ -102,6 +102,7 @@ router.post('/update', async (req, res) => { if (title !== undefined) note.title = title; if (content !== undefined) note.content = content; if (folder !== undefined) note.folder = folder; + if (color !== undefined) note.color = color; await note.save(); res.json({ status: 'ok', note }); } catch (err) { diff --git a/frontend/app/components/managers/ContextMenuManager.vue b/frontend/app/components/managers/ContextMenuManager.vue index dc1de138..2aae493a 100644 --- a/frontend/app/components/managers/ContextMenuManager.vue +++ b/frontend/app/components/managers/ContextMenuManager.vue @@ -73,6 +73,16 @@ onMounted(() => { height: 16px; } + .context-menu-swatch { + width: 14px; + height: 14px; + flex-grow: 0; + padding-right: 0; + border-radius: 4px; + border: 1px solid var(--color-border); + flex-shrink: 0; + } + &:hover { background-color: var(--color-background-softest); } diff --git a/frontend/app/components/partials/ContentSidebar.vue b/frontend/app/components/partials/ContentSidebar.vue index a69f99b1..4b574141 100644 --- a/frontend/app/components/partials/ContentSidebar.vue +++ b/frontend/app/components/partials/ContentSidebar.vue @@ -143,11 +143,11 @@ async function fetchCampaignNotes() { } folders.value = response.data.folders.map((folder) => ({ - _id: folder._id, name: folder.name, date: folder.date + _id: folder._id, name: folder.name, date: folder.date, color: folder.color })); notes.value = response.data.notes.map((note) => { - return { key: note._id, title: note.title, text: note.content ?? '', date: note.date }; + return { key: note._id, title: note.title, text: note.content ?? '', date: note.date, color: note.color }; }); } catch (error) { notes.value = []; diff --git a/frontend/app/components/partials/NestedNoteList.vue b/frontend/app/components/partials/NestedNoteList.vue index 74e92ad4..665789bd 100644 --- a/frontend/app/components/partials/NestedNoteList.vue +++ b/frontend/app/components/partials/NestedNoteList.vue @@ -20,6 +20,18 @@ const emit = defineEmits(['open-note', 'reload-notes']); const loadingFolders = new Set(); const dragHoveredFolderId = ref(null); +// Preset colors for notes and folders (shown as swatches in the context menu) +const entryColors = [ + { name: 'Red', value: '#e74c3c' }, + { name: 'Orange', value: '#e67e22' }, + { name: 'Yellow', value: '#f1c40f' }, + { name: 'Green', value: '#2ecc71' }, + { name: 'Teal', value: '#1abc9c' }, + { name: 'Blue', value: '#3498db' }, + { name: 'Purple', value: '#9b59b6' }, + { name: 'Pink', value: '#fd79a8' } +]; + // Cache of loaded folder contents — persists across reloads until cleared // Each entry: { [folderId]: { notes: [], subfolders: [] } } const folderContentCache = ref({}); @@ -96,7 +108,7 @@ function loadFolderContents(folderId) { .then(res => { if (res.data.status !== 'ok') return; folderContentCache.value[folderId] = { - notes: res.data.notes.map(n => ({ key: n._id, title: n.title, text: n.content || '' })), + notes: res.data.notes.map(n => ({ key: n._id, title: n.title, text: n.content || '', color: n.color })), subfolders: res.data.subfolders || [] }; }).catch(() => {}).finally(() => { @@ -183,6 +195,7 @@ function buildNoteContextMenu(note) { return [ { name: 'Open', icon: '/icons/iconoir/regular/book.svg', action: () => emit('open-note', note) }, { name: 'Rename', icon: '/icons/iconoir/regular/edit-pencil.svg', action: () => renameNote(note) }, + { name: 'Color', icon: '/icons/iconoir/regular/palette.svg', context: buildColorMenu('note', note) }, { name: 'Move to Folder...', icon: '/icons/iconoir/regular/folder.svg', context: buildMoveToMenu(note) @@ -197,10 +210,39 @@ function buildFolderContextMenu(folder) { return [ { name: 'New Note Here', icon: '/icons/iconoir/regular/plus.svg', action: () => createNoteInFolder(folder._id) }, { name: 'Rename', icon: '/icons/iconoir/regular/edit-pencil.svg', action: () => renameFolder(folder._id, folder.name) }, + { name: 'Color', icon: '/icons/iconoir/regular/palette.svg', context: buildColorMenu('folder', folder) }, { name: 'Delete Folder', icon: '/icons/iconoir/regular/trash.svg', action: () => deleteFolder(folder._id) } ]; } +function buildColorMenu(kind, item) { + const colorItems = entryColors.map((color) => ({ + name: color.name, color: color.value, action: () => setEntryColor(kind, item, color.value) + })); + + colorItems.push({ divider: true }); + colorItems.push({ name: 'Default', icon: '/icons/iconoir/regular/xmark-circle.svg', action: () => setEntryColor(kind, item, null) }); + return colorItems; +} + +async function setEntryColor(kind, item, color) { + const isNote = kind === 'note'; + try { + const response = await Server().post(isNote ? '/note/update' : '/folder/update', { + id: isNote ? item.key : item._id, + color + }); + if (response.data.status !== 'ok') return; + item.color = color; + } catch (e) {} finally { + HideContextMenu(); + } +} + +function entryColorStyle(item) { + return item.color ? { '--entry-color': item.color } : null; +} + let selectedNoteForMove = {}; function buildMoveToMenu(note) { @@ -259,7 +301,7 @@ function createNoteInFolder(folderId) { @dragover.prevent="setDragHover(folder._id)" @dragleave.self="clearDragHover" @drop.stop="handleDropNoteOnFolder(folder._id, $event)"> -