import { Subscription } from 'rxjs'
-import { filter, take } from 'rxjs/operators'
+import { filter } from 'rxjs/operators'
import { Component, Input, OnDestroy, OnInit, ViewChild } from '@angular/core'
import { NavigationEnd, Router } from '@angular/router'
import { MenuService, ScreenService } from '@app/core'
+import { scrollToTop } from '@app/helpers'
import { GlobalIconName } from '@app/shared/shared-icons'
import { NgbDropdown, NgbModal } from '@ng-bootstrap/ng-bootstrap'
export type TopMenuDropdownParam = {
label: string
routerLink?: string
+ isDisplayed?: () => boolean // Default: () => true
children?: {
label: string
routerLink: string
-
iconName?: GlobalIconName
+
+ isDisplayed?: () => boolean // Default: () => true
}[]
}
isModalOpened = false
currentMenuEntryIndex: number
- private openedOnHover = false
private routeSub: Subscription
constructor (
return this.screen.isInSmallView(marginLeft)
}
+ get isBroadcastMessageDisplayed () {
+ return this.screen.isBroadcastMessageDisplayed
+ }
+
ngOnInit () {
this.updateChildLabels(window.location.pathname)
if (this.routeSub) this.routeSub.unsubscribe()
}
- openDropdownOnHover (dropdown: NgbDropdown) {
- this.openedOnHover = true
- dropdown.open()
-
- // Menu was closed
- dropdown.openChange
- .pipe(take(1))
- .subscribe(() => this.openedOnHover = false)
- }
-
dropdownAnchorClicked (dropdown: NgbDropdown) {
- if (this.openedOnHover) {
- this.openedOnHover = false
- return
- }
-
return dropdown.toggle()
}
- closeDropdownIfHovered (dropdown: NgbDropdown) {
- if (this.openedOnHover === false) return
-
- dropdown.close()
- this.openedOnHover = false
- }
-
openModal (index: number) {
this.currentMenuEntryIndex = index
this.isModalOpened = true
this.isModalOpened = false
}
+ onActiveLinkScrollToTop (link: HTMLAnchorElement) {
+ if (!this.isBroadcastMessageDisplayed && this.router.url.includes(link.getAttribute('href'))) {
+ scrollToTop('smooth')
+ }
+ }
+
dismissOtherModals () {
this.modalService.dismissAll()
}
+ isDisplayed (obj: { isDisplayed?: () => boolean }) {
+ if (typeof obj.isDisplayed !== 'function') return true
+
+ return obj.isDisplayed()
+ }
+
private updateChildLabels (path: string) {
this.suffixLabels = {}