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.ts50
1 files changed, 43 insertions, 7 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
index 24a083654..f98240804 100644
--- a/client/src/app/shared/menu/top-menu-dropdown.component.ts
+++ b/client/src/app/shared/menu/top-menu-dropdown.component.ts
@@ -1,8 +1,14 @@
1import { Component, Input, OnDestroy, OnInit } from '@angular/core' 1import {
2 Component,
3 Input,
4 OnDestroy,
5 OnInit,
6 ViewChild
7} from '@angular/core'
2import { filter, take } from 'rxjs/operators' 8import { filter, take } from 'rxjs/operators'
3import { NavigationEnd, Router } from '@angular/router' 9import { NavigationEnd, Router } from '@angular/router'
4import { Subscription } from 'rxjs' 10import { Subscription } from 'rxjs'
5import { NgbDropdown } from '@ng-bootstrap/ng-bootstrap' 11import { NgbDropdown, NgbModal } from '@ng-bootstrap/ng-bootstrap'
6import { GlobalIconName } from '@app/shared/images/global-icon.component' 12import { GlobalIconName } from '@app/shared/images/global-icon.component'
7import { ScreenService } from '@app/shared/misc/screen.service' 13import { ScreenService } from '@app/shared/misc/screen.service'
8 14
@@ -26,31 +32,40 @@ export type TopMenuDropdownParam = {
26export class TopMenuDropdownComponent implements OnInit, OnDestroy { 32export class TopMenuDropdownComponent implements OnInit, OnDestroy {
27 @Input() menuEntries: TopMenuDropdownParam[] = [] 33 @Input() menuEntries: TopMenuDropdownParam[] = []
28 34
35 @ViewChild('modal', { static: true }) modal: NgbModal
36
29 suffixLabels: { [ parentLabel: string ]: string } 37 suffixLabels: { [ parentLabel: string ]: string }
30 hasIcons = false 38 hasIcons = false
31 container: undefined | 'body' = undefined 39 container: undefined | 'body' = undefined
40 isModalOpened = false
41 currentMenuEntryIndex: number
32 42
33 private openedOnHover = false 43 private openedOnHover = false
34 private routeSub: Subscription 44 private routeSub: Subscription
35 45
36 constructor ( 46 constructor (
37 private router: Router, 47 private router: Router,
48 private modalService: NgbModal,
38 private screen: ScreenService 49 private screen: ScreenService
39 ) {} 50 ) { }
51
52 get isInSmallView () {
53 return this.screen.isInSmallView()
54 }
40 55
41 ngOnInit () { 56 ngOnInit () {
42 this.updateChildLabels(window.location.pathname) 57 this.updateChildLabels(window.location.pathname)
43 58
44 this.routeSub = this.router.events 59 this.routeSub = this.router.events
45 .pipe(filter(event => event instanceof NavigationEnd)) 60 .pipe(filter(event => event instanceof NavigationEnd))
46 .subscribe(() => this.updateChildLabels(window.location.pathname)) 61 .subscribe(() => this.updateChildLabels(window.location.pathname))
47 62
48 this.hasIcons = this.menuEntries.some( 63 this.hasIcons = this.menuEntries.some(
49 e => e.children && e.children.some(c => !!c.iconName) 64 e => e.children && e.children.some(c => !!c.iconName)
50 ) 65 )
51 66
52 // We have to set body for the container to avoid scroll overflow on mobile view 67 // We have to set body for the container to avoid scroll overflow on mobile and small views
53 if (this.screen.isInMobileView()) { 68 if (this.isInSmallView) {
54 this.container = 'body' 69 this.container = 'body'
55 } 70 }
56 } 71 }
@@ -85,6 +100,27 @@ export class TopMenuDropdownComponent implements OnInit, OnDestroy {
85 this.openedOnHover = false 100 this.openedOnHover = false
86 } 101 }
87 102
103 openModal (index: number) {
104 this.currentMenuEntryIndex = index
105 this.isModalOpened = true
106
107 this.modalService.open(this.modal, {
108 centered: true,
109 beforeDismiss: async () => {
110 this.onModalDismiss()
111 return true
112 }
113 })
114 }
115
116 onModalDismiss () {
117 this.isModalOpened = false
118 }
119
120 dismissOtherModals () {
121 this.modalService.dismissAll()
122 }
123
88 private updateChildLabels (path: string) { 124 private updateChildLabels (path: string) {
89 this.suffixLabels = {} 125 this.suffixLabels = {}
90 126