From 2c0e173c5b4eacf3a9d99951cce5fdd4dca969d3 Mon Sep 17 00:00:00 2001 From: Bertrand Zuchuat Date: Tue, 10 Oct 2023 15:19:16 +0200 Subject: [PATCH] library switch: fix switch on mobile Co-Authored-by: Bertrand Zuchuat --- .../menu-mobile/menu-mobile.component.html | 4 +- .../menu/menu-mobile/menu-mobile.component.ts | 17 ++- .../sub-menu/sub-menu.component.html | 1 + .../sub-menu/sub-menu.component.ts | 15 ++- .../menu-switch-library.component.ts | 76 +------------ .../admin/src/app/menu/menu.component.html | 4 +- .../library-switch-menu-event.service.ts | 106 ++++++++++++++++++ 7 files changed, 145 insertions(+), 78 deletions(-) create mode 100644 projects/admin/src/app/menu/service/library-switch-menu-event.service.ts diff --git a/projects/admin/src/app/menu/menu-mobile/menu-mobile.component.html b/projects/admin/src/app/menu/menu-mobile/menu-mobile.component.html index ececd108d..fd04c4ecd 100644 --- a/projects/admin/src/app/menu/menu-mobile/menu-mobile.component.html +++ b/projects/admin/src/app/menu/menu-mobile/menu-mobile.component.html @@ -18,7 +18,9 @@ + [menu]="menuLibrariesSwitch" + (clickItem)="eventLibrarySwitchMenuClick($event)" +>
diff --git a/projects/admin/src/app/menu/menu-mobile/menu-mobile.component.ts b/projects/admin/src/app/menu/menu-mobile/menu-mobile.component.ts index 3c0a02191..c04525e10 100644 --- a/projects/admin/src/app/menu/menu-mobile/menu-mobile.component.ts +++ b/projects/admin/src/app/menu/menu-mobile/menu-mobile.component.ts @@ -1,6 +1,6 @@ /* * RERO ILS UI - * Copyright (C) 2020-2022 RERO + * Copyright (C) 2020-2023 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 @@ -15,9 +15,10 @@ * along with this program. If not, see . */ import { Component, OnInit } from '@angular/core'; -import { MenuItemInterface } from '@rero/ng-core'; +import { MenuItem, MenuItemInterface } from '@rero/ng-core'; import { LibrarySwitchMenuService } from '../service/library-switch-menu.service'; import { MenuService } from '../service/menu.service'; +import { LibrarySwitchMenuEventService } from '../service/library-switch-menu-event.service'; @Component({ selector: 'admin-menu-mobile', @@ -49,10 +50,12 @@ export class MenuMobileComponent implements OnInit { * Constructor * @param _menuService - MenuService * @param _librarySwitchMenuService - LibrarySwitchMenuService + * @param _librarySwitchMenuEventService - LibrarySwitchMenuEventService */ constructor( private _menuService: MenuService, - private _librarySwitchMenuService: LibrarySwitchMenuService + private _librarySwitchMenuService: LibrarySwitchMenuService, + private _librarySwitchMenuEventService: LibrarySwitchMenuEventService ) { } /** OnInit hook */ @@ -73,4 +76,12 @@ export class MenuMobileComponent implements OnInit { this._menuService.generateLanguageMenu(); } } + + /** + * Event on library switch menu click + * @param event - MenuItem + */ + eventLibrarySwitchMenuClick(event: MenuItem): void { + this._librarySwitchMenuEventService.eventMenuClick(event); + } } diff --git a/projects/admin/src/app/menu/menu-mobile/sub-menu/sub-menu.component.html b/projects/admin/src/app/menu/menu-mobile/sub-menu/sub-menu.component.html index f085fdc28..b0f78eb94 100644 --- a/projects/admin/src/app/menu/menu-mobile/sub-menu/sub-menu.component.html +++ b/projects/admin/src/app/menu/menu-mobile/sub-menu/sub-menu.component.html @@ -30,6 +30,7 @@
[attr.target]="subItem.getAttribute('target')" [routerLink]="subItem.getRouterLink()" [queryParams]="subItem.getQueryParams() ? subItem.getQueryParams() : {}" + (click)="doClick(subItem)" > {{ subItem.getName() }} diff --git a/projects/admin/src/app/menu/menu-mobile/sub-menu/sub-menu.component.ts b/projects/admin/src/app/menu/menu-mobile/sub-menu/sub-menu.component.ts index 194e7882f..658ce109c 100644 --- a/projects/admin/src/app/menu/menu-mobile/sub-menu/sub-menu.component.ts +++ b/projects/admin/src/app/menu/menu-mobile/sub-menu/sub-menu.component.ts @@ -15,8 +15,8 @@ * along with this program. If not, see . */ -import { Component, Input } from '@angular/core'; -import { MenuItemInterface } from '@rero/ng-core'; +import { Component, EventEmitter, Input, Output } from '@angular/core'; +import { MenuItem, MenuItemInterface } from '@rero/ng-core'; @Component({ selector: 'admin-sub-menu', @@ -25,4 +25,15 @@ import { MenuItemInterface } from '@rero/ng-core'; export class SubMenuComponent { /** menu */ @Input() menu: MenuItemInterface; + + /** Event */ + @Output() clickItem = new EventEmitter(); + + /** + * Emit a event on click item menu + * @param item - MenuItem + */ + doClick(item: MenuItem | MenuItemInterface) { + this.clickItem.emit(item); + } } diff --git a/projects/admin/src/app/menu/menu-switch-library/menu-switch-library.component.ts b/projects/admin/src/app/menu/menu-switch-library/menu-switch-library.component.ts index ef1d0da03..de7c0a861 100644 --- a/projects/admin/src/app/menu/menu-switch-library/menu-switch-library.component.ts +++ b/projects/admin/src/app/menu/menu-switch-library/menu-switch-library.component.ts @@ -1,6 +1,6 @@ /* * RERO ILS UI - * Copyright (C) 2020 RERO + * Copyright (C) 2020-2023 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 @@ -16,14 +16,9 @@ */ import { Component } from '@angular/core'; -import { PRIMARY_OUTLET, Router } from '@angular/router'; -import { TranslateService } from '@ngx-translate/core'; -import { DialogService, MenuItem, MenuItemInterface } from '@rero/ng-core'; -import { UserService } from '@rero/shared'; -import { Observable } from 'rxjs'; -import { AppConfigService } from '../../service/app-config.service'; +import { MenuItem, MenuItemInterface } from '@rero/ng-core'; +import { LibrarySwitchMenuEventService } from '../service/library-switch-menu-event.service'; import { LibrarySwitchMenuService } from '../service/library-switch-menu.service'; -import { LibrarySwitchService } from '../service/library-switch.service'; @Component({ selector: 'admin-menu-switch-library', @@ -43,22 +38,12 @@ export class MenuSwitchLibraryComponent { /** * Constructor - * @param _appConfigService - AppConfigService * @param _librarySwitchMenuService - LibrarySwitchMenuService - * @param _librarySwitchService - LibrarySwitchService - * @param _dialogService - DialogService - * @param _translateService - TranslateService - * @param _router - Router - * @param _userService - UserService + * @param _librarySwitchMenuEventService - LibrarySwitchMenuEventService */ constructor( - private _appConfigService: AppConfigService, private _librarySwitchMenuService: LibrarySwitchMenuService, - private _librarySwitchService: LibrarySwitchService, - private _dialogService: DialogService, - private _translateService: TranslateService, - private _router: Router, - private _userService: UserService + private _librarySwitchMenuEventService: LibrarySwitchMenuEventService ) { } /** @@ -66,55 +51,6 @@ export class MenuSwitchLibraryComponent { * @param event - MenuItem */ eventMenuClick(event: MenuItem): void { - if (this._userService.user.currentLibrary !== event.getExtra('id')) { - const url = this._router.url; - const urlTree = this._router.parseUrl(url); - const children = urlTree.root.children[PRIMARY_OUTLET]; - if (children) { - const urlParams = children.segments.map(segment => segment.path); - 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')); - } - } else { - this._switchAndNavigate(event.getExtra('id')); - } - } - } - - /** - * Dialog configuration - * @return Observable - */ - private _dialog(): Observable { - 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): void { - this._librarySwitchService.switch(id); - this._router.navigate(['/']); + this._librarySwitchMenuEventService.eventMenuClick(event); } } diff --git a/projects/admin/src/app/menu/menu.component.html b/projects/admin/src/app/menu/menu.component.html index e76cc8056..00abfcfb7 100644 --- a/projects/admin/src/app/menu/menu.component.html +++ b/projects/admin/src/app/menu/menu.component.html @@ -50,11 +50,11 @@
- -