Skip to content

Commit

Permalink
menu: improve the switch library entry
Browse files Browse the repository at this point in the history
The switch library was only displayed on the root page of the
professional interface. This commit change this behavior and now this
menu is displayed on all pages (if user has required rights).
However, the menu is disabled on all pages except on the homepage. This
implementation avoid problems if user should edit some resource link to
the current library.

This commit also removes the top panel containing the current library
name. The current library code is now used as label of the switch
library menu instead of "Switch library" string.

This commit also fix the dynamic population problem of the switch
library menu : When a new library was added, this library was not
dynamically added to the switch library menu. This commit fixes this
problem.

- Closes rero/rero-ils#821
- Closes rero/rero-ils#822

Co-Authored-by: Bertrand Zuchuat <bertrand.zuchuat@rero.ch>
Co-Authored-by: Renaud Michotte <renaud.michotte@gmail.com>
  • Loading branch information
zannkukai and Garfield-fr committed Jun 24, 2020
1 parent 5e42130 commit f9b3672
Show file tree
Hide file tree
Showing 19 changed files with 118 additions and 197 deletions.
4 changes: 1 addition & 3 deletions projects/admin/src/app/app.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import { RecordModule } from '@rero/ng-core';
import { HttpClientModule } from '@angular/common/http';
import { TranslateModule } from '@ngx-translate/core';
import { FormsModule } from '@angular/forms';
import { InterfaceInfoComponent } from './interface-info/interface-info.component';

describe('AppComponent', () => {
beforeEach(async(() => {
Expand All @@ -45,8 +44,7 @@ describe('AppComponent', () => {
],
declarations: [
AppComponent,
MenuComponent,
InterfaceInfoComponent
MenuComponent
]
}).compileComponents();
}));
Expand Down
5 changes: 0 additions & 5 deletions projects/admin/src/app/app.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,11 +142,6 @@ export class AppComponent implements OnInit, OnDestroy {
this.localStorageService.updateDate(User.STORAGE_KEY);
}
}

// Library Switch menu show only on homepage
this.librarySwitchService.show(
(event.url === '/') ? true : false
);
})
);
}
Expand Down
3 changes: 0 additions & 3 deletions projects/admin/src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ import { ErrorPageComponent } from './error/error-page/error-page.component';
import { FrontpageBoardComponent } from './frontpage/frontpage-board/frontpage-board.component';
import { FrontpageComponent } from './frontpage/frontpage.component';
import { NoCacheHeaderInterceptor } from './interceptor/no-cache-header.interceptor';
import { InterfaceInfoComponent } from './interface-info/interface-info.component';
import { MenuComponent } from './menu/menu.component';
import { BioInformationsPipe } from './pipe/bio-informations.pipe';
import { BirthDatePipe } from './pipe/birth-date.pipe';
Expand Down Expand Up @@ -158,10 +157,8 @@ import { SharedPipesModule } from './shared/shared-pipes.module';
ItemTransactionComponent,
ItemTransactionsComponent,
PatronDetailViewComponent,
InterfaceInfoComponent,
RefComponent,
RemoteAutocompleteInputTypeComponent,
InterfaceInfoComponent,
VendorDetailViewComponent,
VendorBriefViewComponent,
AddressTypeComponent,
Expand Down

This file was deleted.

55 changes: 0 additions & 55 deletions projects/admin/src/app/interface-info/interface-info.component.ts

This file was deleted.

3 changes: 1 addition & 2 deletions projects/admin/src/app/menu/menu.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
 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/>.
-->
<admin-interface-info></admin-interface-info>
<nav class="navbar navbar-expand-lg navbar-dark bg-dark d-flex">
<div class="container">
<a [routerLink]="['/']" class="navbar-brand pr-2 text-sm">
Expand All @@ -39,11 +38,11 @@

<div class="collapse navbar-collapse" id="navbarSupportedContent" [collapse]="isCollapsed" [isAnimated]="true">
<ng-core-menu class="mr-auto" [menu]="linksMenu"></ng-core-menu>
<!-- RIGHT MENU ENTRIES -->
<ng-core-menu
class="userMenu"
[menu]="librariesSwitchMenu"
(clickItem)="changeLibrary($event)"
*ngIf="isVisibleLibrarySwitchMenu && isVisible"
></ng-core-menu>
<ng-core-menu [menu]="languagesMenu" (clickItem)="changeLang($event)"></ng-core-menu>
<ng-core-menu [menu]="userMenu"></ng-core-menu>
Expand Down
2 changes: 1 addition & 1 deletion projects/admin/src/app/menu/menu.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ describe('MenuComponent', () => {

const libraryTestingSwitchService = jasmine.createSpyObj(
'LibrarySwitchService', ['generateMenu']);
libraryTestingSwitchService.onVisibleMenu$ = of(false);
libraryTestingSwitchService.entries = [{ entries: [] }];
libraryTestingSwitchService.onGenerate$ = of([]);
libraryTestingSwitchService.currentLibraryRecord$ = of({code: 1});

const userTestingService = jasmine.createSpyObj(
'UserService', ['getCurrentUser', 'hasRole']
Expand Down
24 changes: 8 additions & 16 deletions projects/admin/src/app/menu/menu.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,9 @@ export class MenuComponent implements OnInit {

librariesSwitchMenu = {
navCssClass: 'navbar-nav',
dropdownMenuCssClass: 'dropdown-menu-right',
entries: [{
name: this._translateService.instant('Switch library'),
name: '', // start with empty value, it will be changed when menu is generated
iconCssClass: 'fa fa-random',
entries: []
}]
Expand All @@ -58,7 +59,6 @@ export class MenuComponent implements OnInit {
userMenu = {
navCssClass: 'navbar-nav',
dropdownMenuCssClass: 'dropdown-menu-right',
iconCssClass: 'fa fa-user',
entries: []
};

Expand All @@ -72,7 +72,7 @@ export class MenuComponent implements OnInit {
private _localeStorageService: LocalStorageService,
private _menuService: MenuService,
private _mainTitlePipe: MainTitlePipe
) { }
) {}

ngOnInit() {
this._initLinksMenu();
Expand All @@ -86,6 +86,7 @@ export class MenuComponent implements OnInit {

this.userMenu.entries.push({
name: `${currentUser.first_name[0]}${currentUser.last_name[0]}`,
iconCssClass: 'fa fa-user',
entries: [
{
name: this._translateService.instant('Public interface'),
Expand Down Expand Up @@ -117,19 +118,10 @@ export class MenuComponent implements OnInit {
this.userMenu.entries[0].entries[0].href = `/${organisation.metadata.code}/`;
});

this._librarySwitchService.onVisibleMenu$.subscribe((visible) => {
if (
visible
&& this._userService.hasRole('system_librarian')
&& this._librarySwitchService.entries.length === 0) {
this._librarySwitchService.generateMenu();
}
});

this._librarySwitchService.onGenerate$.subscribe((entries: any) => {
this.librariesSwitchMenu.entries[0].entries = entries;
});

// SWITCH LIBRARY MENU ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
this._librarySwitchService.generateMenu();
this._librarySwitchService.onGenerate$.subscribe((entries: any) => this.librariesSwitchMenu.entries[0].entries = entries);
this._librarySwitchService.currentLibraryRecord$.subscribe((library: any) => this.librariesSwitchMenu.entries[0].name = library.code);
}

/**
Expand Down
9 changes: 6 additions & 3 deletions projects/admin/src/app/service/library-switch.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,18 @@
* 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 { HttpClientModule } from '@angular/common/http';
import { TestBed } from '@angular/core/testing';

import { RouterTestingModule } from '@angular/router/testing';
import { TranslateModule } from '@ngx-translate/core';
import { LibrarySwitchService } from './library-switch.service';
import { HttpClientModule } from '@angular/common/http';

describe('LibrarySwitchService', () => {
beforeEach(() => TestBed.configureTestingModule({
imports: [
HttpClientModule
HttpClientModule,
TranslateModule.forRoot(),
RouterTestingModule
]
}));

Expand Down
Loading

0 comments on commit f9b3672

Please sign in to comment.