@@ -7,9 +7,12 @@ import { BehaviorSubject, of } from 'rxjs';
77/**
88 * Component that displays the total number of downloads for all bitstreams within a DSpace item.
99 *
10- * This component fetches download statistics for a given item using its UUID and aggregates
11- * the download counts from all bitstreams associated with that item. The result is displayed
12- * as a single total download count.
10+ * This component checks the 'item.view.total.downloads.enabled' configuration property
11+ * to determine if download statistics should be displayed. If enabled, it fetches download
12+ * statistics for a given item using its UUID and aggregates the download counts from all
13+ * bitstreams associated with that item. The result is displayed as a single total download count.
14+ *
15+ * If the configuration is disabled or set to 'false', the component will not be displayed.
1316 */
1417@Component ( {
1518 selector : 'ds-total-downloads' ,
@@ -31,7 +34,8 @@ export class TotalDownloadsComponent implements OnInit {
3134
3235 /**
3336 * Flag indicating whether the total downloads feature is enabled in the configuration.
34- * Defaults to false to hide downloads unless explicitly enabled in configuration.
37+ * Uses BehaviorSubject to allow reactive updates. Defaults to false and will only be
38+ * set to true if the configuration explicitly contains 'true' value.
3539 */
3640 totalDownloadsEnabled = new BehaviorSubject < boolean > ( false ) ;
3741
@@ -51,11 +55,11 @@ export class TotalDownloadsComponent implements OnInit {
5155 * and if enabled, fetches the total download statistics for the item specified by itemUuid.
5256 * The component will:
5357 * 1. Check the 'item.view.total.downloads.enabled' configuration property
54- * 2. If enabled (configuration value is 'true'), call the UsageReportDataService,
55- * if config is not found, defaults to false
58+ * 2. If enabled (configuration value is explicitly 'true'), call the UsageReportDataService
59+ * If configuration is not found or fails to load , defaults to false (disabled)
5660 * 3. Aggregate all download counts (views) from all bitstreams in the response
5761 * 4. Set the totalDownloads property with the sum
58- * 5. Handle errors gracefully by setting totalDownloads to 0 and logging the error
62+ * 5. Handle errors gracefully by returning null and logging the error
5963 *
6064 * @throws Will log an error to console if the API call fails, but won't throw an exception
6165 */
@@ -69,20 +73,20 @@ export class TotalDownloadsComponent implements OnInit {
6973 . pipe (
7074 catchError ( error => {
7175 console . error ( 'Failed to fetch total downloads configuration:' , error ) ;
72- // Default to true if configuration cannot be retrieved
76+ // Default to false if configuration cannot be retrieved
7377 return of ( null ) ;
7478 } )
7579 )
7680 . subscribe ( configData => {
77- // Extract configuration value, default to 'true ' if not found
81+ // Extract configuration value, default to 'false ' if not found
7882 const itemViewTotalDownloadsEnabled = configData ?. payload ?. values ?. [ 0 ] ;
7983 this . totalDownloadsEnabled . next ( itemViewTotalDownloadsEnabled === 'true' ) ;
8084
8185 // Only fetch download statistics if the feature is enabled
8286 if ( this . totalDownloadsEnabled . value ) {
8387 this . fetchDownloadStatistics ( ) ;
8488 } else {
85- this . totalDownloads = 0 ; // Ensure it's 0 when disabled
89+ this . totalDownloads = null ; // Ensure it's null when disabled
8690 }
8791 } ) ;
8892 }
0 commit comments