This commit is contained in:
@@ -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/<filename>`.
|
||||
`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.
|
||||
|
||||
|
||||
@@ -12,6 +12,7 @@ const FolderSchema = new Schema({
|
||||
type: Schema.Types.ObjectId,
|
||||
ref: 'Folder'
|
||||
},
|
||||
color: { type: String },
|
||||
date: { type: Date, default: Date.now }
|
||||
});
|
||||
|
||||
|
||||
@@ -13,6 +13,7 @@ const NoteSchema = new Schema({
|
||||
type: Schema.Types.ObjectId,
|
||||
ref: 'Folder'
|
||||
},
|
||||
color: { type: String },
|
||||
date: { type: Date, default: Date.now }
|
||||
});
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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 = [];
|
||||
|
||||
@@ -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)">
|
||||
<button type="button" class="folder-toggle" @click="toggleExpanded(folder._id)" @contextmenu.prevent="ShowContextMenu(buildFolderContextMenu(folder))">
|
||||
<button type="button" class="folder-toggle" :class="{ 'has-color': !!folder.color }" :style="entryColorStyle(folder)" @click="toggleExpanded(folder._id)" @contextmenu.prevent="ShowContextMenu(buildFolderContextMenu(folder))">
|
||||
<img
|
||||
class="folder-arrow"
|
||||
:src="expandedFolderIds.includes(folder._id) ? '/icons/iconoir/regular/nav-arrow-down.svg' : '/icons/iconoir/regular/nav-arrow-right.svg'"
|
||||
@@ -297,7 +339,7 @@ function createNoteInFolder(folderId) {
|
||||
|
||||
<!-- Notes at this level -->
|
||||
<template v-for="note in notes" :key="note.key">
|
||||
<button type="button" class="note-link" draggable="true" @dragstart="startDragNote($event, note)" @click.stop="$emit('open-note', note)" @contextmenu.prevent="ShowContextMenu(buildNoteContextMenu(note))">
|
||||
<button type="button" class="note-link" :class="{ 'has-color': !!note.color }" :style="entryColorStyle(note)" draggable="true" @dragstart="startDragNote($event, note)" @click.stop="$emit('open-note', note)" @contextmenu.prevent="ShowContextMenu(buildNoteContextMenu(note))">
|
||||
<span class="note-link-title">{{ note.title }}</span>
|
||||
</button>
|
||||
</template>
|
||||
@@ -318,6 +360,8 @@ function createNoteInFolder(folderId) {
|
||||
|
||||
.folder-toggle { width: 100%; padding: 6px 8px; margin: 0; border: none; background: transparent; display: flex; align-items: center; gap: 6px; cursor: grab; border-radius: 10px; color: var(--color-text); font-size: inherit; transition: background-color 0.15s ease; }
|
||||
.folder-toggle:hover { background: var(--color-background-soft); }
|
||||
.folder-toggle.has-color { background: color-mix(in srgb, var(--entry-color) 32%, transparent); }
|
||||
.folder-toggle.has-color:hover { background: color-mix(in srgb, var(--entry-color) 50%, transparent); }
|
||||
|
||||
.folder-arrow { width: 14px; height: 14px; filter: invert(var(--color-icon-invert)); opacity: 0.5; }
|
||||
.folder-icon { width: 16px; height: 16px; filter: invert(var(--color-icon-invert)); }
|
||||
@@ -326,7 +370,9 @@ function createNoteInFolder(folderId) {
|
||||
.folder-children { padding-left: 20px; margin-top: 2px; cursor: default; }
|
||||
.folder-children.drag-over { background: #ffffff22; border-radius: 10px; }
|
||||
|
||||
.note-link { width: 100%; padding: 6px; margin: 0; box-shadow: none; border: none; display: flex; flex-direction: column; align-items: flex-start; text-align: left; cursor: grab; }
|
||||
.note-link { width: 100%; padding: 6px; margin: 0; box-shadow: none; border: none; display: flex; flex-direction: column; align-items: flex-start; text-align: left; cursor: grab; border-radius: 8px; }
|
||||
.note-link.has-color { background: color-mix(in srgb, var(--entry-color) 32%, transparent); }
|
||||
.note-link.has-color:hover { background: color-mix(in srgb, var(--entry-color) 50%, transparent); }
|
||||
.note-link-title { font-weight: 600; word-break: break-word; }
|
||||
|
||||
.sidebar-state { padding: 12px; border-radius: 10px; background: var(--color-background-soft); font-size: 14px; }
|
||||
|
||||
@@ -44,7 +44,13 @@ function PopulateContext(val){
|
||||
spanInfo.innerHTML = element.name;
|
||||
contextMenuElement.appendChild(spanInfo);
|
||||
|
||||
if(element.icon){
|
||||
if(element.color){
|
||||
let swatch = document.createElement('span');
|
||||
swatch.classList.add("context-menu-swatch");
|
||||
swatch.style.backgroundColor = element.color;
|
||||
contextMenuElement.appendChild(swatch);
|
||||
}
|
||||
else if(element.icon){
|
||||
let iconContextElement = document.createElement('img');
|
||||
iconContextElement.src = element.icon;
|
||||
contextMenuElement.appendChild(iconContextElement);
|
||||
|
||||
Reference in New Issue
Block a user