mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-24 17:32:15 +00:00
[ADF-2562] Download a previous version (#3141)
* [ADF-2562] Download a previous version * [ADF-2562] add input property to enable/disable version downloads * [ADF-2562] add example in demo-shell * [ADF-2562] unit tests * [ADF-2561] View comments on previous versions (#3137) * [ADF-2561] View comments on previous versions add input property to enable/disable viewing version comments * [ADF-2561] add more tests * remove name property * test fixes
This commit is contained in:
committed by
Denys Vuika
parent
9792f83c9b
commit
7b7e39d989
@@ -41,6 +41,10 @@ export class VersionListComponent implements OnChanges {
|
||||
@Input()
|
||||
showComments: boolean = true;
|
||||
|
||||
/** Enable/disable possibility to download a version of the current node. */
|
||||
@Input()
|
||||
enableDownload: boolean = true;
|
||||
|
||||
constructor(private alfrescoApi: AlfrescoApiService) {
|
||||
this.versionsApi = this.alfrescoApi.versionsApi;
|
||||
}
|
||||
@@ -62,4 +66,29 @@ export class VersionListComponent implements OnChanges {
|
||||
this.isLoading = false;
|
||||
});
|
||||
}
|
||||
|
||||
downloadVersion(versionId) {
|
||||
if (this.enableDownload) {
|
||||
const versionDownloadUrl = this.getVersionContentUrl(this.id, versionId, true);
|
||||
this.downloadContent(versionDownloadUrl);
|
||||
}
|
||||
}
|
||||
|
||||
private getVersionContentUrl(nodeId: string, versionId: string, attachment?: boolean) {
|
||||
const nodeDownloadUrl = this.alfrescoApi.contentApi.getContentUrl(nodeId, attachment);
|
||||
return nodeDownloadUrl.replace('/content', '/versions/' + versionId + '/content');
|
||||
}
|
||||
|
||||
downloadContent(url: string) {
|
||||
if (url) {
|
||||
const link = document.createElement('a');
|
||||
|
||||
link.style.display = 'none';
|
||||
link.href = url;
|
||||
|
||||
document.body.appendChild(link);
|
||||
link.click();
|
||||
document.body.removeChild(link);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user