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

Creating task swap function #179

Open
wants to merge 7 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
14 changes: 14 additions & 0 deletions .oh-my-zsh/custom/plugins/taskbook/taskbook.plugin.zsh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Taskbook command completion

# Functio

_taskbook_commands () {
if which tb &> /dev/null; then
array_of_lines=("${(@f)$(tb | grep -o '[0-9]\+\..*\|@\w*')}")
compadd -d array_of_lines -X 'Some completions' -- $(tb | grep -o '[0-9]\+\.\|@\w*' | grep -o '[0-9]\+\|@\w*')
fi
}

# Completion setup
compdef _taskbook_commands tb

4 changes: 4 additions & 0 deletions cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ const cli = meow(help, {
type: 'boolean',
alias: 'p'
},
swap: {
type: 'boolean',
alias: 'w'
},
find: {
type: 'boolean',
alias: 'f'
Expand Down
4 changes: 4 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ const taskbookCLI = (input, flags) => {
return taskbook.updatePriority(input);
}

if (flags.swap) {
return taskbook.swapItems(input);
}

if (flags.copy) {
return taskbook.copyToClipboard(input);
}
Expand Down
10 changes: 10 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ $ tb --help
--priority, -p Update priority of task
--restore, -r Restore items from archive
--star, -s Star/unstar item
--swap, -w Swap items
--task, -t Create task
--timeline, -i Display timeline view
--version, -v Display installed version
Expand All @@ -138,6 +139,7 @@ $ tb --help
$ tb --priority @3 2
$ tb --restore 4
$ tb --star 2
$ tb --swap 2 1
$ tb --task @coding @reviews Review PR #42
$ tb --task @coding Improve documentation
$ tb --task Make some buttercream
Expand Down Expand Up @@ -254,6 +256,14 @@ To mark one or more items as favorite, use the `--star`/`-s` option followed by
$ tb -s 1 2 3
```

### Swap items

To swap items positions, use the `--swap`/`-s` option followed by the ids of the 2 items which will be swapped.

```
$ tb -w 2 1
```

### Copy Item Description

To copy to your system's clipboard the description of one or more items, use the `--copy`/`-y` option followed by the ids of the target items. Note that the option will also include the newline character as a separator to each pair of adjacent copied descriptions, thus resulting in a clear and readable stack of sentences on paste.
Expand Down
2 changes: 2 additions & 0 deletions src/help.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ module.exports = `
--priority, -p Update priority of task
--restore, -r Restore items from archive
--star, -s Star/unstar item
--swap, -w Swap items
--task, -t Create task
--timeline, -i Display timeline view
--version, -v Display installed version
Expand All @@ -41,6 +42,7 @@ module.exports = `
$ tb --priority @3 2
$ tb --restore 4
$ tb --star 2
$ tb --swap 2 1
$ tb --task @coding @reviews Review PR #42
$ tb --task @coding Improve documentation
$ tb --task Make some buttercream
Expand Down
16 changes: 16 additions & 0 deletions src/render.js
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,12 @@ class Render {
error({prefix, message});
}

notEnoughIDsNumber() {
const prefix = '\n';
const message = 'Not enough ids were given as input';
error({prefix, message});
}

invalidPriority() {
const prefix = '\n';
const message = 'Priority can only be 1, 2 or 3';
Expand Down Expand Up @@ -278,6 +284,16 @@ class Render {
success({prefix, message, suffix});
}

swapSuccess(ids) {
if (ids.length != 2) {
return;
}

const [prefix, suffix] = ['\n', grey(ids.join(', '))];
const message = `Swapped items:`;
success({prefix, message, suffix});
}

missingBoards() {
const prefix = '\n';
const message = 'No boards were given as input';
Expand Down
29 changes: 29 additions & 0 deletions src/taskbook.js
Original file line number Diff line number Diff line change
Expand Up @@ -214,12 +214,15 @@ class Taskbook {
break;

case 'done':
case 'check':
case 'checked':
case 'complete':
data = this._filterComplete(data);
break;

case 'progress':
case 'start':
case 'doing':
case 'started':
case 'begun':
data = this._filterInProgress(data);
Expand Down Expand Up @@ -529,6 +532,32 @@ class Taskbook {
render.markUnstarred(unstarred);
}

swapItems(ids) {
ids = this._validateIDs(ids);

if (ids.length > 2 ) {
render.invalidIDsNumber();
process.exit(1);
}

if (ids.length < 2) {
render.notEnoughIDsNumber();
process.exit(1);
}

const {_data} = this;

_data[ids[0]]._id = ids[1];
_data[ids[1]]._id = ids[0];

var tmp = _data[ids[0]];
_data[ids[0]] = _data[ids[1]];
_data[ids[1]] = tmp;

this._save(_data);
render.swapSuccess(ids);
}

updatePriority(input) {
const level = input.find(x => ['1', '2', '3'].indexOf(x) > -1);

Expand Down