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 22, 2020
1 parent 5e5a75a commit e5831c9
Show file tree
Hide file tree
Showing 22 changed files with 152 additions and 193 deletions.
13 changes: 13 additions & 0 deletions package-lock.json

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

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@
"lodash-es": "4.17.14",
"moment": "^2.24.0",
"ngx-bootstrap": "^5.6.2",
"ngx-bootstrap-slider": "^1.8.0",
"ngx-toastr": "^10.2.0",
"ngx-toggle-switch": "^2.0.5",
"rxjs": "^6.4.0",
Expand Down
2 changes: 1 addition & 1 deletion projects/admin/src/app/app-routing.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ const routes: Routes = [
];

@NgModule({
imports: [RouterModule.forRoot(routes)],
imports: [RouterModule.forRoot(routes, {onSameUrlNavigation: 'reload'}) ],
exports: [RouterModule]
})
export class AppRoutingModule {
Expand Down
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
9 changes: 4 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,10 @@ 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
);
// Library Switch menu is enabled only on homepage
// We use this restriction to avoid problems if user is on page using the current library value (my library, some forms, ...)
// To avoid all potential problem, the simplest way is to enable the menu only on the homepage.
this.librarySwitchService.enable( event.url === '/');
})
);
}
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 @@ -157,10 +156,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.

13 changes: 11 additions & 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,12 +38,22 @@

<div class="collapse navbar-collapse" id="navbarSupportedContent" [collapse]="isCollapsed" [isAnimated]="true">
<ng-core-menu class="mr-auto" [menu]="linksMenu"></ng-core-menu>

<ng-core-menu
class="userMenu"
[menu]="librariesSwitchMenu"
(clickItem)="changeLibrary($event)"
*ngIf="isVisibleLibrarySwitchMenu && isVisible"
></ng-core-menu>
<ng-template #switchLibraryOff>
<ul class="navbar-nav">
<li class="nav-item">
<div class="nav-link">
<i class="fa fa-random"></i> {{ librariesSwitchMenu.entries[0].name }}
</div>
</li>
</ul>
</ng-template>

<ng-core-menu [menu]="languagesMenu" (clickItem)="changeLang($event)"></ng-core-menu>
<ng-core-menu [menu]="userMenu"></ng-core-menu>
</div>
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
7 changes: 4 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,16 @@
* 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 { 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()
]
}));

Expand Down
Loading

0 comments on commit e5831c9

Please sign in to comment.