From e7d8c0175d2683c4602b1f52bb3f6fb4ee29882c Mon Sep 17 00:00:00 2001 From: Stefan Wienert Date: Fri, 6 Oct 2017 16:13:43 +0200 Subject: [PATCH 1/2] Implemented resume command --- src/gtt-resume.js | 21 +++++++++++++++++++++ src/gtt.js | 1 + src/include/tasks.js | 23 +++++++++++++++++++++++ 3 files changed, 45 insertions(+) create mode 100644 src/gtt-resume.js diff --git a/src/gtt-resume.js b/src/gtt-resume.js new file mode 100644 index 0000000..8b11ba7 --- /dev/null +++ b/src/gtt-resume.js @@ -0,0 +1,21 @@ +const program = require('commander'); +const colors = require('colors'); +const moment = require('moment'); + +const Config = require('./include/file-config'); +const Cli = require('./include/cli'); +const Tasks = require('./include/tasks'); + +program + .option('--verbose', 'show verbose output') + .parse(process.argv); + +Cli.verbose = program.verbose; + +let config = new Config(process.cwd()), + tasks = new Tasks(config); + + +tasks.resume() + .then(frame => console.log(`Starting project ${config.get('project').magenta} ${frame.resource.type.blue} ${('#' + frame.resource.id).blue} at ${moment().format('HH:mm').green}`)) + .catch(error => Cli.error(error)); diff --git a/src/gtt.js b/src/gtt.js index d7a8cec..ae16d85 100755 --- a/src/gtt.js +++ b/src/gtt.js @@ -9,6 +9,7 @@ program .command('create [project] [title]', 'start monitoring time for the given project and create a new issue or merge request with the given title') .command('status', 'shows if time monitoring is running') .command('stop', 'stop monitoring time') + .command('resume', 'resume monitoring time for last stopped record') .command('cancel', 'cancel and discard active monitoring time') .command('log', 'log recorded time records') .command('sync', 'sync local time records to GitLab') diff --git a/src/include/tasks.js b/src/include/tasks.js index 6a05a16..1ba40fc 100755 --- a/src/include/tasks.js +++ b/src/include/tasks.js @@ -174,6 +174,29 @@ class tasks { }); } + /** + * + * @returns {Promise} + */ + resume() { + return new Promise((resolve, reject) => { + let project; + let frames = new FrameCollection(this.config).frames + if (project = this.config.get('project')) { + frames = frames.filter(frame => frame.project == project) + } + const last = frames.filter(frame => frame.stop) + .sort((a, b) => -1 * a.stop.localeCompare(b.stop))[0] + if (last) { + this.start(last.project, last.resource.type, last.resource.id) + .then(frames => resolve(frames)) + .catch(error => reject(error)) + } else { + reject("No recent entry found for project") + } + }); + } + /** * * @param project From acade2bdddfe4b734abcdbfe771d7344f36034aa Mon Sep 17 00:00:00 2001 From: Stefan Wienert Date: Fri, 6 Oct 2017 16:23:36 +0200 Subject: [PATCH 2/2] made gtt-resume.js executable --- src/gtt-resume.js | 0 1 file changed, 0 insertions(+), 0 deletions(-) mode change 100644 => 100755 src/gtt-resume.js diff --git a/src/gtt-resume.js b/src/gtt-resume.js old mode 100644 new mode 100755