From 5b168af13487596404a48d63fb8c751687db278c Mon Sep 17 00:00:00 2001 From: Cilibiu Bogdan Date: Tue, 15 Jan 2019 18:28:41 +0200 Subject: [PATCH] [ADF-3897] Upload Dialog - upload file error tooltip (#4148) --- lib/content-services/i18n/en.json | 10 ++++ .../file-uploading-list-row.component.html | 4 +- .../file-uploading-list-row.component.spec.ts | 3 +- .../pipes/file-upload-error.pipe.spec.ts | 48 +++++++++++++++++++ .../upload/pipes/file-upload-error.pipe.ts | 33 +++++++++++++ lib/content-services/upload/public-api.ts | 2 + lib/content-services/upload/upload.module.ts | 7 ++- lib/core/models/file.model.ts | 2 + lib/core/services/upload.service.ts | 1 + 9 files changed, 106 insertions(+), 4 deletions(-) create mode 100644 lib/content-services/upload/pipes/file-upload-error.pipe.spec.ts create mode 100644 lib/content-services/upload/pipes/file-upload-error.pipe.ts diff --git a/lib/content-services/i18n/en.json b/lib/content-services/i18n/en.json index 917babaca4..71cd50f25d 100644 --- a/lib/content-services/i18n/en.json +++ b/lib/content-services/i18n/en.json @@ -152,6 +152,16 @@ }, "ACTION": { "UNDO": "Undo" + }, + "ERRORS": { + "GENERIC": "Upload unsuccessful. Contact IT if this problem persists", + "500": "Internal server error, try again or contact IT support [500]", + "504": "The server timed out, try again or contact IT support [504]", + "403": "Insufficient permissions to upload in this location [403]", + "404": "Upload location no longer exists [404]" + }, + "ARIA-LABEL": { + "ERROR": "Upload error" } }, "WEBSCRIPT": { diff --git a/lib/content-services/upload/components/file-uploading-list-row.component.html b/lib/content-services/upload/components/file-uploading-list-row.component.html index e005bffc4a..192491d5d3 100644 --- a/lib/content-services/upload/components/file-uploading-list-row.component.html +++ b/lib/content-services/upload/components/file-uploading-list-row.component.html @@ -65,7 +65,9 @@
- + report_problem
diff --git a/lib/content-services/upload/components/file-uploading-list-row.component.spec.ts b/lib/content-services/upload/components/file-uploading-list-row.component.spec.ts index 791947102c..1772b35853 100644 --- a/lib/content-services/upload/components/file-uploading-list-row.component.spec.ts +++ b/lib/content-services/upload/components/file-uploading-list-row.component.spec.ts @@ -16,7 +16,7 @@ */ import { ComponentFixture, TestBed } from '@angular/core/testing'; -import { FileModel } from '@alfresco/adf-core'; +import { FileModel, CoreModule } from '@alfresco/adf-core'; import { UploadModule } from '../upload.module'; import { FileUploadingListRowComponent } from './file-uploading-list-row.component'; @@ -28,6 +28,7 @@ describe('FileUploadingListRowComponent', () => { beforeEach(() => { TestBed.configureTestingModule({ imports: [ + CoreModule.forRoot(), UploadModule ] }).compileComponents(); diff --git a/lib/content-services/upload/pipes/file-upload-error.pipe.spec.ts b/lib/content-services/upload/pipes/file-upload-error.pipe.spec.ts new file mode 100644 index 0000000000..17cebf589e --- /dev/null +++ b/lib/content-services/upload/pipes/file-upload-error.pipe.spec.ts @@ -0,0 +1,48 @@ +/*! + * @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 { TranslationMock } from '@alfresco/adf-core'; +import { FileUploadErrorPipe } from './file-upload-error.pipe'; + +describe('FileUploadErrorPipe', () => { + + let pipe: FileUploadErrorPipe; + + beforeEach(() => { + pipe = new FileUploadErrorPipe(new TranslationMock()); + }); + + it('should return generic message when error code is null', () => { + expect(pipe.transform(null)).toBe('FILE_UPLOAD.ERRORS.GENERIC'); + }); + + it('should return 500 message', () => { + expect(pipe.transform(500)).toBe('FILE_UPLOAD.ERRORS.500'); + }); + + it('should return 504 message', () => { + expect(pipe.transform(504)).toBe('FILE_UPLOAD.ERRORS.504'); + }); + + it('should return 403 message', () => { + expect(pipe.transform(403)).toBe('FILE_UPLOAD.ERRORS.403'); + }); + + it('should return 404 message', () => { + expect(pipe.transform(404)).toBe('FILE_UPLOAD.ERRORS.404'); + }); +}); diff --git a/lib/content-services/upload/pipes/file-upload-error.pipe.ts b/lib/content-services/upload/pipes/file-upload-error.pipe.ts new file mode 100644 index 0000000000..569e0944a2 --- /dev/null +++ b/lib/content-services/upload/pipes/file-upload-error.pipe.ts @@ -0,0 +1,33 @@ +/*! + * @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 { Pipe, PipeTransform } from '@angular/core'; +import { TranslationService } from '@alfresco/adf-core'; + +@Pipe({ + name: 'adfFileUploadError', + pure: true +}) +export class FileUploadErrorPipe implements PipeTransform { + + constructor(private translation: TranslationService) { + } + + transform(errorCode: number): string { + return this.translation.instant(`FILE_UPLOAD.ERRORS.${errorCode || 'GENERIC'}`); + } +} diff --git a/lib/content-services/upload/public-api.ts b/lib/content-services/upload/public-api.ts index 70650cacc3..ea1f0a1b9b 100644 --- a/lib/content-services/upload/public-api.ts +++ b/lib/content-services/upload/public-api.ts @@ -25,6 +25,8 @@ export * from './components/upload-files.event'; export * from './directives/file-draggable.directive'; +export * from './pipes/file-upload-error.pipe'; + export * from './components/base-upload/upload-base'; export * from './upload.module'; diff --git a/lib/content-services/upload/upload.module.ts b/lib/content-services/upload/upload.module.ts index aebb09eb81..cc17e9ea47 100644 --- a/lib/content-services/upload/upload.module.ts +++ b/lib/content-services/upload/upload.module.ts @@ -25,6 +25,7 @@ import { FileUploadingListComponent } from './components/file-uploading-list.com import { UploadButtonComponent } from './components/upload-button.component'; import { UploadVersionButtonComponent } from './components/upload-version-button.component'; import { UploadDragAreaComponent } from './components/upload-drag-area.component'; +import { FileUploadErrorPipe } from './pipes/file-upload-error.pipe'; import { CoreModule } from '@alfresco/adf-core'; import { FileDraggableDirective } from './directives/file-draggable.directive'; @@ -42,7 +43,8 @@ import { FileDraggableDirective } from './directives/file-draggable.directive'; UploadVersionButtonComponent, FileUploadingDialogComponent, FileUploadingListComponent, - FileUploadingListRowComponent + FileUploadingListRowComponent, + FileUploadErrorPipe ], exports: [ FileDraggableDirective, @@ -51,7 +53,8 @@ import { FileDraggableDirective } from './directives/file-draggable.directive'; UploadVersionButtonComponent, FileUploadingDialogComponent, FileUploadingListComponent, - FileUploadingListRowComponent + FileUploadingListRowComponent, + FileUploadErrorPipe ] }) export class UploadModule {} diff --git a/lib/core/models/file.model.ts b/lib/core/models/file.model.ts index cc96633cf3..d93c6c3042 100644 --- a/lib/core/models/file.model.ts +++ b/lib/core/models/file.model.ts @@ -54,6 +54,7 @@ export class FileModel { id: string; status: FileUploadStatus = FileUploadStatus.Pending; + errorCode: number; progress: FileUploadProgress; options: FileUploadOptions; data: any; @@ -64,6 +65,7 @@ export class FileModel { this.name = file.name; this.size = file.size; this.data = null; + this.errorCode = null; this.progress = { loaded: 0, diff --git a/lib/core/services/upload.service.ts b/lib/core/services/upload.service.ts index b7cb5403d3..b80125b7d4 100644 --- a/lib/core/services/upload.service.ts +++ b/lib/core/services/upload.service.ts @@ -250,6 +250,7 @@ export class UploadService { private onUploadError(file: FileModel, error: any): void { if (file) { + file.errorCode = ( error || {} ).status; file.status = FileUploadStatus.Error; this.totalError++;