mirror of
https://github.com/laurent22/joplin.git
synced 2025-02-07 19:30:04 +02:00
Desktop: Don't count completed to-dos in note counts when they are not shown (#2288)
* Desktop: don't count completed to-dos in note counts when they are not shown * Desktop: review comments for commit 0383dcc * Desktop: fix remaining lint issues with commit 1fe4685
This commit is contained in:
parent
8a392e1c06
commit
960d7f84eb
@ -150,4 +150,31 @@ describe('models_Folder', function() {
|
|||||||
expect(foldersById[f4.id].note_count).toBe(0);
|
expect(foldersById[f4.id].note_count).toBe(0);
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
it('should not count completed to-dos', asyncTest(async () => {
|
||||||
|
|
||||||
|
let f1 = await Folder.save({ title: 'folder1' });
|
||||||
|
let f2 = await Folder.save({ title: 'folder2', parent_id: f1.id });
|
||||||
|
let f3 = await Folder.save({ title: 'folder3', parent_id: f2.id });
|
||||||
|
let f4 = await Folder.save({ title: 'folder4' });
|
||||||
|
|
||||||
|
let n1 = await Note.save({ title: 'note1', parent_id: f3.id });
|
||||||
|
let n2 = await Note.save({ title: 'note2', parent_id: f3.id });
|
||||||
|
let n3 = await Note.save({ title: 'note3', parent_id: f1.id });
|
||||||
|
let n4 = await Note.save({ title: 'note4', parent_id: f3.id, is_todo: true, todo_completed: 0 });
|
||||||
|
let n5 = await Note.save({ title: 'note5', parent_id: f3.id, is_todo: true, todo_completed: 999 });
|
||||||
|
let n6 = await Note.save({ title: 'note6', parent_id: f3.id, is_todo: true, todo_completed: 999 });
|
||||||
|
|
||||||
|
const folders = await Folder.all();
|
||||||
|
await Folder.addNoteCounts(folders, false);
|
||||||
|
|
||||||
|
const foldersById = {};
|
||||||
|
folders.forEach((f) => { foldersById[f.id] = f; });
|
||||||
|
|
||||||
|
expect(folders.length).toBe(4);
|
||||||
|
expect(foldersById[f1.id].note_count).toBe(4);
|
||||||
|
expect(foldersById[f2.id].note_count).toBe(3);
|
||||||
|
expect(foldersById[f3.id].note_count).toBe(3);
|
||||||
|
expect(foldersById[f4.id].note_count).toBe(0);
|
||||||
|
}));
|
||||||
|
|
||||||
});
|
});
|
||||||
|
@ -450,11 +450,14 @@ class BaseApplication {
|
|||||||
refreshFolders = true;
|
refreshFolders = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.hasGui() && ((action.type == 'SETTING_UPDATE_ONE' && action.key.indexOf('folders.sortOrder') === 0) || action.type == 'SETTING_UPDATE_ALL')) {
|
if (this.hasGui() && action.type == 'SETTING_UPDATE_ALL') {
|
||||||
refreshFolders = 'now';
|
refreshFolders = 'now';
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.hasGui() && ((action.type == 'SETTING_UPDATE_ONE' && action.key == 'showNoteCounts') || action.type == 'SETTING_UPDATE_ALL')) {
|
if (this.hasGui() && action.type == 'SETTING_UPDATE_ONE' && (
|
||||||
|
action.key.indexOf('folders.sortOrder') === 0 ||
|
||||||
|
action.key == 'showNoteCounts' ||
|
||||||
|
action.key == 'showCompletedTodos')) {
|
||||||
refreshFolders = 'now';
|
refreshFolders = 'now';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -26,7 +26,8 @@ class FoldersScreenUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (Setting.value('showNoteCounts')) {
|
if (Setting.value('showNoteCounts')) {
|
||||||
await Folder.addNoteCounts(folders);
|
await Folder.addNoteCounts(folders,
|
||||||
|
Setting.value('showCompletedTodos'));
|
||||||
}
|
}
|
||||||
|
|
||||||
return folders;
|
return folders;
|
||||||
|
@ -107,15 +107,19 @@ class Folder extends BaseItem {
|
|||||||
|
|
||||||
// Calculates note counts for all folders and adds the note_count attribute to each folder
|
// 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
|
// Note: this only calculates the overall number of nodes for this folder and all its descendants
|
||||||
static async addNoteCounts(folders) {
|
static async addNoteCounts(folders, includeCompletedTodos = true) {
|
||||||
const foldersById = {};
|
const foldersById = {};
|
||||||
folders.forEach((f) => {
|
folders.forEach((f) => {
|
||||||
foldersById[f.id] = f;
|
foldersById[f.id] = f;
|
||||||
|
f.note_count = 0;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const where = !includeCompletedTodos ? 'WHERE (notes.is_todo = 0 OR notes.todo_completed = 0)' : '';
|
||||||
|
|
||||||
const sql = `SELECT folders.id as folder_id, count(notes.parent_id) as note_count
|
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
|
FROM folders LEFT JOIN notes ON notes.parent_id = folders.id
|
||||||
GROUP BY folders.id`;
|
${where} GROUP BY folders.id`;
|
||||||
|
|
||||||
const noteCounts = await this.db().selectAll(sql);
|
const noteCounts = await this.db().selectAll(sql);
|
||||||
noteCounts.forEach((noteCount) => {
|
noteCounts.forEach((noteCount) => {
|
||||||
let parentId = noteCount.folder_id;
|
let parentId = noteCount.folder_id;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user