-
-
+
🏷️ Tags
+
+
+
+
+
+
+
+
+
No tags
+
+
+
+
Add tag:
+
+
+
+
+
-
+ Add tag
-
-
-
+
+
+
+ + New tag
+
+
🗑 Delete
@@ -874,8 +898,10 @@ document.addEventListener('alpine:init', function() {
// Context menu
ctxMenu: {visible:false,x:0,y:0,node:null,tags:[]},
- ctxTagSub: false,
ctxTagAdding: false,
+ ctxAvailTags: [],
+ ctxNewTagColor: '#787774',
+ ctxTagColors: ['#787774','#E03E3E','#D9730D','#DFAB01','#0F7B6C','#0B6E99','#6940A5','#AD1A72','#E16259','#D4A72C','#448361','#337EA9','#9065B0','#C94D8B'],
// Tags
workspaceTags: [],
@@ -1236,8 +1262,16 @@ document.addEventListener('alpine:init', function() {
node: node,
tags: [...(node.tags||[])]
};
- this.ctxTagSub = false;
this.ctxTagAdding = false;
+ this.ctxNewTagColor = '#787774';
+ // Load available tags (not already on the item)
+ this.ctxAvailTags = (this.workspaceTags || []).filter(function(t) {
+ return !(node.tags||[]).some(function(nt) { return nt.id === t.id; });
+ });
+ },
+
+ ctxAddExistingTag(tag) {
+ this.ctxAddNewTag(tag.name, tag.color);
},
ctxMenuOpenPage() {
@@ -1266,14 +1300,19 @@ document.addEventListener('alpine:init', function() {
var node = this.ctxMenu.node;
if (!node) return;
this.removeTag(node.id, tagId);
- // Update ctxMenu tags
this.ctxMenu.tags = this.ctxMenu.tags.filter(function(t) { return t.id !== tagId; });
- this.ctxTagSub = true; // keep sub open
+ // Refresh available tags
+ this.ctxAvailTags = (this.workspaceTags || []).filter(function(t) {
+ return !(this.ctxMenu.tags||[]).some(function(nt) { return nt.id === t.id; });
+ }.bind(this));
},
- async ctxAddTag(tagName) {
+ async ctxAddNewTag(tagName, color) {
+ tagName = (tagName || '').trim();
+ if (!tagName) return;
var node = this.ctxMenu.node;
- if (!node || !tagName) return;
+ if (!node) return;
+ color = color || this.ctxNewTagColor;
var r = await fetch('/api/local-workspace/items/' + node.id + '/tags', {
method: 'POST', headers: {'Content-Type':'application/json'},
body: JSON.stringify({name: tagName.trim()})
@@ -1284,9 +1323,15 @@ document.addEventListener('alpine:init', function() {
this._updateNodeTags(this.tree, node.id, d.tag, 'add');
this.displayTree = [...this.tree];
this.loadWorkspaceTags();
+ // Refresh available tags
+ var self = this;
+ setTimeout(function() { self.loadWorkspaceTags().then(function() {
+ self.ctxAvailTags = (self.workspaceTags || []).filter(function(t) {
+ return !(self.ctxMenu.tags||[]).some(function(nt) { return nt.id === t.id; });
+ });
+ }); }, 200);
}
this.ctxTagAdding = false;
- this.ctxTagSub = true;
},
_markTree(nodes, depth) {