mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-24 17:32:15 +00:00
[ADF-1443] Refactor Download directive (#4028)
* [ADF-1443] Refactor Download directive * [ADF-1443] Node Download Directive now accepts single node and an array as input * [ADF-1443] Fix Unit tests * [ADF-1443] Fix unit test related to viewer component
This commit is contained in:
committed by
Eugenio Romano
parent
b99f6d57dc
commit
7197e1e13a
@@ -21,7 +21,6 @@ import { FormsModule, ReactiveFormsModule } from '@angular/forms';
|
|||||||
import { CoreModule } from '@alfresco/adf-core';
|
import { CoreModule } from '@alfresco/adf-core';
|
||||||
|
|
||||||
import { MaterialModule } from '../material.module';
|
import { MaterialModule } from '../material.module';
|
||||||
import { DownloadZipDialogComponent } from './download-zip.dialog';
|
|
||||||
import { FolderDialogComponent } from './folder.dialog';
|
import { FolderDialogComponent } from './folder.dialog';
|
||||||
import { NodeLockDialogComponent } from './node-lock.dialog';
|
import { NodeLockDialogComponent } from './node-lock.dialog';
|
||||||
import { ConfirmDialogComponent } from './confirm.dialog';
|
import { ConfirmDialogComponent } from './confirm.dialog';
|
||||||
@@ -40,21 +39,18 @@ import { LibraryDialogComponent } from './library/library.dialog';
|
|||||||
MatDatetimepickerModule
|
MatDatetimepickerModule
|
||||||
],
|
],
|
||||||
declarations: [
|
declarations: [
|
||||||
DownloadZipDialogComponent,
|
|
||||||
FolderDialogComponent,
|
FolderDialogComponent,
|
||||||
NodeLockDialogComponent,
|
NodeLockDialogComponent,
|
||||||
ConfirmDialogComponent,
|
ConfirmDialogComponent,
|
||||||
LibraryDialogComponent
|
LibraryDialogComponent
|
||||||
],
|
],
|
||||||
exports: [
|
exports: [
|
||||||
DownloadZipDialogComponent,
|
|
||||||
FolderDialogComponent,
|
FolderDialogComponent,
|
||||||
NodeLockDialogComponent,
|
NodeLockDialogComponent,
|
||||||
ConfirmDialogComponent,
|
ConfirmDialogComponent,
|
||||||
LibraryDialogComponent
|
LibraryDialogComponent
|
||||||
],
|
],
|
||||||
entryComponents: [
|
entryComponents: [
|
||||||
DownloadZipDialogComponent,
|
|
||||||
FolderDialogComponent,
|
FolderDialogComponent,
|
||||||
NodeLockDialogComponent,
|
NodeLockDialogComponent,
|
||||||
ConfirmDialogComponent,
|
ConfirmDialogComponent,
|
||||||
|
@@ -15,7 +15,6 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
export * from './download-zip.dialog';
|
|
||||||
export * from './folder.dialog';
|
export * from './folder.dialog';
|
||||||
export * from './node-lock.dialog';
|
export * from './node-lock.dialog';
|
||||||
export * from './confirm.dialog';
|
export * from './confirm.dialog';
|
||||||
|
@@ -19,7 +19,6 @@ import { CommonModule } from '@angular/common';
|
|||||||
import { NgModule } from '@angular/core';
|
import { NgModule } from '@angular/core';
|
||||||
import { MaterialModule } from '../material.module';
|
import { MaterialModule } from '../material.module';
|
||||||
|
|
||||||
import { NodeDownloadDirective } from './node-download.directive';
|
|
||||||
import { NodeLockDirective } from './node-lock.directive';
|
import { NodeLockDirective } from './node-lock.directive';
|
||||||
|
|
||||||
@NgModule({
|
@NgModule({
|
||||||
@@ -28,11 +27,9 @@ import { NodeLockDirective } from './node-lock.directive';
|
|||||||
MaterialModule
|
MaterialModule
|
||||||
],
|
],
|
||||||
declarations: [
|
declarations: [
|
||||||
NodeDownloadDirective,
|
|
||||||
NodeLockDirective
|
NodeLockDirective
|
||||||
],
|
],
|
||||||
exports: [
|
exports: [
|
||||||
NodeDownloadDirective,
|
|
||||||
NodeLockDirective
|
NodeLockDirective
|
||||||
]
|
]
|
||||||
})
|
})
|
||||||
|
@@ -15,6 +15,4 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
export * from './node-download.directive';
|
|
||||||
|
|
||||||
export * from './content-directive.module';
|
export * from './content-directive.module';
|
||||||
|
@@ -18,12 +18,11 @@
|
|||||||
import { Injectable, Output, EventEmitter } from '@angular/core';
|
import { Injectable, Output, EventEmitter } from '@angular/core';
|
||||||
import { MinimalNodeEntryEntity, MinimalNodeEntity } from 'alfresco-js-api';
|
import { MinimalNodeEntryEntity, MinimalNodeEntity } from 'alfresco-js-api';
|
||||||
import { Subject } from 'rxjs';
|
import { Subject } from 'rxjs';
|
||||||
import { AlfrescoApiService, ContentService } from '@alfresco/adf-core';
|
import { AlfrescoApiService, ContentService, NodeDownloadDirective } from '@alfresco/adf-core';
|
||||||
import { MatDialog } from '@angular/material';
|
import { MatDialog } from '@angular/material';
|
||||||
|
|
||||||
import { DocumentListService } from './document-list.service';
|
import { DocumentListService } from './document-list.service';
|
||||||
import { ContentNodeDialogService } from '../../content-node-selector/content-node-dialog.service';
|
import { ContentNodeDialogService } from '../../content-node-selector/content-node-dialog.service';
|
||||||
import { NodeDownloadDirective } from '../../directives/node-download.directive';
|
|
||||||
|
|
||||||
@Injectable({
|
@Injectable({
|
||||||
providedIn: 'root'
|
providedIn: 'root'
|
||||||
|
@@ -45,6 +45,7 @@ import { TemplateModule } from './templates/template.module';
|
|||||||
import { ClipboardModule } from './clipboard/clipboard.module';
|
import { ClipboardModule } from './clipboard/clipboard.module';
|
||||||
|
|
||||||
import { DirectiveModule } from './directives/directive.module';
|
import { DirectiveModule } from './directives/directive.module';
|
||||||
|
import { DialogModule } from './dialogs/dialog.module';
|
||||||
import { PipeModule } from './pipes/pipe.module';
|
import { PipeModule } from './pipes/pipe.module';
|
||||||
|
|
||||||
import { AlfrescoApiService } from './services/alfresco-api.service';
|
import { AlfrescoApiService } from './services/alfresco-api.service';
|
||||||
@@ -66,6 +67,7 @@ export function createTranslateLoader(http: HttpClient) {
|
|||||||
PipeModule,
|
PipeModule,
|
||||||
CommonModule,
|
CommonModule,
|
||||||
DirectiveModule,
|
DirectiveModule,
|
||||||
|
DialogModule,
|
||||||
ClipboardModule,
|
ClipboardModule,
|
||||||
FormsModule,
|
FormsModule,
|
||||||
ReactiveFormsModule,
|
ReactiveFormsModule,
|
||||||
@@ -103,6 +105,7 @@ export function createTranslateLoader(http: HttpClient) {
|
|||||||
PipeModule,
|
PipeModule,
|
||||||
CommonModule,
|
CommonModule,
|
||||||
DirectiveModule,
|
DirectiveModule,
|
||||||
|
DialogModule,
|
||||||
ClipboardModule,
|
ClipboardModule,
|
||||||
FormsModule,
|
FormsModule,
|
||||||
ReactiveFormsModule,
|
ReactiveFormsModule,
|
||||||
@@ -139,6 +142,7 @@ export class CoreModuleLazy {
|
|||||||
PipeModule,
|
PipeModule,
|
||||||
CommonModule,
|
CommonModule,
|
||||||
DirectiveModule,
|
DirectiveModule,
|
||||||
|
DialogModule,
|
||||||
FormsModule,
|
FormsModule,
|
||||||
ReactiveFormsModule,
|
ReactiveFormsModule,
|
||||||
HttpClientModule,
|
HttpClientModule,
|
||||||
@@ -175,6 +179,7 @@ export class CoreModuleLazy {
|
|||||||
PipeModule,
|
PipeModule,
|
||||||
CommonModule,
|
CommonModule,
|
||||||
DirectiveModule,
|
DirectiveModule,
|
||||||
|
DialogModule,
|
||||||
ClipboardModule,
|
ClipboardModule,
|
||||||
FormsModule,
|
FormsModule,
|
||||||
ReactiveFormsModule,
|
ReactiveFormsModule,
|
||||||
|
43
lib/core/dialogs/dialog.module.ts
Executable file
43
lib/core/dialogs/dialog.module.ts
Executable file
@@ -0,0 +1,43 @@
|
|||||||
|
/*!
|
||||||
|
* @license
|
||||||
|
* Copyright 2016 Alfresco Software, Ltd.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import { CommonModule } from '@angular/common';
|
||||||
|
import { NgModule } from '@angular/core';
|
||||||
|
|
||||||
|
import { MaterialModule } from '../material.module';
|
||||||
|
import { DownloadZipDialogComponent } from './download-zip.dialog';
|
||||||
|
import { TranslateModule } from '@ngx-translate/core';
|
||||||
|
import { PipeModule } from '../pipes/pipe.module';
|
||||||
|
|
||||||
|
@NgModule({
|
||||||
|
imports: [
|
||||||
|
CommonModule,
|
||||||
|
MaterialModule,
|
||||||
|
TranslateModule.forChild(),
|
||||||
|
PipeModule
|
||||||
|
],
|
||||||
|
declarations: [
|
||||||
|
DownloadZipDialogComponent
|
||||||
|
],
|
||||||
|
exports: [
|
||||||
|
DownloadZipDialogComponent
|
||||||
|
],
|
||||||
|
entryComponents: [
|
||||||
|
DownloadZipDialogComponent
|
||||||
|
]
|
||||||
|
})
|
||||||
|
export class DialogModule {}
|
2
lib/content-services/dialogs/download-zip.dialog.html → lib/core/dialogs/download-zip.dialog.html
Normal file → Executable file
2
lib/content-services/dialogs/download-zip.dialog.html → lib/core/dialogs/download-zip.dialog.html
Normal file → Executable file
@@ -4,7 +4,7 @@
|
|||||||
</div>
|
</div>
|
||||||
<div mat-dialog-actions>
|
<div mat-dialog-actions>
|
||||||
<span class="adf-spacer"></span>
|
<span class="adf-spacer"></span>
|
||||||
<button mat-button color="primary" (click)="cancelDownload()">
|
<button mat-button color="primary" id="cancel-button" (click)="cancelDownload()">
|
||||||
{{ 'CORE.DIALOG.DOWNLOAD_ZIP.ACTIONS.CANCEL' | translate }}
|
{{ 'CORE.DIALOG.DOWNLOAD_ZIP.ACTIONS.CANCEL' | translate }}
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
0
lib/content-services/dialogs/download-zip.dialog.scss → lib/core/dialogs/download-zip.dialog.scss
Normal file → Executable file
0
lib/content-services/dialogs/download-zip.dialog.scss → lib/core/dialogs/download-zip.dialog.scss
Normal file → Executable file
149
lib/core/dialogs/download-zip.dialog.spec.ts
Executable file
149
lib/core/dialogs/download-zip.dialog.spec.ts
Executable file
@@ -0,0 +1,149 @@
|
|||||||
|
/*!
|
||||||
|
* @license
|
||||||
|
* Copyright 2016 Alfresco Software, Ltd.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import { TestBed } from '@angular/core/testing';
|
||||||
|
import { ComponentFixture } from '@angular/core/testing';
|
||||||
|
import { MatDialogRef, MAT_DIALOG_DATA } from '@angular/material';
|
||||||
|
import { DownloadZipDialogComponent } from './download-zip.dialog';
|
||||||
|
import { setupTestBed } from '../testing/setupTestBed';
|
||||||
|
import { CoreTestingModule } from '../testing/core.testing.module';
|
||||||
|
import { DownloadZipService } from '../services/download-zip.service';
|
||||||
|
import { of } from 'rxjs';
|
||||||
|
|
||||||
|
describe('DownloadZipDialogComponent', () => {
|
||||||
|
|
||||||
|
let fixture: ComponentFixture<DownloadZipDialogComponent>;
|
||||||
|
let component: DownloadZipDialogComponent;
|
||||||
|
let element: HTMLElement;
|
||||||
|
let downloadZipService: DownloadZipService;
|
||||||
|
let dialogRef = {
|
||||||
|
close: jasmine.createSpy('close')
|
||||||
|
};
|
||||||
|
|
||||||
|
let dataMock = {
|
||||||
|
nodeIds: [
|
||||||
|
'123'
|
||||||
|
]
|
||||||
|
};
|
||||||
|
|
||||||
|
let pendingDownloadEntry = {
|
||||||
|
entry: {
|
||||||
|
bytesAdded: 0,
|
||||||
|
filesAdded: 0,
|
||||||
|
id: '5bfb0907',
|
||||||
|
status: 'PENDING',
|
||||||
|
totalBytes: 0,
|
||||||
|
totalFiles: 0
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
setupTestBed({
|
||||||
|
imports: [CoreTestingModule],
|
||||||
|
providers: [
|
||||||
|
{ provide: MatDialogRef, useValue: dialogRef },
|
||||||
|
{ provide: MAT_DIALOG_DATA, useValue: dataMock }
|
||||||
|
]
|
||||||
|
});
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
dialogRef.close.calls.reset();
|
||||||
|
fixture = TestBed.createComponent(DownloadZipDialogComponent);
|
||||||
|
downloadZipService = TestBed.get(DownloadZipService);
|
||||||
|
component = fixture.componentInstance;
|
||||||
|
element = fixture.nativeElement;
|
||||||
|
});
|
||||||
|
|
||||||
|
afterEach(() => {
|
||||||
|
fixture.destroy();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should call downloadZip when it is not cancelled', () => {
|
||||||
|
component.cancelled = false;
|
||||||
|
spyOn(component, 'downloadZip');
|
||||||
|
|
||||||
|
component.ngOnInit();
|
||||||
|
|
||||||
|
expect(component.downloadZip).toHaveBeenCalledWith(['123']);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should not call downloadZip when it is cancelled', () => {
|
||||||
|
component.cancelled = true;
|
||||||
|
spyOn(component, 'downloadZip');
|
||||||
|
|
||||||
|
component.ngOnInit();
|
||||||
|
|
||||||
|
expect(component.downloadZip).not.toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should not call downloadZip when it contains zero nodeIds', () => {
|
||||||
|
component.data = {
|
||||||
|
nodeIds: []
|
||||||
|
};
|
||||||
|
spyOn(component, 'downloadZip');
|
||||||
|
|
||||||
|
component.ngOnInit();
|
||||||
|
|
||||||
|
expect(component.downloadZip).not.toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should call cancelDownload when CANCEL button is clicked', () => {
|
||||||
|
fixture.detectChanges();
|
||||||
|
spyOn(component, 'cancelDownload').and.callThrough();
|
||||||
|
|
||||||
|
const cancelButton: HTMLButtonElement = <HTMLButtonElement> element.querySelector('#cancel-button');
|
||||||
|
cancelButton.click();
|
||||||
|
|
||||||
|
expect(component.cancelDownload).toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should call createDownload when component is initialize', () => {
|
||||||
|
const createDownloadSpy = spyOn(downloadZipService, 'createDownload').and.returnValue(of(pendingDownloadEntry));
|
||||||
|
fixture.detectChanges();
|
||||||
|
expect(createDownloadSpy).toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should close dialog when download is completed', () => {
|
||||||
|
component.download('fakeUrl', 'fileName');
|
||||||
|
spyOn(downloadZipService, 'cancelDownload');
|
||||||
|
fixture.detectChanges();
|
||||||
|
expect(dialogRef.close).toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should close dialog when download is cancelled', () => {
|
||||||
|
fixture.detectChanges();
|
||||||
|
component.download('url', 'filename');
|
||||||
|
spyOn(downloadZipService, 'cancelDownload');
|
||||||
|
component.cancelDownload();
|
||||||
|
expect(dialogRef.close).toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should interrupt download when cancel button is clicked', () => {
|
||||||
|
spyOn(component, 'downloadZip');
|
||||||
|
spyOn(component, 'download');
|
||||||
|
spyOn(component, 'cancelDownload').and.callThrough();
|
||||||
|
|
||||||
|
fixture.detectChanges();
|
||||||
|
|
||||||
|
expect(component.downloadZip).toHaveBeenCalled();
|
||||||
|
|
||||||
|
const cancelButton: HTMLButtonElement = <HTMLButtonElement> element.querySelector('#cancel-button');
|
||||||
|
cancelButton.click();
|
||||||
|
|
||||||
|
expect(component.cancelDownload).toHaveBeenCalled();
|
||||||
|
expect(component.download).not.toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
});
|
31
lib/content-services/dialogs/download-zip.dialog.ts → lib/core/dialogs/download-zip.dialog.ts
Normal file → Executable file
31
lib/content-services/dialogs/download-zip.dialog.ts → lib/core/dialogs/download-zip.dialog.ts
Normal file → Executable file
@@ -18,7 +18,8 @@
|
|||||||
import { Component, Inject, OnInit, ViewEncapsulation } from '@angular/core';
|
import { Component, Inject, OnInit, ViewEncapsulation } from '@angular/core';
|
||||||
import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material';
|
import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material';
|
||||||
import { DownloadEntry, MinimalNodeEntity } from 'alfresco-js-api';
|
import { DownloadEntry, MinimalNodeEntity } from 'alfresco-js-api';
|
||||||
import { LogService, AlfrescoApiService } from '@alfresco/adf-core';
|
import { LogService } from '../services/log.service';
|
||||||
|
import { DownloadZipService } from '../services/download-zip.service';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'adf-download-zip-dialog',
|
selector: 'adf-download-zip-dialog',
|
||||||
@@ -30,12 +31,14 @@ import { LogService, AlfrescoApiService } from '@alfresco/adf-core';
|
|||||||
export class DownloadZipDialogComponent implements OnInit {
|
export class DownloadZipDialogComponent implements OnInit {
|
||||||
|
|
||||||
// flag for async threads
|
// flag for async threads
|
||||||
private cancelled = false;
|
cancelled = false;
|
||||||
|
downloadId: string;
|
||||||
|
|
||||||
constructor(private apiService: AlfrescoApiService,
|
constructor(private dialogRef: MatDialogRef<DownloadZipDialogComponent>,
|
||||||
private dialogRef: MatDialogRef<DownloadZipDialogComponent>,
|
@Inject(MAT_DIALOG_DATA)
|
||||||
@Inject(MAT_DIALOG_DATA) private data: any,
|
public data: any,
|
||||||
private logService: LogService) {
|
private logService: LogService,
|
||||||
|
private downloadZipService: DownloadZipService) {
|
||||||
}
|
}
|
||||||
|
|
||||||
ngOnInit() {
|
ngOnInit() {
|
||||||
@@ -50,25 +53,21 @@ export class DownloadZipDialogComponent implements OnInit {
|
|||||||
|
|
||||||
cancelDownload() {
|
cancelDownload() {
|
||||||
this.cancelled = true;
|
this.cancelled = true;
|
||||||
|
this.downloadZipService.cancelDownload(this.downloadId);
|
||||||
this.dialogRef.close(false);
|
this.dialogRef.close(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
downloadZip(nodeIds: string[]) {
|
downloadZip(nodeIds: string[]) {
|
||||||
if (nodeIds && nodeIds.length > 0) {
|
if (nodeIds && nodeIds.length > 0) {
|
||||||
|
|
||||||
const promise: any = this.apiService.getInstance().core.downloadsApi.createDownload({ nodeIds });
|
this.downloadZipService.createDownload({ nodeIds }).subscribe((data: DownloadEntry) => {
|
||||||
|
|
||||||
promise.on('progress', (progress) => this.logService.log('Progress', progress));
|
|
||||||
promise.on('error', (error) => this.logService.error('Error', error));
|
|
||||||
promise.on('abort', (data) => this.logService.log('Abort', data));
|
|
||||||
|
|
||||||
promise.on('success', (data: DownloadEntry) => {
|
|
||||||
if (data && data.entry && data.entry.id) {
|
if (data && data.entry && data.entry.id) {
|
||||||
const url = this.apiService.getInstance().content.getContentUrl(data.entry.id, true);
|
const url = this.downloadZipService.getContentUrl(data.entry.id, true);
|
||||||
|
|
||||||
this.apiService.getInstance().core.nodesApi.getNode(data.entry.id).then((downloadNode: MinimalNodeEntity) => {
|
this.downloadZipService.getNode(data.entry.id).subscribe((downloadNode: MinimalNodeEntity) => {
|
||||||
this.logService.log(downloadNode);
|
this.logService.log(downloadNode);
|
||||||
const fileName = downloadNode.entry.name;
|
const fileName = downloadNode.entry.name;
|
||||||
|
this.downloadId = data.entry.id;
|
||||||
this.waitAndDownload(data.entry.id, url, fileName);
|
this.waitAndDownload(data.entry.id, url, fileName);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -81,7 +80,7 @@ export class DownloadZipDialogComponent implements OnInit {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.apiService.getInstance().core.downloadsApi.getDownload(downloadId).then((downloadEntry: DownloadEntry) => {
|
this.downloadZipService.getDownload(downloadId).subscribe((downloadEntry: DownloadEntry) => {
|
||||||
if (downloadEntry.entry) {
|
if (downloadEntry.entry) {
|
||||||
if (downloadEntry.entry.status === 'DONE') {
|
if (downloadEntry.entry.status === 'DONE') {
|
||||||
this.download(url, fileName);
|
this.download(url, fileName);
|
18
lib/core/dialogs/index.ts
Executable file
18
lib/core/dialogs/index.ts
Executable file
@@ -0,0 +1,18 @@
|
|||||||
|
/*!
|
||||||
|
* @license
|
||||||
|
* Copyright 2016 Alfresco Software, Ltd.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
export * from './public-api';
|
20
lib/core/dialogs/public-api.ts
Executable file
20
lib/core/dialogs/public-api.ts
Executable file
@@ -0,0 +1,20 @@
|
|||||||
|
/*!
|
||||||
|
* @license
|
||||||
|
* Copyright 2016 Alfresco Software, Ltd.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
export * from './download-zip.dialog';
|
||||||
|
|
||||||
|
export * from './dialog.module';
|
@@ -26,6 +26,7 @@ import { NodeFavoriteDirective } from './node-favorite.directive';
|
|||||||
import { NodePermissionDirective } from './node-permission.directive';
|
import { NodePermissionDirective } from './node-permission.directive';
|
||||||
import { NodeRestoreDirective } from './node-restore.directive';
|
import { NodeRestoreDirective } from './node-restore.directive';
|
||||||
import { UploadDirective } from './upload.directive';
|
import { UploadDirective } from './upload.directive';
|
||||||
|
import { NodeDownloadDirective } from './node-download.directive';
|
||||||
|
|
||||||
@NgModule({
|
@NgModule({
|
||||||
imports: [
|
imports: [
|
||||||
@@ -39,6 +40,7 @@ import { UploadDirective } from './upload.directive';
|
|||||||
NodeFavoriteDirective,
|
NodeFavoriteDirective,
|
||||||
NodePermissionDirective,
|
NodePermissionDirective,
|
||||||
NodeRestoreDirective,
|
NodeRestoreDirective,
|
||||||
|
NodeDownloadDirective,
|
||||||
UploadDirective
|
UploadDirective
|
||||||
],
|
],
|
||||||
exports: [
|
exports: [
|
||||||
@@ -48,6 +50,7 @@ import { UploadDirective } from './upload.directive';
|
|||||||
NodeFavoriteDirective,
|
NodeFavoriteDirective,
|
||||||
NodePermissionDirective,
|
NodePermissionDirective,
|
||||||
NodeRestoreDirective,
|
NodeRestoreDirective,
|
||||||
|
NodeDownloadDirective,
|
||||||
UploadDirective
|
UploadDirective
|
||||||
]
|
]
|
||||||
})
|
})
|
||||||
|
10
lib/content-services/directives/node-download.directive.spec.ts → lib/core/directives/node-download.directive.spec.ts
Normal file → Executable file
10
lib/content-services/directives/node-download.directive.spec.ts → lib/core/directives/node-download.directive.spec.ts
Normal file → Executable file
@@ -19,9 +19,11 @@ import { TestBed, ComponentFixture } from '@angular/core/testing';
|
|||||||
import { By } from '@angular/platform-browser';
|
import { By } from '@angular/platform-browser';
|
||||||
import { MatDialog } from '@angular/material';
|
import { MatDialog } from '@angular/material';
|
||||||
import { Component, DebugElement } from '@angular/core';
|
import { Component, DebugElement } from '@angular/core';
|
||||||
import { AlfrescoApiService, setupTestBed, CoreModule, AlfrescoApiServiceMock } from '@alfresco/adf-core';
|
import { setupTestBed } from '../testing/setupTestBed';
|
||||||
|
import { CoreModule } from '../core.module';
|
||||||
import { DialogModule } from '../dialogs/dialog.module';
|
import { DialogModule } from '../dialogs/dialog.module';
|
||||||
|
import { AlfrescoApiServiceMock } from '../mock/alfresco-api.service.mock';
|
||||||
|
import { AlfrescoApiService } from '../services/alfresco-api.service';
|
||||||
import { NodeDownloadDirective } from './node-download.directive';
|
import { NodeDownloadDirective } from './node-download.directive';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
@@ -47,11 +49,9 @@ describe('NodeDownloadDirective', () => {
|
|||||||
],
|
],
|
||||||
providers: [
|
providers: [
|
||||||
{ provide: AlfrescoApiService, useClass: AlfrescoApiServiceMock }
|
{ provide: AlfrescoApiService, useClass: AlfrescoApiServiceMock }
|
||||||
// { provide: AppConfigService, useValue: AppConfigServiceMock },
|
|
||||||
],
|
],
|
||||||
declarations: [
|
declarations: [
|
||||||
TestComponent,
|
TestComponent
|
||||||
NodeDownloadDirective
|
|
||||||
]
|
]
|
||||||
});
|
});
|
||||||
|
|
27
lib/content-services/directives/node-download.directive.ts → lib/core/directives/node-download.directive.ts
Normal file → Executable file
27
lib/content-services/directives/node-download.directive.ts → lib/core/directives/node-download.directive.ts
Normal file → Executable file
@@ -17,10 +17,9 @@
|
|||||||
|
|
||||||
import { Directive, Input, HostListener } from '@angular/core';
|
import { Directive, Input, HostListener } from '@angular/core';
|
||||||
import { MatDialog } from '@angular/material';
|
import { MatDialog } from '@angular/material';
|
||||||
import { MinimalNodeEntity } from 'alfresco-js-api';
|
import { AlfrescoApiService } from '../services/alfresco-api.service';
|
||||||
import { AlfrescoApiService } from '@alfresco/adf-core';
|
|
||||||
|
|
||||||
import { DownloadZipDialogComponent } from '../dialogs/download-zip.dialog';
|
import { DownloadZipDialogComponent } from '../dialogs/download-zip.dialog';
|
||||||
|
import { MinimalNodeEntity } from 'alfresco-js-api';
|
||||||
|
|
||||||
@Directive({
|
@Directive({
|
||||||
selector: '[adfNodeDownload]'
|
selector: '[adfNodeDownload]'
|
||||||
@@ -30,7 +29,7 @@ export class NodeDownloadDirective {
|
|||||||
/** Nodes to download. */
|
/** Nodes to download. */
|
||||||
// tslint:disable-next-line:no-input-rename
|
// tslint:disable-next-line:no-input-rename
|
||||||
@Input('adfNodeDownload')
|
@Input('adfNodeDownload')
|
||||||
nodes: MinimalNodeEntity[];
|
nodes: MinimalNodeEntity | MinimalNodeEntity[];
|
||||||
|
|
||||||
@HostListener('click')
|
@HostListener('click')
|
||||||
onClick() {
|
onClick() {
|
||||||
@@ -47,15 +46,19 @@ export class NodeDownloadDirective {
|
|||||||
* Packs result into a .ZIP archive if there is more than one node selected.
|
* Packs result into a .ZIP archive if there is more than one node selected.
|
||||||
* @param selection Multiple selected nodes to download
|
* @param selection Multiple selected nodes to download
|
||||||
*/
|
*/
|
||||||
downloadNodes(selection: Array<MinimalNodeEntity>) {
|
downloadNodes(selection: MinimalNodeEntity | Array<MinimalNodeEntity>) {
|
||||||
if (!selection || selection.length === 0) {
|
|
||||||
|
if (!this.isSelectionValid(selection)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (selection instanceof Array) {
|
||||||
if (selection.length === 1) {
|
if (selection.length === 1) {
|
||||||
this.downloadNode(selection[0]);
|
this.downloadNode(selection[0]);
|
||||||
|
} else {
|
||||||
|
this.downloadZip(selection);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
this.downloadZip(selection);
|
this.downloadNode(selection);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -83,6 +86,10 @@ export class NodeDownloadDirective {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private isSelectionValid(selection: MinimalNodeEntity | Array<MinimalNodeEntity>) {
|
||||||
|
return selection || (selection instanceof Array && selection.length > 0);
|
||||||
|
}
|
||||||
|
|
||||||
private downloadFile(node: MinimalNodeEntity) {
|
private downloadFile(node: MinimalNodeEntity) {
|
||||||
if (node && node.entry) {
|
if (node && node.entry) {
|
||||||
const contentApi = this.apiService.getInstance().content;
|
const contentApi = this.apiService.getInstance().content;
|
@@ -21,6 +21,7 @@ export * from './node-delete.directive';
|
|||||||
export * from './node-favorite.directive';
|
export * from './node-favorite.directive';
|
||||||
export * from './node-permission.directive';
|
export * from './node-permission.directive';
|
||||||
export * from './node-restore.directive';
|
export * from './node-restore.directive';
|
||||||
|
export * from './node-download.directive';
|
||||||
export * from './upload.directive';
|
export * from './upload.directive';
|
||||||
|
|
||||||
export * from './directive.module';
|
export * from './directive.module';
|
||||||
|
@@ -39,6 +39,7 @@ export * from './pipes/index';
|
|||||||
export * from './services/index';
|
export * from './services/index';
|
||||||
export * from './directives/index';
|
export * from './directives/index';
|
||||||
export * from './clipboard/index';
|
export * from './clipboard/index';
|
||||||
|
export * from './dialogs/index';
|
||||||
|
|
||||||
export * from './utils/index';
|
export * from './utils/index';
|
||||||
export * from './interface/index';
|
export * from './interface/index';
|
||||||
|
60
lib/core/services/download-zip.service.ts
Executable file
60
lib/core/services/download-zip.service.ts
Executable file
@@ -0,0 +1,60 @@
|
|||||||
|
/*!
|
||||||
|
* @license
|
||||||
|
* Copyright 2016 Alfresco Software, Ltd.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import { NodeEntry, DownloadEntry, DownloadBodyCreate } from 'alfresco-js-api';
|
||||||
|
import { Injectable } from '@angular/core';
|
||||||
|
import { Observable, from, throwError } from 'rxjs';
|
||||||
|
import { LogService } from './log.service';
|
||||||
|
import { AlfrescoApiService } from './alfresco-api.service';
|
||||||
|
import { catchError } from 'rxjs/operators';
|
||||||
|
|
||||||
|
@Injectable({
|
||||||
|
providedIn: 'root'
|
||||||
|
})
|
||||||
|
export class DownloadZipService {
|
||||||
|
|
||||||
|
constructor(private apiService: AlfrescoApiService,
|
||||||
|
private logService: LogService) {
|
||||||
|
}
|
||||||
|
|
||||||
|
createDownload(payload: DownloadBodyCreate): Observable<DownloadEntry> {
|
||||||
|
return from(this.apiService.getInstance().core.downloadsApi.createDownload(payload)).pipe(
|
||||||
|
catchError((err) => this.handleError(err))
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
getContentUrl(nodeId: string, attachment?: boolean): string {
|
||||||
|
return this.apiService.getInstance().content.getContentUrl(nodeId, attachment);
|
||||||
|
}
|
||||||
|
|
||||||
|
getNode(nodeId: string): Observable<NodeEntry> {
|
||||||
|
return from(this.apiService.getInstance().core.nodesApi.getNode(nodeId));
|
||||||
|
}
|
||||||
|
|
||||||
|
getDownload(downloadId: string): Observable<DownloadEntry> {
|
||||||
|
return from(this.apiService.getInstance().core.downloadsApi.getDownload(downloadId));
|
||||||
|
}
|
||||||
|
|
||||||
|
cancelDownload(downloadId: string) {
|
||||||
|
this.apiService.getInstance().core.downloadsApi.cancelDownload(downloadId);
|
||||||
|
}
|
||||||
|
|
||||||
|
private handleError(error: any) {
|
||||||
|
this.logService.error(error);
|
||||||
|
return throwError(error || 'Server error');
|
||||||
|
}
|
||||||
|
}
|
@@ -51,3 +51,4 @@ export * from './comment-content.service';
|
|||||||
export * from './login-dialog.service';
|
export * from './login-dialog.service';
|
||||||
export * from './external-alfresco-api.service';
|
export * from './external-alfresco-api.service';
|
||||||
export * from './jwt-helper.service';
|
export * from './jwt-helper.service';
|
||||||
|
export * from './download-zip.service';
|
||||||
|
@@ -76,7 +76,7 @@
|
|||||||
mat-icon-button
|
mat-icon-button
|
||||||
title="{{ 'ADF_VIEWER.ACTIONS.DOWNLOAD' | translate }}"
|
title="{{ 'ADF_VIEWER.ACTIONS.DOWNLOAD' | translate }}"
|
||||||
data-automation-id="adf-toolbar-download"
|
data-automation-id="adf-toolbar-download"
|
||||||
(click)="downloadContent()">
|
[adfNodeDownload]="node">
|
||||||
<mat-icon>file_download</mat-icon>
|
<mat-icon>file_download</mat-icon>
|
||||||
</button>
|
</button>
|
||||||
|
|
||||||
|
@@ -345,7 +345,10 @@ describe('ViewerComponent', () => {
|
|||||||
const nodeDetails = { name: displayName, id: '12' };
|
const nodeDetails = { name: displayName, id: '12' };
|
||||||
const contentUrl = '/content/url/path';
|
const contentUrl = '/content/url/path';
|
||||||
const alfrescoApiInstanceMock = {
|
const alfrescoApiInstanceMock = {
|
||||||
nodes: { getNodeInfo: () => Promise.resolve(nodeDetails) },
|
nodes: {
|
||||||
|
getNodeInfo: () => Promise.resolve(nodeDetails),
|
||||||
|
getNode: () => Promise.resolve({ id: 'fake-node' })
|
||||||
|
},
|
||||||
content: { getContentUrl: () => contentUrl }
|
content: { getContentUrl: () => contentUrl }
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -370,6 +373,8 @@ describe('ViewerComponent', () => {
|
|||||||
Promise.resolve({ name: 'file2', content: {} })
|
Promise.resolve({ name: 'file2', content: {} })
|
||||||
);
|
);
|
||||||
|
|
||||||
|
spyOn(alfrescoApiService.nodesApi, 'getNode').and.returnValue(Promise.resolve({ id: 'fake-node' }));
|
||||||
|
|
||||||
component.urlFile = null;
|
component.urlFile = null;
|
||||||
component.displayName = null;
|
component.displayName = null;
|
||||||
component.blobFile = null;
|
component.blobFile = null;
|
||||||
@@ -549,35 +554,6 @@ describe('ViewerComponent', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should invoke download action with the toolbar button', (done) => {
|
|
||||||
component.allowDownload = true;
|
|
||||||
spyOn(component, 'downloadContent').and.stub();
|
|
||||||
fixture.detectChanges();
|
|
||||||
|
|
||||||
const button: HTMLButtonElement = element.querySelector('[data-automation-id="adf-toolbar-download"]') as HTMLButtonElement;
|
|
||||||
button.click();
|
|
||||||
|
|
||||||
fixture.whenStable().then(() => {
|
|
||||||
expect(component.downloadContent).toHaveBeenCalled();
|
|
||||||
done();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should raise download event with the toolbar button', (done) => {
|
|
||||||
component.allowDownload = true;
|
|
||||||
component.downloadUrl = 'URL';
|
|
||||||
component.fileName = 'fileName';
|
|
||||||
fixture.detectChanges();
|
|
||||||
|
|
||||||
component.download.subscribe((e) => {
|
|
||||||
expect(e).not.toBeNull();
|
|
||||||
done();
|
|
||||||
});
|
|
||||||
|
|
||||||
const button: HTMLButtonElement = element.querySelector('[data-automation-id="adf-toolbar-download"]') as HTMLButtonElement;
|
|
||||||
button.click();
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should render default print button', (done) => {
|
it('should render default print button', (done) => {
|
||||||
component.allowPrint = true;
|
component.allowPrint = true;
|
||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
@@ -674,6 +650,30 @@ describe('ViewerComponent', () => {
|
|||||||
button.click();
|
button.click();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should get and assign node for download', (done) => {
|
||||||
|
const node = { id: 'fake-node' };
|
||||||
|
component.fileNodeId = '12';
|
||||||
|
component.urlFile = '';
|
||||||
|
const displayName = 'the-name';
|
||||||
|
const nodeDetails = { name: displayName, id: '12', content: { mimeType: 'txt' } };
|
||||||
|
const contentUrl = '/content/url/path';
|
||||||
|
const alfrescoApiInstanceMock = {
|
||||||
|
nodes: {
|
||||||
|
getNodeInfo: () => Promise.resolve(nodeDetails),
|
||||||
|
getNode: () => Promise.resolve(node)
|
||||||
|
},
|
||||||
|
content: { getContentUrl: () => contentUrl }
|
||||||
|
};
|
||||||
|
spyOn(alfrescoApiService, 'getInstance').and.returnValue(alfrescoApiInstanceMock);
|
||||||
|
|
||||||
|
component.ngOnChanges(null);
|
||||||
|
fixture.whenStable().then(() => {
|
||||||
|
fixture.detectChanges();
|
||||||
|
expect(component.node).toBe(node);
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('View', () => {
|
describe('View', () => {
|
||||||
@@ -923,7 +923,10 @@ describe('ViewerComponent', () => {
|
|||||||
const nodeDetails = { name: displayName, id: '12', content: { mimeType: 'txt' } };
|
const nodeDetails = { name: displayName, id: '12', content: { mimeType: 'txt' } };
|
||||||
const contentUrl = '/content/url/path';
|
const contentUrl = '/content/url/path';
|
||||||
const alfrescoApiInstanceMock = {
|
const alfrescoApiInstanceMock = {
|
||||||
nodes: { getNodeInfo: () => Promise.resolve(nodeDetails) },
|
nodes: {
|
||||||
|
getNodeInfo: () => Promise.resolve(nodeDetails),
|
||||||
|
getNode: () => Promise.resolve({ id: 'fake-node' })
|
||||||
|
},
|
||||||
content: { getContentUrl: () => contentUrl }
|
content: { getContentUrl: () => contentUrl }
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -998,7 +1001,6 @@ describe('ViewerComponent', () => {
|
|||||||
component.enterFullScreen();
|
component.enterFullScreen();
|
||||||
expect(domElement.msRequestFullscreen).toHaveBeenCalled();
|
expect(domElement.msRequestFullscreen).toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
@@ -21,7 +21,7 @@ import {
|
|||||||
Input, OnChanges, Output, SimpleChanges, TemplateRef,
|
Input, OnChanges, Output, SimpleChanges, TemplateRef,
|
||||||
ViewEncapsulation, OnInit, OnDestroy
|
ViewEncapsulation, OnInit, OnDestroy
|
||||||
} from '@angular/core';
|
} from '@angular/core';
|
||||||
import { MinimalNodeEntryEntity, RenditionEntry } from 'alfresco-js-api';
|
import { MinimalNodeEntryEntity, RenditionEntry, MinimalNodeEntity } from 'alfresco-js-api';
|
||||||
import { BaseEvent } from '../../events';
|
import { BaseEvent } from '../../events';
|
||||||
import { AlfrescoApiService } from '../../services/alfresco-api.service';
|
import { AlfrescoApiService } from '../../services/alfresco-api.service';
|
||||||
import { LogService } from '../../services/log.service';
|
import { LogService } from '../../services/log.service';
|
||||||
@@ -196,10 +196,6 @@ export class ViewerComponent implements OnChanges, OnInit, OnDestroy {
|
|||||||
@Input()
|
@Input()
|
||||||
fileName: string;
|
fileName: string;
|
||||||
|
|
||||||
/** URL to download. */
|
|
||||||
@Input()
|
|
||||||
downloadUrl: string = null;
|
|
||||||
|
|
||||||
/** Number of times the Viewer will retry fetching content Rendition.
|
/** Number of times the Viewer will retry fetching content Rendition.
|
||||||
* There is a delay of at least one second between attempts.
|
* There is a delay of at least one second between attempts.
|
||||||
*/
|
*/
|
||||||
@@ -210,10 +206,6 @@ export class ViewerComponent implements OnChanges, OnInit, OnDestroy {
|
|||||||
@Output()
|
@Output()
|
||||||
goBack = new EventEmitter<BaseEvent<any>>();
|
goBack = new EventEmitter<BaseEvent<any>>();
|
||||||
|
|
||||||
/** Emitted when user clicks the 'Download' button. */
|
|
||||||
@Output()
|
|
||||||
download = new EventEmitter<BaseEvent<any>>();
|
|
||||||
|
|
||||||
/** Emitted when user clicks the 'Print' button. */
|
/** Emitted when user clicks the 'Print' button. */
|
||||||
@Output()
|
@Output()
|
||||||
print = new EventEmitter<BaseEvent<any>>();
|
print = new EventEmitter<BaseEvent<any>>();
|
||||||
@@ -244,7 +236,7 @@ export class ViewerComponent implements OnChanges, OnInit, OnDestroy {
|
|||||||
|
|
||||||
viewerType = 'unknown';
|
viewerType = 'unknown';
|
||||||
isLoading = false;
|
isLoading = false;
|
||||||
node: MinimalNodeEntryEntity;
|
node: MinimalNodeEntity;
|
||||||
|
|
||||||
extensionTemplates: { template: TemplateRef<any>, isVisible: boolean }[] = [];
|
extensionTemplates: { template: TemplateRef<any>, isVisible: boolean }[] = [];
|
||||||
externalExtensions: string[] = [];
|
externalExtensions: string[] = [];
|
||||||
@@ -332,6 +324,12 @@ export class ViewerComponent implements OnChanges, OnInit, OnDestroy {
|
|||||||
this.logService.error('This node does not exist');
|
this.logService.error('This node does not exist');
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
this.apiService.nodesApi.getNode(this.nodeId).then(
|
||||||
|
(node) => {
|
||||||
|
this.node = node;
|
||||||
|
}
|
||||||
|
);
|
||||||
} else if (this.sharedLinkId) {
|
} else if (this.sharedLinkId) {
|
||||||
|
|
||||||
this.apiService.sharedLinksApi.getSharedLink(this.sharedLinkId).then(
|
this.apiService.sharedLinksApi.getSharedLink(this.sharedLinkId).then(
|
||||||
@@ -366,7 +364,6 @@ export class ViewerComponent implements OnChanges, OnInit, OnDestroy {
|
|||||||
this.extension = this.getFileExtension(filenameFromUrl);
|
this.extension = this.getFileExtension(filenameFromUrl);
|
||||||
this.urlFileContent = this.urlFile;
|
this.urlFileContent = this.urlFile;
|
||||||
|
|
||||||
this.downloadUrl = this.urlFile;
|
|
||||||
this.fileName = this.displayName;
|
this.fileName = this.displayName;
|
||||||
|
|
||||||
this.viewerType = this.urlFileViewer || this.getViewerTypeByExtension(this.extension);
|
this.viewerType = this.urlFileViewer || this.getViewerTypeByExtension(this.extension);
|
||||||
@@ -393,7 +390,6 @@ export class ViewerComponent implements OnChanges, OnInit, OnDestroy {
|
|||||||
this.extension = this.getFileExtension(data.name);
|
this.extension = this.getFileExtension(data.name);
|
||||||
|
|
||||||
this.fileName = data.name;
|
this.fileName = data.name;
|
||||||
this.downloadUrl = this.apiService.contentApi.getContentUrl(data.id, true);
|
|
||||||
|
|
||||||
this.viewerType = this.getViewerTypeByExtension(this.extension);
|
this.viewerType = this.getViewerTypeByExtension(this.extension);
|
||||||
if (this.viewerType === 'unknown') {
|
if (this.viewerType === 'unknown') {
|
||||||
@@ -419,7 +415,6 @@ export class ViewerComponent implements OnChanges, OnInit, OnDestroy {
|
|||||||
this.fileName = details.entry.name;
|
this.fileName = details.entry.name;
|
||||||
|
|
||||||
this.urlFileContent = this.apiService.contentApi.getSharedLinkContentUrl(this.sharedLinkId, false);
|
this.urlFileContent = this.apiService.contentApi.getSharedLinkContentUrl(this.sharedLinkId, false);
|
||||||
this.downloadUrl = this.apiService.contentApi.getSharedLinkContentUrl(this.sharedLinkId, true);
|
|
||||||
|
|
||||||
this.viewerType = this.getViewerTypeByMimeType(this.mimeType);
|
this.viewerType = this.getViewerTypeByMimeType(this.mimeType);
|
||||||
if (this.viewerType === 'unknown') {
|
if (this.viewerType === 'unknown') {
|
||||||
@@ -608,25 +603,6 @@ export class ViewerComponent implements OnChanges, OnInit, OnDestroy {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
downloadContent() {
|
|
||||||
if (this.allowDownload && this.downloadUrl && this.fileName) {
|
|
||||||
const args = new BaseEvent();
|
|
||||||
this.download.next(args);
|
|
||||||
|
|
||||||
if (!args.defaultPrevented) {
|
|
||||||
const link = document.createElement('a');
|
|
||||||
|
|
||||||
link.style.display = 'none';
|
|
||||||
link.download = this.fileName;
|
|
||||||
link.href = this.downloadUrl;
|
|
||||||
|
|
||||||
document.body.appendChild(link);
|
|
||||||
link.click();
|
|
||||||
document.body.removeChild(link);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
printContent() {
|
printContent() {
|
||||||
if (this.allowPrint) {
|
if (this.allowPrint) {
|
||||||
const args = new BaseEvent();
|
const args = new BaseEvent();
|
||||||
@@ -767,5 +743,4 @@ export class ViewerComponent implements OnChanges, OnInit, OnDestroy {
|
|||||||
private generateCacheBusterNumber() {
|
private generateCacheBusterNumber() {
|
||||||
this.cacheBusterNumber = Date.now();
|
this.cacheBusterNumber = Date.now();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -39,6 +39,7 @@ import { ViewerToolbarComponent } from './components/viewer-toolbar.component';
|
|||||||
import { ViewerComponent } from './components/viewer.component';
|
import { ViewerComponent } from './components/viewer.component';
|
||||||
import { ViewerExtensionDirective } from './directives/viewer-extension.directive';
|
import { ViewerExtensionDirective } from './directives/viewer-extension.directive';
|
||||||
import { ViewerToolbarActionsComponent } from './components/viewer-toolbar-actions.component';
|
import { ViewerToolbarActionsComponent } from './components/viewer-toolbar-actions.component';
|
||||||
|
import { DirectiveModule } from '../directives/directive.module';
|
||||||
|
|
||||||
@NgModule({
|
@NgModule({
|
||||||
imports: [
|
imports: [
|
||||||
@@ -49,7 +50,8 @@ import { ViewerToolbarActionsComponent } from './components/viewer-toolbar-actio
|
|||||||
ReactiveFormsModule,
|
ReactiveFormsModule,
|
||||||
ToolbarModule,
|
ToolbarModule,
|
||||||
PipeModule,
|
PipeModule,
|
||||||
FlexLayoutModule
|
FlexLayoutModule,
|
||||||
|
DirectiveModule
|
||||||
],
|
],
|
||||||
declarations: [
|
declarations: [
|
||||||
PdfPasswordDialogComponent,
|
PdfPasswordDialogComponent,
|
||||||
|
Reference in New Issue
Block a user