From ddb83e49ece4e76df1af98aeea30c1d8d133f48c Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Wed, 5 Dec 2018 14:21:10 +0100 Subject: My account menu -> open entries on hover --- .../shared/menu/top-menu-dropdown.component.html | 18 ++++++ .../shared/menu/top-menu-dropdown.component.scss | 14 ++++ .../app/shared/menu/top-menu-dropdown.component.ts | 75 ++++++++++++++++++++++ 3 files changed, 107 insertions(+) create mode 100644 client/src/app/shared/menu/top-menu-dropdown.component.html create mode 100644 client/src/app/shared/menu/top-menu-dropdown.component.scss create mode 100644 client/src/app/shared/menu/top-menu-dropdown.component.ts (limited to 'client/src/app/shared/menu') 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..2d6d1c4bf --- /dev/null +++ b/client/src/app/shared/menu/top-menu-dropdown.component.html @@ -0,0 +1,18 @@ + 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..f3ef8f814 --- /dev/null +++ b/client/src/app/shared/menu/top-menu-dropdown.component.scss @@ -0,0 +1,14 @@ +.parent-entry { + span[role=button] { + cursor: pointer; + } + + a { + display: block; + } +} + +/deep/ .dropdown-toggle::after { + position: relative; + top: 2px; +} 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..272b721b2 --- /dev/null +++ b/client/src/app/shared/menu/top-menu-dropdown.component.ts @@ -0,0 +1,75 @@ +import { Component, Input, OnDestroy, OnInit } from '@angular/core' +import { filter, take } from 'rxjs/operators' +import { NavigationStart, Router } from '@angular/router' +import { Subscription } from 'rxjs' +import { NgbDropdown } from '@ng-bootstrap/ng-bootstrap' +import { drop } from 'lodash-es' + +export type TopMenuDropdownParam = { + label: string + routerLink?: string + + children?: { + label: string + routerLink: string + }[] +} + +@Component({ + selector: 'my-top-menu-dropdown', + templateUrl: './top-menu-dropdown.component.html', + styleUrls: [ './top-menu-dropdown.component.scss' ] +}) +export class TopMenuDropdownComponent implements OnInit, OnDestroy { + @Input() menuEntries: TopMenuDropdownParam[] = [] + + suffixLabels: { [ parentLabel: string ]: string } + + private openedOnHover = false + private routeSub: Subscription + + constructor (private router: Router) {} + + ngOnInit () { + this.updateChildLabels(window.location.pathname) + + this.routeSub = this.router.events + .pipe(filter(event => event instanceof NavigationStart)) + .subscribe(() => this.updateChildLabels(window.location.pathname)) + } + + ngOnDestroy () { + if (this.routeSub) this.routeSub.unsubscribe() + } + + openDropdownOnHover (dropdown: NgbDropdown) { + this.openedOnHover = true + dropdown.open() + + // Menu was closed + dropdown.openChange + .pipe(take(1)) + .subscribe(e => this.openedOnHover = false) + } + + closeDropdownIfHovered (dropdown: NgbDropdown) { + if (this.openedOnHover === false) return + + dropdown.close() + this.openedOnHover = false + } + + private updateChildLabels (path: string) { + this.suffixLabels = {} + + for (const entry of this.menuEntries) { + if (!entry.children) continue + + for (const child of entry.children) { + if (path.startsWith(child.routerLink)) { + this.suffixLabels[entry.label] = child.label + } + } + } + } +} -- cgit v1.2.3 From 80bfd33c0bf910e2cfdd3270b14ba9eddd90e2e8 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Tue, 18 Dec 2018 09:31:09 +0100 Subject: Add history page on client --- .../src/app/shared/menu/top-menu-dropdown.component.html | 5 ++++- .../src/app/shared/menu/top-menu-dropdown.component.scss | 4 ++++ client/src/app/shared/menu/top-menu-dropdown.component.ts | 14 +++++++++++--- 3 files changed, 19 insertions(+), 4 deletions(-) (limited to 'client/src/app/shared/menu') diff --git a/client/src/app/shared/menu/top-menu-dropdown.component.html b/client/src/app/shared/menu/top-menu-dropdown.component.html index 2d6d1c4bf..d3c896019 100644 --- a/client/src/app/shared/menu/top-menu-dropdown.component.html +++ b/client/src/app/shared/menu/top-menu-dropdown.component.html @@ -4,7 +4,10 @@ {{ menuEntry.label }}
- + {{ menuEntry.label }} - {{ suffixLabels[menuEntry.label] }} diff --git a/client/src/app/shared/menu/top-menu-dropdown.component.scss b/client/src/app/shared/menu/top-menu-dropdown.component.scss index f3ef8f814..77159532f 100644 --- a/client/src/app/shared/menu/top-menu-dropdown.component.scss +++ b/client/src/app/shared/menu/top-menu-dropdown.component.scss @@ -12,3 +12,7 @@ position: relative; top: 2px; } + +/deep/ .dropdown-menu { + margin-top: 0 !important; +} 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 272b721b2..e859c30dd 100644 --- a/client/src/app/shared/menu/top-menu-dropdown.component.ts +++ b/client/src/app/shared/menu/top-menu-dropdown.component.ts @@ -1,9 +1,8 @@ import { Component, Input, OnDestroy, OnInit } from '@angular/core' import { filter, take } from 'rxjs/operators' -import { NavigationStart, Router } from '@angular/router' +import { NavigationEnd, Router } from '@angular/router' import { Subscription } from 'rxjs' import { NgbDropdown } from '@ng-bootstrap/ng-bootstrap' -import { drop } from 'lodash-es' export type TopMenuDropdownParam = { label: string @@ -34,7 +33,7 @@ export class TopMenuDropdownComponent implements OnInit, OnDestroy { this.updateChildLabels(window.location.pathname) this.routeSub = this.router.events - .pipe(filter(event => event instanceof NavigationStart)) + .pipe(filter(event => event instanceof NavigationEnd)) .subscribe(() => this.updateChildLabels(window.location.pathname)) } @@ -52,6 +51,15 @@ export class TopMenuDropdownComponent implements OnInit, OnDestroy { .subscribe(e => this.openedOnHover = false) } + dropdownAnchorClicked (dropdown: NgbDropdown) { + if (this.openedOnHover) { + this.openedOnHover = false + return + } + + return dropdown.toggle() + } + closeDropdownIfHovered (dropdown: NgbDropdown) { if (this.openedOnHover === false) return -- cgit v1.2.3