From cb37a633309c1c747639ca6f203cdac2f3447be4 Mon Sep 17 00:00:00 2001 From: Urse Daniel Date: Sat, 8 May 2021 10:25:43 +0300 Subject: [PATCH] Revert changes from dev-durse-ADF-5378-integration (#2112) * revert changes from dev-durse-ADF-5378-integration * remove comma --- .../store/src/actions/upload.actions.ts | 9 +- .../app-layout/app-layout.component.scss | 2 - .../components/viewer/viewer.component.html | 2 - src/app/components/viewer/viewer.component.ts | 12 +-- src/app/store/effects/upload.effects.spec.ts | 100 ++---------------- src/app/store/effects/upload.effects.ts | 44 ++------ src/assets/i18n/en.json | 3 - 7 files changed, 18 insertions(+), 154 deletions(-) diff --git a/projects/aca-shared/store/src/actions/upload.actions.ts b/projects/aca-shared/store/src/actions/upload.actions.ts index fcb8282fd..05e8e163a 100644 --- a/projects/aca-shared/store/src/actions/upload.actions.ts +++ b/projects/aca-shared/store/src/actions/upload.actions.ts @@ -28,8 +28,7 @@ import { Action } from '@ngrx/store'; export enum UploadActionTypes { UploadFiles = 'UPLOAD_FILES', UploadFolder = 'UPLOAD_FOLDER', - UploadFileVersion = 'UPLOAD_FILE_VERSION', - UploadImage = 'UPLOAD_IMAGE' + UploadFileVersion = 'UPLOAD_FILE_VERSION' } export class UploadFilesAction implements Action { @@ -44,12 +43,6 @@ export class UploadFolderAction implements Action { constructor(public payload: any) {} } -export class UploadNewImageAction implements Action { - readonly type = UploadActionTypes.UploadImage; - - constructor(public payload: any) {} -} - export class UploadFileVersionAction implements Action { readonly type = UploadActionTypes.UploadFileVersion; diff --git a/src/app/components/layout/app-layout/app-layout.component.scss b/src/app/components/layout/app-layout/app-layout.component.scss index f80819974..e9e226cab 100644 --- a/src/app/components/layout/app-layout/app-layout.component.scss +++ b/src/app/components/layout/app-layout/app-layout.component.scss @@ -19,8 +19,6 @@ adf-file-uploading-dialog { z-index: 1100; } - - } @media screen and (max-width: 599px) { diff --git a/src/app/components/viewer/viewer.component.html b/src/app/components/viewer/viewer.component.html index 2b5da1866..f62a0a2ff 100644 --- a/src/app/components/viewer/viewer.component.html +++ b/src/app/components/viewer/viewer.component.html @@ -14,8 +14,6 @@ [allowDownload]="false" [allowFullScreen]="false" [overlayMode]="true" - [readOnly]="!canUpdateNode" - (fileSubmit)="onFileSubmit($event)" (showViewerChange)="onViewerVisibilityChanged()" [canNavigateBefore]="previousNodeId" [canNavigateNext]="nextNodeId" diff --git a/src/app/components/viewer/viewer.component.ts b/src/app/components/viewer/viewer.component.ts index 709b36ca1..c1d60f7f0 100644 --- a/src/app/components/viewer/viewer.component.ts +++ b/src/app/components/viewer/viewer.component.ts @@ -33,7 +33,6 @@ import { ReloadDocumentListAction, SetCurrentNodeVersionAction, SetSelectedNodesAction, - UploadNewImageAction, ViewerActionTypes, ViewNodeAction } from '@alfresco/aca-shared/store'; @@ -46,7 +45,6 @@ import { Store } from '@ngrx/store'; import { from, Observable, Subject } from 'rxjs'; import { debounceTime, takeUntil } from 'rxjs/operators'; import { Actions, ofType } from '@ngrx/effects'; -import { ContentManagementService } from '../../services/content-management.service'; @Component({ selector: 'app-viewer', @@ -66,7 +64,6 @@ export class AppViewerComponent implements OnInit, OnDestroy { selection: SelectionState; infoDrawerOpened$: Observable; - canUpdateNode = false; showRightSide = false; openWith: ContentActionRef[] = []; toolbarActions: ContentActionRef[] = []; @@ -115,8 +112,7 @@ export class AppViewerComponent implements OnInit, OnDestroy { private preferences: UserPreferencesService, private apiService: AlfrescoApiService, private uploadService: UploadService, - private appHookService: AppHookService, - private content: ContentManagementService + private appHookService: AppHookService ) {} ngOnInit() { @@ -212,7 +208,6 @@ export class AppViewerComponent implements OnInit, OnDestroy { if (nodeId) { try { this.node = await this.contentApi.getNodeInfo(nodeId).toPromise(); - this.canUpdateNode = this.content.canUpdateNode(this.node); this.store.dispatch(new SetSelectedNodesAction([{ entry: this.node }])); this.navigateMultiple = this.extensions.canShowViewerNavigation({ entry: this.node }); if (!this.navigateMultiple) { @@ -259,11 +254,6 @@ export class AppViewerComponent implements OnInit, OnDestroy { this.store.dispatch(new ViewNodeAction(this.nextNodeId, { location })); } - onFileSubmit(newBlob: Blob) { - const newImageFile: File = new File([newBlob], this?.node?.name, { type: this?.node?.content?.mimeType }); - this.store.dispatch(new UploadNewImageAction(newImageFile)); - } - /** * Retrieves nearest node information for the given node and folder. * @param nodeId Unique identifier of the document node diff --git a/src/app/store/effects/upload.effects.spec.ts b/src/app/store/effects/upload.effects.spec.ts index 85577b68b..d4b94966d 100644 --- a/src/app/store/effects/upload.effects.spec.ts +++ b/src/app/store/effects/upload.effects.spec.ts @@ -25,23 +25,13 @@ import { Store } from '@ngrx/store'; import { TestBed } from '@angular/core/testing'; -import { Actions, EffectsModule } from '@ngrx/effects'; +import { EffectsModule } from '@ngrx/effects'; import { UploadEffects } from './upload.effects'; import { AppTestingModule } from '../../testing/app-testing.module'; import { NgZone } from '@angular/core'; import { UploadService, FileUploadCompleteEvent, FileModel } from '@alfresco/adf-core'; -import { - SnackbarErrorAction, - SnackbarInfoAction, - UnlockWriteAction, - UploadFileVersionAction, - UploadNewImageAction -} from '@alfresco/aca-shared/store'; +import { UnlockWriteAction, UploadFileVersionAction } from '@alfresco/aca-shared/store'; import { ContentManagementService } from '../../services/content-management.service'; -import { Observable, of, throwError } from 'rxjs'; -import { MinimalNodeEntryEntity } from '@alfresco/js-api'; -import { cold, hot } from 'jasmine-marbles'; -import { provideMockActions } from '@ngrx/effects/testing'; describe('UploadEffects', () => { let store: Store; @@ -49,35 +39,10 @@ describe('UploadEffects', () => { let effects: UploadEffects; let zone: NgZone; let contentManagementService: ContentManagementService; - let actions$: Observable = of(); - const fakeNode: MinimalNodeEntryEntity = { - createdAt: undefined, - modifiedAt: undefined, - modifiedByUser: undefined, - isFile: true, - createdByUser: { - id: 'admin.adf@alfresco.com', - displayName: 'Administrator' - }, - nodeType: 'cm:content', - content: { - mimeType: 'image/jpeg', - mimeTypeName: 'JPEG Image', - sizeInBytes: 175540, - encoding: 'UTF-8' - }, - parentId: 'dff2bc1e-d092-42ac-82d1-87c82f6e56cb', - isFolder: false, - name: 'GoqZhm.jpg', - id: '1bf8a8f7-18ac-4eef-919d-61d952eaa179', - allowableOperations: ['delete', 'update', 'updatePermissions'], - isFavorite: false - }; beforeEach(() => { TestBed.configureTestingModule({ - imports: [AppTestingModule, EffectsModule.forRoot([UploadEffects])], - providers: [provideMockActions(() => actions$)] + imports: [AppTestingModule, EffectsModule.forRoot([UploadEffects])] }); zone = TestBed.inject(NgZone); @@ -91,6 +56,11 @@ describe('UploadEffects', () => { effects = TestBed.inject(UploadEffects); }); + beforeEach(() => { + spyOn(effects['fileVersionInput'], 'click'); + spyOn(effects, 'uploadVersion').and.callThrough(); + }); + describe('uploadAndUnlock()', () => { it('should not upload and unlock file if param not provided', () => { effects.uploadAndUnlock(null); @@ -181,17 +151,8 @@ describe('UploadEffects', () => { }); describe('upload file version', () => { - beforeEach(() => { - actions$ = TestBed.inject(Actions); - }); - it('should trigger upload file from context menu', () => { - spyOn(effects['fileVersionInput'], 'click'); - actions$ = hot('a', { - a: new UploadFileVersionAction(undefined) - }); - const expected = cold('b', {}); - expect(effects.uploadVersion$).toBeObservable(expected); + store.dispatch({ type: 'UPLOAD_FILE_VERSION' }); expect(effects['fileVersionInput'].click).toHaveBeenCalled(); }); @@ -245,50 +206,9 @@ describe('UploadEffects', () => { } } }); - actions$ = hot('a', { - a: new UploadFileVersionAction(fakeEvent) - }); - - const expected = cold('b', {}); - expect(effects.uploadVersion$).toBeObservable(expected); + store.dispatch(new UploadFileVersionAction(fakeEvent)); expect(contentManagementService.versionUpdateDialog).toHaveBeenCalledWith(fakeEvent.detail.data.node.entry, fakeEvent.detail.files[0].file); }); }); - - describe('image versioning', () => { - beforeEach(() => { - actions$ = TestBed.inject(Actions); - }); - - it('should trigger upload file version from viewer', () => { - spyOn(contentManagementService, 'getNodeInfo').and.returnValue(of(fakeNode)); - const data = atob('iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNk+M9QDwADhgGAWjR9awAAAABJRU5ErkJggg=='); - const fakeBlob = new Blob([data], { type: 'image/png' }); - const newImageFile: File = new File([fakeBlob], 'GoqZhm.jpg'); - actions$ = hot('a', { - a: new UploadNewImageAction(newImageFile) - }); - - const expected = cold('b', { - b: new SnackbarInfoAction('APP.MESSAGES.UPLOAD.SUCCESS.MEDIA_MANAGEMENT') - }); - expect(effects.uploadNewImage$).toBeObservable(expected); - }); - - it('should display snackbar if can`t retrieve node details', () => { - spyOn(contentManagementService, 'getNodeInfo').and.returnValue(throwError(fakeNode)); - const data = atob('iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNk+M9QDwADhgGAWjR9awAAAABJRU5ErkJggg=='); - const fakeBlob = new Blob([data], { type: 'image/png' }); - const newImageFile: File = new File([fakeBlob], 'GoqZhm.jpg'); - actions$ = hot('a', { - a: new UploadNewImageAction(newImageFile) - }); - - const expected = cold('b', { - b: new SnackbarErrorAction('APP.MESSAGES.UPLOAD.ERROR.GENERIC') - }); - expect(effects.uploadNewImage$).toBeObservable(expected); - }); - }); }); diff --git a/src/app/store/effects/upload.effects.ts b/src/app/store/effects/upload.effects.ts index 999bc8448..62f47ad50 100644 --- a/src/app/store/effects/upload.effects.ts +++ b/src/app/store/effects/upload.effects.ts @@ -31,16 +31,14 @@ import { UploadFilesAction, UploadFileVersionAction, UploadFolderAction, - getCurrentFolder, - UploadNewImageAction, - SnackbarInfoAction + getCurrentFolder } from '@alfresco/aca-shared/store'; import { FileModel, FileUtils, UploadService } from '@alfresco/adf-core'; import { Injectable, NgZone, RendererFactory2 } from '@angular/core'; import { Actions, Effect, ofType } from '@ngrx/effects'; import { Store } from '@ngrx/store'; import { of } from 'rxjs'; -import { catchError, map, mergeMap, switchMap, take } from 'rxjs/operators'; +import { catchError, map, take } from 'rxjs/operators'; import { ContentManagementService } from '../../services/content-management.service'; import { MinimalNodeEntryEntity } from '@alfresco/js-api'; @@ -103,47 +101,17 @@ export class UploadEffects { }) ); - @Effect({ dispatch: false }) - uploadNewImage$ = this.actions$.pipe( - ofType(UploadActionTypes.UploadImage), - switchMap((action) => { - return this.contentService.getNodeInfo().pipe( - mergeMap((node) => { - if (node?.id) { - const newFile = new FileModel( - action?.payload, - { - majorVersion: false, - newVersion: true, - parentId: node?.parentId, - nodeType: node?.content?.mimeType - }, - node?.id - ); - this.uploadQueue([newFile]); - return of(new SnackbarInfoAction('APP.MESSAGES.UPLOAD.SUCCESS.MEDIA_MANAGEMENT')); - } - return of(null); - }), - catchError(() => { - return of(new SnackbarErrorAction('APP.MESSAGES.UPLOAD.ERROR.GENERIC')); - }) - ); - }) - ); - @Effect({ dispatch: false }) uploadVersion$ = this.actions$.pipe( ofType(UploadActionTypes.UploadFileVersion), - mergeMap((action) => { + map((action) => { if (action?.payload) { const node = action?.payload?.detail?.data?.node?.entry; const file: any = action?.payload?.detail?.files[0]?.file; - return of(this.contentService.versionUpdateDialog(node, file)); - } else if (!action.payload) { - return of(this.fileVersionInput.click()); + this.contentService.versionUpdateDialog(node, file); + } else if (!action?.payload) { + this.fileVersionInput.click(); } - return of(null); }) ); diff --git a/src/assets/i18n/en.json b/src/assets/i18n/en.json index c4e3125b0..24ebd82ce 100644 --- a/src/assets/i18n/en.json +++ b/src/assets/i18n/en.json @@ -301,9 +301,6 @@ "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]" - }, - "SUCCESS": { - "MEDIA_MANAGEMENT_SUCCESS": "Version updated successfully" } }, "INFO": {