forked from DSpace/dspace-angular
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathclarin-files-section.component.ts
More file actions
141 lines (118 loc) · 4.56 KB
/
Copy pathclarin-files-section.component.ts
File metadata and controls
141 lines (118 loc) · 4.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
import { Component, Input, OnInit } from '@angular/core';
import { Item } from '../../core/shared/item.model';
import { getAllSucceededRemoteListPayload, getFirstSucceededRemoteDataPayload } from '../../core/shared/operators';
import { getItemPageRoute } from '../item-page-routing-paths';
import { MetadataBitstream } from '../../core/metadata/metadata-bitstream.model';
import { RegistryService } from '../../core/registry/registry.service';
import { Router } from '@angular/router';
import { HALEndpointService } from '../../core/shared/hal-endpoint.service';
import { ConfigurationDataService } from '../../core/data/configuration-data.service';
import { BehaviorSubject } from 'rxjs';
@Component({
selector: 'ds-clarin-files-section',
templateUrl: './clarin-files-section.component.html',
styleUrls: ['./clarin-files-section.component.scss']
})
export class ClarinFilesSectionComponent implements OnInit {
/**
* The item to display files for
*/
@Input() item: Item;
/**
* handle of the current item
*/
@Input() itemHandle: string;
canShowCurlDownload = false;
/**
* If download by command button is click, the command line will be shown
*/
isCommandLineVisible = false;
/**
* command for the download command feature
*/
command: string;
/**
* determine to show download all zip button or not
*/
canDownloadAllFiles = false;
/**
* total size of list of files uploaded by users to this item
*/
totalFileSizes: BehaviorSubject<number> = new BehaviorSubject<number>(-1);
/**
* list of files uploaded by users to this item
*/
listOfFiles: BehaviorSubject<MetadataBitstream[]> = new BehaviorSubject<MetadataBitstream[]>([]);
/**
* min file size to show `Download all ZIP` button, this value is loaded from the configuration property
* `download.all.alert.min.file.size`
*/
downloadZipMinFileSize: BehaviorSubject<number> = new BehaviorSubject<number>(-1);
/**
* max file size to show `Download all ZIP` button, this value is loaded from the configuration property
* `download.all.limit.max.file.size`
*/
downloadZipMaxFileSize: BehaviorSubject<number> = new BehaviorSubject<number>(-1);
/**
* min count of files to show `Download all ZIP` button, this value is loaded from the configuration property
* `download.all.limit.min.file.count`
*/
downloadZipMinFileCount: BehaviorSubject<number> = new BehaviorSubject<number>(-1);
constructor(protected registryService: RegistryService,
protected router: Router,
protected halService: HALEndpointService,
protected configurationService: ConfigurationDataService) {
}
ngOnInit(): void {
this.registryService
.getMetadataBitstream(this.itemHandle, 'ORIGINAL')
.pipe(getAllSucceededRemoteListPayload())
.subscribe((data: MetadataBitstream[]) => {
this.listOfFiles.next(data);
this.generateCurlCommand();
});
this.totalFileSizes.next(Number(this.item.firstMetadataValue('local.files.size')));
this.loadDownloadZipConfigProperties();
}
setCommandline() {
this.isCommandLineVisible = !this.isCommandLineVisible;
}
downloadFiles() {
void this.router.navigate([getItemPageRoute(this.item), 'download', 'zip']);
}
generateCurlCommand() {
const fileNames = this.listOfFiles.value.map((file: MetadataBitstream) => {
if (file.canPreview) {
this.canShowCurlDownload = true;
}
return file.name;
});
// Generate curl command for individual bitstream downloads
const baseUrl = `${this.halService.getRootHref()}/bitstream/${this.itemHandle}`;
const fileNamesFormatted = fileNames.map((fileName, index) => `/${index}/${fileName}`).join(',');
this.command = `curl -O ${baseUrl}{${fileNamesFormatted}} -k`;
}
loadDownloadZipConfigProperties() {
this.configurationService.findByPropertyName('download.all.limit.min.file.count')
.pipe(
getFirstSucceededRemoteDataPayload()
)
.subscribe((config) => {
this.downloadZipMinFileCount.next(Number(config.values[0]));
});
this.configurationService.findByPropertyName('download.all.limit.max.file.size')
.pipe(
getFirstSucceededRemoteDataPayload()
)
.subscribe((config) => {
this.downloadZipMaxFileSize.next(Number(config.values[0]));
});
this.configurationService.findByPropertyName('download.all.alert.min.file.size')
.pipe(
getFirstSucceededRemoteDataPayload()
)
.subscribe((config) => {
this.downloadZipMinFileSize.next(Number(config.values[0]));
});
}
}