Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
4 changes: 3 additions & 1 deletion src/gtt-log.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,10 @@ tasks.log()
frames[date]
.sort((a, b) => a.start.isBefore(b.start) ? -1 : 1)
.forEach(frame => {
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${toHumanReadable(frame.duration)}\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
24 changes: 23 additions & 1 deletion src/gtt-report.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ const Output = {
pdf: require('./output/pdf'),
markdown: require('./output/markdown'),
invoice: require('./output/invoice'),
invoice2: require('./output/invoice2'),
dump: require('./output/dump'),
xlsx: require('./output/xlsx')
};
Expand Down Expand Up @@ -72,8 +73,11 @@ program
.option('--invoiceCurrencyPerHour <number>', 'hourly wage rate on invoice')
.option('--invoiceVAT <number>', 'vat decimal (20% = 0.2)')
.option('--invoiceDate <number>', 'date string')
.option('--invoiceCurrencyMaxUnit <number>', 'rouning invoice total, e.g. 0.01, 0.05 or 1')
.option('--invoiceTimeMaxUnit <number>', 'rounds up invoice times, e.g. 60 rounds every issue per day to 1 minute')
.option('--invoiceCurrencyMaxUnit <number>', 'rounding invoice total, e.g. 0.01, 0.05 or 1')
.option('--invoicePositionText <text>', 'invoice position text')
.option('--invoicePositionExtraText <text>', 'extra invoice position: text')
.option('--invoicePositionExtraValue <number>', 'extra invoice position: value')
.parse(process.argv);

// init helpers
Expand Down Expand Up @@ -140,8 +144,11 @@ config
.set('invoiceCurrencyPerHour', program.opts().invoiceCurrencyPerHour)
.set('invoiceVAT', program.opts().invoiceVAT)
.set('invoiceDate', program.opts().invoiceDate)
.set('invoiceTimeMaxUnit', program.opts().invoiceTimeMaxUnit)
.set('invoiceCurrencyMaxUnit', program.opts().invoiceCurrencyMaxUnit)
.set('invoicePositionText', program.opts().invoicePositionText)
.set('invoicePositionExtraText', program.opts().invoicePositionExtraText)
.set('invoicePositionExtraValue', program.opts().invoicePositionExtraValue)
.set('_createDump', program.opts().output === 'dump');

// date shortcuts
Expand Down Expand Up @@ -308,6 +315,21 @@ new Promise(resolve => {
.then(() => resolve());
}))

// get timelogs
.then(() => new Promise(resolve => {
Cli.list(`${Cli.fetch} Loading timelogs`);

reports
.forEach((report, done) => {
report.getTimelogs()
.catch(error => done(error))
.then(() => done());
})
.catch(error => Cli.x(`could not load timelogs.`, error))
.then(() => Cli.mark())
.then(() => resolve());
}))

// merge reports
.then(() => new Promise(resolve => {
Cli.list(`${Cli.merge} Merging reports`);
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?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
33 changes: 33 additions & 0 deletions src/models/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,39 @@ class base {
}));
}


/**
* query the given path
* @param path
* @param data
* @returns {*}
*/
graphQL(data) {
// remove v4/ from url, add graphql
const path = this.url.substr(0, this.url.length-3) + 'graphql';

let key = base.createDumpKey(path, data);
if (this.config.dump) return this.getDump(key);

return new Promise((resolve, reject) => throttle(() => {
request.post(`${path}`, {
json: true,
body: data,
insecure: this._insecure,
proxy: this._proxy,
resolveWithFullResponse: true,
headers: {
'Authorization': 'Bearer '+this.token,
'Content-Type': 'application/json'
}
}).then(response => {
if (this.config.get('_createDump')) this.setDump(response, key);
resolve(response);
}).catch(e => reject(e));
}));
}


/**
* query the given path
* @param path
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
51 changes: 51 additions & 0 deletions src/models/dayReport.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@

/**
* day model of one item
*/
class dayReport {
constructor(iid, title, spentAt, chargeRatio) {
this.iid = iid;
this.title = title;
this.spentAt = spentAt;
this.chargeRatio = chargeRatio;

this.spent = 0;
this.notes = [];
}

getIid() {
return this.iid;
}

getTitle() {
return this.title;
}
getSpent(invoiceTimeMaxUnit) {
if(!invoiceTimeMaxUnit) {
invoiceTimeMaxUnit = 1.0;
}
return Math.ceil(this.spent / invoiceTimeMaxUnit) * invoiceTimeMaxUnit;
}

getDate() {
return this.spentAt;
}

getNotes() {
return this.notes;
}

addSpent(seconds) {
this.spent += seconds;
}
addNote(note) {
this.notes.push(note);
}
getChargeRatio() {
return this.chargeRatio;
}


}

module.exports = dayReport;
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
Loading