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
4 changes: 4 additions & 0 deletions cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ const cli = meow(help, {
move: {
type: 'boolean',
alias: 'm'
},
table: {
type: 'boolean',
alias: 'T'
}
}
});
Expand Down
4 changes: 4 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ const taskbookCLI = (input, flags) => {
return taskbook.moveBoards(input);
}

if (flags.table) {
return taskbook.displayTable(input);
}

taskbook.displayByBoard();
return taskbook.displayStats();
};
Expand Down
3 changes: 3 additions & 0 deletions lib/help.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ module.exports = `
--priority, -p Update priority of task
--archive, -a Display archived items
--restore, -r Restore items from archive
--table, -T Display tasks in table format
--help, -h Display help message
--version, -v Display installed version

Expand All @@ -35,6 +36,8 @@ module.exports = `
$ tb --timeline
$ tb --edit @3 Merge PR #42
$ tb --move @1 cooking
$ tb --table
$ tb --table code
$ tb --find documentation
$ tb --list pending coding
$ tb --archive
Expand Down
10 changes: 10 additions & 0 deletions lib/render.js
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,16 @@ class Render {
const message = `Restored ${ids.length > 1 ? 'items' : 'item'}:`;
success({prefix, message, suffix});
}

table(data) {
process.stdout.write(data);
}

noItemFind() {
const [prefix, suffix] = ['\n'];
const message = 'No item found';
error({prefix, message, suffix});
}
}

module.exports = new Render();
36 changes: 36 additions & 0 deletions lib/taskbook.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
#!/usr/bin/env node
'use strict';
const chalk = require('chalk');
const Table = require('cli-table');
const Task = require('./task');
const Note = require('./note');
const Storage = require('./storage');
const render = require('./render');

const {green} = chalk;
class Taskbook {
constructor() {
this._storage = new Storage();
Expand Down Expand Up @@ -499,6 +502,39 @@ class Taskbook {
this._save(_data);
render.successPriority(id, level);
}

displayTable(input) {
const {_data} = this;
let _tableData = _data;

const table = new Table({
head: [green('SL'), green('Date'), green('Timestamp'), green('Description'), green('Starred'), green('Boards'), green('Task'), green('Complete'), green('Priority')]
});

if (input.length > 0) {
const grouped = [];
Object.entries(_data).forEach(([_, item]) => {
input.forEach(board => {
if (item.boards.includes(board)) {
if (Array.isArray(grouped[board])) {
return grouped[board].push(item);
}
grouped.push(item);
return grouped;
}
});
});
_tableData = grouped;
}

Object.values(_tableData).map(item => item).map(value => table.push(Object.values(value)));

if (Object.entries(_tableData).length > 0) {
render.table(table.toString());
} else {
render.noItemFind();
}
}
}

module.exports = new Taskbook();
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",
"cli-table": "^0.3.1",
"meow": "^5.0.0",
"signale": "^1.2.1",
"update-notifier": "^2.5.0"
Expand Down
3 changes: 3 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ $ tb --help
--priority, -p Update priority of task
--archive, -a Display archived items
--restore, -r Restore items from archive
--table, -T Display tasks in table format
--help, -h Display help message
--version, -v Display installed version

Expand All @@ -101,6 +102,8 @@ $ tb --help
$ tb --timeline
$ tb --edit @3 Merge PR #42
$ tb --move @1 cooking
$ tb --table
$ tb --table code
$ tb --find documentation
$ tb --list pending coding
$ tb --archive
Expand Down