From 61dd4cefbcc7f01b6d8d549a0a972d38780d15e1 Mon Sep 17 00:00:00 2001 From: Laurent Cozic Date: Wed, 9 May 2018 21:00:05 +0100 Subject: [PATCH] All: Resolves #345: Option to hide completed todos --- ElectronClient/app/app.js | 8 ++++++++ ReactNativeClient/lib/BaseApplication.js | 5 +++++ ReactNativeClient/lib/components/screens/notes.js | 7 +++++++ ReactNativeClient/lib/models/Note.js | 5 +++++ ReactNativeClient/lib/models/Setting.js | 1 + 5 files changed, 26 insertions(+) diff --git a/ElectronClient/app/app.js b/ElectronClient/app/app.js index efe779260..500596463 100644 --- a/ElectronClient/app/app.js +++ b/ElectronClient/app/app.js @@ -437,6 +437,14 @@ class Application extends BaseApplication { click: () => { Setting.setValue('uncompletedTodosOnTop', !Setting.value('uncompletedTodosOnTop')); }, + }, { + label: Setting.settingMetadata('showCompletedTodos').label(), + type: 'checkbox', + checked: Setting.value('showCompletedTodos'), + screens: ['Main'], + click: () => { + Setting.setValue('showCompletedTodos', !Setting.value('showCompletedTodos')); + }, }], }, { label: _('Tools'), diff --git a/ReactNativeClient/lib/BaseApplication.js b/ReactNativeClient/lib/BaseApplication.js index e8002ac7e..030a8e463 100644 --- a/ReactNativeClient/lib/BaseApplication.js +++ b/ReactNativeClient/lib/BaseApplication.js @@ -199,6 +199,7 @@ class BaseApplication { let options = { order: stateUtils.notesOrder(state.settings), uncompletedTodosOnTop: Setting.value('uncompletedTodosOnTop'), + showCompletedTodos: Setting.value('showCompletedTodos'), caseInsensitive: true, }; @@ -283,6 +284,10 @@ class BaseApplication { refreshNotes = true; } + if (this.hasGui() && ((action.type == 'SETTING_UPDATE_ONE' && action.key == 'showCompletedTodos') || action.type == 'SETTING_UPDATE_ALL')) { + refreshNotes = true; + } + if (this.hasGui() && ((action.type == 'SETTING_UPDATE_ONE' && action.key.indexOf('notes.sortOrder') === 0) || action.type == 'SETTING_UPDATE_ALL')) { refreshNotes = true; } diff --git a/ReactNativeClient/lib/components/screens/notes.js b/ReactNativeClient/lib/components/screens/notes.js index 1de762947..3998c7726 100644 --- a/ReactNativeClient/lib/components/screens/notes.js +++ b/ReactNativeClient/lib/components/screens/notes.js @@ -53,6 +53,11 @@ class NotesScreenComponent extends BaseScreenComponent { id: { name: 'uncompletedTodosOnTop', value: !Setting.value('uncompletedTodosOnTop') }, }); + buttons.push({ + text: makeCheckboxText(Setting.value('showCompletedTodos'), 'tick', '[ ' + Setting.settingMetadata('showCompletedTodos').label() + ' ]'), + id: { name: 'showCompletedTodos', value: !Setting.value('showCompletedTodos') }, + }); + const r = await dialogs.pop(this, Setting.settingMetadata('notes.sortOrder.field').label(), buttons); if (!r) return; @@ -79,6 +84,7 @@ class NotesScreenComponent extends BaseScreenComponent { let options = { order: props.notesOrder, uncompletedTodosOnTop: props.uncompletedTodosOnTop, + showCompletedTodos: props.showCompletedTodos, caseInsensitive: true, }; @@ -219,6 +225,7 @@ const NotesScreen = connect( notes: state.notes, notesSource: state.notesSource, uncompletedTodosOnTop: state.settings.uncompletedTodosOnTop, + showCompletedTodos: state.settings.showCompletedTodos, theme: state.settings.theme, noteSelectionEnabled: state.noteSelectionEnabled, notesOrder: stateUtils.notesOrder(state.settings), diff --git a/ReactNativeClient/lib/models/Note.js b/ReactNativeClient/lib/models/Note.js index 27f7a7260..417cd7740 100644 --- a/ReactNativeClient/lib/models/Note.js +++ b/ReactNativeClient/lib/models/Note.js @@ -237,6 +237,7 @@ class Note extends BaseItem { if (!options.conditionsParams) options.conditionsParams = []; if (!options.fields) options.fields = this.previewFields(); if (!options.uncompletedTodosOnTop) options.uncompletedTodosOnTop = false; + if (!('showCompletedTodos' in options)) options.showCompletedTodos = true; if (parentId == BaseItem.getClass('Folder').conflictFolderId()) { options.conditions.push('is_conflict = 1'); @@ -265,6 +266,10 @@ class Note extends BaseItem { } } + if (!options.showCompletedTodos) { + options.conditions.push('todo_completed <= 0'); + } + if (options.uncompletedTodosOnTop && hasTodos) { let cond = options.conditions.slice(); cond.push('is_todo = 1'); diff --git a/ReactNativeClient/lib/models/Setting.js b/ReactNativeClient/lib/models/Setting.js index 14bb5f977..3c2f298ce 100644 --- a/ReactNativeClient/lib/models/Setting.js +++ b/ReactNativeClient/lib/models/Setting.js @@ -61,6 +61,7 @@ class Setting extends BaseModel { return output; }}, 'uncompletedTodosOnTop': { value: true, type: Setting.TYPE_BOOL, public: true, appTypes: ['cli'], label: () => _('Uncompleted to-dos on top') }, + 'showCompletedTodos': { value: true, type: Setting.TYPE_BOOL, public: true, appTypes: ['cli'], label: () => _('Show completed to-dos') }, 'notes.sortOrder.field': { value: 'user_updated_time', type: Setting.TYPE_STRING, isEnum: true, public: true, appTypes: ['cli'], label: () => _('Sort notes by'), options: () => { const Note = require('lib/models/Note'); const noteSortFields = ['user_updated_time', 'user_created_time', 'title'];