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 Rename boards #73

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: 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'
},
renameBoard: {
type: 'boolean',
alias: 'rb'
}
}
});
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.renameBoard) {
return taskbook.renameBoard(input);
}

taskbook.displayByBoard();
return taskbook.displayStats();
};
Expand Down
5 changes: 1 addition & 4 deletions lib/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,8 @@ class Config {
}

get() {
let config = {};

const content = fs.readFileSync(this._configFile, 'utf8');
config = JSON.parse(content);

const config = JSON.parse(content);
return Object.assign({}, defaultConfig, config);
}
}
Expand Down
34 changes: 18 additions & 16 deletions lib/help.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,23 @@ module.exports = `
$ tb [<options> ...]

Options
none Display board view
--task, -t Create task
--note, -n Create note
--timeline, -i Display timeline view
--delete, -d Delete item
--check, -c Check/uncheck task
--star, -s Star/unstar item
--list, -l List items by attributes
--find, -f Search for items
--edit, -e Edit item description
--move, -m Move item between boards
--priority, -p Update priority of task
--archive, -a Display archived items
--restore, -r Restore items from archive
--help, -h Display help message
--version, -v Display installed version
none Display board view
--task, -t Create task
--note, -n Create note
--timeline, -i Display timeline view
--delete, -d Delete item
--check, -c Check/uncheck task
--star, -s Star/unstar item
--list, -l List items by attributes
--find, -f Search for items
--edit, -e Edit item description
--move, -m Move item between boards
--priority, -p Update priority of task
--archive, -a Display archived items
--restore, -r Restore items from archive
--rename-board, -rb Rename board; boards with spaces - specify via "_" symbol like My_Board
--help, -h Display help message
--version, -v Display installed version

Examples
$ tb
Expand All @@ -39,4 +40,5 @@ module.exports = `
$ tb --list pending coding
$ tb --archive
$ tb --restore 4
$ tb --rename-board My_Board Todo
Copy link

Choose a reason for hiding this comment

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

Nitpick: But can we keep the stylizing of the board names consistent. Elsewhere, boards are referred to as all lower case, single words. Here, you've introduced a camel-case, "_" separated pattern that clashes a bit with the above examples

Choose a reason for hiding this comment

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

Why not use quotes?
This would be the only place in the application where we need to replace spaces with underscores.

Why not:
tb --rename-board "My Board" Todo
?

`;
12 changes: 12 additions & 0 deletions lib/render.js
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,18 @@ class Render {
error({prefix, message});
}

missingStorage() {
const prefix = '\n';
const message = 'There are no any boards, please create some task at least to start';
Copy link

Choose a reason for hiding this comment

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

Can we change the copy to: "There are currently no boards"

error({prefix, message});
}

missingBoardName(name) {
const prefix = '\n';
const message = `There are no any board with name: ${name}`;
Copy link

Choose a reason for hiding this comment

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

Can we change the copy here to:
"There are no boards with the name: ${name}"

error({prefix, message});
}

successCreate({_id, _isTask}) {
const [prefix, suffix] = ['\n', grey(_id)];
const message = `Created ${_isTask ? 'task:' : 'note:'}`;
Expand Down
29 changes: 29 additions & 0 deletions lib/storage.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,35 @@ class Storage {
return archive;
}

renameBoardsWithName(oldName, newName) {

Choose a reason for hiding this comment

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

I don't agree with this approach.

The task data manipulation is not done in the Storage class, this class is supposed to read and write the data, not perform logic like this.
You should move this logic to the TaskBoard class itself and just use the Storage to read and write data back.

let finalData = null;
fs.stat(this._mainStorageFile, (err, res) => {
if (err || !res.isFile()) {
render.missingStorage();
return finalData;
}
const rs = fs.createReadStream(this._mainStorageFile, 'utf8');
rs.on('data', rsData => {
const _rsData = JSON.parse(rsData);
Object.keys(_rsData).forEach(k => {
_rsData[k].boards.forEach((boardName, i) => {
if (boardName === oldName) {
_rsData[k].boards[i] = newName;
finalData = {..._rsData};
finalData = JSON.stringify(finalData, null, 2);
}
});
});
});
rs.on('end', () => {
if (!finalData) {
return render.missingBoardName(oldName);
}
fs.createWriteStream(this._mainStorageFile).write(finalData);
});
});
}

set(data) {
data = JSON.stringify(data, null, 4);
const tempStorageFile = this._getTempFile(this._mainStorageFile);
Expand Down
5 changes: 5 additions & 0 deletions lib/taskbook.js
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,11 @@ class Taskbook {
render.displayByBoard(this._groupByBoard(data, boards));
}

renameBoard(input) {
const oldName = input[1].replace(/_/g, ' ');
this._storage.renameBoardsWithName(oldName, input[2]);
}

moveBoards(input) {
let boards = [];
const targets = input.filter(x => x.startsWith('@'));
Expand Down