Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions cli.js
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ const cli = meow(help, {
move: {
type: 'boolean',
alias: 'm'
},
after: {
type: 'string'
}
}
});
Expand Down
7 changes: 6 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ const taskbookCLI = (input, flags) => {
}

if (flags.list) {
taskbook.listByAttributes(input);
taskbook.listByAttributes(input, flags.after);
return taskbook.displayStats();
}

Expand All @@ -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();
};
Expand Down
23 changes: 21 additions & 2 deletions lib/taskbook.js
Original file line number Diff line number Diff line change
@@ -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();
Expand Down Expand Up @@ -237,6 +241,16 @@ class Taskbook {
return data;
}

_filterAfterDate(date = format(new Date(), DATE_FORMATTER), data = this._data) {
Object.entries(data).forEach(([id, item]) => {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this be re-written as the following?

Object.entries(data).filter(([id, item]) => {
  return moment(item._timestamp).isAfter(moment(date))
});

Copy link

@rjoydip-zz rjoydip-zz Aug 7, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, the filter is better than foreach for this case. Also deleting object is a little bit time expensive

Copy link
Author

@WellerQu WellerQu Aug 8, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sorry, I can NOT, because the data is not an array, and I have to change the data directy in this project.

if (!isAfter(item._timestamp, date)) {
delete data[id];
}
});

return data;
}

_groupByBoard(data = this._data, boards = this._getBoards()) {
const grouped = {};

Expand Down Expand Up @@ -398,7 +412,7 @@ class Taskbook {
render.displayByBoard(this._groupByBoard(result));
}

listByAttributes(terms) {
listByAttributes(terms, afterDate) {
let [boards, attributes] = [[], []];
const storedBoards = this._getBoards();

Expand All @@ -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));
}

Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
1 change: 1 addition & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down