Skip to content

Commit 64186d6

Browse files
authored
Merge pull request #23 from ndu2/develop
Develop
2 parents 3516aff + 8862152 commit 64186d6

File tree

15 files changed

+658
-34
lines changed

15 files changed

+658
-34
lines changed

src/gtt-log.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,10 @@ tasks.log()
4646
frames[date]
4747
.sort((a, b) => a.start.isBefore(b.start) ? -1 : 1)
4848
.forEach(frame => {
49+
let toSync = (Math.ceil(frame.duration) - parseInt(_.reduce(frame.notes, (n, m) => (n + m.time), 0))) != 0;
50+
let durationText = toSync ? toHumanReadable(frame.duration).yellow : toHumanReadable(frame.duration);
4951
let issue = frame.resource.new ? `new ${frame.resource.type + ' "' + frame.resource.id.blue}"` : `${(frame.resource.type + ' #' + frame.resource.id).blue}`;
50-
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}`)
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:''}`)
5153
});
5254
});
5355
}

src/gtt-report.js

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ const Output = {
1515
pdf: require('./output/pdf'),
1616
markdown: require('./output/markdown'),
1717
invoice: require('./output/invoice'),
18+
invoice2: require('./output/invoice2'),
1819
dump: require('./output/dump'),
1920
xlsx: require('./output/xlsx')
2021
};
@@ -72,8 +73,11 @@ program
7273
.option('--invoiceCurrencyPerHour <number>', 'hourly wage rate on invoice')
7374
.option('--invoiceVAT <number>', 'vat decimal (20% = 0.2)')
7475
.option('--invoiceDate <number>', 'date string')
75-
.option('--invoiceCurrencyMaxUnit <number>', 'rouning invoice total, e.g. 0.01, 0.05 or 1')
76+
.option('--invoiceTimeMaxUnit <number>', 'rounds up invoice times, e.g. 60 rounds every issue per day to 1 minute')
77+
.option('--invoiceCurrencyMaxUnit <number>', 'rounding invoice total, e.g. 0.01, 0.05 or 1')
7678
.option('--invoicePositionText <text>', 'invoice position text')
79+
.option('--invoicePositionExtraText <text>', 'extra invoice position: text')
80+
.option('--invoicePositionExtraValue <number>', 'extra invoice position: value')
7781
.parse(process.argv);
7882

7983
// init helpers
@@ -140,8 +144,11 @@ config
140144
.set('invoiceCurrencyPerHour', program.opts().invoiceCurrencyPerHour)
141145
.set('invoiceVAT', program.opts().invoiceVAT)
142146
.set('invoiceDate', program.opts().invoiceDate)
147+
.set('invoiceTimeMaxUnit', program.opts().invoiceTimeMaxUnit)
143148
.set('invoiceCurrencyMaxUnit', program.opts().invoiceCurrencyMaxUnit)
144149
.set('invoicePositionText', program.opts().invoicePositionText)
150+
.set('invoicePositionExtraText', program.opts().invoicePositionExtraText)
151+
.set('invoicePositionExtraValue', program.opts().invoicePositionExtraValue)
145152
.set('_createDump', program.opts().output === 'dump');
146153

147154
// date shortcuts
@@ -308,6 +315,21 @@ new Promise(resolve => {
308315
.then(() => resolve());
309316
}))
310317

318+
// get timelogs
319+
.then(() => new Promise(resolve => {
320+
Cli.list(`${Cli.fetch} Loading timelogs`);
321+
322+
reports
323+
.forEach((report, done) => {
324+
report.getTimelogs()
325+
.catch(error => done(error))
326+
.then(() => done());
327+
})
328+
.catch(error => Cli.x(`could not load timelogs.`, error))
329+
.then(() => Cli.mark())
330+
.then(() => resolve());
331+
}))
332+
311333
// merge reports
312334
.then(() => new Promise(resolve => {
313335
Cli.list(`${Cli.merge} Merging reports`);

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?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/base.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,39 @@ class base {
5353
}));
5454
}
5555

56+
57+
/**
58+
* query the given path
59+
* @param path
60+
* @param data
61+
* @returns {*}
62+
*/
63+
graphQL(data) {
64+
// remove v4/ from url, add graphql
65+
const path = this.url.substr(0, this.url.length-3) + 'graphql';
66+
67+
let key = base.createDumpKey(path, data);
68+
if (this.config.dump) return this.getDump(key);
69+
70+
return new Promise((resolve, reject) => throttle(() => {
71+
request.post(`${path}`, {
72+
json: true,
73+
body: data,
74+
insecure: this._insecure,
75+
proxy: this._proxy,
76+
resolveWithFullResponse: true,
77+
headers: {
78+
'Authorization': 'Bearer '+this.token,
79+
'Content-Type': 'application/json'
80+
}
81+
}).then(response => {
82+
if (this.config.get('_createDump')) this.setDump(response, key);
83+
resolve(response);
84+
}).catch(e => reject(e));
85+
}));
86+
}
87+
88+
5689
/**
5790
* query the given path
5891
* @param path

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/dayReport.js

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
2+
/**
3+
* day model of one item
4+
*/
5+
class dayReport {
6+
constructor(iid, title, spentAt, chargeRatio) {
7+
this.iid = iid;
8+
this.title = title;
9+
this.spentAt = spentAt;
10+
this.chargeRatio = chargeRatio;
11+
12+
this.spent = 0;
13+
this.notes = [];
14+
}
15+
16+
getIid() {
17+
return this.iid;
18+
}
19+
20+
getTitle() {
21+
return this.title;
22+
}
23+
getSpent(invoiceTimeMaxUnit) {
24+
if(!invoiceTimeMaxUnit) {
25+
invoiceTimeMaxUnit = 1.0;
26+
}
27+
return Math.ceil(this.spent / invoiceTimeMaxUnit) * invoiceTimeMaxUnit;
28+
}
29+
30+
getDate() {
31+
return this.spentAt;
32+
}
33+
34+
getNotes() {
35+
return this.notes;
36+
}
37+
38+
addSpent(seconds) {
39+
this.spent += seconds;
40+
}
41+
addNote(note) {
42+
this.notes.push(note);
43+
}
44+
getChargeRatio() {
45+
return this.chargeRatio;
46+
}
47+
48+
49+
}
50+
51+
module.exports = dayReport;

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

0 commit comments

Comments
 (0)