1
0
mirror of https://github.com/laurent22/joplin.git synced 2024-11-24 08:12:24 +02:00

Desktop: don't count completed to-dos in note counts when they are not shown

This commit is contained in:
lightray22 2020-01-10 18:15:04 -05:00
parent 0a13c988fa
commit 0383dcc865
4 changed files with 40 additions and 14 deletions

View File

@ -128,25 +128,42 @@ describe('models_Folder', function() {
}));
it('should add node counts', asyncTest(async () => {
let folders, foldersById;
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: 'note1', parent_id: f3.id });
let n3 = await Note.save({ title: 'note1', parent_id: f1.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);
folders = await Folder.all();
await Folder.addNoteCounts(folders, true); // count completed
const foldersById = {};
foldersById = {};
folders.forEach((f) => { foldersById[f.id] = f; });
expect(folders.length).toBe(4);
expect(foldersById[f1.id].note_count).toBe(3);
expect(foldersById[f2.id].note_count).toBe(2);
expect(foldersById[f3.id].note_count).toBe(2);
expect(foldersById[f1.id].note_count).toBe(6);
expect(foldersById[f2.id].note_count).toBe(5);
expect(foldersById[f3.id].note_count).toBe(5);
expect(foldersById[f4.id].note_count).toBe(0);
folders = await Folder.all();
await Folder.addNoteCounts(folders, false); // don't count completed
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);
}));

View File

@ -450,11 +450,16 @@ class BaseApplication {
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';
}
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';
}

View File

@ -26,7 +26,8 @@ class FoldersScreenUtils {
}
if (Setting.value('showNoteCounts')) {
await Folder.addNoteCounts(folders);
await Folder.addNoteCounts(folders,
Setting.value('showCompletedTodos'));
}
return folders;

View File

@ -107,15 +107,18 @@ 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) {
static async addNoteCounts(folders, showDone) {
const foldersById = {};
folders.forEach((f) => {
foldersById[f.id] = f;
f.note_count = 0;
});
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`;
FROM folders LEFT JOIN notes ON notes.parent_id = folders.id`
+ (!showDone ? ' WHERE (notes.is_todo = 0 OR notes.todo_completed = 0)' : '')
+ ` GROUP BY folders.id`;
const noteCounts = await this.db().selectAll(sql);
noteCounts.forEach((noteCount) => {
let parentId = noteCount.folder_id;