11import { Component , Input , OnInit } from '@angular/core' ;
22import { Item } from '../../core/shared/item.model' ;
3- import { getAllSucceededRemoteListPayload } from '../../core/shared/operators' ;
3+ import { getAllSucceededRemoteListPayload , getFirstSucceededRemoteDataPayload } from '../../core/shared/operators' ;
44import { getItemPageRoute } from '../item-page-routing-paths' ;
55import { MetadataBitstream } from '../../core/metadata/metadata-bitstream.model' ;
66import { RegistryService } from '../../core/registry/registry.service' ;
77import { Router } from '@angular/router' ;
88import { HALEndpointService } from '../../core/shared/hal-endpoint.service' ;
9+ import { ConfigurationDataService } from '../../core/data/configuration-data.service' ;
10+ import { BehaviorSubject } from 'rxjs' ;
911
1012@Component ( {
1113 selector : 'ds-clarin-files-section' ,
@@ -44,28 +46,48 @@ export class ClarinFilesSectionComponent implements OnInit {
4446 /**
4547 * total size of list of files uploaded by users to this item
4648 */
47- totalFileSizes : number ;
49+ totalFileSizes : BehaviorSubject < number > = new BehaviorSubject < number > ( - 1 ) ;
4850
4951 /**
5052 * list of files uploaded by users to this item
5153 */
52- listOfFiles : MetadataBitstream [ ] ;
54+ listOfFiles : BehaviorSubject < MetadataBitstream [ ] > = new BehaviorSubject < MetadataBitstream [ ] > ( [ ] ) ;
55+
56+ /**
57+ * min file size to show `Download all ZIP` button, this value is loaded from the configuration property
58+ * `download.all.alert.min.file.size`
59+ */
60+ downloadZipMinFileSize : BehaviorSubject < number > = new BehaviorSubject < number > ( - 1 ) ;
61+
62+ /**
63+ * max file size to show `Download all ZIP` button, this value is loaded from the configuration property
64+ * `download.all.limit.max.file.size`
65+ */
66+ downloadZipMaxFileSize : BehaviorSubject < number > = new BehaviorSubject < number > ( - 1 ) ;
67+
68+ /**
69+ * min count of files to show `Download all ZIP` button, this value is loaded from the configuration property
70+ * `download.all.limit.min.file.count`
71+ */
72+ downloadZipMinFileCount : BehaviorSubject < number > = new BehaviorSubject < number > ( - 1 ) ;
5373
5474
5575 constructor ( protected registryService : RegistryService ,
5676 protected router : Router ,
57- protected halService : HALEndpointService ) {
77+ protected halService : HALEndpointService ,
78+ protected configurationService : ConfigurationDataService ) {
5879 }
5980
6081 ngOnInit ( ) : void {
6182 this . registryService
6283 . getMetadataBitstream ( this . itemHandle , 'ORIGINAL,TEXT,THUMBNAIL' )
6384 . pipe ( getAllSucceededRemoteListPayload ( ) )
6485 . subscribe ( ( data : MetadataBitstream [ ] ) => {
65- this . listOfFiles = data ;
86+ this . listOfFiles . next ( data ) ;
6687 this . generateCurlCommand ( ) ;
67- this . sumFileSizes ( ) ;
6888 } ) ;
89+ this . totalFileSizes . next ( Number ( this . item . firstMetadataValue ( 'local.files.size' ) ) ) ;
90+ this . loadDownloadZipConfigProperties ( ) ;
6991 }
7092
7193 setCommandline ( ) {
@@ -77,12 +99,7 @@ export class ClarinFilesSectionComponent implements OnInit {
7799 }
78100
79101 generateCurlCommand ( ) {
80- const fileNames = this . listOfFiles . map ( ( file : MetadataBitstream ) => {
81- // Show `Download All Files` only if there are more files.
82- if ( this . listOfFiles . length > 1 ) {
83- this . canDownloadAllFiles = true ;
84- }
85-
102+ const fileNames = this . listOfFiles . value . map ( ( file : MetadataBitstream ) => {
86103 if ( file . canPreview ) {
87104 this . canShowCurlDownload = true ;
88105 }
@@ -95,11 +112,29 @@ export class ClarinFilesSectionComponent implements OnInit {
95112 } /{${ fileNames . join ( ',' ) } }`;
96113 }
97114
98- sumFileSizes ( ) {
99- let totalBytes = 0 ;
100- this . listOfFiles . forEach ( ( file ) => {
101- totalBytes += file . fileSize ;
102- } ) ;
103- this . totalFileSizes = totalBytes ;
115+ loadDownloadZipConfigProperties ( ) {
116+ this . configurationService . findByPropertyName ( 'download.all.limit.min.file.count' )
117+ . pipe (
118+ getFirstSucceededRemoteDataPayload ( )
119+ )
120+ . subscribe ( ( config ) => {
121+ this . downloadZipMinFileCount . next ( Number ( config . values [ 0 ] ) ) ;
122+ } ) ;
123+
124+ this . configurationService . findByPropertyName ( 'download.all.limit.max.file.size' )
125+ . pipe (
126+ getFirstSucceededRemoteDataPayload ( )
127+ )
128+ . subscribe ( ( config ) => {
129+ this . downloadZipMaxFileSize . next ( Number ( config . values [ 0 ] ) ) ;
130+ } ) ;
131+
132+ this . configurationService . findByPropertyName ( 'download.all.alert.min.file.size' )
133+ . pipe (
134+ getFirstSucceededRemoteDataPayload ( )
135+ )
136+ . subscribe ( ( config ) => {
137+ this . downloadZipMinFileSize . next ( Number ( config . values [ 0 ] ) ) ;
138+ } ) ;
104139 }
105140}
0 commit comments