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

Multi task create #76

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
4 changes: 2 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ const taskbookCLI = (input, flags) => {
}

if (flags.task) {
return taskbook.createTask(input);
return taskbook.createTasks(input);
}

if (flags.restore) {
return taskbook.restoreItems(input);
}

if (flags.note) {
return taskbook.createNote(input);
return taskbook.createNotes(input);
}

if (flags.delete) {
Expand Down
2 changes: 2 additions & 0 deletions lib/help.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ module.exports = `
$ tb --task Make some buttercream
$ tb --task @coding Improve documentation
$ tb --task @coding @reviews Review PR #42
$ tb --task @shopping bananas::bread::brown sugar
$ tb --note @coding Mergesort worse-case O(nlogn)
$ tb --note @styles red borders::blue underline::black text
$ tb --check 1 2
$ tb --delete 4
$ tb --star 2
Expand Down
7 changes: 4 additions & 3 deletions lib/render.js
Original file line number Diff line number Diff line change
Expand Up @@ -242,9 +242,10 @@ class Render {
error({prefix, message});
}

successCreate({_id, _isTask}) {
const [prefix, suffix] = ['\n', grey(_id)];
const message = `Created ${_isTask ? 'task:' : 'note:'}`;
successCreate(ids, areTasks) {
const [prefix, suffix] = ['\n', grey(ids.join(', '))];
let message = `Created ${areTasks ? 'task' : 'note'}`;
message += ids.length > 1 ? 's:' : ':';
success({prefix, message, suffix});
}

Expand Down
41 changes: 28 additions & 13 deletions lib/taskbook.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,6 @@ class Taskbook {
process.exit(1);
}

const id = this._generateID();
const priority = this._getPriority(input);

input.forEach(x => {
Expand All @@ -111,13 +110,13 @@ class Taskbook {
}
});

const description = desc.join(' ');
const descriptions = desc.join(' ').split('::');

Choose a reason for hiding this comment

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

Maybe just add this as a constant or even an option somewhere to be changed easily.


if (boards.length === 0) {
boards.push('My Board');
}

return {boards, description, id, priority};
return {boards, descriptions, priority};
}

_getStats() {
Expand Down Expand Up @@ -297,13 +296,21 @@ class Taskbook {
this._save(_data);
}

createNote(desc) {
const {id, description, boards} = this._getOptions(desc);
const note = new Note({id, description, boards});
createNotes(desc) {
const {boards, descriptions} = this._getOptions(desc);

const {_data} = this;
_data[id] = note;
const initialID = this._generateID();
const ids = descriptions.map((description, i) => {
const id = initialID + i;
const note = new Note({id, description, boards});
_data[id] = note;

return id;
});

this._save(_data);
render.successCreate(note);
render.successCreate(ids, false);
}

checkTasks(ids) {
Expand All @@ -318,13 +325,21 @@ class Taskbook {
render.markComplete(ids);
}

createTask(desc) {
const {boards, description, id, priority} = this._getOptions(desc);
const task = new Task({id, description, boards, priority});
createTasks(desc) {
const {boards, descriptions, priority} = this._getOptions(desc);

const {_data} = this;
_data[id] = task;
const initialID = this._generateID();
const ids = descriptions.map((description, i) => {
const id = initialID + i;
const task = new Task({id, description, boards, priority});
_data[id] = task;

return id;
});

this._save(_data);
render.successCreate(task);
render.successCreate(ids, true);
}

deleteItems(ids) {
Expand Down
14 changes: 9 additions & 5 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,9 @@ $ tb --help
$ tb --task Make some buttercream
$ tb --task @coding Improve documentation
$ tb --task @coding @reviews Review PR #42
$ tb --task @shopping bananas::bread::brown sugar
$ tb --note @coding Mergesort worse-case O(nlogn)
$ tb --note @styles red borders::blue underline::black text
$ tb --check 1 2
$ tb --delete 4
$ tb --star 2
Expand Down Expand Up @@ -173,18 +175,20 @@ 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. Create multiple tasks at once by using `::` as a delimiter between task descriptions. Multiple tasks are creating using the same boards and priority specified.

```
$ tb -t Improve documentation
$ tb -t Fix translations::Add validation::Write unit tests
```

### 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. Multiple notes can also be created at once by using `::` as a delimiter between note descriptions. Multiple notes are created using the same boards specified.

```
$ tb -n Mergesort worse-case O(nlogn)
$ tb -n Font size is 16px::Background color is f4f7fb::Margin size is 2rem
```

### Create Board
Expand Down Expand Up @@ -230,8 +234,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 Down Expand Up @@ -296,7 +300,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