Skip to content

Commit f44599a

Browse files
authored
Merge pull request #4270 from oscar-escire/Issue/4204
fixed flash and translate problems on statistics
2 parents 3370bda + 3c1d514 commit f44599a

File tree

4 files changed

+7
-43
lines changed

4 files changed

+7
-43
lines changed

src/app/core/statistics/models/usage-report.model.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ export class UsageReport extends HALResource {
3232
id: string;
3333

3434
@autoserializeAs('report-type')
35-
reportType: string;
35+
reportType: string;
3636

3737
@autoserialize
3838
points: Point[];

src/app/statistics-page/statistics-table/statistics-table.component.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,15 @@ <h2 class="m-1">
1111
@for (header of headers; track header) {
1212
<th scope="col"
1313
class="{{header}}-header">
14-
{{ header }}
14+
{{ 'statistics.table.header.' + header | translate }}
1515
</th>
1616
}
1717
</tr>
1818
@for (point of report.points; track point) {
1919
<tr
2020
class="{{point.id}}-data">
2121
<th scope="row" data-test="statistics-label">
22-
{{ getLabel(point) | async }}
22+
{{ point.label }}
2323
</th>
2424
@for (header of headers; track header) {
2525
<td

src/app/statistics-page/statistics-table/statistics-table.component.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,9 @@ describe('StatisticsTableComponent', () => {
8383
expect(de.query(By.css('table'))).toBeTruthy();
8484

8585
expect(de.query(By.css('th.views-header')).nativeElement.innerText)
86-
.toEqual('views');
86+
.toEqual('statistics.table.header.views');
8787
expect(de.query(By.css('th.downloads-header')).nativeElement.innerText)
88-
.toEqual('downloads');
88+
.toEqual('statistics.table.header.downloads');
8989

9090
expect(de.query(By.css('td.item_1-views-data')).nativeElement.innerText)
9191
.toEqual('7');

src/app/statistics-page/statistics-table/statistics-table.component.ts

Lines changed: 2 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -4,27 +4,11 @@ import {
44
Input,
55
OnInit,
66
} from '@angular/core';
7-
import {
8-
TranslateModule,
9-
TranslateService,
10-
} from '@ngx-translate/core';
11-
import {
12-
Observable,
13-
of,
14-
} from 'rxjs';
15-
import { map } from 'rxjs/operators';
7+
import { TranslateModule } from '@ngx-translate/core';
168

179
import { DSONameService } from '../../core/breadcrumbs/dso-name.service';
1810
import { DSpaceObjectDataService } from '../../core/data/dspace-object-data.service';
19-
import {
20-
getFinishedRemoteData,
21-
getRemoteDataPayload,
22-
} from '../../core/shared/operators';
23-
import {
24-
Point,
25-
UsageReport,
26-
} from '../../core/statistics/models/usage-report.model';
27-
import { isEmpty } from '../../shared/empty.util';
11+
import { UsageReport } from '../../core/statistics/models/usage-report.model';
2812

2913
/**
3014
* Component representing a statistics table for a given usage report.
@@ -57,7 +41,6 @@ export class StatisticsTableComponent implements OnInit {
5741
constructor(
5842
protected dsoService: DSpaceObjectDataService,
5943
protected nameService: DSONameService,
60-
private translateService: TranslateService,
6144
) {
6245

6346
}
@@ -68,23 +51,4 @@ export class StatisticsTableComponent implements OnInit {
6851
this.headers = Object.keys(this.report.points[0].values);
6952
}
7053
}
71-
72-
/**
73-
* Get the row label to display for a statistics point.
74-
* @param point the statistics point to get the label for
75-
*/
76-
getLabel(point: Point): Observable<string> {
77-
switch (this.report.reportType) {
78-
case 'TotalVisits':
79-
return this.dsoService.findById(point.id).pipe(
80-
getFinishedRemoteData(),
81-
getRemoteDataPayload(),
82-
map((item) => !isEmpty(item) ? this.nameService.getName(item) : this.translateService.instant('statistics.table.no-name')),
83-
);
84-
case 'TopCities':
85-
case 'topCountries':
86-
default:
87-
return of(point.label);
88-
}
89-
}
9054
}

0 commit comments

Comments
 (0)