Skip to content

Commit

Permalink
add feature to delete a board with all items in it
Browse files Browse the repository at this point in the history
  • Loading branch information
alepop committed Aug 5, 2018
1 parent 9c97de7 commit 707ff03
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 9 deletions.
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const taskbookCLI = (input, flags) => {
}

if (flags.delete) {
return taskbook.deleteItems(input);
return taskbook.deleteEntities(input);
}

if (flags.check) {
Expand Down
1 change: 1 addition & 0 deletions lib/help.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ module.exports = `
$ tb --note @coding Mergesort worse-case O(nlogn)
$ tb --check 1 2
$ tb --delete 4
$ tb --delete @coding
$ tb --star 2
$ tb --priority @3 2
$ tb --timeline
Expand Down
8 changes: 7 additions & 1 deletion lib/render.js
Original file line number Diff line number Diff line change
Expand Up @@ -254,12 +254,18 @@ class Render {
success({prefix, message, suffix});
}

successDelete(ids) {
successDeleteItems(ids) {
const [prefix, suffix] = ['\n', grey(ids.join(', '))];
const message = `Deleted ${ids.length > 1 ? 'items' : 'item'}:`;
success({prefix, message, suffix});
}

successDeleteBoards(boards) {
const [prefix, suffix] = [`\n`, grey(boards.join(', '))];
const message = `Deleted ${boards.length > 1 ? `boards` : `board`}:`;
success({prefix, message, suffix});
}

successMove(id, boards) {
const [prefix, suffix] = ['\n', grey(boards.join(', '))];
const message = `Move item: ${grey(id)} to`;
Expand Down
34 changes: 33 additions & 1 deletion lib/taskbook.js
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,15 @@ class Taskbook {
render.successCreate(task);
}

deleteEntities(inputs) {
const boards = inputs.filter(x => x.startsWith('@'));
if (boards.length > 0) {
this.deleteBoards(boards);
} else {
this.deleteItems(inputs);
}
}

deleteItems(ids) {
ids = this._validateIDs(ids);
const {_data} = this;
Expand All @@ -335,7 +344,30 @@ class Taskbook {
});

this._save(_data);
render.successDelete(ids);
render.successDeleteItems(ids);
}

deleteBoards(boards) {
const ids = [];
const {_data} = this;
const itemsInBoards = Object.values(this._groupByBoard(this._data, boards))
.reduce((a, b) => a.concat(b), []);

const items = this._removeDuplicates(itemsInBoards);
items.forEach(item => {
const notInAnotherBoard = item.boards.every(b => boards.includes(b));
if (notInAnotherBoard) {
ids.push(item._id);
} else {
_data[item._id].boards = item.boards.filter(b => !boards.includes(b));
this._save(_data);
}
});

render.successDeleteBoards(boards);
if (ids.length > 0) {
this.deleteItems(ids);
}
}

displayArchive() {
Expand Down
14 changes: 8 additions & 6 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ $ tb --help
$ tb --note @coding Mergesort worse-case O(nlogn)
$ tb --check 1 2
$ tb --delete 4
$ tb --delete @coding
$ tb --star 2
$ tb --priority @3 2
$ tb --timeline
Expand Down Expand Up @@ -171,15 +172,15 @@ In case you spotted an error or think that an example is not to clear enough and

### Create Task

To create a new task use the `--task`/`-t` option with your task's description following right after.
To create a new task use the `--task`/`-t` option with your task's description following right after.

```
$ tb -t Improve documentation
```

### Create Note

To create a new note use the `--note`/`-n` option with your note's body following right after.
To create a new note use the `--note`/`-n` option with your note's body following right after.

```
$ tb -n Mergesort worse-case O(nlogn)
Expand Down Expand Up @@ -228,8 +229,8 @@ $ tb -i
### Set Priority

To set a priority level for a task while initializing it, include the `p:x` syntax in the task's description, where x can be an integer of value `1`, `2` or `3`. Note that all tasks by default are created with a normal priority - `1`.
- `1` - Normal priority

- `1` - Normal priority
- `2` - Medium priority
- `3` - High priority

Expand All @@ -253,10 +254,11 @@ $ tb -m @1 myboard reviews

### Delete Item

To delete one or more items, use the `--delete`/`-d` options followed by the ids of the target items. Note that deleted items are automatically archived, and can be inspected or restored at any moment. Duplicate ids are automatically filtered out.
To delete one or more items, use the `--delete`/`-d` options followed by the ids of the target items or boards name prefixed by `@`. Note that deleted items are automatically archived, and can be inspected or restored at any moment. Duplicate ids are automatically filtered out.

```
$ tb -d 1 2
$ tb -d @coding
```

### Display Archive
Expand Down Expand Up @@ -294,7 +296,7 @@ The by default supported listing attributes, together with their respective alia

### Search Items

To search for one of more items, use the `--find`/`-f` option, followed by your search terms.
To search for one of more items, use the `--find`/`-f` option, followed by your search terms.

```
$ tb -f documentation
Expand Down

0 comments on commit 707ff03

Please sign in to comment.