From 13db4fb339b25906c38d292472c479010c5e6f03 Mon Sep 17 00:00:00 2001 From: Suzana Dirla Date: Fri, 23 Nov 2018 16:23:26 +0200 Subject: [PATCH] [ACA-1607][ACA-1985] Leave library action (#824) * [ACA-1607] leave library action * [ACA-1607] confirm leave action * [ACA-1607] confirm leave action * [ACA-1607] remove comment --- .../favorite-libraries.component.ts | 1 + .../libraries/libraries.component.ts | 1 + .../search-libraries-results.component.ts | 3 ++ src/app/services/content-api.service.ts | 4 +++ .../services/content-management.service.ts | 33 +++++++++++++++++++ src/app/store/actions/library.actions.ts | 6 ++++ src/app/store/effects/library.effects.ts | 23 ++++++++++++- src/assets/app.extensions.json | 32 ++++++++++++++++++ src/assets/i18n/en.json | 15 +++++++-- 9 files changed, 114 insertions(+), 4 deletions(-) diff --git a/src/app/components/favorite-libraries/favorite-libraries.component.ts b/src/app/components/favorite-libraries/favorite-libraries.component.ts index 980bbcb45..062f7f9cf 100644 --- a/src/app/components/favorite-libraries/favorite-libraries.component.ts +++ b/src/app/components/favorite-libraries/favorite-libraries.component.ts @@ -63,6 +63,7 @@ export class FavoriteLibrariesComponent extends PageComponent this.content.libraryDeleted.subscribe(() => this.reloadList()), this.content.libraryUpdated.subscribe(() => this.reloadList()), this.content.libraryJoined.subscribe(() => this.reloadList()), + this.content.libraryLeft.subscribe(() => this.reloadList()), this.content.favoriteLibraryToggle.subscribe(() => this.reloadList()), this.breakpointObserver diff --git a/src/app/components/libraries/libraries.component.ts b/src/app/components/libraries/libraries.component.ts index 8b1affc39..377c1f32a 100644 --- a/src/app/components/libraries/libraries.component.ts +++ b/src/app/components/libraries/libraries.component.ts @@ -56,6 +56,7 @@ export class LibrariesComponent extends PageComponent implements OnInit { this.subscriptions.push( this.content.libraryDeleted.subscribe(() => this.reload()), this.content.libraryUpdated.subscribe(() => this.reload()), + this.content.libraryLeft.subscribe(() => this.reload()), this.breakpointObserver .observe([Breakpoints.HandsetPortrait, Breakpoints.HandsetLandscape]) diff --git a/src/app/components/search/search-libraries-results/search-libraries-results.component.ts b/src/app/components/search/search-libraries-results/search-libraries-results.component.ts index 74a29ee8e..6011e3f04 100644 --- a/src/app/components/search/search-libraries-results/search-libraries-results.component.ts +++ b/src/app/components/search/search-libraries-results/search-libraries-results.component.ts @@ -79,6 +79,9 @@ export class SearchLibrariesResultsComponent extends PageComponent this.content.libraryDeleted.subscribe(() => this.librariesQueryBuilder.update() ), + this.content.libraryLeft.subscribe(() => + this.librariesQueryBuilder.update() + ), this.librariesQueryBuilder.updated.subscribe(() => { this.isLoading = true; diff --git a/src/app/services/content-api.service.ts b/src/app/services/content-api.service.ts index 323be86a9..0d73df922 100644 --- a/src/app/services/content-api.service.ts +++ b/src/app/services/content-api.service.ts @@ -220,6 +220,10 @@ export class ContentApiService { return from(this.api.sitesApi.deleteSite(siteId, opts)); } + leaveSite(siteId?: string): Observable { + return from(this.api.sitesApi.removeSiteMember(siteId, '-me-')); + } + createSite( siteBody: SiteBody, opts?: { diff --git a/src/app/services/content-management.service.ts b/src/app/services/content-management.service.ts index 4069413b2..49e624fc4 100644 --- a/src/app/services/content-management.service.ts +++ b/src/app/services/content-management.service.ts @@ -83,6 +83,7 @@ export class ContentManagementService { libraryCreated = new Subject(); libraryUpdated = new Subject(); libraryJoined = new Subject(); + libraryLeft = new Subject(); library400Error = new Subject(); joinLibraryToggle = new Subject(); linksUnshared = new Subject(); @@ -301,6 +302,38 @@ export class ContentManagementService { ); } + leaveLibrary(siteId: string): void { + const dialogRef = this.dialogRef.open(ConfirmDialogComponent, { + data: { + title: 'APP.DIALOGS.CONFIRM_LEAVE.TITLE', + message: 'APP.DIALOGS.CONFIRM_LEAVE.MESSAGE', + yesLabel: 'APP.DIALOGS.CONFIRM_LEAVE.YES_LABEL', + noLabel: 'APP.DIALOGS.CONFIRM_LEAVE.NO_LABEL' + }, + minWidth: '250px' + }); + + dialogRef.afterClosed().subscribe(result => { + if (result === true) { + this.contentApi.leaveSite(siteId).subscribe( + () => { + this.libraryLeft.next(siteId); + this.store.dispatch( + new SnackbarInfoAction('APP.MESSAGES.INFO.LEFT_LIBRARY') + ); + }, + () => { + this.store.dispatch( + new SnackbarErrorAction( + 'APP.MESSAGES.ERRORS.LEAVE_LIBRARY_FAILED' + ) + ); + } + ); + } + }); + } + updateLibrary(siteId: string, siteBody: SiteBody) { this.contentApi.updateLibrary(siteId, siteBody).subscribe( (siteEntry: SiteEntry) => { diff --git a/src/app/store/actions/library.actions.ts b/src/app/store/actions/library.actions.ts index 3ab9f1e40..d44a39358 100644 --- a/src/app/store/actions/library.actions.ts +++ b/src/app/store/actions/library.actions.ts @@ -30,6 +30,7 @@ export const DELETE_LIBRARY = 'DELETE_LIBRARY'; export const CREATE_LIBRARY = 'CREATE_LIBRARY'; export const NAVIGATE_LIBRARY = 'NAVIGATE_LIBRARY'; export const UPDATE_LIBRARY = 'UPDATE_LIBRARY'; +export const LEAVE_LIBRARY = 'LEAVE_LIBRARY'; export class DeleteLibraryAction implements Action { readonly type = DELETE_LIBRARY; @@ -50,3 +51,8 @@ export class UpdateLibraryAction implements Action { readonly type = UPDATE_LIBRARY; constructor(public payload?: SiteBody) {} } + +export class LeaveLibraryAction implements Action { + readonly type = LEAVE_LIBRARY; + constructor(public payload?: string) {} +} diff --git a/src/app/store/effects/library.effects.ts b/src/app/store/effects/library.effects.ts index 8c1e6c034..f432fa3b8 100644 --- a/src/app/store/effects/library.effects.ts +++ b/src/app/store/effects/library.effects.ts @@ -34,7 +34,9 @@ import { NavigateLibraryAction, NAVIGATE_LIBRARY, UpdateLibraryAction, - UPDATE_LIBRARY + UPDATE_LIBRARY, + LeaveLibraryAction, + LEAVE_LIBRARY } from '../actions'; import { ContentManagementService } from '../../services/content-management.service'; import { Store } from '@ngrx/store'; @@ -73,6 +75,25 @@ export class LibraryEffects { }) ); + @Effect({ dispatch: false }) + leaveLibrary$ = this.actions$.pipe( + ofType(LEAVE_LIBRARY), + map(action => { + if (action.payload) { + this.content.leaveLibrary(action.payload); + } else { + this.store + .select(appSelection) + .pipe(take(1)) + .subscribe(selection => { + if (selection && selection.library) { + this.content.leaveLibrary(selection.library.entry.id); + } + }); + } + }) + ); + @Effect() createLibrary$ = this.actions$.pipe( ofType(CREATE_LIBRARY), diff --git a/src/assets/app.extensions.json b/src/assets/app.extensions.json index 9011c73ec..a57c0a972 100644 --- a/src/assets/app.extensions.json +++ b/src/assets/app.extensions.json @@ -122,6 +122,14 @@ { "type": "rule", "value": "app.selection.hasNoLibraryRole" } ] }, + { + "id": "app.libraries.toolbar.canLeaveLibrary", + "type": "core.every", + "parameters": [ + { "type": "rule", "value": "app.selection.library" }, + { "type": "rule", "value": "app.selection.hasLibraryRole" } + ] + }, { "id": "app.toolbar.canCopyNode", "type": "core.every", @@ -417,6 +425,18 @@ "visible": "app.libraries.toolbar.canToggleJoin" } }, + { + "id": "app.toolbar.leaveLibrary", + "order": 705, + "title": "APP.ACTIONS.LEAVE", + "icon": "not_interested", + "actions": { + "click": "LEAVE_LIBRARY" + }, + "rules": { + "visible": "app.libraries.toolbar.canLeaveLibrary" + } + }, { "id": "app.toolbar.more", "type": "menu", @@ -649,6 +669,18 @@ "visible": "app.libraries.toolbar.canToggleJoin" } }, + { + "id": "app.context.leaveLibrary", + "order": 703, + "title": "APP.ACTIONS.LEAVE", + "icon": "not_interested", + "actions": { + "click": "LEAVE_LIBRARY" + }, + "rules": { + "visible": "app.libraries.toolbar.canLeaveLibrary" + } + }, { "id": "app.context.menu.copy", "title": "APP.ACTIONS.COPY", diff --git a/src/assets/i18n/en.json b/src/assets/i18n/en.json index 6911550d4..b1932624f 100644 --- a/src/assets/i18n/en.json +++ b/src/assets/i18n/en.json @@ -200,7 +200,8 @@ "PRINT": "Print", "FULLSCREEN": "Activate full-screen mode", "JOIN": "Join", - "CANCEL_JOIN": "Cancel join" + "CANCEL_JOIN": "Cancel join", + "LEAVE": "Leave library" }, "DIALOGS": { "CONFIRM_PURGE": { @@ -208,6 +209,12 @@ "MESSAGE": "This will permanently remove the selected item(s).", "YES_LABEL": "Delete", "NO_LABEL": "Keep" + }, + "CONFIRM_LEAVE": { + "TITLE": "Leave this library?", + "MESSAGE": "This will remove you as a member of this library.", + "YES_LABEL": "OK", + "NO_LABEL": "Cancel" } }, "DOCUMENT_LIST": { @@ -267,7 +274,8 @@ }, "DELETE_LIBRARY_FAILED": "Cannot delete the library", "JOIN_REQUEST_FAILED": "Cannot join the library", - "JOIN_CANCEL_FAILED": "Cannot cancel the request to join the library" + "JOIN_CANCEL_FAILED": "Cannot cancel the request to join the library", + "LEAVE_LIBRARY_FAILED": "Cannot leave this library" }, "UPLOAD": { "ERROR": { @@ -315,7 +323,8 @@ "LIBRARY_DELETED": "Library deleted", "JOINED": "Library joined", "JOIN_REQUESTED": "Join library request sent", - "JOIN_CANCELED": "Canceled the request to join the library" + "JOIN_CANCELED": "Canceled the request to join the library", + "LEFT_LIBRARY": "You have left the library" } }, "CONTENT_METADATA": {