You've already forked joplin
mirror of
https://github.com/laurent22/joplin.git
synced 2025-12-20 23:30:05 +02:00
All: Added support for hierarchical/nested tags (#2572)
The implementation uses / symbol as a nesting separator. I.e. tag/subtag is a nested tag, where tag is the parent tag and subtag is its child. Creating a tag named tag/subtag/subsubtag creates three tags, one for each level. The tags are associated using parent_id field. In the app, viewing notes with a tag will also show all notes that are associated with any of the tag's descendant tags (same for the note count). Deleting a tag will also delete all its descendant tags. In the desktop app the tags are shown nested just like the notebooks.
This commit is contained in:
33
ReactNativeClient/lib/migrations/31.js
Normal file
33
ReactNativeClient/lib/migrations/31.js
Normal file
@@ -0,0 +1,33 @@
|
||||
const Tag = require('lib/models/Tag');
|
||||
|
||||
const script = {};
|
||||
|
||||
script.exec = async function() {
|
||||
const tags = await Tag.all();
|
||||
|
||||
// In case tags with `/` exist, we want to transform them into nested tags
|
||||
for (let i = 0; i < tags.length; i++) {
|
||||
const tag = Object.assign({}, tags[i]);
|
||||
// Remove any starting sequence of '/'
|
||||
tag.title = tag.title.replace(/^\/*/, '');
|
||||
// Remove any ending sequence of '/'
|
||||
tag.title = tag.title.replace(/\/*$/, '');
|
||||
// Trim any sequence of '/'+ to a single '/'
|
||||
tag.title = tag.title.replace(/\/\/+/g, '/');
|
||||
|
||||
const tag_title = tag.title;
|
||||
let other = await Tag.loadByTitle(tag_title);
|
||||
let count = 1;
|
||||
// In case above trimming creates duplicate tags
|
||||
// then add a counter to the dupes
|
||||
while ((other && other.id != tag.id) && count < 1000) {
|
||||
tag.title = `${tag_title}-${count}`;
|
||||
other = await Tag.loadByTitle(tag.title);
|
||||
count++;
|
||||
}
|
||||
|
||||
await Tag.saveNested(tag, tag.title);
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = script;
|
||||
Reference in New Issue
Block a user