diff options
author | Chocobozzz <me@florianbigard.com> | 2020-06-23 14:10:17 +0200 |
---|---|---|
committer | Chocobozzz <chocobozzz@cpy.re> | 2020-06-23 16:00:49 +0200 |
commit | 67ed6552b831df66713bac9e672738796128d33f (patch) | |
tree | 59c97d41e0b49d75a90aa3de987968ab9b1ff447 /client/src/app/shared/menu/top-menu-dropdown.component.ts | |
parent | 0c4bacbff53bc732f5a2677d62a6ead7752e2405 (diff) | |
download | PeerTube-67ed6552b831df66713bac9e672738796128d33f.tar.gz PeerTube-67ed6552b831df66713bac9e672738796128d33f.tar.zst PeerTube-67ed6552b831df66713bac9e672738796128d33f.zip |
Reorganize client shared modules
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.ts | 138 |
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 @@ | |||
1 | import { | ||
2 | Component, | ||
3 | Input, | ||
4 | OnDestroy, | ||
5 | OnInit, | ||
6 | ViewChild | ||
7 | } from '@angular/core' | ||
8 | import { filter, take } from 'rxjs/operators' | ||
9 | import { NavigationEnd, Router } from '@angular/router' | ||
10 | import { Subscription } from 'rxjs' | ||
11 | import { NgbDropdown, NgbModal } from '@ng-bootstrap/ng-bootstrap' | ||
12 | import { GlobalIconName } from '@app/shared/images/global-icon.component' | ||
13 | import { ScreenService } from '@app/shared/misc/screen.service' | ||
14 | import { MenuService } from '@app/core/menu' | ||
15 | |||
16 | export 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 | }) | ||
33 | export 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 | } | ||