Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add feature to delete a board with all items in it #60

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
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
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 @@ -31,6 +31,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 @@ -327,6 +327,15 @@ class Taskbook {
render.successCreate(task);
}

deleteEntities(inputs) {
Copy link

@WellerQu WellerQu Aug 6, 2018

Choose a reason for hiding this comment

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

no offense, will we just remove boards and ignore other tasks, example: tb -d @coding 1 2

Copy link
Author

Choose a reason for hiding this comment

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

You are right if any board is passed as parameters then task ids are ignored. I will improve PR.

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 @@ -337,7 +346,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 @@ -98,6 +98,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 @@ -173,15 +174,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 @@ -230,8 +231,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 @@ -255,10 +256,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 @@ -296,7 +298,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