mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-24 17:32:15 +00:00
[ACA-4677] Added download functionality on DownloadPromptDialog (#8467)
* [ACA-4677] Added download functionality on DownloadPromptDialog * [ACA-4677] Added downloadFile event emitter documentation to ViewerComponent README. Updated reference of NonResponsiveDialog to DownloadPromptDialog * [ACA-4677] Corrected typo in documentation for downloadFile event * [ACA-4677] Updated test case to check for method call via actual event handling instead of calling the method manually
This commit is contained in:
@@ -85,12 +85,13 @@ See the [Custom layout](#custom-layout) section for full details of all availabl
|
|||||||
|
|
||||||
### Events
|
### Events
|
||||||
|
|
||||||
| Name | Type | Description |
|
| Name | Type | Description |
|
||||||
| ---- | ---- | ----------- |
|
|------------------|---------------------------------------------------------------------------------------------------------------------------------|----------------------------------------------------------------------------|
|
||||||
| navigateBefore | [`EventEmitter`](https://angular.io/api/core/EventEmitter)`<KeyboardEvent \| MouseEvent>` | Emitted when user clicks 'Navigate Before' ("<") button. |
|
| navigateBefore | [`EventEmitter`](https://angular.io/api/core/EventEmitter)`<KeyboardEvent \| MouseEvent>` | Emitted when user clicks 'Navigate Before' ("<") button. |
|
||||||
| navigateNext | [`EventEmitter`](https://angular.io/api/core/EventEmitter)`<KeyboardEvent \| MouseEvent>` | Emitted when user clicks 'Navigate Next' (">") button. |
|
| navigateNext | [`EventEmitter`](https://angular.io/api/core/EventEmitter)`<KeyboardEvent \| MouseEvent>` | Emitted when user clicks 'Navigate Next' (">") button. |
|
||||||
| showViewerChange | [`EventEmitter`](https://angular.io/api/core/EventEmitter)`<boolean>` | Emitted when the viewer close |
|
| showViewerChange | [`EventEmitter`](https://angular.io/api/core/EventEmitter)`<boolean>` | Emitted when the viewer close |
|
||||||
| submitFile | [`EventEmitter`](https://angular.io/api/core/EventEmitter)`<`[`Blob`](https://developer.mozilla.org/en-US/docs/Web/API/Blob)`>` | Emitted when the img is submitted in the img viewer. |
|
| submitFile | [`EventEmitter`](https://angular.io/api/core/EventEmitter)`<`[`Blob`](https://developer.mozilla.org/en-US/docs/Web/API/Blob)`>` | Emitted when the img is submitted in the img viewer. |
|
||||||
|
| downloadFile | [`EventEmitter`](https://angular.io/api/core/EventEmitter)`<`[`void`](https://developer.mozilla.org/en-US/docs/Web/API/Blob)`>` | Emitted when download button is clicked on the Download File Prompt. |
|
||||||
|
|
||||||
## Keyboard shortcuts
|
## Keyboard shortcuts
|
||||||
|
|
||||||
|
@@ -21,6 +21,7 @@
|
|||||||
[urlFile]="urlFileContent"
|
[urlFile]="urlFileContent"
|
||||||
[tracks]="tracks"
|
[tracks]="tracks"
|
||||||
[readOnly]="readOnly"
|
[readOnly]="readOnly"
|
||||||
|
(downloadFile)="onDownloadFile()"
|
||||||
(navigateBefore)="onNavigateBeforeClick($event)"
|
(navigateBefore)="onNavigateBeforeClick($event)"
|
||||||
(navigateNext)="onNavigateNextClick($event)"
|
(navigateNext)="onNavigateNextClick($event)"
|
||||||
(showViewerChange)="onClose()"
|
(showViewerChange)="onClose()"
|
||||||
|
@@ -26,19 +26,20 @@ import { AppExtensionService, ViewerExtensionRef } from '@alfresco/adf-extension
|
|||||||
import { MatButtonModule } from '@angular/material/button';
|
import { MatButtonModule } from '@angular/material/button';
|
||||||
import { MatIconModule } from '@angular/material/icon';
|
import { MatIconModule } from '@angular/material/icon';
|
||||||
import { NodeEntry, VersionEntry } from '@alfresco/js-api';
|
import { NodeEntry, VersionEntry } from '@alfresco/js-api';
|
||||||
import { AlfrescoViewerComponent, RenditionService } from '@alfresco/adf-content-services';
|
import { AlfrescoViewerComponent, NodeActionsService, RenditionService } from '@alfresco/adf-content-services';
|
||||||
import {
|
import {
|
||||||
CoreTestingModule,
|
CoreTestingModule,
|
||||||
setupTestBed,
|
setupTestBed,
|
||||||
EventMock,
|
EventMock,
|
||||||
ViewUtilService
|
ViewUtilService, ViewerComponent
|
||||||
} from '@alfresco/adf-core';
|
} from '@alfresco/adf-core';
|
||||||
import { NodesApiService } from '../../common/services/nodes-api.service';
|
import { NodesApiService } from '../../common/services/nodes-api.service';
|
||||||
import { UploadService } from '../../common/services/upload.service';
|
import { UploadService } from '../../common/services/upload.service';
|
||||||
import { FileModel } from '../../common/models/file.model';
|
import { FileModel } from '../../common/models/file.model';
|
||||||
import { throwError } from 'rxjs';
|
import { throwError } from 'rxjs';
|
||||||
import { Component } from '@angular/core';
|
import { Component, CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
|
||||||
import { ESCAPE } from '@angular/cdk/keycodes';
|
import { ESCAPE } from '@angular/cdk/keycodes';
|
||||||
|
import { By } from '@angular/platform-browser';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'adf-viewer-container-toolbar',
|
selector: 'adf-viewer-container-toolbar',
|
||||||
@@ -149,6 +150,7 @@ describe('AlfrescoViewerComponent', () => {
|
|||||||
let extensionService: AppExtensionService;
|
let extensionService: AppExtensionService;
|
||||||
let renditionService: RenditionService;
|
let renditionService: RenditionService;
|
||||||
let viewUtilService: ViewUtilService;
|
let viewUtilService: ViewUtilService;
|
||||||
|
let nodeActionsService: NodeActionsService;
|
||||||
|
|
||||||
setupTestBed({
|
setupTestBed({
|
||||||
imports: [
|
imports: [
|
||||||
@@ -174,7 +176,8 @@ describe('AlfrescoViewerComponent', () => {
|
|||||||
},
|
},
|
||||||
{provide: Location, useClass: SpyLocation},
|
{provide: Location, useClass: SpyLocation},
|
||||||
MatDialog
|
MatDialog
|
||||||
]
|
],
|
||||||
|
schemas: [CUSTOM_ELEMENTS_SCHEMA]
|
||||||
});
|
});
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
@@ -188,6 +191,7 @@ describe('AlfrescoViewerComponent', () => {
|
|||||||
extensionService = TestBed.inject(AppExtensionService);
|
extensionService = TestBed.inject(AppExtensionService);
|
||||||
renditionService = TestBed.inject(RenditionService);
|
renditionService = TestBed.inject(RenditionService);
|
||||||
viewUtilService = TestBed.inject(ViewUtilService);
|
viewUtilService = TestBed.inject(ViewUtilService);
|
||||||
|
nodeActionsService = TestBed.inject(NodeActionsService);
|
||||||
});
|
});
|
||||||
|
|
||||||
afterEach(() => {
|
afterEach(() => {
|
||||||
@@ -350,6 +354,15 @@ describe('AlfrescoViewerComponent', () => {
|
|||||||
expect(component.nodeId).toBe('id1');
|
expect(component.nodeId).toBe('id1');
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
it('should download file when downloadFile event is emitted', () => {
|
||||||
|
spyOn(nodeActionsService, 'downloadNode');
|
||||||
|
const viewerComponent = fixture.debugElement.query(By.directive(ViewerComponent));
|
||||||
|
viewerComponent.triggerEventHandler('downloadFile');
|
||||||
|
|
||||||
|
fixture.detectChanges();
|
||||||
|
expect(nodeActionsService.downloadNode).toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
|
||||||
describe('Viewer Example Component Rendering', () => {
|
describe('Viewer Example Component Rendering', () => {
|
||||||
|
|
||||||
it('should use custom toolbar', (done) => {
|
it('should use custom toolbar', (done) => {
|
||||||
|
@@ -60,6 +60,7 @@ import { ContentService } from '../../common/services/content.service';
|
|||||||
import { NodesApiService } from '../../common/services/nodes-api.service';
|
import { NodesApiService } from '../../common/services/nodes-api.service';
|
||||||
import { UploadService } from '../../common/services/upload.service';
|
import { UploadService } from '../../common/services/upload.service';
|
||||||
import { FileModel } from '../../common/models/file.model';
|
import { FileModel } from '../../common/models/file.model';
|
||||||
|
import { NodeActionsService } from '../../document-list';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'adf-alfresco-viewer',
|
selector: 'adf-alfresco-viewer',
|
||||||
@@ -238,7 +239,8 @@ export class AlfrescoViewerComponent implements OnChanges, OnInit, OnDestroy {
|
|||||||
private contentService: ContentService,
|
private contentService: ContentService,
|
||||||
private uploadService: UploadService,
|
private uploadService: UploadService,
|
||||||
public dialog: MatDialog,
|
public dialog: MatDialog,
|
||||||
private cdr: ChangeDetectorRef) {
|
private cdr: ChangeDetectorRef,
|
||||||
|
private nodeActionsService: NodeActionsService) {
|
||||||
renditionService.maxRetries = this.maxRetries;
|
renditionService.maxRetries = this.maxRetries;
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -449,4 +451,7 @@ export class AlfrescoViewerComponent implements OnChanges, OnInit, OnDestroy {
|
|||||||
this.onDestroy$.complete();
|
this.onDestroy$.complete();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
onDownloadFile() {
|
||||||
|
this.nodeActionsService.downloadNode(this.nodeEntry);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -675,5 +675,15 @@ describe('ViewerComponent', () => {
|
|||||||
flush();
|
flush();
|
||||||
discardPeriodicTasks();
|
discardPeriodicTasks();
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
it('should emit downloadFileEvent when DownloadPromptDialog return DownloadPromptActions.DOWNLOAD on close', fakeAsync( () => {
|
||||||
|
dialogOpenSpy.and.returnValue({ afterClosed: () => of(DownloadPromptActions.DOWNLOAD) } as any);
|
||||||
|
spyOn(component.downloadFile, 'emit');
|
||||||
|
fixture.detectChanges();
|
||||||
|
tick(3000);
|
||||||
|
fixture.detectChanges();
|
||||||
|
|
||||||
|
expect(component.downloadFile.emit).toHaveBeenCalled();
|
||||||
|
}));
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@@ -190,6 +190,12 @@ export class ViewerComponent<T> implements OnDestroy, OnInit, OnChanges {
|
|||||||
* */
|
* */
|
||||||
downloadPromptReminderDelay: number = 15;
|
downloadPromptReminderDelay: number = 15;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Emitted when user clicks on download button on download prompt dialog.
|
||||||
|
* */
|
||||||
|
@Output()
|
||||||
|
downloadFile: EventEmitter<void> = new EventEmitter<void>();
|
||||||
|
|
||||||
/** Emitted when user clicks 'Navigate Before' ("<") button. */
|
/** Emitted when user clicks 'Navigate Before' ("<") button. */
|
||||||
@Output()
|
@Output()
|
||||||
navigateBefore = new EventEmitter<MouseEvent | KeyboardEvent>();
|
navigateBefore = new EventEmitter<MouseEvent | KeyboardEvent>();
|
||||||
@@ -388,7 +394,10 @@ export class ViewerComponent<T> implements OnDestroy, OnInit, OnChanges {
|
|||||||
this.isDialogVisible = true;
|
this.isDialogVisible = true;
|
||||||
this.dialog.open(DownloadPromptDialogComponent, { disableClose: true }).afterClosed().pipe(first()).subscribe((result: DownloadPromptActions) => {
|
this.dialog.open(DownloadPromptDialogComponent, { disableClose: true }).afterClosed().pipe(first()).subscribe((result: DownloadPromptActions) => {
|
||||||
this.isDialogVisible = false;
|
this.isDialogVisible = false;
|
||||||
if (result === DownloadPromptActions.WAIT) {
|
if (result === DownloadPromptActions.DOWNLOAD) {
|
||||||
|
this.downloadFile.emit();
|
||||||
|
this.onClose();
|
||||||
|
} else if (result === DownloadPromptActions.WAIT) {
|
||||||
if (this.enableDownloadPromptReminder) {
|
if (this.enableDownloadPromptReminder) {
|
||||||
this.clearDownloadPromptTimeouts();
|
this.clearDownloadPromptTimeouts();
|
||||||
this.downloadPromptReminderTimer = window.setTimeout(() => {
|
this.downloadPromptReminderTimer = window.setTimeout(() => {
|
||||||
|
Reference in New Issue
Block a user