You've already forked joplin
mirror of
https://github.com/laurent22/joplin.git
synced 2025-12-05 22:57:29 +02:00
Desktop: Add new setting to show note counts for folders and tags (#2006)
* Adding node counts for folders and tags * Add unit tests * Fix count update when the tag list for a note is updated * Right align note counts and remove from the settings screen * Folder note count calculation update to include descendants * Update Setting.js * Change count style and fix click on counts * Fix tag/folder count update on delete/add note * Review updates
This commit is contained in:
committed by
Laurent Cozic
parent
c0dd8d0332
commit
9c98fb5312
@@ -105,6 +105,28 @@ class Folder extends BaseItem {
|
||||
};
|
||||
}
|
||||
|
||||
// Calculates note counts for all folders and adds the note_count attribute to each folder
|
||||
// Note: this only calculates the overall number of nodes for this folder and all its descendants
|
||||
static async addNoteCounts(folders) {
|
||||
const foldersById = {};
|
||||
folders.forEach((f) => {
|
||||
foldersById[f.id] = f;
|
||||
});
|
||||
|
||||
const sql = `SELECT folders.id as folder_id, count(notes.parent_id) as note_count
|
||||
FROM folders LEFT JOIN notes ON notes.parent_id = folders.id
|
||||
GROUP BY folders.id`;
|
||||
const noteCounts = await this.db().selectAll(sql);
|
||||
noteCounts.forEach((noteCount) => {
|
||||
let parentId = noteCount.folder_id;
|
||||
do {
|
||||
let folder = foldersById[parentId];
|
||||
folder.note_count = (folder.note_count || 0) + noteCount.note_count;
|
||||
parentId = folder.parent_id;
|
||||
} while (parentId);
|
||||
});
|
||||
}
|
||||
|
||||
// Folders that contain notes that have been modified recently go on top.
|
||||
// The remaining folders, that don't contain any notes are sorted by their own user_updated_time
|
||||
static async orderByLastModified(folders, dir = 'DESC') {
|
||||
|
||||
Reference in New Issue
Block a user