Skip to content

Commit e7d8c01

Browse files
committed
Implemented resume command
1 parent 8c835d7 commit e7d8c01

File tree

3 files changed

+45
-0
lines changed

3 files changed

+45
-0
lines changed

src/gtt-resume.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
const program = require('commander');
2+
const colors = require('colors');
3+
const moment = require('moment');
4+
5+
const Config = require('./include/file-config');
6+
const Cli = require('./include/cli');
7+
const Tasks = require('./include/tasks');
8+
9+
program
10+
.option('--verbose', 'show verbose output')
11+
.parse(process.argv);
12+
13+
Cli.verbose = program.verbose;
14+
15+
let config = new Config(process.cwd()),
16+
tasks = new Tasks(config);
17+
18+
19+
tasks.resume()
20+
.then(frame => console.log(`Starting project ${config.get('project').magenta} ${frame.resource.type.blue} ${('#' + frame.resource.id).blue} at ${moment().format('HH:mm').green}`))
21+
.catch(error => Cli.error(error));

src/gtt.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ program
99
.command('create [project] [title]', 'start monitoring time for the given project and create a new issue or merge request with the given title')
1010
.command('status', 'shows if time monitoring is running')
1111
.command('stop', 'stop monitoring time')
12+
.command('resume', 'resume monitoring time for last stopped record')
1213
.command('cancel', 'cancel and discard active monitoring time')
1314
.command('log', 'log recorded time records')
1415
.command('sync', 'sync local time records to GitLab')

src/include/tasks.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,29 @@ class tasks {
174174
});
175175
}
176176

177+
/**
178+
*
179+
* @returns {Promise}
180+
*/
181+
resume() {
182+
return new Promise((resolve, reject) => {
183+
let project;
184+
let frames = new FrameCollection(this.config).frames
185+
if (project = this.config.get('project')) {
186+
frames = frames.filter(frame => frame.project == project)
187+
}
188+
const last = frames.filter(frame => frame.stop)
189+
.sort((a, b) => -1 * a.stop.localeCompare(b.stop))[0]
190+
if (last) {
191+
this.start(last.project, last.resource.type, last.resource.id)
192+
.then(frames => resolve(frames))
193+
.catch(error => reject(error))
194+
} else {
195+
reject("No recent entry found for project")
196+
}
197+
});
198+
}
199+
177200
/**
178201
*
179202
* @param project

0 commit comments

Comments
 (0)