Skip to content

Commit

Permalink
switch library: fix the display of the switch menu on the homepage
Browse files Browse the repository at this point in the history
* Close #141

Co-Authored-by: Bertrand Zuchuat <[email protected]>
  • Loading branch information
Garfield-fr committed Feb 7, 2020
1 parent 6697eac commit 8113817
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
9 changes: 9 additions & 0 deletions projects/admin/src/app/menu/menu.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,15 @@ export class MenuComponent implements OnInit {
]
});

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;
});
Expand Down
15 changes: 14 additions & 1 deletion projects/admin/src/app/service/library-switch.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ export class LibrarySwitchService {
*/
private onGenerateMenu: Subject<Array<any>> = new Subject();

/**
* On Visible Menu
*/
private onVisibleMenu: Subject<boolean> = new Subject();

/**
* Entries for library switch menu
*/
Expand All @@ -48,12 +53,19 @@ export class LibrarySwitchService {
private menuVisible = false;

/**
* Retour on Generate Menu Observable
* Return on generate menu observable
*/
get onGenerate$() {
return this.onGenerateMenu.asObservable();
}

/**
* Return on visible menu observable
*/
get onVisibleMenu$() {
return this.onVisibleMenu.asObservable();
}

/**
* Return library entries menu
*/
Expand Down Expand Up @@ -106,6 +118,7 @@ export class LibrarySwitchService {
*/
show(visible: boolean) {
this.menuVisible = visible;
this.onVisibleMenu.next(visible);
}

/**
Expand Down

0 comments on commit 8113817

Please sign in to comment.