forked from rero/rero-ils-ui
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
menu: allow the librarian to switch library
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
1 parent
080c958
commit b7e0dd2
Showing
44 changed files
with
972 additions
and
587 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
projects/admin/src/app/menu/menu-switch-library/menu-switch-library.component.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
62 changes: 62 additions & 0 deletions
62
projects/admin/src/app/menu/menu-switch-library/menu-switch-library.component.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
}); | ||
}); |
110 changes: 110 additions & 0 deletions
110
projects/admin/src/app/menu/menu-switch-library/menu-switch-library.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(['/']); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.