Skip to content

Commit 800b016

Browse files
author
Andreas Müller
committed
add a note to timeentries
1 parent 694fafa commit 800b016

File tree

7 files changed

+31
-12
lines changed

7 files changed

+31
-12
lines changed

src/gtt-log.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ tasks.log()
4949
let toSync = (Math.ceil(frame.duration) - parseInt(_.reduce(frame.notes, (n, m) => (n + m.time), 0))) != 0;
5050
let durationText = toSync ? toHumanReadable(frame.duration).yellow : toHumanReadable(frame.duration);
5151
let issue = frame.resource.new ? `new ${frame.resource.type + ' "' + frame.resource.id.blue}"` : `${(frame.resource.type + ' #' + frame.resource.id).blue}`;
52-
console.log(` ${frame.id} ${frame.start.clone().format('HH:mm').green} to ${frame.stop.clone().format('HH:mm').green}\t${durationText}\t\t${frame.project.magenta}\t\t${issue}`)
52+
console.log(` ${frame.id} ${frame.start.clone().format('HH:mm').green} to ${frame.stop.clone().format('HH:mm').green}\t${durationText}\t\t${frame.project.magenta}\t\t${issue}\t\t${frame.note!=null?frame.note:''}`)
5353
});
5454
});
5555
}

src/gtt-start.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ program
1212
.option('-m', 'shorthand for --type=merge_request')
1313
.option('-i', 'shorthand for --type=issue')
1414
.option('--verbose', 'show verbose output')
15+
.option('--note <note>', 'specify note')
1516
.parse(process.argv);
1617

1718
Cli.verbose = program.opts().verbose;
@@ -27,13 +28,17 @@ if (program.opts().i) {
2728
} else if (program.opts().m) {
2829
type = 'merge_request';
2930
}
31+
let note = null;
32+
if (program.opts().note) {
33+
note = program.opts().note;
34+
}
3035

3136
if (program.args.length < 2 && !config.get('project'))
3237
Cli.error('No project set');
3338

3439
if (!id)
3540
Cli.error('Wrong or missing issue/merge_request id');
3641

37-
tasks.start(project, type, id)
42+
tasks.start(project, type, id, note)
3843
.then(frame => console.log(`Starting project ${config.get('project').magenta} ${type.blue} ${('#' + id).blue} at ${moment().format('HH:mm').green}`))
3944
.catch(error => Cli.error(error));

src/gtt-status.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,6 @@ tasks.status()
2222
return;
2323
}
2424

25-
frames.forEach(frame => console.log(`Project ${frame.project.magenta} ${frame.resource.type.blue} ${('#' + frame.resource.id).blue} is running, started ${moment(frame.start).fromNow().green} (id: ${frame.id})`));
25+
frames.forEach(frame => console.log(`Project ${frame.project.magenta} ${frame.resource.type.blue} ${('#' + frame.resource.id).blue} "${frame.note}" is running, started ${moment(frame.start).fromNow().green} (id: ${frame.id})`));
2626
})
2727
.catch(error => Cli.error('Could not read frames.', error));

src/include/tasks.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ class tasks {
117117
return new Promise((resolve, reject) => {
118118
let resource = this.sync.resources[frame.resource.type][frame.resource.id];
119119

120-
resource.createTime(Math.ceil(time), frame._stop)
120+
resource.createTime(Math.ceil(time), frame._stop, frame.note)
121121
.then(() => resource.getNotes())
122122
.then(() => {
123123
if (frame.resource.new) {
@@ -213,7 +213,7 @@ class tasks {
213213
* @param id
214214
* @returns {Promise}
215215
*/
216-
start(project, type, id) {
216+
start(project, type, id, note) {
217217
this.config.set('project', project);
218218

219219
return new Promise((resolve, reject) => {
@@ -222,7 +222,7 @@ class tasks {
222222
if (frames.length > 0)
223223
return reject("Already running. Please stop it first with 'gtt stop'.");
224224

225-
resolve(new Frame(this.config, id, type).startMe());
225+
resolve(new Frame(this.config, id, type, note).startMe());
226226
})
227227
.catch(error => reject(error));
228228
})

src/models/baseFrame.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,9 @@ class baseFrame {
1010
* @param config
1111
* @param id
1212
* @param type
13+
* @param note
1314
*/
14-
constructor(config, id, type) {
15+
constructor(config, id, type, note) {
1516
this.config = config;
1617
this.project = config.get('project');
1718
this.resource = {id, type};
@@ -24,10 +25,11 @@ class baseFrame {
2425
this._stop = false;
2526
this.timezone = config.get('timezone');
2627
this.notes = [];
28+
this._note = note;
2729
}
2830

2931
static fromJson(config, json) {
30-
let frame = new this(config, json.resource.id, json.resource.type);
32+
let frame = new this(config, json.resource.id, json.resource.type, json.note);
3133
frame.project = json.project;
3234
frame.id = json.id;
3335
frame._start = json.start;
@@ -68,7 +70,8 @@ class baseFrame {
6870
start: frame._start,
6971
stop: frame._stop,
7072
timezone: frame.timezone,
71-
modified: frame.modified
73+
modified: frame.modified,
74+
note: frame._note,
7275
});
7376
}
7477

@@ -88,6 +91,10 @@ class baseFrame {
8891
return this.timezone ? this._stop ? moment(this._stop).tz(this.timezone) : false : (this._stop ? moment(this._stop) : false );
8992
}
9093

94+
get note() {
95+
return this._note;
96+
}
97+
9198
/**
9299
* generate a unique id
93100
* @returns {number}

src/models/frame.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ class frame extends BaseFrame {
4242
start: this._start,
4343
stop: this._stop,
4444
timezone: this.timezone,
45-
modified: skipModified ? this.modified : moment()
45+
modified: skipModified ? this.modified : moment(),
46+
note: this._note
4647
}, null, "\t"));
4748
}
4849

src/models/hasTimes.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,17 @@ class hasTimes extends Base {
2424
* @param time
2525
* @returns {*}
2626
*/
27-
createTime(time, created_at) {
27+
createTime(time, created_at, note) {
28+
if(note === null) {
29+
note = '';
30+
}
31+
else {
32+
note = '\n\n' + note;
33+
}
2834
var date = new Date(created_at);
2935
var spentAt = date.getUTCFullYear()+"-"+(date.getUTCMonth()+1)+"-"+date.getUTCDate();
3036
return this.post(`projects/${this.data.project_id}/${this._type}/${this.iid}/notes`, {
31-
body: '/spend '+Time.toHumanReadable(time, this.config.get('hoursPerDay'), '[%sign][%days>d ][%hours>h ][%minutes>m ][%seconds>s]'+' '+spentAt),
37+
body: '/spend '+Time.toHumanReadable(time, this.config.get('hoursPerDay'), '[%sign][%days>d ][%hours>h ][%minutes>m ][%seconds>s]'+' '+spentAt + note),
3238
});
3339
}
3440

0 commit comments

Comments
 (0)