aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app/shared/menu/top-menu-dropdown.component.ts
diff options
context:
space:
mode:
Diffstat (limited to 'client/src/app/shared/menu/top-menu-dropdown.component.ts')
-rw-r--r--client/src/app/shared/menu/top-menu-dropdown.component.ts138
1 files changed, 0 insertions, 138 deletions
diff --git a/client/src/app/shared/menu/top-menu-dropdown.component.ts b/client/src/app/shared/menu/top-menu-dropdown.component.ts
deleted file mode 100644
index 3f121e785..000000000
--- a/client/src/app/shared/menu/top-menu-dropdown.component.ts
+++ /dev/null
@@ -1,138 +0,0 @@
1import {
2 Component,
3 Input,
4 OnDestroy,
5 OnInit,
6 ViewChild
7} from '@angular/core'
8import { filter, take } from 'rxjs/operators'
9import { NavigationEnd, Router } from '@angular/router'
10import { Subscription } from 'rxjs'
11import { NgbDropdown, NgbModal } from '@ng-bootstrap/ng-bootstrap'
12import { GlobalIconName } from '@app/shared/images/global-icon.component'
13import { ScreenService } from '@app/shared/misc/screen.service'
14import { MenuService } from '@app/core/menu'
15
16export type TopMenuDropdownParam = {
17 label: string
18 routerLink?: string
19
20 children?: {
21 label: string
22 routerLink: string
23
24 iconName?: GlobalIconName
25 }[]
26}
27
28@Component({
29 selector: 'my-top-menu-dropdown',
30 templateUrl: './top-menu-dropdown.component.html',
31 styleUrls: [ './top-menu-dropdown.component.scss' ]
32})
33export class TopMenuDropdownComponent implements OnInit, OnDestroy {
34 @Input() menuEntries: TopMenuDropdownParam[] = []
35
36 @ViewChild('modal', { static: true }) modal: NgbModal
37
38 suffixLabels: { [ parentLabel: string ]: string }
39 hasIcons = false
40 isModalOpened = false
41 currentMenuEntryIndex: number
42
43 private openedOnHover = false
44 private routeSub: Subscription
45
46 constructor (
47 private router: Router,
48 private modalService: NgbModal,
49 private screen: ScreenService,
50 private menuService: MenuService
51 ) { }
52
53 get isInSmallView () {
54 let marginLeft = 0
55 if (this.menuService.isMenuDisplayed) {
56 marginLeft = this.menuService.menuWidth
57 }
58
59 return this.screen.isInSmallView(marginLeft)
60 }
61
62 ngOnInit () {
63 this.updateChildLabels(window.location.pathname)
64
65 this.routeSub = this.router.events
66 .pipe(filter(event => event instanceof NavigationEnd))
67 .subscribe(() => this.updateChildLabels(window.location.pathname))
68
69 this.hasIcons = this.menuEntries.some(
70 e => e.children && e.children.some(c => !!c.iconName)
71 )
72 }
73
74 ngOnDestroy () {
75 if (this.routeSub) this.routeSub.unsubscribe()
76 }
77
78 openDropdownOnHover (dropdown: NgbDropdown) {
79 this.openedOnHover = true
80 dropdown.open()
81
82 // Menu was closed
83 dropdown.openChange
84 .pipe(take(1))
85 .subscribe(() => this.openedOnHover = false)
86 }
87
88 dropdownAnchorClicked (dropdown: NgbDropdown) {
89 if (this.openedOnHover) {
90 this.openedOnHover = false
91 return
92 }
93
94 return dropdown.toggle()
95 }
96
97 closeDropdownIfHovered (dropdown: NgbDropdown) {
98 if (this.openedOnHover === false) return
99
100 dropdown.close()
101 this.openedOnHover = false
102 }
103
104 openModal (index: number) {
105 this.currentMenuEntryIndex = index
106 this.isModalOpened = true
107
108 this.modalService.open(this.modal, {
109 centered: true,
110 beforeDismiss: async () => {
111 this.onModalDismiss()
112 return true
113 }
114 })
115 }
116
117 onModalDismiss () {
118 this.isModalOpened = false
119 }
120
121 dismissOtherModals () {
122 this.modalService.dismissAll()
123 }
124
125 private updateChildLabels (path: string) {
126 this.suffixLabels = {}
127
128 for (const entry of this.menuEntries) {
129 if (!entry.children) continue
130
131 for (const child of entry.children) {
132 if (path.startsWith(child.routerLink)) {
133 this.suffixLabels[entry.label] = child.label
134 }
135 }
136 }
137 }
138}