Skip to content

Commit

Permalink
menu: allow the librarian to switch library
Browse files Browse the repository at this point in the history
Enables the librarian to change from one libary to another
if he or she works in several libraries.

* Fixes patron view to display multiple libraries.
* Fix populate of select in the routing system.
* closes rero/rero-ils#1510
* closes rero/rero-ils#1508

Co-Authored-by: Bertrand Zuchuat <bertrand.zuchuat@rero.ch>
Co-Authored-by: Renaud Michotte <renaud.michotte@gmail.com>
  • Loading branch information
Garfield-fr and zannkukai committed Nov 27, 2020
1 parent 080c958 commit b7e0dd2
Show file tree
Hide file tree
Showing 44 changed files with 972 additions and 587 deletions.
6 changes: 3 additions & 3 deletions projects/admin/src/app/app.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
-->
<ngx-spinner type="ball-spin-clockwise" size="medium"></ngx-spinner>
<ng-container *ngIf="user">
<ng-container *ngIf="loaded">
<header>
<admin-menu *ngIf="user.adminInterfaceAccess"></admin-menu>
<admin-menu *ngIf="allowed"></admin-menu>
</header>
<div class="container-fluid px-5" *ngIf="user.adminInterfaceAccess; else noaccess">
<div class="container-fluid px-5" *ngIf="allowed; else noaccess">
<router-outlet></router-outlet>
</div>
<footer class="rero-ils-footer container-fluid px-5 d-flex justify-content-center align-items-center border-top mt-4 py-4">
Expand Down
14 changes: 8 additions & 6 deletions projects/admin/src/app/app.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import { NgxSpinnerService } from 'ngx-spinner';
import { UserService } from '@rero/shared';
import { AppRouterEventService } from './service/app-router-event.service';
import { KeyboardShortcutsService } from './service/keyboard-shortcuts.service';
import { NavigateService } from './service/navigate.service';
import { CustomShortcutHelpComponent } from './widgets/custom-shortcut-help/custom-shortcut-help.component';

@Component({
Expand All @@ -32,16 +31,21 @@ import { CustomShortcutHelpComponent } from './widgets/custom-shortcut-help/cust
})
export class AppComponent implements OnInit, AfterViewInit {

get user() {
return this._userService.user;
/** User loaded */
get loaded() {
return this._userService.loaded;
}

/** Allowed access to admin interface */
get allowed() {
return this._userService.allowAdminInterfaceAddess;
}

/**
* Constructor
* @param _userService - UserService
* @param _appRouterEventService - AppRouterEventService
* @param _spinner - NgxSpinnerService
* @param _navigateService - NavigateService
* @param _keyboardShortcutsService - KeyboardShortcutsService
* @param _hotKeysService - HotkeysService,
* @param _modalService - BsModalService
Expand All @@ -50,7 +54,6 @@ export class AppComponent implements OnInit, AfterViewInit {
private _userService: UserService,
private _appRouterEventService: AppRouterEventService,
private _spinner: NgxSpinnerService,
private _navigateService: NavigateService,
private _keyboardShortcutsService: KeyboardShortcutsService,
private _hotKeysService: HotkeysService,
private _modalService: BsModalService
Expand All @@ -60,7 +63,6 @@ export class AppComponent implements OnInit, AfterViewInit {
ngOnInit() {
this._spinner.show();
this._appRouterEventService.initializeEvents();
this._navigateService.initialize();
this._keyboardShortcutsService.initializeShortcuts();
this._spinner.hide();
}
Expand Down
4 changes: 3 additions & 1 deletion projects/admin/src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ import { MefTypeahead } from './class/mef-typeahead';
import { TabOrderDirective } from './directives/tab-order.directive';
import { ErrorPageComponent } from './error/error-page/error-page.component';
import { NoCacheHeaderInterceptor } from './interceptor/no-cache-header.interceptor';
import { MenuSwitchLibraryComponent } from './menu/menu-switch-library/menu-switch-library.component';
import { MenuComponent } from './menu/menu.component';
import { MarcPipe } from './pipe/marc.pipe';
import { NotesFormatPipe } from './pipe/notes-format.pipe';
Expand Down Expand Up @@ -217,7 +218,8 @@ export function appInitFactory(appInitService: AppInitService) {
CustomShortcutHelpComponent,
ContributionDetailViewComponent,
PersonDetailViewComponent,
CorporateBodiesDetailViewComponent
CorporateBodiesDetailViewComponent,
MenuSwitchLibraryComponent
],
imports: [
AppRoutingModule,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ export class CheckinComponent implements OnInit {
this._itemsService.checkin(itemBarcode, this._loggedUser.getCurrentLibrary()).subscribe(
item => {
// TODO: remove this when policy will be in place
if (item === null || item.location.organisation.pid !== this._loggedUser.library.organisation.pid) {
if (item === null || item.location.organisation.pid !== this._loggedUser.getCurrentOrganisation()) {
this._toastService.error(
this._translate.instant('Item or patron not found!'),
this._translate.instant('Checkin')
Expand Down Expand Up @@ -195,7 +195,7 @@ export class CheckinComponent implements OnInit {
if (
patron !== null &&
patron.organisation.pid !==
this._loggedUser.library.organisation.pid
this._loggedUser.getCurrentOrganisation()
) {
this._toastService.warning(
this._translate.instant('Patron not found!'),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<!--
RERO ILS UI
 Copyright (C) 2020 RERO

 This program is free software: you can redistribute it and/or modify
 it under the terms of the GNU Affero General Public License as published by
 the Free Software Foundation, version 3 of the License.

 This program 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 Affero General Public License for more details.

 You should have received a copy of the GNU Affero General Public License
 along with this program. If not, see <http://www.gnu.org/licenses/>.
-->

<ng-core-menu-widget
*ngIf="isVisible"
[menu]="menuLibrariesSwitch"
(clickItem)="eventMenuClick($event)"
></ng-core-menu-widget>
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/*
* RERO ILS UI
* Copyright (C) 2020 RERO
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, version 3 of the License.
*
* This program 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 Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

import { HttpClientTestingModule } from '@angular/common/http/testing';
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { RouterTestingModule } from '@angular/router/testing';
import { TranslateModule } from '@ngx-translate/core';
import { CoreModule } from '@rero/ng-core';
import { User } from '@rero/shared';
import { MenuSwitchLibraryComponent } from './menu-switch-library.component';
import { LibrarySwitchMenuService } from './service/library-switch-menu.service';


describe('MenuSwithLibraryComponent', () => {
let component: MenuSwitchLibraryComponent;
let fixture: ComponentFixture<MenuSwitchLibraryComponent>;

const librarySwitchMenuServiceSpy = jasmine.createSpyObj('LibrarySwitchMenuService', ['']);
librarySwitchMenuServiceSpy._user = new User({
roles: ['system_librarian']
});

beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ MenuSwitchLibraryComponent ],
imports: [
CoreModule,
HttpClientTestingModule,
TranslateModule.forRoot(),
RouterTestingModule
],
providers: [
{ provide: LibrarySwitchMenuService, useValue: librarySwitchMenuServiceSpy }
]
})
.compileComponents();
}));

beforeEach(() => {
fixture = TestBed.createComponent(MenuSwitchLibraryComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});

it('should create', () => {
expect(component).toBeTruthy();
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
/*
* RERO ILS UI
* Copyright (C) 2020 RERO
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, version 3 of the License.
*
* This program 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 Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

import { Component } from '@angular/core';
import { Router } from '@angular/router';
import { TranslateService } from '@ngx-translate/core';
import { DialogService, MenuItem } from '@rero/ng-core';
import { Observable } from 'rxjs';
import { AppConfigService } from '../../service/app-config.service';
import { LibrarySwitchMenuService } from './service/library-switch-menu.service';
import { LibrarySwitchService } from './service/library-switch.service';

@Component({
selector: 'admin-menu-swith-library',
templateUrl: './menu-switch-library.component.html'
})
export class MenuSwitchLibraryComponent {

/** Menu libraries switch */
get menuLibrariesSwitch() {
return this._librarySwitchMenuService.menu;
}

/** Menu is visible */
get isVisible() {
return this._librarySwitchMenuService.visible;
}

/**
* Constructor
* @param _appConfigService - AppConfigService
* @param _menuSwitchMenuService - LibrarySwitchMenuService
* @param _librarySwitchService - LibrarySwitchService
* @param _dialogService - DialogService
* @param _translateService - TranslateService
* @param _router - Router
*/
constructor(
private _appConfigService: AppConfigService,
private _librarySwitchMenuService: LibrarySwitchMenuService,
private _librarySwitchService: LibrarySwitchService,
private _dialogService: DialogService,
private _translateService: TranslateService,
private _router: Router
) { }

/**
* Event on menu click
* @param event - MenuItem
*/
eventMenuClick(event: MenuItem) {
// TODO: Implement this with a guard (implement in ng-core and ui)
const url = this._router.url;
const urlParams = url.split('/').filter(n => n);
if (
this._appConfigService.librarySwitchCheckParamsUrl
.some(param => urlParams.includes(param))
) {
this._dialog().subscribe((confirmation: boolean) => {
if (confirmation) {
this._switchAndNavigate(event.getExtra('id'));
}
});
} else {
this._switchAndNavigate(event.getExtra('id'));
}
}

/**
* Dialog configuration
* @return Observable
*/
private _dialog(): Observable<boolean> {
return this._dialogService.show({
ignoreBackdropClick: false,
initialState: {
title: this._translateService.instant('Quit the page'),
body: this._translateService.instant(
'Do you want to quit the page? The changes made so far will be lost.'
),
confirmButton: true,
confirmTitleButton: this._translateService.instant('Quit'),
cancelTitleButton: this._translateService.instant('Stay')
}
});
}

/**
* Switch and navigate
* @param id - string, library pid
*/
private _switchAndNavigate(id: string) {
this._librarySwitchService.switch(id);
this._router.navigate(['/']);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,24 +14,22 @@
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

import { HttpClientTestingModule } from '@angular/common/http/testing';
import { TestBed } from '@angular/core/testing';
import { RouterTestingModule } from '@angular/router/testing';
import { inject, TestBed } from '@angular/core/testing';
import { TranslateModule } from '@ngx-translate/core';
import { NavigateService } from './navigate.service';
import { LibrarySwitchMenuService } from './library-switch-menu.service';

describe('NavigateService', () => {
beforeEach(() => TestBed.configureTestingModule({
imports: [
RouterTestingModule,
HttpClientTestingModule,
TranslateModule.forRoot()
]
}));
describe('Service: LibrarySwitchMenu', () => {
beforeEach(() => {
TestBed.configureTestingModule({
imports: [
HttpClientTestingModule,
TranslateModule.forRoot()
]
});
});

it('should be created', () => {
const service: NavigateService = TestBed.get(NavigateService);
it('should ...', inject([LibrarySwitchMenuService], (service: LibrarySwitchMenuService) => {
expect(service).toBeTruthy();
});
}));
});
Loading

0 comments on commit b7e0dd2

Please sign in to comment.