mirror of
https://github.com/zadam/trilium.git
synced 2025-02-27 00:29:21 +08:00
initial implementation of tree prefix
This commit is contained in:
parent
b4e6245f7b
commit
160c1c455c
8 changed files with 9678 additions and 4 deletions
1
migrations/0045__add_prefix_to_notes_tree.sql
Normal file
1
migrations/0045__add_prefix_to_notes_tree.sql
Normal file
|
@ -0,0 +1 @@
|
|||
ALTER TABLE notes_tree ADD COLUMN `prefix` TEXT
|
9585
package-lock.json
generated
Normal file
9585
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load diff
|
@ -54,10 +54,12 @@ const contextMenu = (function() {
|
|||
delegate: "span.fancytree-title",
|
||||
autoFocus: true,
|
||||
menu: [
|
||||
{title: "Insert note here", cmd: "insertNoteHere", uiIcon: "ui-icon-pencil"},
|
||||
{title: "Insert child note", cmd: "insertChildNote", uiIcon: "ui-icon-pencil"},
|
||||
{title: "Insert note here", cmd: "insertNoteHere", uiIcon: "ui-icon-plus"},
|
||||
{title: "Insert child note", cmd: "insertChildNote", uiIcon: "ui-icon-plus"},
|
||||
{title: "Delete", cmd: "delete", uiIcon: "ui-icon-trash"},
|
||||
{title: "----"},
|
||||
{title: "Edit tree prefix", cmd: "editTreePrefix", uiIcon: "ui-icon-pencil"},
|
||||
{title: "----"},
|
||||
{title: "Protect sub-tree", cmd: "protectSubTree", uiIcon: "ui-icon-locked"},
|
||||
{title: "Unprotect sub-tree", cmd: "unprotectSubTree", uiIcon: "ui-icon-unlocked"},
|
||||
{title: "----"},
|
||||
|
@ -91,6 +93,9 @@ const contextMenu = (function() {
|
|||
else if (ui.cmd === "insertChildNote") {
|
||||
noteTree.createNote(node, node.data.note_id, 'into');
|
||||
}
|
||||
else if (ui.cmd === "editTreePrefix") {
|
||||
editTreePrefix.showDialog(node);
|
||||
}
|
||||
else if (ui.cmd === "protectSubTree") {
|
||||
protected_session.protectSubTree(node.data.note_id, true);
|
||||
}
|
||||
|
|
58
public/javascripts/dialogs/edit_tree_prefix.js
Normal file
58
public/javascripts/dialogs/edit_tree_prefix.js
Normal file
|
@ -0,0 +1,58 @@
|
|||
"use strict";
|
||||
|
||||
const editTreePrefix = (function() {
|
||||
const dialogEl = $("#edit-tree-prefix-dialog");
|
||||
const formEl = $("#edit-tree-prefix-form");
|
||||
const treePrefixInputEl = $("#tree-prefix-input");
|
||||
const noteTitleEl = $('#tree-prefix-note-title');
|
||||
|
||||
function showDialog() {
|
||||
glob.activeDialog = dialogEl;
|
||||
|
||||
dialogEl.dialog({
|
||||
modal: true,
|
||||
width: 800
|
||||
});
|
||||
|
||||
const currentNode = noteTree.getCurrentNode();
|
||||
|
||||
treePrefixInputEl.val(currentNode.data.prefix).focus();
|
||||
|
||||
const noteTitle = noteTree.getNoteTitle(currentNode.data.note_id);
|
||||
|
||||
noteTitleEl.html(noteTitle);
|
||||
}
|
||||
|
||||
formEl.submit(() => {
|
||||
const prefix = treePrefixInputEl.val();
|
||||
const currentNode = noteTree.getCurrentNode();
|
||||
const noteTreeId = currentNode.data.note_tree_id;
|
||||
|
||||
$.ajax({
|
||||
url: baseApiUrl + 'tree/' + noteTreeId + '/setPrefix',
|
||||
type: 'PUT',
|
||||
contentType: 'application/json',
|
||||
data: JSON.stringify({
|
||||
prefix: prefix
|
||||
}),
|
||||
success: () => {
|
||||
const noteTitle = noteTree.getNoteTitle(currentNode.data.note_id);
|
||||
|
||||
const title = (prefix ? (prefix + " - ") : "") + noteTitle;
|
||||
|
||||
currentNode.setTitle(title);
|
||||
},
|
||||
error: () => showError("Error setting prefix.")
|
||||
});
|
||||
|
||||
dialogEl.dialog("close");
|
||||
|
||||
return false;
|
||||
});
|
||||
|
||||
$(document).bind('keydown', 'alt+l', showDialog);
|
||||
|
||||
return {
|
||||
showDialog
|
||||
};
|
||||
})();
|
|
@ -143,7 +143,7 @@ const noteTree = (function() {
|
|||
note_pid: noteTree.note_pid,
|
||||
note_tree_id: noteTree.note_tree_id,
|
||||
is_protected: noteTree.is_protected,
|
||||
title: noteIdToTitle[noteTree.note_id],
|
||||
title: (noteTree.prefix ? (noteTree.prefix + " - ") : "") + noteIdToTitle[noteTree.note_id],
|
||||
extraClasses: getExtraClasses(noteTree),
|
||||
refKey: noteTree.note_id,
|
||||
expanded: noteTree.is_expanded
|
||||
|
|
|
@ -48,4 +48,17 @@ router.put('/:noteId/protectSubTree/:isProtected', auth.checkApiAuth, async (req
|
|||
res.send({});
|
||||
});
|
||||
|
||||
router.put('/:noteTreeId/setPrefix', auth.checkApiAuth, async (req, res, next) => {
|
||||
const noteTreeId = req.params.noteTreeId;
|
||||
const prefix = req.body.prefix;
|
||||
|
||||
await sql.doInTransaction(async () => {
|
||||
await sql.execute("UPDATE notes_tree SET prefix = ? WHERE note_tree_id = ?", [prefix, noteTreeId]);
|
||||
|
||||
await sync_table.addNoteTreeSync(noteTreeId);
|
||||
});
|
||||
|
||||
res.send({});
|
||||
});
|
||||
|
||||
module.exports = router;
|
||||
|
|
|
@ -4,7 +4,7 @@ const options = require('./options');
|
|||
const fs = require('fs-extra');
|
||||
const log = require('./log');
|
||||
|
||||
const APP_DB_VERSION = 44;
|
||||
const APP_DB_VERSION = 45;
|
||||
const MIGRATIONS_DIR = "migrations";
|
||||
|
||||
async function migrate() {
|
||||
|
|
|
@ -256,6 +256,17 @@
|
|||
<ul id="event-log-list"></ul>
|
||||
</div>
|
||||
|
||||
<div id="edit-tree-prefix-dialog" title="Edit tree prefix" style="display: none; padding: 20px;">
|
||||
<form id="edit-tree-prefix-form">
|
||||
<div class="form-group">
|
||||
<label for="tree-prefix-input">Prefix</label>
|
||||
<input id="tree-prefix-input" style="width: 20em;"> - <span id="tree-prefix-note-title"></span>
|
||||
</div>
|
||||
|
||||
<button name="action" class="btn btn-sm">Save</button>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<div id="tooltip" style="display: none;"></div>
|
||||
|
||||
<script type="text/javascript">
|
||||
|
@ -312,6 +323,7 @@
|
|||
<script src="javascripts/dialogs/note_history.js"></script>
|
||||
<script src="javascripts/dialogs/recent_changes.js"></script>
|
||||
<script src="javascripts/dialogs/event_log.js"></script>
|
||||
<script src="javascripts/dialogs/edit_tree_prefix.js"></script>
|
||||
|
||||
<script src="javascripts/link.js"></script>
|
||||
<script src="javascripts/status.js"></script>
|
||||
|
|
Loading…
Reference in a new issue