Skip to content

Commit

Permalink
menu: generation of menus by services
Browse files Browse the repository at this point in the history
Menu refactoring to allow future easy addition of further entries.

* Fixes url parsing on library switch.

Co-Authored-by: Bertrand Zuchuat <bertrand.zuchuat@rero.ch>
  • Loading branch information
Garfield-fr committed Dec 15, 2020
1 parent c7cfbf4 commit 772e91e
Show file tree
Hide file tree
Showing 55 changed files with 1,708 additions and 611 deletions.
6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
"@ngx-formly/bootstrap": "^5.10.6",
"@ngx-formly/core": "^5.10.6",
"@ngx-translate/core": "^13.0.0",
"@rero/ng-core": "^1.0.0",
"@rero/ng-core": "^1.1.0",
"bootstrap": "^4.5.3",
"crypto-js": "^3.3.0",
"document-register-element": "^1.14.10",
Expand Down
23 changes: 17 additions & 6 deletions projects/admin/src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ import { HotkeysModule, HotkeysService } from '@ngneat/hotkeys';
import { FormlyModule } from '@ngx-formly/core';
import { TranslateLoader as BaseTranslateLoader, TranslateModule } from '@ngx-translate/core';
import {
CoreConfigService, LocalStorageService, RecordModule, RemoteTypeaheadService, TranslateLoader, TranslateService, TruncateTextPipe
CoreConfigService, LocalStorageService, RecordModule, RemoteTypeaheadService,
TranslateLoader, TranslateService, TruncateTextPipe
} from '@rero/ng-core';
import { LoggedUserService, MainTitlePipe, SharedConfigService, SharedModule, UserService } from '@rero/shared';
import { CollapseModule } from 'ngx-bootstrap/collapse';
Expand All @@ -45,9 +46,13 @@ import { PatronsTypeahead } from './class/typeahead/patrons-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 { MenuDashboardComponent } from './menu/menu-dashboard/menu-dashboard.component';
import { MenuLanguageComponent } from './menu/menu-language/menu-language.component';
import { MenuSwitchLibraryComponent } from './menu/menu-switch-library/menu-switch-library.component';
import { LibrarySwitchService } from './menu/menu-switch-library/service/library-switch.service';
import { MenuUserServicesComponent } from './menu/menu-user-services/menu-user-services.component';
import { MenuUserComponent } from './menu/menu-user/menu-user.component';
import { MenuComponent } from './menu/menu.component';
import { LibrarySwitchService } from './menu/service/library-switch.service';
import { MarcPipe } from './pipe/marc.pipe';
import { NotesFormatPipe } from './pipe/notes-format.pipe';
import { AcquisitionOrderBriefViewComponent } from './record/brief-view/acquisition-order-brief-view.component';
Expand Down Expand Up @@ -122,6 +127,7 @@ import { DayOpeningHoursComponent } from './record/detail-view/library-detail-vi
import { ExceptionDateComponent } from './record/detail-view/library-detail-view/exception-date/exception-date.component';
import { LibraryDetailViewComponent } from './record/detail-view/library-detail-view/library-detail-view.component';
import { LocationComponent } from './record/detail-view/library-detail-view/location/location.component';
import { LocalFieldComponent } from './record/detail-view/local-field/local-field.component';
import { LocationDetailViewComponent } from './record/detail-view/location-detail-view/location-detail-view.component';
import { BudgetSelectLineComponent } from './record/detail-view/organisation-detail-view/budget-select-line/budget-select-line.component';
import { BudgetSelectComponent } from './record/detail-view/organisation-detail-view/budget-select/budget-select.component';
Expand All @@ -138,9 +144,9 @@ import { OrganisationService } from './service/organisation.service';
import { TypeaheadFactoryService, typeaheadToken } from './service/typeahead-factory.service';
import { UiRemoteTypeaheadService } from './service/ui-remote-typeahead.service';
import { CustomShortcutHelpComponent } from './widgets/custom-shortcut-help/custom-shortcut-help.component';
import { FrontpageBoardComponent } from './widgets/frontpage/frontpage-board/frontpage-board.component';
import { FrontpageComponent } from './widgets/frontpage/frontpage.component';
import { LocalFieldComponent } from './record/detail-view/local-field/local-field.component';
import { MenuMobileComponent } from './menu/menu-mobile/menu-mobile.component';
import { SubMenuComponent } from './menu/menu-mobile/sub-menu/sub-menu.component';

/** Init application factory */
export function appInitFactory(appInitService: AppInitService) {
Expand Down Expand Up @@ -201,7 +207,6 @@ export function appInitFactory(appInitService: AppInitService) {
OrganisationDetailViewComponent,
BudgetSelectComponent,
BudgetSelectLineComponent,
FrontpageBoardComponent,
RelatedResourceComponent,
ResourceComponent,
ItemRequestComponent,
Expand Down Expand Up @@ -230,7 +235,13 @@ export function appInitFactory(appInitService: AppInitService) {
CustomShortcutHelpComponent,
HoldingItemNoteComponent,
MenuSwitchLibraryComponent,
LocalFieldComponent
LocalFieldComponent,
MenuUserServicesComponent,
MenuLanguageComponent,
MenuUserComponent,
MenuDashboardComponent,
MenuMobileComponent,
SubMenuComponent
],
imports: [
AppRoutingModule,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

import { HttpClientTestingModule } from '@angular/common/http/testing';
import { LOCALE_ID } from '@angular/core';
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { async, ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing';
import { TranslateModule } from '@ngx-translate/core';
import { SharedModule } from '@rero/shared';
import { BsModalRef } from 'ngx-bootstrap/modal';
Expand All @@ -29,7 +29,7 @@ describe('FixedDateFormComponent', () => {
let component: FixedDateFormComponent;
let fixture: ComponentFixture<FixedDateFormComponent>;

beforeEach(async(() => {
beforeEach(waitForAsync(() => {
TestBed.configureTestingModule({
imports: [
CirculationModule,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<!--
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-container *ngIf="menu">
<div class="row justify-content-center">
<ng-container *ngFor="let item of menu.getChildren()">
<div class="col-lg-2">
<div class="card mb-2" [attr.id]="item.getAttribute('id') | idAttribute:{prefix: 'dashboard'}">
<div class="card-header bg-dark text-white text-wrap">
<i *ngIf="item.hasExtra('iconClass')" [ngClass]="item.getExtra('iconClass')"></i>
{{ item.getName() }}
</div>
<div class="list-group list-group-flush">
<ng-container *ngFor="let subItem of item.getChildren()">
<a
class="list-group-item list-group-item-action text-wrap border-bottom-0 my-0 py-2"
[attr.id]="subItem.getAttribute('id') | idAttribute:{prefix: 'dashboard'}"
[attr.target]="subItem.getAttribute('target')"
[routerLink]="subItem.getRouterLink()"
[queryParams]="subItem.getQueryParams() ? subItem.getQueryParams() : {}"
>
<i *ngIf="subItem.hasExtra('iconClass')" [ngClass]="subItem.getExtra('iconClass')"></i>
{{ subItem.getName() }}
</a>
</ng-container>
</div>
</div>
</div>
</ng-container>
</div>
</ng-container>
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/*
* 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 { ComponentFixture, TestBed } from '@angular/core/testing';
import { TranslateModule } from '@ngx-translate/core';
import { IdAttributePipe, SharedModule, User, UserService } from '@rero/shared';

import { MenuDashboardComponent } from './menu-dashboard.component';

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

const user = new User({
currentLibrary: 1
});
const userServiceSpy = jasmine.createSpyObj('UserService', ['']);
userServiceSpy.user = user;

beforeEach(async () => {
await TestBed.configureTestingModule({
declarations: [MenuDashboardComponent],
imports: [
SharedModule,
HttpClientTestingModule,
TranslateModule.forRoot()
],
providers: [
IdAttributePipe,
{ provide: UserService, useValue: userServiceSpy }
]
})
.compileComponents();
});

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

it('should create', () => {
expect(component).toBeTruthy();
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
* 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, OnInit } from '@angular/core';
import { MenuItemInterface } from '@rero/ng-core';
import { MenuUserServicesService } from '../service/menu-user-services.service';

@Component({
selector: 'admin-menu-dashboard',
templateUrl: './menu-dashboard.component.html'
})
export class MenuDashboardComponent implements OnInit {

/** User menu */
private _menu: MenuItemInterface;

/**
* User services menu
* @return MenuItemInterface
*/
get menu(): MenuItemInterface {
return this._menu;
}

/**
* Constructor
* @param _menuUserService - MenuUserService
*/
constructor(private _menuUserServicesService: MenuUserServicesService) { }

/** Init */
ngOnInit() {
if (!(this._menuUserServicesService.menu)) {
this._menuUserServicesService.generate();
}
this._menu = this._menuUserServicesService.menu;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<!--
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 [menu]="menu" (clickItem)="changeLang($event)"></ng-core-menu-widget>
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
* 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 { ComponentFixture, TestBed } from '@angular/core/testing';
import { TranslateModule, TranslateService } from '@ngx-translate/core';
import { BsLocaleService } from 'ngx-bootstrap/datepicker';
import { MenuLanguageComponent } from './menu-language.component';


describe('MenuLanguageComponent', () => {
let component: MenuLanguageComponent;
let fixture: ComponentFixture<MenuLanguageComponent>;
let translateService: TranslateService;

beforeEach(async () => {
await TestBed.configureTestingModule({
declarations: [ MenuLanguageComponent ],
imports: [
TranslateModule.forRoot()
],
providers: [
BsLocaleService
]
})
.compileComponents();
});

beforeEach(() => {
translateService = TestBed.inject(TranslateService);
translateService.use('en');
fixture = TestBed.createComponent(MenuLanguageComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});

it('should create', () => {
expect(component).toBeTruthy();
});
});
Loading

0 comments on commit 772e91e

Please sign in to comment.