Skip to content

Commit

Permalink
feat(amend): adds inline or editor-edit currently tracked entry’s note
Browse files Browse the repository at this point in the history
  • Loading branch information
Ephigenia committed Apr 6, 2018
1 parent 0142520 commit ad435c7
Show file tree
Hide file tree
Showing 5 changed files with 105 additions and 5 deletions.
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ Before you can start you’ll have to setup your mite account and api key which

- Create and start new Entries with interactive survey-like cli interface
- Show & filter time entries to show reports for last month, current week etc.
- Edit (amend) the currently running entries text for fast updating the work log
- Delete single entries by id
- List, sort, filter user accounts, customers, projects & services
- Highlight JIRA identifiers in time entry notes
Expand Down Expand Up @@ -119,6 +120,20 @@ Stops any tracked time tracker.

mite stop

## Edit Currently Tracked Note

When there’s a tracker running you may want to update the note without opening the browser and enter the new details. You can use `amend` or `reword` command which will load the time entry and you can enter the new note.

mite amend

You can also add the `--editor` option so that your favorite editor opens up with the current note prefilled. Make sure your `$EDITOR` is correctly set.

mite amend --editor

You can also alter the notes of other time entries when you specify their id

mite amend 1847132

## Delete entry

Delete a single entry
Expand Down
15 changes: 10 additions & 5 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,10 @@
},
"dependencies": {
"async": "^2.5.0",
"bluebird": "^3.5.1",
"chalk": "^2.3.1",
"commander": "^2.14.1",
"external-editor": "^2.2.0",
"inquirer": "^5.1.0",
"mite-api": "marcel-devdude/mite-api#master",
"nconf": "^0.10.0",
Expand Down
76 changes: 76 additions & 0 deletions source/mite-amend.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
#!/usr/bin/env node
'use strict'

const program = require('commander');
const miteApi = require('mite-api');
const bluebird = require('bluebird');
const inquirer = require('inquirer');
const ExternalEditor = require('external-editor');

const pkg = require('./../package.json')
const config = require('./config.js')
const tracker = require('./lib/mite-tracker');

program
.version(pkg.version)
.description(
'Rewrite the note for the given time entry id or use the currently ' +
'running time entry and edit it’s note'
)
.option(
'-e, --editor',
'open preferred $EDITOR for editing'
)
.arguments('<timeEntryId>')
.action((timeEntryId) => {
main(timeEntryId);
})
.parse(process.argv);

if (!program.args.length) {
main(null)
}


function main(timeEntryId) {
const mite = miteApi(config.get());
const miteTracker = tracker(config.get());
const getTimeEntry = bluebird.promisify(mite.getTimeEntry);
const updateTimeEntry = bluebird.promisify(mite.updateTimeEntry);
const edit = bluebird.promisify(ExternalEditor.editAsync);

let promise = null;
if (!timeEntryId) {
promise = miteTracker.get()
.then(result => getTimeEntry(result.tracker.tracking_time_entry.id));
} else {
promise = getTimeEntry(timeEntryId);
}
promise.then(data => data.time_entry)
.then(timeEntry => {
timeEntryId = timeEntry.id;
if (program.editor) {
return edit(timeEntry.note).then((editedText) => {
return { note: editedText }
});
}

const questions = [
{
type: program.editor ? 'editor' : 'input',
name: 'note',
message: 'Note',
default: timeEntry.note,
},
];
return inquirer.prompt(questions);
})
.then(entry => updateTimeEntry(timeEntryId, entry))
.then(() => {
console.log('Successfully modified note of time entry (id: %s)', timeEntryId);
})
.catch((err) => {
console.error(err.message);
process.exit(1);
});
}
2 changes: 2 additions & 0 deletions source/mite.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ const pkg = require('./../package.json')

program
.version(pkg.version)
.command('amend', 'edit the text for a specific time entry or the currently runnning entry')
.alias('reword')
.command('budgets', 'list money and time budgets for current month')
.command('config', 'show or set configuration settings')
.command('delete', 'delete a specific time entry')
Expand Down

0 comments on commit ad435c7

Please sign in to comment.