Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
3 changes: 2 additions & 1 deletion src/app/core/statistics/models/usage-report.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,5 +47,6 @@ export interface Point {
type: string;
values: {
views: number;
}[];
[key: string]: number;
};
}
6 changes: 6 additions & 0 deletions src/app/item-page/item-page.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ import { ItemAlertsComponent } from './alerts/item-alerts.component';
import { ItemVersionsModule } from './versions/item-versions.module';
import { BitstreamRequestACopyPageComponent } from './bitstreams/request-a-copy/bitstream-request-a-copy-page.component';
import { FileSectionComponent } from './simple/field-components/file-section/file-section.component';
import { TotalDownloadsComponent } from './simple/field-components/file-section/total-downloads.component';
import { ItemSharedModule } from './item-shared.module';
import { DsoPageModule } from '../shared/dso-page/dso-page.module';
import { ThemedItemAlertsComponent } from './alerts/themed-item-alerts.component';
Expand Down Expand Up @@ -90,6 +91,7 @@ import { ClarinIdentifierItemFieldComponent } from './simple/field-components/cl
import { ClarinDateItemFieldComponent } from './simple/field-components/clarin-date-item-field/clarin-date-item-field.component';
import { ClarinDescriptionItemFieldComponent } from './simple/field-components/clarin-description-item-field/clarin-description-item-field.component';
import { ClarinFilesSectionComponent } from './clarin-files-section/clarin-files-section.component';
import { UsageReportDataService } from '../core/statistics/usage-report-data.service';

const ENTRY_COMPONENTS = [
// put only entry components that use custom decorator
Expand All @@ -99,6 +101,7 @@ const ENTRY_COMPONENTS = [

const DECLARATIONS = [
FileSectionComponent,
TotalDownloadsComponent,
ThemedFileSectionComponent,
ItemPageComponent,
ThemedItemPageComponent,
Expand Down Expand Up @@ -181,6 +184,9 @@ const DECLARATIONS = [
],
exports: [
...DECLARATIONS,
],
providers: [
UsageReportDataService,
]
})
export class ItemPageModule {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<ds-metadata-field-wrapper [label]="downloadsLabel | translate">
<div class="total-downloads-section">
<div class="total-downloads-count">
<span>{{ totalDownloads }}</span>
</div>
</div>
</ds-metadata-field-wrapper>
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
import { Component, OnInit, Input } from '@angular/core';
import { UsageReportDataService } from 'src/app/core/statistics/usage-report-data.service';
import { catchError } from 'rxjs/operators';
import { of } from 'rxjs';

/**
* Component that displays the total number of downloads for all bitstreams within a DSpace item.
*
* This component fetches download statistics for a given item using its UUID and aggregates
* the download counts from all bitstreams associated with that item. The result is displayed
* as a single total download count.
*/
@Component({
selector: 'ds-total-downloads',
templateUrl: './total-downloads.component.html',
styleUrls: ['./total-downloads.component.scss']
})
export class TotalDownloadsComponent implements OnInit {

/**
* The UUID of the DSpace item for which to fetch download statistics.
*/
@Input() itemUuid!: string;

/**
* The total number of downloads across all bitstreams for the item.
* Defaults to 0 and will show 0 if no data is available or an error occurs.
*/
totalDownloads: number = 0;

/**
* The translation key for the downloadsLabel displayed alongside the download count.
*/
readonly downloadsLabel = 'item.page.files.downloads';


constructor(private usageReportDataService: UsageReportDataService) { }

/**
* Fetches the total download statistics for the item specified by itemUuid.
* The component will:
* 1. Call the UsageReportDataService with the item UUID and 'TotalDownloads' report type
* 2. Aggregate all download counts (views) from all bitstreams in the response
* 3. Set the totalDownloads property with the sum
* 4. Handle errors gracefully by setting totalDownloads to 0 and logging the error
*
* @throws Will log an error to console if the API call fails, but won't throw an exception
*/
ngOnInit(): void {
if (!this.itemUuid) {
return;
}

const reportType = 'TotalDownloads';
this.usageReportDataService.getStatistic(this.itemUuid, reportType)
.pipe(
catchError(error => {
console.error('Failed to fetch total downloads statistics:', error);
return of(null);
})
)
.subscribe(report => {
if (report) {
this.totalDownloads = report.points.reduce((total, point) => {
const views = point.values.views || 0;
return total + views;
}, 0);
} else {
this.totalDownloads = 0; // Show 0 instead of null when no data is available
}
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@
<div *ngIf="mediaViewer.image || mediaViewer.video" class="mb-2">
<ds-themed-media-viewer [item]="object"></ds-themed-media-viewer>
</div>
<ds-themed-item-page-file-section [item]="object"></ds-themed-item-page-file-section>
<ds-themed-item-page-file-section [item]="object"></ds-themed-item-page-file-section>
<ds-total-downloads [itemUuid]="object.uuid"></ds-total-downloads>
<ds-item-page-date-field [item]="object"></ds-item-page-date-field>
<ds-themed-metadata-representation-list class="ds-item-page-mixed-author-field"
[parentItem]="object"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@
<div *ngIf="mediaViewer.image || mediaViewer.video" class="mb-2">
<ds-themed-media-viewer [item]="object"></ds-themed-media-viewer>
</div>
<ds-themed-item-page-file-section [item]="object"></ds-themed-item-page-file-section>
<ds-themed-item-page-file-section [item]="object"></ds-themed-item-page-file-section>
<ds-total-downloads [itemUuid]="object.uuid"></ds-total-downloads>
<ds-item-page-date-field [item]="object"></ds-item-page-date-field>
<ds-themed-metadata-representation-list class="ds-item-page-mixed-author-field"
[parentItem]="object"
Expand Down
5 changes: 4 additions & 1 deletion src/assets/i18n/cs.json5
Original file line number Diff line number Diff line change
Expand Up @@ -3794,6 +3794,9 @@
// "item.page.files": "Files",
"item.page.files": "Soubory",

// "item.page.files.downloads": "Downloads",
"item.page.files.downloads": "Stažení",

// "item.page.filesection.description": "Description:",
"item.page.filesection.description": "Popis:",

Expand Down Expand Up @@ -11542,4 +11545,4 @@

// "clarin-license-agreement-page.download-error": "An error occurred while downloading the file. Please try again later.",
"clarin-license-agreement-page.download-error": "Při stahování souboru došlo k chybě. Zkuste to prosím znovu později.",
}
}
4 changes: 3 additions & 1 deletion src/assets/i18n/en.json5
Original file line number Diff line number Diff line change
Expand Up @@ -2529,6 +2529,8 @@

"item.page.files": "Files",

"item.page.files.downloads": "Downloads",

"item.page.filesection.description": "Description:",

"item.page.filesection.download": "Download",
Expand Down Expand Up @@ -6220,4 +6222,4 @@
"change.submitter.page.items.name.message": "Item's name: ",

"clarin-license-agreement-page.download-error": "An error occurred while downloading the file. Please try again later.",
}
}
Loading