forked from kriskbx/gitlab-time-tracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathxlsx.js
More file actions
108 lines (85 loc) · 3.08 KB
/
xlsx.js
File metadata and controls
108 lines (85 loc) · 3.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
const _ = require('underscore');
const fs = require('fs');
const path = require('path');
const XLSX = require('xlsx');
const Base = require('./base');
const Cli = require('./../include/cli');
/**
* xlsx output
*/
class xlsx extends Base {
makeStats() {
let stats = [[], []];
_.each(this.stats, (time, name) => {
stats[0].push(name);
stats[1].push(time);
});
if (this.projects.length > 1) {
_.each(this.projects, (time, name) => {
stats[0].push(name);
stats[1].push(time);
});
}
_.each(this.users, (time, name) => {
stats[0].push(name);
stats[1].push(time);
});
this.xlsxStats = XLSX.utils.aoa_to_sheet(stats);
}
makeIssues() {
let issues = [];
issues.push(this.config.get('issueColumns'));
this.report.issues.forEach(issue => issues.push(this.prepare(issue, this.config.get('issueColumns'))));
this.xlsxIssues = XLSX.utils.aoa_to_sheet(issues);
}
makeMergeRequests() {
let mergeRequests = [];
mergeRequests.push(this.config.get('mergeRequestColumns'));
this.report.mergeRequests.forEach(mergeRequest => mergeRequests.push(this.prepare(mergeRequest, this.config.get('mergeRequestColumns'))));
this.xlsxMergeRequests = XLSX.utils.aoa_to_sheet(mergeRequests);
}
makeRecords() {
let times = [];
times.push(this.config.get('recordColumns'));
this.times.forEach(time => times.push(this.prepare(time, this.config.get('recordColumns'))));
this.xlsxRecords = XLSX.utils.aoa_to_sheet(times);
}
toFile(file, resolve) {
let fileName = path.basename(file);
let extName = path.extname(file);
let workbook = XLSX.utils.book_new();
if (this.config.get('report').includes('stats')) {
XLSX.utils.book_append_sheet(workbook, this.xlsxStats, 'Stats');
}
if (this.config.get('report').includes('issues')) {
XLSX.utils.book_append_sheet(workbook, this.xlsxIssues, 'Issues');
}
if (this.config.get('report').includes('merge_requests')) {
XLSX.utils.book_append_sheet(workbook, this.xlsxMergeRequests, 'Merge Requests');
}
if (this.config.get('report').includes('records')) {
XLSX.utils.book_append_sheet(workbook, this.xlsxRecords, 'Records');
}
XLSX.writeFile(workbook, fileName);
resolve();
}
toStdOut() {
Cli.error(`Can't output xlsx to std out`);
}
/**
* prepare the given object by converting numeric
* columns/properties as numbers instead of strings
* on top of what the parent method already does
*
* suboptimally done here to avoid impacts on other outputs
*
* @param obj
* @param columns
* @returns {Array}
*/
prepare(obj = {}, columns = []) {
let formattedObj = super.prepare(obj, columns);
return formattedObj.map(field => isNaN(field) ? field : Number(field));
}
}
module.exports = xlsx;