mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-24 17:32:15 +00:00
[ADF-1403] Upload Dialog - Delete files event (#2234)
* remove provisional service * Error and Delete events * delete status * separate upload events * update demo * files upload counter and errors * pendig files icon and action * remove multiple files error key * handle cancel files * fixed component theme * remove fdescribe * resolved comments * throw error
This commit is contained in:
committed by
Mario Romano
parent
1deaa22570
commit
07ba8bc15f
@@ -34,3 +34,19 @@ export class FileUploadCompleteEvent extends FileUploadEvent {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export class FileUploadDeleteEvent extends FileUploadEvent {
|
||||
|
||||
constructor(file: FileModel, public totalComplete: number = 0) {
|
||||
super(file, FileUploadStatus.Deleted);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export class FileUploadErrorEvent extends FileUploadEvent {
|
||||
|
||||
constructor(file: FileModel, public error: any, public totalError: number = 0) {
|
||||
super(file, FileUploadStatus.Error);
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -34,7 +34,8 @@ export enum FileUploadStatus {
|
||||
Progress = 3,
|
||||
Cancelled = 4,
|
||||
Aborted = 5,
|
||||
Error = 6
|
||||
Error = 6,
|
||||
Deleted = 7
|
||||
}
|
||||
|
||||
export class FileModel {
|
||||
|
@@ -17,7 +17,7 @@
|
||||
|
||||
import { EventEmitter } from '@angular/core';
|
||||
import { TestBed } from '@angular/core/testing';
|
||||
import { FileModel, FileUploadOptions } from '../models/file.model';
|
||||
import { FileModel, FileUploadOptions, FileUploadStatus } from '../models/file.model';
|
||||
import { AlfrescoApiService } from './alfresco-api.service';
|
||||
import { AlfrescoSettingsService } from './alfresco-settings.service';
|
||||
import { AppConfigModule } from './app-config.service';
|
||||
@@ -214,4 +214,31 @@ describe('UploadService', () => {
|
||||
expect(result.length).toBe(1);
|
||||
expect(result[0]).toBe(file4);
|
||||
});
|
||||
|
||||
it('should call onUploadDeleted if file was deleted', () => {
|
||||
const file = <any> ({ status: FileUploadStatus.Deleted });
|
||||
spyOn(service.fileUploadDeleted, 'next');
|
||||
|
||||
service.cancelUpload(file);
|
||||
|
||||
expect(service.fileUploadDeleted.next).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should call fileUploadError if file has error status', () => {
|
||||
const file = <any> ({ status: FileUploadStatus.Error });
|
||||
spyOn(service.fileUploadError, 'next');
|
||||
|
||||
service.cancelUpload(file);
|
||||
|
||||
expect(service.fileUploadError.next).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should call fileUploadCancelled if file is in pending', () => {
|
||||
const file = <any> ({ status: FileUploadStatus.Pending });
|
||||
spyOn(service.fileUploadCancelled, 'next');
|
||||
|
||||
service.cancelUpload(file);
|
||||
|
||||
expect(service.fileUploadCancelled.next).toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
@@ -18,7 +18,7 @@
|
||||
import { EventEmitter, Injectable } from '@angular/core';
|
||||
import * as minimatch from 'minimatch';
|
||||
import { Subject } from 'rxjs/Rx';
|
||||
import { FileUploadCompleteEvent, FileUploadEvent } from '../events/file.event';
|
||||
import { FileUploadCompleteEvent, FileUploadDeleteEvent, FileUploadErrorEvent, FileUploadEvent } from '../events/file.event';
|
||||
import { FileModel, FileUploadProgress, FileUploadStatus } from '../models/file.model';
|
||||
import { AlfrescoApiService } from './alfresco-api.service';
|
||||
import { AppConfigService } from './app-config.service';
|
||||
@@ -30,6 +30,7 @@ export class UploadService {
|
||||
private cache: { [key: string]: any } = {};
|
||||
private totalComplete: number = 0;
|
||||
private totalAborted: number = 0;
|
||||
private totalError: number = 0;
|
||||
private activeTask: Promise<any> = null;
|
||||
private excludedFileList: String[] = [];
|
||||
|
||||
@@ -39,8 +40,9 @@ export class UploadService {
|
||||
fileUploadCancelled: Subject<FileUploadEvent> = new Subject<FileUploadEvent>();
|
||||
fileUploadProgress: Subject<FileUploadEvent> = new Subject<FileUploadEvent>();
|
||||
fileUploadAborted: Subject<FileUploadEvent> = new Subject<FileUploadEvent>();
|
||||
fileUploadError: Subject<FileUploadEvent> = new Subject<FileUploadEvent>();
|
||||
fileUploadError: Subject<FileUploadErrorEvent> = new Subject<FileUploadErrorEvent>();
|
||||
fileUploadComplete: Subject<FileUploadCompleteEvent> = new Subject<FileUploadCompleteEvent>();
|
||||
fileUploadDeleted: Subject<FileUploadDeleteEvent> = new Subject<FileUploadDeleteEvent>();
|
||||
|
||||
constructor(private apiService: AlfrescoApiService, private appConfigService: AppConfigService) {
|
||||
this.excludedFileList = <String[]> this.appConfigService.get('files.excluded');
|
||||
@@ -123,17 +125,15 @@ export class UploadService {
|
||||
|
||||
cancelUpload(...files: FileModel[]) {
|
||||
files.forEach(file => {
|
||||
file.status = FileUploadStatus.Cancelled;
|
||||
|
||||
const promise = this.cache[file.id];
|
||||
|
||||
if (promise) {
|
||||
promise.abort();
|
||||
delete this.cache[file.id];
|
||||
} else {
|
||||
const performAction = this.getAction(file);
|
||||
performAction();
|
||||
}
|
||||
|
||||
const event = new FileUploadEvent(file, FileUploadStatus.Cancelled);
|
||||
this.fileUpload.next(event);
|
||||
this.fileUploadCancelled.next(event);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -141,6 +141,7 @@ export class UploadService {
|
||||
this.queue = [];
|
||||
this.totalComplete = 0;
|
||||
this.totalAborted = 0;
|
||||
this.totalError = 0;
|
||||
}
|
||||
|
||||
getUploadPromise(file: FileModel) {
|
||||
@@ -183,7 +184,7 @@ export class UploadService {
|
||||
emitter.emit({ value: data });
|
||||
})
|
||||
.catch(err => {
|
||||
this.onUploadError(file, err);
|
||||
throw err;
|
||||
});
|
||||
|
||||
return promise;
|
||||
@@ -212,13 +213,14 @@ export class UploadService {
|
||||
private onUploadError(file: FileModel, error: any): void {
|
||||
if (file) {
|
||||
file.status = FileUploadStatus.Error;
|
||||
this.totalError++;
|
||||
|
||||
const promise = this.cache[file.id];
|
||||
if (promise) {
|
||||
delete this.cache[file.id];
|
||||
}
|
||||
|
||||
const event = new FileUploadEvent(file, FileUploadStatus.Error, error);
|
||||
const event = new FileUploadErrorEvent(file, error, this.totalError);
|
||||
this.fileUpload.next(event);
|
||||
this.fileUploadError.next(event);
|
||||
}
|
||||
@@ -257,4 +259,35 @@ export class UploadService {
|
||||
promise.next();
|
||||
}
|
||||
}
|
||||
|
||||
private onUploadCancelled(file: FileModel): void {
|
||||
if (file) {
|
||||
file.status = FileUploadStatus.Cancelled;
|
||||
|
||||
const event = new FileUploadEvent(file, FileUploadStatus.Cancelled);
|
||||
this.fileUpload.next(event);
|
||||
this.fileUploadCancelled.next(event);
|
||||
}
|
||||
}
|
||||
|
||||
private onUploadDeleted(file: FileModel): void {
|
||||
if (file) {
|
||||
file.status = FileUploadStatus.Deleted;
|
||||
this.totalComplete--;
|
||||
|
||||
const event = new FileUploadDeleteEvent(file, this.totalComplete);
|
||||
this.fileUpload.next(event);
|
||||
this.fileUploadDeleted.next(event);
|
||||
}
|
||||
}
|
||||
|
||||
private getAction(file) {
|
||||
const actions = {
|
||||
[FileUploadStatus.Pending]: () => this.onUploadCancelled(file),
|
||||
[FileUploadStatus.Deleted]: () => this.onUploadDeleted(file),
|
||||
[FileUploadStatus.Error]: () => this.onUploadError(file, null)
|
||||
};
|
||||
|
||||
return actions[file.status];
|
||||
}
|
||||
}
|
||||
|
@@ -43,7 +43,7 @@
|
||||
@include mat-comment-list-theme($theme);
|
||||
@include mat-start-task-theme($theme);
|
||||
@include mat-people-search-theme($theme);
|
||||
@include mat-file-uploading-list-theme($theme);
|
||||
@include mat-file-uploading-row-theme($theme);
|
||||
@include mat-people-theme($theme);
|
||||
@include mat-login-theme($theme);
|
||||
@include mat-accordion-theme($theme);
|
||||
|
Reference in New Issue
Block a user