Skip to content

Commit

Permalink
Allow completed tasks to be hidden.
Browse files Browse the repository at this point in the history
  • Loading branch information
mikaeljorhult committed Apr 20, 2017
1 parent a86dba5 commit 12df76e
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 1 deletion.
5 changes: 5 additions & 0 deletions html/dialog-settings.html
Expand Up @@ -66,6 +66,11 @@ <h1 class="dialog-title">{{ Strings.SETTINGS_DIALOG_TITLE }}</h1>
<input type="checkbox" name="todo-settings-sort-done" id="todo-settings-sort-done" />
{{ Strings.SETTINGS_DIALOG_SORT_DONE }}
</label>

<label for="todo-settings-hide-done">
<input type="checkbox" name="todo-settings-hide-done" id="todo-settings-hide-done" />
{{ Strings.SETTINGS_DIALOG_HIDE_DONE }}
</label>
</fieldset>
</div>

Expand Down
3 changes: 3 additions & 0 deletions modules/Defaults.js
Expand Up @@ -20,6 +20,9 @@ define(function () {
},
sort: {
done: true
},
hide: {
done: true
}
};

Expand Down
13 changes: 13 additions & 0 deletions modules/Files.js
Expand Up @@ -46,6 +46,7 @@ define(function (require) {

// Get todos from file.
file.todos = Parser.parse(data, expression, file.file.fullPath);
file.todos = reject(file.todos);
file.todos = sort(file.todos);

// Move on to next file.
Expand All @@ -64,6 +65,18 @@ define(function (require) {
});
}

function reject (todos) {
// Hide completed todos if requested.
if (Settings.get().hide.done) {
return todos.filter(function (todo) {
// Remove todo if completed.
return !todo.done;
});
}

return todos;
}

function sort (todos) {
// Sort todos if requested.
if (Settings.get().sort.done) {
Expand Down
4 changes: 4 additions & 0 deletions modules/SettingsDialog.js
Expand Up @@ -38,6 +38,9 @@ define(function (require) {
},
sort: {
done: $('#todo-settings-sort-done', $dialog).prop('checked')
},
hide: {
done: $('#todo-settings-hide-done', $dialog).prop('checked')
}
};
}
Expand All @@ -63,6 +66,7 @@ define(function (require) {

// Sorting and filtering.
$('#todo-settings-sort-done').prop('checked', (settings.sort !== undefined && settings.sort.done !== undefined ? settings.sort.done : true));
$('#todo-settings-hide-done').prop('checked', (settings.hide !== undefined && settings.hide.done !== undefined ? settings.hide.done : true));
}

/**
Expand Down
3 changes: 2 additions & 1 deletion nls/root/Strings.js
Expand Up @@ -34,7 +34,8 @@ define({
SETTINGS_DIALOG_EXCLUDE_FILES: 'Files',
SETTINGS_DIALOG_EXCLUDE_FILES_TITLE: 'Full or part of file names, separated by commas, which should be excluded from search.',
SETTINGS_DIALOG_SORTING_FILTERING: 'Sorting and filtering',
SETTINGS_DIALOG_SORT_DONE: 'Move done tasks to bottom of list.',
SETTINGS_DIALOG_SORT_DONE: 'Move completed tasks to bottom of list.',
SETTINGS_DIALOG_HIDE_DONE: 'Hide completed tasks.',
SETTINGS_DIALOG_SAVE_FILE: 'Save to .todo',
SETTINGS_DIALOG_RESET: 'Reset'
});

0 comments on commit 12df76e

Please sign in to comment.