Skip to content

Commit 14be74b

Browse files
Guido Quezadascastillo-jp
authored andcommitted
feat: #571 technology report - custom excel export
1 parent a7c8f59 commit 14be74b

File tree

4 files changed

+117
-35
lines changed

4 files changed

+117
-35
lines changed
Lines changed: 44 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,74 @@
11
[
22
{
33
"id": 1,
4-
"name_technology": "Superman",
4+
"name_technology": "Pascal",
55
"users": [
66
{
77
"id": 1,
8-
"email_user": "[email protected]",
8+
"email_user": "[email protected]",
9+
"time_spent": 30,
10+
"projects": [
11+
{
12+
"id": 1,
13+
"project_name": "Time tracker",
14+
"time_spent": 15
15+
},
16+
{
17+
"id": 2,
18+
"project_name": "New Project",
19+
"time_spent": 10
20+
},
21+
{
22+
"id": 3,
23+
"project_name": "Old Project",
24+
"time_spent": 5
25+
}
26+
]
27+
},
28+
{
29+
"id": 2,
30+
"email_user": "[email protected]",
31+
"time_spent": 20,
32+
"projects": [
33+
{
34+
"id": 1,
35+
"project_name": "Time tracker",
36+
"time_spent": 20
37+
}
38+
]
39+
},
40+
{
41+
"id": 3,
42+
"email_user": "[email protected]",
943
"time_spent": 10,
10-
"project": [
44+
"projects": [
1145
{
1246
"id": 1,
1347
"project_name": "Time tracker",
14-
"time_spent": 8
48+
"time_spent": 10
1549
}
1650
]
1751
}
1852
],
19-
"time_spent": 10
53+
"time_spent": 60
2054
},
2155
{
2256
"id": 2,
23-
"name_technology": "Tor",
57+
"name_technology": "Pascual",
2458
"users": [
2559
{
2660
"id": 1,
27-
"email_user": "junito@gmail.com",
61+
"email_user": "catgirl@gmail.com",
2862
"time_spent": 10,
29-
"project": [
63+
"projects": [
3064
{
3165
"id": 1,
3266
"project_name": "Time tracker",
33-
"time_spent": 8
67+
"time_spent": 10
3468
}
3569
]
3670
}
3771
],
3872
"time_spent": 10
3973
}
40-
]
74+
]

src/app/modules/technology-report/components/technology-report-table/technology-report-table.component.html

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@
99
>
1010
<thead class="thead-blue">
1111
<tr class="d-flex">
12-
<th class="none">Technology</th>
13-
<th class="none">Time spend</th>
12+
<th class="col md-col">Technology</th>
13+
<th class="col md-col">Time spend</th>
14+
<th class="none"></th>
1415
</tr>
1516
</thead>
1617
<app-loading-bar
@@ -19,10 +20,25 @@
1920
<tbody>
2021
<tr
2122
class="d-flex"
22-
*ngFor="let data of technologies"
23+
*ngFor="let tech of technologies"
2324
>
24-
<td class="col md-col">{{ data.name_technology || '' }}</td>
25-
<td class="col lg-col">{{ data.time_spent || ''}}</td>
25+
<td class="col md-col">{{ tech.name_technology || '' }}</td>
26+
<td class="col lg-col">{{ tech.time_spent || ''}}</td>
27+
<td class="none">
28+
<table>
29+
<div *ngFor="let user of tech.users">
30+
<tr
31+
>
32+
<th>{{ user.email_user }}</th>
33+
<th>{{ user.time_spent || '' }}</th>
34+
</tr>
35+
<tr *ngFor="let project of user.projects">
36+
<td>{{ project.project_name }}</td>
37+
<td>{{ project.time_spent || '' }}</td>
38+
</tr>
39+
</div>
40+
</table>
41+
</td>
2642
</tr>
2743
</tbody>
2844
</table>
Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -53,25 +53,8 @@ describe('Reports Page', () => {
5353
fixture.detectChanges();
5454
}));
5555

56-
fit('component should be created', async () => {
56+
it('component should be created', async () => {
5757
expect(component).toBeTruthy();
5858
});
59-
60-
// it('on success load time entries, the report should be populated', () => {
61-
// component.reportDataSource$.subscribe(ds => {
62-
// expect(ds.data).toEqual(state.reportDataSource.data);
63-
// });
64-
// });
65-
66-
// it('after the component is initialized it should initialize the table', () => {
67-
// spyOn(component.dtTrigger, 'next');
68-
// component.ngAfterViewInit();
69-
70-
// expect(component.dtTrigger.next).toHaveBeenCalled();
71-
// });
72-
73-
afterEach(() => {
74-
fixture.destroy();
75-
});
7659
});
7760
});

src/app/modules/technology-report/components/technology-report-table/technology-report-table.component.ts

Lines changed: 51 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,57 @@ export class TechnologyReportTableComponent implements OnInit, OnDestroy, AfterV
4040
}
4141
}
4242
},
43+
customize: (xlsx) => {
44+
const sheet = xlsx.xl.worksheets['sheet1.xml'];
45+
const sheetData = $('sheetData', sheet).clone();
46+
47+
$('sheetData', sheet).empty();
48+
let rowCount = 1;
49+
50+
sheetData.children().each(function(index) {
51+
if (index > 0) {
52+
const row = $(this.outerHTML);
53+
54+
row.attr('r', rowCount);
55+
let colCount = 1;
56+
57+
row.children().each(function() {
58+
const cell = $(this);
59+
let rc = cell.attr('r');
60+
rc = rc.replace(/\d+$/, '') + rowCount;
61+
62+
cell.attr('r', rc);
63+
if (colCount === 3) {
64+
cell.html('');
65+
}
66+
colCount++;
67+
68+
});
69+
const rowa = row[0].outerHTML;
70+
$('sheetData', sheet).append(rowa);
71+
rowCount++;
72+
73+
} else {
74+
const row = $(this.outerHTML);
75+
let colCount = 1;
76+
77+
row.children().each(function() {
78+
const cell = $(this);
79+
if (colCount === 3) {
80+
cell.html('');
81+
}
82+
colCount++;
83+
84+
});
85+
const rowa = row[0].outerHTML;
86+
$('sheetData', sheet).append(rowa);
87+
rowCount++;
88+
89+
}
90+
});
91+
},
4392
text: 'Excel',
44-
filename: `time-entries-${formatDate(new Date(), 'MM_dd_yyyy-HH_mm', 'en')}`
93+
filename: `technologies-${formatDate(new Date(), 'MM_dd_yyyy-HH_mm', 'en')}`
4594
},
4695
{
4796
extend: 'csv',
@@ -55,7 +104,7 @@ export class TechnologyReportTableComponent implements OnInit, OnDestroy, AfterV
55104
}
56105
},
57106
text: 'CSV',
58-
filename: `time-entries-${formatDate(new Date(), 'MM_dd_yyyy-HH_mm', 'en')}`
107+
filename: `technologies-${formatDate(new Date(), 'MM_dd_yyyy-HH_mm', 'en')}`
59108
}
60109
],
61110
responsive: true

0 commit comments

Comments
 (0)