diff --git a/cli.js b/cli.js old mode 100644 new mode 100755 index f6ef3d18..1834b9b2 --- a/cli.js +++ b/cli.js @@ -67,6 +67,9 @@ const cli = meow(help, { move: { type: 'boolean', alias: 'm' + }, + after: { + type: 'string' } } }); diff --git a/index.js b/index.js index fac1837d..b9e92914 100644 --- a/index.js +++ b/index.js @@ -45,7 +45,7 @@ const taskbookCLI = (input, flags) => { } if (flags.list) { - taskbook.listByAttributes(input); + taskbook.listByAttributes(input, flags.after); return taskbook.displayStats(); } @@ -57,6 +57,11 @@ const taskbookCLI = (input, flags) => { return taskbook.moveBoards(input); } + if (flags.after) { + taskbook.listByAttributes([], flags.after); + return taskbook.displayStats(); + } + taskbook.displayByBoard(); return taskbook.displayStats(); }; diff --git a/lib/taskbook.js b/lib/taskbook.js index 51562c5e..08a875cc 100644 --- a/lib/taskbook.js +++ b/lib/taskbook.js @@ -1,10 +1,14 @@ #!/usr/bin/env node 'use strict'; +const isAfter = require('date-fns/is_after'); +const format = require('date-fns/format'); const Task = require('./task'); const Note = require('./note'); const Storage = require('./storage'); const render = require('./render'); +const DATE_FORMATTER = 'YYYYMMDD'; + class Taskbook { constructor() { this._storage = new Storage(); @@ -237,6 +241,16 @@ class Taskbook { return data; } + _filterAfterDate(date = format(new Date(), DATE_FORMATTER), data = this._data) { + Object.entries(data).forEach(([id, item]) => { + if (!isAfter(item._timestamp, date)) { + delete data[id]; + } + }); + + return data; + } + _groupByBoard(data = this._data, boards = this._getBoards()) { const grouped = {}; @@ -398,7 +412,7 @@ class Taskbook { render.displayByBoard(this._groupByBoard(result)); } - listByAttributes(terms) { + listByAttributes(terms, afterDate) { let [boards, attributes] = [[], []]; const storedBoards = this._getBoards(); @@ -411,7 +425,12 @@ class Taskbook { [boards, attributes] = [boards, attributes].map(x => this._removeDuplicates(x)); - const data = this._filterByAttributes(attributes); + let data = this._filterByAttributes(attributes); + + if (afterDate) { + data = this._filterAfterDate(afterDate, data); + } + render.displayByBoard(this._groupByBoard(data, boards)); } diff --git a/package.json b/package.json index 57d21c7a..81aa9efc 100644 --- a/package.json +++ b/package.json @@ -45,6 +45,7 @@ }, "dependencies": { "chalk": "^2.4.1", + "date-fns": "^1.29.0", "meow": "^5.0.0", "signale": "^1.2.1", "update-notifier": "^2.5.0" diff --git a/readme.md b/readme.md index fef9b9ee..e03ec24d 100644 --- a/readme.md +++ b/readme.md @@ -89,6 +89,7 @@ $ tb --help --restore, -r Restore items from archive --help, -h Display help message --version, -v Display installed version + --after Filter items by special date Examples $ tb