forked from DSpace/dspace-angular
-
Notifications
You must be signed in to change notification settings - Fork 2
VSB-TUO/Display total downloads for each item #961
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
milanmajchrak
merged 4 commits into
customer/vsb-tuo
from
vsb-tuo/display-item-total-downloads
Sep 2, 2025
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -47,5 +47,6 @@ export interface Point { | |
| type: string; | ||
| values: { | ||
| views: number; | ||
| }[]; | ||
| [key: string]: number; | ||
| }; | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
src/app/item-page/simple/field-components/file-section/total-downloads.component.html
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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> |
Empty file.
73 changes: 73 additions & 0 deletions
73
src/app/item-page/simple/field-components/file-section/total-downloads.component.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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({ | ||
milanmajchrak marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| 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 | ||
| } | ||
| }); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.