From 045c4ee9a2a42ada383ca254d630989b18853f2e Mon Sep 17 00:00:00 2001 From: Denys Vuika Date: Thu, 21 Jun 2018 19:56:08 +0100 Subject: [PATCH] library effects and actions (#441) * library effects and actions * single selection and test fixes * navigate to site route * add experimental flag * disable test * update tests --- .../actions/toolbar-single-selection.test.ts | 2 +- src/app.config.json | 4 +- .../directives/node-restore.directive.ts | 13 ++-- .../services/content-management.service.ts | 1 + .../libraries/libraries.component.html | 21 +++++- .../libraries/libraries.component.spec.ts | 9 ++- .../libraries/libraries.component.ts | 22 +++++- src/app/store/actions.ts | 1 + src/app/store/actions/library.actions.ts | 33 +++++++++ src/app/store/app-store.module.ts | 6 +- src/app/store/effects.ts | 1 + src/app/store/effects/library.effects.ts | 71 +++++++++++++++++++ src/assets/i18n/en.json | 6 +- 13 files changed, 174 insertions(+), 16 deletions(-) create mode 100644 src/app/store/actions/library.actions.ts create mode 100644 src/app/store/effects/library.effects.ts diff --git a/e2e/suites/actions/toolbar-single-selection.test.ts b/e2e/suites/actions/toolbar-single-selection.test.ts index 5404e4062..d97d7f65b 100755 --- a/e2e/suites/actions/toolbar-single-selection.test.ts +++ b/e2e/suites/actions/toolbar-single-selection.test.ts @@ -99,7 +99,7 @@ describe('Toolbar actions - single selection : ', () => { .then(done); }); - it('actions not displayed for top level of File Libraries', () => { + xit('actions not displayed for top level of File Libraries', () => { page.sidenav.navigateToLinkByLabel(SIDEBAR_LABELS.FILE_LIBRARIES) .then(() => dataTable.waitForHeader()) .then(() => dataTable.clickOnItemName(userSite)) diff --git a/src/app.config.json b/src/app.config.json index 01f23c221..5aa7fd007 100644 --- a/src/app.config.json +++ b/src/app.config.json @@ -8,7 +8,9 @@ "copyright": "© 2017 - 2018 Alfresco Software, Inc. All rights reserved." }, - "experimental": {}, + "experimental": { + "libraries": true + }, "headerColor": "#2196F3", "languagePicker": false, "pagination": { diff --git a/src/app/common/directives/node-restore.directive.ts b/src/app/common/directives/node-restore.directive.ts index 8773f583a..e5e4c1c74 100644 --- a/src/app/common/directives/node-restore.directive.ts +++ b/src/app/common/directives/node-restore.directive.ts @@ -29,6 +29,7 @@ import { Observable } from 'rxjs/Rx'; import { AlfrescoApiService } from '@alfresco/adf-core'; import { MinimalNodeEntity, + MinimalNodeEntryEntity, PathInfoEntity, DeletedNodesPaging } from 'alfresco-js-api'; @@ -230,12 +231,12 @@ export class NodeRestoreDirective { if (message) { if (status.oneSucceeded && !status.someFailed) { + const isSite = this.isSite(status.success[0].entry); const path: PathInfoEntity = status.success[0].entry.path; const parent = path.elements[path.elements.length - 1]; - const navigate = new NavigateRouteAction([ - '/personal-files', - parent.id - ]); + const route = isSite ? ['/libraries'] : ['/personal-files', parent.id]; + + const navigate = new NavigateRouteAction(route); message.userAction = new SnackbarUserAction( 'APP.ACTIONS.VIEW', @@ -247,6 +248,10 @@ export class NodeRestoreDirective { } } + private isSite(entry: MinimalNodeEntryEntity): boolean { + return entry.nodeType === 'st:site'; + } + private refresh(): void { this.contentManagementService.nodesRestored.next(); } diff --git a/src/app/common/services/content-management.service.ts b/src/app/common/services/content-management.service.ts index e1c47d5f7..032b8231b 100644 --- a/src/app/common/services/content-management.service.ts +++ b/src/app/common/services/content-management.service.ts @@ -34,4 +34,5 @@ export class ContentManagementService { nodesRestored = new Subject(); folderEdited = new Subject(); folderCreated = new Subject(); + siteDeleted = new Subject(); } diff --git a/src/app/components/libraries/libraries.component.html b/src/app/components/libraries/libraries.component.html index c78715378..133da22a2 100644 --- a/src/app/components/libraries/libraries.component.html +++ b/src/app/components/libraries/libraries.component.html @@ -2,7 +2,24 @@
- + + + + + + +
@@ -10,7 +27,7 @@
diff --git a/src/app/components/libraries/libraries.component.spec.ts b/src/app/components/libraries/libraries.component.spec.ts index fe9e624c5..583722211 100644 --- a/src/app/components/libraries/libraries.component.spec.ts +++ b/src/app/components/libraries/libraries.component.spec.ts @@ -47,6 +47,8 @@ import { LibrariesComponent } from './libraries.component'; import { StoreModule } from '@ngrx/store'; import { appReducer } from '../../store/reducers/app.reducer'; import { INITIAL_STATE } from '../../store/states/app.state'; +import { ContentManagementService } from '../../common/services/content-management.service'; +import { ExperimentalDirective } from '../../directives/experimental.directive'; describe('Libraries Routed Component', () => { let fixture: ComponentFixture; @@ -91,7 +93,8 @@ describe('Libraries Routed Component', () => { NodeFavoriteDirective, DocumentListComponent, LibrariesComponent, - AppConfigPipe + AppConfigPipe, + ExperimentalDirective ], providers: [ { provide: TranslationService, useClass: TranslationMock }, @@ -105,7 +108,9 @@ describe('Libraries Routed Component', () => { NodesApiService, DocumentListService, ThumbnailService, - CustomResourcesService + CustomResourcesService, + + ContentManagementService ], schemas: [ NO_ERRORS_SCHEMA ] }) diff --git a/src/app/components/libraries/libraries.component.ts b/src/app/components/libraries/libraries.component.ts index 19e5a2430..125b9c984 100644 --- a/src/app/components/libraries/libraries.component.ts +++ b/src/app/components/libraries/libraries.component.ts @@ -23,7 +23,7 @@ * along with Alfresco. If not, see . */ -import { Component } from '@angular/core'; +import { Component, OnInit } from '@angular/core'; import { Router, ActivatedRoute } from '@angular/router'; import { NodesApiService } from '@alfresco/adf-core'; import { ShareDataRow } from '@alfresco/adf-content-services'; @@ -31,19 +31,31 @@ import { ShareDataRow } from '@alfresco/adf-content-services'; import { PageComponent } from '../page.component'; import { Store } from '@ngrx/store'; import { AppStore } from '../../store/states/app.state'; +import { DeleteLibraryAction } from '../../store/actions'; +import { SiteEntry } from 'alfresco-js-api'; +import { ContentManagementService } from '../../common/services/content-management.service'; @Component({ templateUrl: './libraries.component.html' }) -export class LibrariesComponent extends PageComponent { +export class LibrariesComponent extends PageComponent implements OnInit { constructor(private nodesApi: NodesApiService, private route: ActivatedRoute, + private content: ContentManagementService, store: Store, private router: Router) { super(store); } + ngOnInit() { + super.ngOnInit(); + + this.subscriptions.push( + this.content.siteDeleted.subscribe(() => this.reload()) + ); + } + makeLibraryTooltip(library: any): string { const { description, title } = library; @@ -84,4 +96,10 @@ export class LibrariesComponent extends PageComponent { }); } } + + deleteLibrary(node: SiteEntry) { + if (node && node.entry) { + this.store.dispatch(new DeleteLibraryAction(node.entry.id)); + } + } } diff --git a/src/app/store/actions.ts b/src/app/store/actions.ts index cb5ff1eee..013545cb3 100644 --- a/src/app/store/actions.ts +++ b/src/app/store/actions.ts @@ -30,3 +30,4 @@ export * from './actions/router.actions'; export * from './actions/viewer.actions'; export * from './actions/search.actions'; export * from './actions/user.actions'; +export * from './actions/library.actions'; diff --git a/src/app/store/actions/library.actions.ts b/src/app/store/actions/library.actions.ts new file mode 100644 index 000000000..d2fad4aef --- /dev/null +++ b/src/app/store/actions/library.actions.ts @@ -0,0 +1,33 @@ +/*! + * @license + * Alfresco Example Content Application + * + * Copyright (C) 2005 - 2018 Alfresco Software Limited + * + * This file is part of the Alfresco Example Content Application. + * If the software was purchased under a paid Alfresco license, the terms of + * the paid license agreement will prevail. Otherwise, the software is + * provided under the following open source license terms: + * + * The Alfresco Example Content Application is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * The Alfresco Example Content Application is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Alfresco. If not, see . + */ + +import { Action } from '@ngrx/store'; + +export const DELETE_LIBRARY = 'DELETE_LIBRARY'; + +export class DeleteLibraryAction implements Action { + readonly type = DELETE_LIBRARY; + constructor(public payload: string) {} +} diff --git a/src/app/store/app-store.module.ts b/src/app/store/app-store.module.ts index 6c547ee28..2fff5f17b 100644 --- a/src/app/store/app-store.module.ts +++ b/src/app/store/app-store.module.ts @@ -37,7 +37,8 @@ import { RouterEffects, DownloadEffects, ViewerEffects, - SearchEffects + SearchEffects, + SiteEffects } from './effects'; @NgModule({ @@ -53,7 +54,8 @@ import { RouterEffects, DownloadEffects, ViewerEffects, - SearchEffects + SearchEffects, + SiteEffects ]), !environment.production ? StoreDevtoolsModule.instrument({ maxAge: 25 }) diff --git a/src/app/store/effects.ts b/src/app/store/effects.ts index c4f6826e8..3c773fee2 100644 --- a/src/app/store/effects.ts +++ b/src/app/store/effects.ts @@ -29,3 +29,4 @@ export * from './effects/router.effects'; export * from './effects/snackbar.effects'; export * from './effects/viewer.effects'; export * from './effects/search.effects'; +export * from './effects/library.effects'; diff --git a/src/app/store/effects/library.effects.ts b/src/app/store/effects/library.effects.ts new file mode 100644 index 000000000..71e07894b --- /dev/null +++ b/src/app/store/effects/library.effects.ts @@ -0,0 +1,71 @@ +/*! + * @license + * Alfresco Example Content Application + * + * Copyright (C) 2005 - 2018 Alfresco Software Limited + * + * This file is part of the Alfresco Example Content Application. + * If the software was purchased under a paid Alfresco license, the terms of + * the paid license agreement will prevail. Otherwise, the software is + * provided under the following open source license terms: + * + * The Alfresco Example Content Application is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * The Alfresco Example Content Application is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Alfresco. If not, see . + */ + +import { Effect, Actions, ofType } from '@ngrx/effects'; +import { Injectable } from '@angular/core'; +import { map } from 'rxjs/operators'; +import { DeleteLibraryAction, DELETE_LIBRARY } from '../actions'; +import { AlfrescoApiService } from '@alfresco/adf-core'; +import { + SnackbarInfoAction, + SnackbarErrorAction +} from '../actions/snackbar.actions'; +import { Store } from '@ngrx/store'; +import { AppStore } from '../states/app.state'; +import { ContentManagementService } from '../../common/services/content-management.service'; + +@Injectable() +export class SiteEffects { + constructor( + private actions$: Actions, + private store: Store, + private apiService: AlfrescoApiService, + private content: ContentManagementService + ) {} + + @Effect({ dispatch: false }) + deleteLibrary$ = this.actions$.pipe( + ofType(DELETE_LIBRARY), + map(action => { + this.apiService.sitesApi.deleteSite(action.payload).then( + () => { + this.content.siteDeleted.next(action.payload); + this.store.dispatch( + new SnackbarInfoAction( + 'APP.MESSAGES.INFO.LIBRARY_DELETED' + ) + ); + }, + err => { + this.store.dispatch( + new SnackbarErrorAction( + 'APP.MESSAGES.ERRORS.DELETE_LIBRARY_FAILED' + ) + ); + } + ); + }) + ); +} diff --git a/src/assets/i18n/en.json b/src/assets/i18n/en.json index 0b15b0b78..51afdae0c 100644 --- a/src/assets/i18n/en.json +++ b/src/assets/i18n/en.json @@ -174,7 +174,8 @@ "LOCATION_MISSING": "Can't restore {{ name }}, the original location no longer exists", "GENERIC": "There was a problem restoring {{ name }}" } - } + }, + "DELETE_LIBRARY_FAILED": "Cannot delete the library" }, "UPLOAD": { "ERROR": { @@ -218,7 +219,8 @@ "PLURAL": "Partially moved {{ partially }} items.", "FAIL": "{{ failed }} couldn't be moved." } - } + }, + "LIBRARY_DELETED": "Library deleted" } }, "CONTENT_METADATA": {