diff options
Diffstat (limited to 'client/src/app/shared/menu')
3 files changed, 122 insertions, 0 deletions
diff --git a/client/src/app/shared/menu/top-menu-dropdown.component.html b/client/src/app/shared/menu/top-menu-dropdown.component.html new file mode 100644 index 000000000..d3c896019 --- /dev/null +++ b/client/src/app/shared/menu/top-menu-dropdown.component.html | |||
@@ -0,0 +1,21 @@ | |||
1 | <div class="sub-menu"> | ||
2 | <ng-container *ngFor="let menuEntry of menuEntries"> | ||
3 | |||
4 | <a *ngIf="menuEntry.routerLink" [routerLink]="menuEntry.routerLink" routerLinkActive="active" class="title-page">{{ menuEntry.label }}</a> | ||
5 | |||
6 | <div *ngIf="!menuEntry.routerLink" ngbDropdown class="parent-entry" #dropdown="ngbDropdown" (mouseleave)="closeDropdownIfHovered(dropdown)"> | ||
7 | <span | ||
8 | (mouseenter)="openDropdownOnHover(dropdown)" [ngClass]="{ active: !!suffixLabels[menuEntry.label] }" ngbDropdownAnchor | ||
9 | (click)="dropdownAnchorClicked(dropdown)" role="button" class="title-page" | ||
10 | > | ||
11 | <ng-container i18n>{{ menuEntry.label }}</ng-container> | ||
12 | <ng-container *ngIf="!!suffixLabels[menuEntry.label]"> - {{ suffixLabels[menuEntry.label] }}</ng-container> | ||
13 | </span> | ||
14 | |||
15 | <div ngbDropdownMenu> | ||
16 | <a *ngFor="let menuChild of menuEntry.children" class="dropdown-item" [routerLink]="menuChild.routerLink">{{ menuChild.label }}</a> | ||
17 | </div> | ||
18 | </div> | ||
19 | |||
20 | </ng-container> | ||
21 | </div> | ||
diff --git a/client/src/app/shared/menu/top-menu-dropdown.component.scss b/client/src/app/shared/menu/top-menu-dropdown.component.scss new file mode 100644 index 000000000..77159532f --- /dev/null +++ b/client/src/app/shared/menu/top-menu-dropdown.component.scss | |||
@@ -0,0 +1,18 @@ | |||
1 | .parent-entry { | ||
2 | span[role=button] { | ||
3 | cursor: pointer; | ||
4 | } | ||
5 | |||
6 | a { | ||
7 | display: block; | ||
8 | } | ||
9 | } | ||
10 | |||
11 | /deep/ .dropdown-toggle::after { | ||
12 | position: relative; | ||
13 | top: 2px; | ||
14 | } | ||
15 | |||
16 | /deep/ .dropdown-menu { | ||
17 | margin-top: 0 !important; | ||
18 | } | ||
diff --git a/client/src/app/shared/menu/top-menu-dropdown.component.ts b/client/src/app/shared/menu/top-menu-dropdown.component.ts new file mode 100644 index 000000000..e859c30dd --- /dev/null +++ b/client/src/app/shared/menu/top-menu-dropdown.component.ts | |||
@@ -0,0 +1,83 @@ | |||
1 | import { Component, Input, OnDestroy, OnInit } from '@angular/core' | ||
2 | import { filter, take } from 'rxjs/operators' | ||
3 | import { NavigationEnd, Router } from '@angular/router' | ||
4 | import { Subscription } from 'rxjs' | ||
5 | import { NgbDropdown } from '@ng-bootstrap/ng-bootstrap' | ||
6 | |||
7 | export type TopMenuDropdownParam = { | ||
8 | label: string | ||
9 | routerLink?: string | ||
10 | |||
11 | children?: { | ||
12 | label: string | ||
13 | routerLink: string | ||
14 | }[] | ||
15 | } | ||
16 | |||
17 | @Component({ | ||
18 | selector: 'my-top-menu-dropdown', | ||
19 | templateUrl: './top-menu-dropdown.component.html', | ||
20 | styleUrls: [ './top-menu-dropdown.component.scss' ] | ||
21 | }) | ||
22 | export class TopMenuDropdownComponent implements OnInit, OnDestroy { | ||
23 | @Input() menuEntries: TopMenuDropdownParam[] = [] | ||
24 | |||
25 | suffixLabels: { [ parentLabel: string ]: string } | ||
26 | |||
27 | private openedOnHover = false | ||
28 | private routeSub: Subscription | ||
29 | |||
30 | constructor (private router: Router) {} | ||
31 | |||
32 | ngOnInit () { | ||
33 | this.updateChildLabels(window.location.pathname) | ||
34 | |||
35 | this.routeSub = this.router.events | ||
36 | .pipe(filter(event => event instanceof NavigationEnd)) | ||
37 | .subscribe(() => this.updateChildLabels(window.location.pathname)) | ||
38 | } | ||
39 | |||
40 | ngOnDestroy () { | ||
41 | if (this.routeSub) this.routeSub.unsubscribe() | ||
42 | } | ||
43 | |||
44 | openDropdownOnHover (dropdown: NgbDropdown) { | ||
45 | this.openedOnHover = true | ||
46 | dropdown.open() | ||
47 | |||
48 | // Menu was closed | ||
49 | dropdown.openChange | ||
50 | .pipe(take(1)) | ||
51 | .subscribe(e => this.openedOnHover = false) | ||
52 | } | ||
53 | |||
54 | dropdownAnchorClicked (dropdown: NgbDropdown) { | ||
55 | if (this.openedOnHover) { | ||
56 | this.openedOnHover = false | ||
57 | return | ||
58 | } | ||
59 | |||
60 | return dropdown.toggle() | ||
61 | } | ||
62 | |||
63 | closeDropdownIfHovered (dropdown: NgbDropdown) { | ||
64 | if (this.openedOnHover === false) return | ||
65 | |||
66 | dropdown.close() | ||
67 | this.openedOnHover = false | ||
68 | } | ||
69 | |||
70 | private updateChildLabels (path: string) { | ||
71 | this.suffixLabels = {} | ||
72 | |||
73 | for (const entry of this.menuEntries) { | ||
74 | if (!entry.children) continue | ||
75 | |||
76 | for (const child of entry.children) { | ||
77 | if (path.startsWith(child.routerLink)) { | ||
78 | this.suffixLabels[entry.label] = child.label | ||
79 | } | ||
80 | } | ||
81 | } | ||
82 | } | ||
83 | } | ||