diff --git a/src/app/components/files/files.component.ts b/src/app/components/files/files.component.ts index 0e1b4e583..bb25fe00c 100644 --- a/src/app/components/files/files.component.ts +++ b/src/app/components/files/files.component.ts @@ -103,7 +103,8 @@ export class FilesComponent extends PageComponent implements OnInit, OnDestroy { contentManagementService.nodesMoved.subscribe(() => this.documentList.reload()), contentManagementService.nodesRestored.subscribe(() => this.documentList.reload()), uploadService.fileUploadComplete.subscribe(file => this.onFileUploadedEvent(file)), - uploadService.fileUploadDeleted.subscribe((file) => this.onFileUploadedEvent(file)) + uploadService.fileUploadDeleted.subscribe((file) => this.onFileUploadedEvent(file)), + uploadService.fileUploadError.subscribe((error) => this.onFileUploadedError(error)) ]); } diff --git a/src/app/components/page.component.ts b/src/app/components/page.component.ts index 61efe7c6b..4bcb4fd30 100644 --- a/src/app/components/page.component.ts +++ b/src/app/components/page.component.ts @@ -24,7 +24,7 @@ */ import { MinimalNodeEntity, MinimalNodeEntryEntity, Pagination } from 'alfresco-js-api'; -import { UserPreferencesService } from '@alfresco/adf-core'; +import { UserPreferencesService, FileUploadErrorEvent } from '@alfresco/adf-core'; import { ShareDataRow, DocumentListComponent } from '@alfresco/adf-content-services'; import { ActivatedRoute, Router } from '@angular/router'; import { OnDestroy, ViewChild, OnInit } from '@angular/core'; @@ -34,6 +34,8 @@ import { AppStore } from '../store/states/app.state'; import { SetSelectedNodesAction } from '../store/actions/node.action'; import { selectedNodes } from '../store/selectors/app.selectors'; import { takeUntil } from 'rxjs/operators'; +import { SnackbarErrorAction } from '../store/actions'; + export abstract class PageComponent implements OnInit, OnDestroy { @@ -181,4 +183,14 @@ export abstract class PageComponent implements OnInit, OnDestroy { this.documentList.reload(); } } + + onFileUploadedError(error: FileUploadErrorEvent) { + let message = null; + + if (error.error.status === 409) { + message = new SnackbarErrorAction('VERSION.MESSAGE.ERROR.CONFLICT'); + } + + this.store.dispatch(message); + } } diff --git a/src/app/components/preview/preview.component.spec.ts b/src/app/components/preview/preview.component.spec.ts index 1bc2bd754..73f0fdc39 100644 --- a/src/app/components/preview/preview.component.spec.ts +++ b/src/app/components/preview/preview.component.spec.ts @@ -30,7 +30,7 @@ import { TestBed, async, ComponentFixture } from '@angular/core/testing'; import { AlfrescoApiService, UserPreferencesService, TranslationService, TranslationMock, - CoreModule + CoreModule, UploadService } from '@alfresco/adf-core'; import { PreviewComponent } from './preview.component'; @@ -63,7 +63,8 @@ describe('PreviewComponent', () => { providers: [ { provide: TranslationService, useClass: TranslationMock }, NodePermissionService, - ContentManagementService + ContentManagementService, + UploadService ], declarations: [ PreviewComponent, diff --git a/src/app/components/preview/preview.component.ts b/src/app/components/preview/preview.component.ts index 554a22f2c..e989fa993 100644 --- a/src/app/components/preview/preview.component.ts +++ b/src/app/components/preview/preview.component.ts @@ -25,13 +25,13 @@ import { Component, OnInit, ViewEncapsulation } from '@angular/core'; import { ActivatedRoute, Router, UrlTree, UrlSegmentGroup, UrlSegment, PRIMARY_OUTLET } from '@angular/router'; -import { AlfrescoApiService, UserPreferencesService, ObjectUtils } from '@alfresco/adf-core'; +import { AlfrescoApiService, UserPreferencesService, ObjectUtils, UploadService } from '@alfresco/adf-core'; import { Node, MinimalNodeEntity } from 'alfresco-js-api'; import { NodePermissionService } from '../../common/services/node-permission.service'; import { Store } from '@ngrx/store'; import { AppStore } from '../../store/states/app.state'; import { DeleteNodesAction } from '../../store/actions'; - +import { PageComponent } from '../page.component'; @Component({ selector: 'app-preview', templateUrl: 'preview.component.html', @@ -40,7 +40,7 @@ import { DeleteNodesAction } from '../../store/actions'; // tslint:disable-next-line:use-host-property-decorator host: { 'class': 'app-preview' } }) -export class PreviewComponent implements OnInit { +export class PreviewComponent extends PageComponent implements OnInit { node: Node; previewLocation: string = null; @@ -57,12 +57,15 @@ export class PreviewComponent implements OnInit { selectedEntities: MinimalNodeEntity[] = []; constructor( - private store: Store, - private router: Router, - private route: ActivatedRoute, + private uploadService: UploadService, private apiService: AlfrescoApiService, - private preferences: UserPreferencesService, + preferences: UserPreferencesService, + route: ActivatedRoute, + router: Router, + store: Store, public permission: NodePermissionService) { + + super(preferences, router, route, store); } ngOnInit() { @@ -90,6 +93,10 @@ export class PreviewComponent implements OnInit { this.displayNode(id); } }); + + this.subscriptions = this.subscriptions.concat([ + this.uploadService.fileUploadError.subscribe((error) => this.onFileUploadedError(error)) + ]); } /** diff --git a/src/app/components/recent-files/recent-files.component.spec.ts b/src/app/components/recent-files/recent-files.component.spec.ts index c74b89c87..43e11c588 100644 --- a/src/app/components/recent-files/recent-files.component.spec.ts +++ b/src/app/components/recent-files/recent-files.component.spec.ts @@ -30,7 +30,7 @@ import { RouterTestingModule } from '@angular/router/testing'; import { HttpClientModule } from '@angular/common/http'; import { NotificationService, TranslationService, TranslationMock, - NodesApiService, AlfrescoApiService, ContentService, + NodesApiService, AlfrescoApiService, ContentService, UploadService, UserPreferencesService, LogService, AppConfigService, StorageService, CookieService, ThumbnailService, AuthenticationService, TimeAgoPipe, NodeNameTooltipPipe, NodeFavoriteDirective, DataTableComponent, AppConfigPipe @@ -99,7 +99,8 @@ describe('RecentFiles Routed Component', () => { NodesApiService, DocumentListService, ThumbnailService, - CustomResourcesService + CustomResourcesService, + UploadService ], schemas: [ NO_ERRORS_SCHEMA ] }) diff --git a/src/app/components/recent-files/recent-files.component.ts b/src/app/components/recent-files/recent-files.component.ts index 0e2670e89..9d8999f6e 100644 --- a/src/app/components/recent-files/recent-files.component.ts +++ b/src/app/components/recent-files/recent-files.component.ts @@ -26,7 +26,7 @@ import { Component, OnInit } from '@angular/core'; import { Router, ActivatedRoute } from '@angular/router'; import { MinimalNodeEntryEntity } from 'alfresco-js-api'; -import { UserPreferencesService } from '@alfresco/adf-core'; +import { UserPreferencesService, UploadService } from '@alfresco/adf-core'; import { ContentManagementService } from '../../common/services/content-management.service'; import { PageComponent } from '../page.component'; @@ -43,6 +43,7 @@ export class RecentFilesComponent extends PageComponent implements OnInit { router: Router, route: ActivatedRoute, store: Store, + private uploadService: UploadService, private content: ContentManagementService, public permission: NodePermissionService, preferences: UserPreferencesService) { @@ -55,7 +56,8 @@ export class RecentFilesComponent extends PageComponent implements OnInit { this.subscriptions = this.subscriptions.concat([ this.content.nodesDeleted.subscribe(() => this.reload()), this.content.nodesMoved.subscribe(() => this.reload()), - this.content.nodesRestored.subscribe(() => this.reload()) + this.content.nodesRestored.subscribe(() => this.reload()), + this.uploadService.fileUploadError.subscribe((error) => this.onFileUploadedError(error)) ]); } diff --git a/src/app/components/shared-files/shared-files.component.spec.ts b/src/app/components/shared-files/shared-files.component.spec.ts index 1ebf9755d..e5de30198 100644 --- a/src/app/components/shared-files/shared-files.component.spec.ts +++ b/src/app/components/shared-files/shared-files.component.spec.ts @@ -31,7 +31,7 @@ import { HttpClientModule } from '@angular/common/http'; import { NotificationService, TranslationService, TranslationMock, NodesApiService, AlfrescoApiService, ContentService, - UserPreferencesService, LogService, AppConfigService, + UserPreferencesService, LogService, AppConfigService, UploadService, StorageService, CookieService, ThumbnailService, AuthenticationService, TimeAgoPipe, NodeNameTooltipPipe, NodeFavoriteDirective, DataTableComponent, AppConfigPipe } from '@alfresco/adf-core'; @@ -101,7 +101,8 @@ describe('SharedFilesComponent', () => { NodesApiService, DocumentListService, ThumbnailService, - CustomResourcesService + CustomResourcesService, + UploadService ], schemas: [ NO_ERRORS_SCHEMA ] }) diff --git a/src/app/components/shared-files/shared-files.component.ts b/src/app/components/shared-files/shared-files.component.ts index 47f9af629..efc889853 100644 --- a/src/app/components/shared-files/shared-files.component.ts +++ b/src/app/components/shared-files/shared-files.component.ts @@ -25,7 +25,7 @@ import { Component, OnInit } from '@angular/core'; import { Router, ActivatedRoute } from '@angular/router'; -import { UserPreferencesService } from '@alfresco/adf-core'; +import { UserPreferencesService, UploadService } from '@alfresco/adf-core'; import { ContentManagementService } from '../../common/services/content-management.service'; import { NodePermissionService } from '../../common/services/node-permission.service'; @@ -41,6 +41,7 @@ export class SharedFilesComponent extends PageComponent implements OnInit { constructor(router: Router, route: ActivatedRoute, store: Store, + private uploadService: UploadService, private content: ContentManagementService, public permission: NodePermissionService, preferences: UserPreferencesService) { @@ -53,7 +54,8 @@ export class SharedFilesComponent extends PageComponent implements OnInit { this.subscriptions = this.subscriptions.concat([ this.content.nodesDeleted.subscribe(() => this.reload()), this.content.nodesMoved.subscribe(() => this.reload()), - this.content.nodesRestored.subscribe(() => this.reload()) + this.content.nodesRestored.subscribe(() => this.reload()), + this.uploadService.fileUploadError.subscribe((error) => this.onFileUploadedError(error)) ]); } diff --git a/src/assets/i18n/en.json b/src/assets/i18n/en.json index 988f46999..2dcbe46ec 100644 --- a/src/assets/i18n/en.json +++ b/src/assets/i18n/en.json @@ -226,6 +226,11 @@ "SEARCH": "Search" }, "VERSION": { + "MESSAGE": { + "ERROR": { + "CONFLICT": "New version not uploaded, another file with the same name already exists" + } + }, "DIALOG": { "TITLE": "Manage Versions", "CLOSE": "Close"