Skip to content
Closed
Show file tree
Hide file tree
Changes from 13 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
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ <h2 class="m-1">
<tbody>

<tr>
<td></td>
<th scope="col">{{ objectHeaderLabel }}</th>
<th scope="col"
*ngFor="let header of headers"
class="{{header}}-header">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,4 +97,31 @@ describe('StatisticsTableComponent', () => {
.toEqual('8');
});
});

describe('getObjectHeaderLabel', () => {

it('should return the correct label for TotalVisits', () => {
expect(component.getObjectHeaderLabel('TotalVisits')).toEqual('statistics.table.header.TotalVisits');
});

it('should return the correct label for TotalVisitsPerMonth', () => {
expect(component.getObjectHeaderLabel('TotalVisitsPerMonth')).toEqual('statistics.table.header.TotalVisitsPerMonth');
});

it('should return the correct label for TotalDownloads', () => {
expect(component.getObjectHeaderLabel('TotalDownloads')).toEqual('statistics.table.header.TotalDownloads');
});

it('should return the correct label for TopCities', () => {
expect(component.getObjectHeaderLabel('TopCities')).toEqual('statistics.table.header.TopCities');
});

it('should return the correct label for topCountries', () => {
expect(component.getObjectHeaderLabel('topCountries')).toEqual('statistics.table.header.topCountries');
});

it('should return an empty string for unknown report types', () => {
expect(component.getObjectHeaderLabel('UnknownType')).toEqual('');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is where your tests are failing. It looks like you previously were expecting getObjectHeaderLabel() to return an empty string if you passed it an unrecognized type.

This isn't going to work the same anymore, because you are always just returning statistics.table.header.[type] in the code in getObjectHeaderLabel(). So, I think you can just remove this test... all types will now be looked up in the i18n files. This seems appropriate though because it allows for adding new report types without having to modify your code.

});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,11 @@ export class StatisticsTableComponent implements OnInit {
*/
headers: string[];

/**
* Object header label
*/
objectHeaderLabel: string;

constructor(
protected dsoService: DSpaceObjectDataService,
protected nameService: DSONameService,
Expand All @@ -71,6 +76,7 @@ export class StatisticsTableComponent implements OnInit {
if (this.hasData) {
this.headers = Object.keys(this.report.points[0].values);
}
this.objectHeaderLabel = this.getObjectHeaderLabel(this.report.reportType);
}

/**
Expand All @@ -91,4 +97,25 @@ export class StatisticsTableComponent implements OnInit {
return of(point.label);
}
}

/**
* Defines a dynamic label for the object column
* @param reportType
*/
getObjectHeaderLabel(reportType: string): string {
switch (reportType) {
case 'TotalVisits':
return this.translateService.instant('statistics.table.header.TotalVisits');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you can get rid of this entire switch if you just append the reportType similar to this:

return this.translateService.instant('statistics.table.header.' + reportType);

That way, if new reports are added, we don't need to add more cases to this switch.

case 'TotalVisitsPerMonth':
return this.translateService.instant('statistics.table.header.TotalVisitsPerMonth');
case 'TotalDownloads':
return this.translateService.instant('statistics.table.header.TotalDownloads');
case 'TopCities':
return this.translateService.instant('statistics.table.header.TopCities');
case 'topCountries':
return this.translateService.instant('statistics.table.header.topCountries');
default:
return '';
}
}
}
10 changes: 10 additions & 0 deletions src/assets/i18n/en.json5
Original file line number Diff line number Diff line change
Expand Up @@ -6757,4 +6757,14 @@
"register-page.registration.aria.label": "Enter your e-mail address",

"forgot-email.form.aria.label": "Enter your e-mail address",

"statistics.table.header.TotalVisits": "Object",

"statistics.table.header.TotalVisitsMonth": "Month",

"statistics.table.header.TotalDownloads": "Downloads",

"statistics.table.header.TopCities": "Cities",

"statistics.table.header.topCountries": "Countries",
}
15 changes: 15 additions & 0 deletions src/assets/i18n/es.json5
Original file line number Diff line number Diff line change
Expand Up @@ -8142,4 +8142,19 @@

// "forgot-email.form.aria.label": "Enter your e-mail address",
"forgot-email.form.aria.label": "Introduzca su dirección de correo electrónico",

// "statistics.table.header.TotalVisits": "Object",
"statistics.table.header.TotalVisits": "Objeto",

// "statistics.table.header.TotalVisitsMonth": "Month",
"statistics.table.header.TotalVisitsMonth": "Mes",

// "statistics.table.header.TotalDownloads": "Downloads",
"statistics.table.header.TotalDownloads": "Descargas",

// "statistics.table.header.TopCities": "Cities",
"statistics.table.header.TopCities": "Ciudades",

// "statistics.table.header.topCountries": "Countries",
"statistics.table.header.topCountries": "Países",
}
15 changes: 15 additions & 0 deletions src/assets/i18n/pt-BR.json5
Original file line number Diff line number Diff line change
Expand Up @@ -10240,4 +10240,19 @@

// "forgot-email.form.aria.label": "Enter your e-mail address",
"forgot-email.form.aria.label": "Digite seu e-mail",

// "statistics.table.header.TotalVisits": "Object",
"statistics.table.header.TotalVisits": "Objeto",

// "statistics.table.header.TotalVisitsMonth": "Month",
"statistics.table.header.TotalVisitsMonth": "Mês",

// "statistics.table.header.TotalDownloads": "Downloads",
"statistics.table.header.TotalDownloads": "Downloads",

// "statistics.table.header.TopCities": "Cities",
"statistics.table.header.TopCities": "Cidades",

// "statistics.table.header.topCountries": "Countries",
"statistics.table.header.topCountries": "Países",
}
Loading