[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
This commit is contained in:
Suzana Dirla
2018-11-23 16:23:26 +02:00
committed by Denys Vuika
parent 62e33efbd0
commit 13db4fb339
9 changed files with 114 additions and 4 deletions

View File

@@ -63,6 +63,7 @@ export class FavoriteLibrariesComponent extends PageComponent
this.content.libraryDeleted.subscribe(() => this.reloadList()), this.content.libraryDeleted.subscribe(() => this.reloadList()),
this.content.libraryUpdated.subscribe(() => this.reloadList()), this.content.libraryUpdated.subscribe(() => this.reloadList()),
this.content.libraryJoined.subscribe(() => this.reloadList()), this.content.libraryJoined.subscribe(() => this.reloadList()),
this.content.libraryLeft.subscribe(() => this.reloadList()),
this.content.favoriteLibraryToggle.subscribe(() => this.reloadList()), this.content.favoriteLibraryToggle.subscribe(() => this.reloadList()),
this.breakpointObserver this.breakpointObserver

View File

@@ -56,6 +56,7 @@ export class LibrariesComponent extends PageComponent implements OnInit {
this.subscriptions.push( this.subscriptions.push(
this.content.libraryDeleted.subscribe(() => this.reload()), this.content.libraryDeleted.subscribe(() => this.reload()),
this.content.libraryUpdated.subscribe(() => this.reload()), this.content.libraryUpdated.subscribe(() => this.reload()),
this.content.libraryLeft.subscribe(() => this.reload()),
this.breakpointObserver this.breakpointObserver
.observe([Breakpoints.HandsetPortrait, Breakpoints.HandsetLandscape]) .observe([Breakpoints.HandsetPortrait, Breakpoints.HandsetLandscape])

View File

@@ -79,6 +79,9 @@ export class SearchLibrariesResultsComponent extends PageComponent
this.content.libraryDeleted.subscribe(() => this.content.libraryDeleted.subscribe(() =>
this.librariesQueryBuilder.update() this.librariesQueryBuilder.update()
), ),
this.content.libraryLeft.subscribe(() =>
this.librariesQueryBuilder.update()
),
this.librariesQueryBuilder.updated.subscribe(() => { this.librariesQueryBuilder.updated.subscribe(() => {
this.isLoading = true; this.isLoading = true;

View File

@@ -220,6 +220,10 @@ export class ContentApiService {
return from(this.api.sitesApi.deleteSite(siteId, opts)); return from(this.api.sitesApi.deleteSite(siteId, opts));
} }
leaveSite(siteId?: string): Observable<any> {
return from(this.api.sitesApi.removeSiteMember(siteId, '-me-'));
}
createSite( createSite(
siteBody: SiteBody, siteBody: SiteBody,
opts?: { opts?: {

View File

@@ -83,6 +83,7 @@ export class ContentManagementService {
libraryCreated = new Subject<SiteEntry>(); libraryCreated = new Subject<SiteEntry>();
libraryUpdated = new Subject<SiteEntry>(); libraryUpdated = new Subject<SiteEntry>();
libraryJoined = new Subject<string>(); libraryJoined = new Subject<string>();
libraryLeft = new Subject<string>();
library400Error = new Subject<any>(); library400Error = new Subject<any>();
joinLibraryToggle = new Subject<string>(); joinLibraryToggle = new Subject<string>();
linksUnshared = new Subject<any>(); linksUnshared = new Subject<any>();
@@ -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) { updateLibrary(siteId: string, siteBody: SiteBody) {
this.contentApi.updateLibrary(siteId, siteBody).subscribe( this.contentApi.updateLibrary(siteId, siteBody).subscribe(
(siteEntry: SiteEntry) => { (siteEntry: SiteEntry) => {

View File

@@ -30,6 +30,7 @@ export const DELETE_LIBRARY = 'DELETE_LIBRARY';
export const CREATE_LIBRARY = 'CREATE_LIBRARY'; export const CREATE_LIBRARY = 'CREATE_LIBRARY';
export const NAVIGATE_LIBRARY = 'NAVIGATE_LIBRARY'; export const NAVIGATE_LIBRARY = 'NAVIGATE_LIBRARY';
export const UPDATE_LIBRARY = 'UPDATE_LIBRARY'; export const UPDATE_LIBRARY = 'UPDATE_LIBRARY';
export const LEAVE_LIBRARY = 'LEAVE_LIBRARY';
export class DeleteLibraryAction implements Action { export class DeleteLibraryAction implements Action {
readonly type = DELETE_LIBRARY; readonly type = DELETE_LIBRARY;
@@ -50,3 +51,8 @@ export class UpdateLibraryAction implements Action {
readonly type = UPDATE_LIBRARY; readonly type = UPDATE_LIBRARY;
constructor(public payload?: SiteBody) {} constructor(public payload?: SiteBody) {}
} }
export class LeaveLibraryAction implements Action {
readonly type = LEAVE_LIBRARY;
constructor(public payload?: string) {}
}

View File

@@ -34,7 +34,9 @@ import {
NavigateLibraryAction, NavigateLibraryAction,
NAVIGATE_LIBRARY, NAVIGATE_LIBRARY,
UpdateLibraryAction, UpdateLibraryAction,
UPDATE_LIBRARY UPDATE_LIBRARY,
LeaveLibraryAction,
LEAVE_LIBRARY
} from '../actions'; } from '../actions';
import { ContentManagementService } from '../../services/content-management.service'; import { ContentManagementService } from '../../services/content-management.service';
import { Store } from '@ngrx/store'; import { Store } from '@ngrx/store';
@@ -73,6 +75,25 @@ export class LibraryEffects {
}) })
); );
@Effect({ dispatch: false })
leaveLibrary$ = this.actions$.pipe(
ofType<LeaveLibraryAction>(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() @Effect()
createLibrary$ = this.actions$.pipe( createLibrary$ = this.actions$.pipe(
ofType<CreateLibraryAction>(CREATE_LIBRARY), ofType<CreateLibraryAction>(CREATE_LIBRARY),

View File

@@ -122,6 +122,14 @@
{ "type": "rule", "value": "app.selection.hasNoLibraryRole" } { "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", "id": "app.toolbar.canCopyNode",
"type": "core.every", "type": "core.every",
@@ -417,6 +425,18 @@
"visible": "app.libraries.toolbar.canToggleJoin" "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", "id": "app.toolbar.more",
"type": "menu", "type": "menu",
@@ -649,6 +669,18 @@
"visible": "app.libraries.toolbar.canToggleJoin" "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", "id": "app.context.menu.copy",
"title": "APP.ACTIONS.COPY", "title": "APP.ACTIONS.COPY",

View File

@@ -200,7 +200,8 @@
"PRINT": "Print", "PRINT": "Print",
"FULLSCREEN": "Activate full-screen mode", "FULLSCREEN": "Activate full-screen mode",
"JOIN": "Join", "JOIN": "Join",
"CANCEL_JOIN": "Cancel join" "CANCEL_JOIN": "Cancel join",
"LEAVE": "Leave library"
}, },
"DIALOGS": { "DIALOGS": {
"CONFIRM_PURGE": { "CONFIRM_PURGE": {
@@ -208,6 +209,12 @@
"MESSAGE": "This will permanently remove the selected item(s).", "MESSAGE": "This will permanently remove the selected item(s).",
"YES_LABEL": "Delete", "YES_LABEL": "Delete",
"NO_LABEL": "Keep" "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": { "DOCUMENT_LIST": {
@@ -267,7 +274,8 @@
}, },
"DELETE_LIBRARY_FAILED": "Cannot delete the library", "DELETE_LIBRARY_FAILED": "Cannot delete the library",
"JOIN_REQUEST_FAILED": "Cannot join 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": { "UPLOAD": {
"ERROR": { "ERROR": {
@@ -315,7 +323,8 @@
"LIBRARY_DELETED": "Library deleted", "LIBRARY_DELETED": "Library deleted",
"JOINED": "Library joined", "JOINED": "Library joined",
"JOIN_REQUESTED": "Join library request sent", "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": { "CONTENT_METADATA": {