Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
add a note to timeentries
  • Loading branch information
Andreas Müller committed Nov 25, 2022
commit 800b0160b004539e75f28e881f58794209b0ebed
2 changes: 1 addition & 1 deletion src/gtt-log.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ tasks.log()
let toSync = (Math.ceil(frame.duration) - parseInt(_.reduce(frame.notes, (n, m) => (n + m.time), 0))) != 0;
let durationText = toSync ? toHumanReadable(frame.duration).yellow : toHumanReadable(frame.duration);
let issue = frame.resource.new ? `new ${frame.resource.type + ' "' + frame.resource.id.blue}"` : `${(frame.resource.type + ' #' + frame.resource.id).blue}`;
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}`)
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:''}`)
});
});
}
Expand Down
7 changes: 6 additions & 1 deletion src/gtt-start.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ program
.option('-m', 'shorthand for --type=merge_request')
.option('-i', 'shorthand for --type=issue')
.option('--verbose', 'show verbose output')
.option('--note <note>', 'specify note')
.parse(process.argv);

Cli.verbose = program.opts().verbose;
Expand All @@ -27,13 +28,17 @@ if (program.opts().i) {
} else if (program.opts().m) {
type = 'merge_request';
}
let note = null;
if (program.opts().note) {
note = program.opts().note;
}

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

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

tasks.start(project, type, id)
tasks.start(project, type, id, note)
.then(frame => console.log(`Starting project ${config.get('project').magenta} ${type.blue} ${('#' + id).blue} at ${moment().format('HH:mm').green}`))
.catch(error => Cli.error(error));
2 changes: 1 addition & 1 deletion src/gtt-status.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,6 @@ tasks.status()
return;
}

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})`));
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})`));
})
.catch(error => Cli.error('Could not read frames.', error));
6 changes: 3 additions & 3 deletions src/include/tasks.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ class tasks {
return new Promise((resolve, reject) => {
let resource = this.sync.resources[frame.resource.type][frame.resource.id];

resource.createTime(Math.ceil(time), frame._stop)
resource.createTime(Math.ceil(time), frame._stop, frame.note)
.then(() => resource.getNotes())
.then(() => {
if (frame.resource.new) {
Expand Down Expand Up @@ -213,7 +213,7 @@ class tasks {
* @param id
* @returns {Promise}
*/
start(project, type, id) {
start(project, type, id, note) {
this.config.set('project', project);

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

resolve(new Frame(this.config, id, type).startMe());
resolve(new Frame(this.config, id, type, note).startMe());
})
.catch(error => reject(error));
})
Expand Down
13 changes: 10 additions & 3 deletions src/models/baseFrame.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ class baseFrame {
* @param config
* @param id
* @param type
* @param note
*/
constructor(config, id, type) {
constructor(config, id, type, note) {
this.config = config;
this.project = config.get('project');
this.resource = {id, type};
Expand All @@ -24,10 +25,11 @@ class baseFrame {
this._stop = false;
this.timezone = config.get('timezone');
this.notes = [];
this._note = note;
}

static fromJson(config, json) {
let frame = new this(config, json.resource.id, json.resource.type);
let frame = new this(config, json.resource.id, json.resource.type, json.note);
frame.project = json.project;
frame.id = json.id;
frame._start = json.start;
Expand Down Expand Up @@ -68,7 +70,8 @@ class baseFrame {
start: frame._start,
stop: frame._stop,
timezone: frame.timezone,
modified: frame.modified
modified: frame.modified,
note: frame._note,
});
}

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

get note() {
return this._note;
}

/**
* generate a unique id
* @returns {number}
Expand Down
3 changes: 2 additions & 1 deletion src/models/frame.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ class frame extends BaseFrame {
start: this._start,
stop: this._stop,
timezone: this.timezone,
modified: skipModified ? this.modified : moment()
modified: skipModified ? this.modified : moment(),
note: this._note
}, null, "\t"));
}

Expand Down
10 changes: 8 additions & 2 deletions src/models/hasTimes.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,17 @@ class hasTimes extends Base {
* @param time
* @returns {*}
*/
createTime(time, created_at) {
createTime(time, created_at, note) {
if(note === null) {
note = '';
}
else {
note = '\n\n' + note;
}
var date = new Date(created_at);
var spentAt = date.getUTCFullYear()+"-"+(date.getUTCMonth()+1)+"-"+date.getUTCDate();
return this.post(`projects/${this.data.project_id}/${this._type}/${this.iid}/notes`, {
body: '/spend '+Time.toHumanReadable(time, this.config.get('hoursPerDay'), '[%sign][%days>d ][%hours>h ][%minutes>m ][%seconds>s]'+' '+spentAt),
body: '/spend '+Time.toHumanReadable(time, this.config.get('hoursPerDay'), '[%sign][%days>d ][%hours>h ][%minutes>m ][%seconds>s]'+' '+spentAt + note),
});
}

Expand Down