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 | |
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')
3 files changed, 0 insertions, 244 deletions
diff --git a/client/src/app/shared/menu/top-menu-dropdown.component.html b/client/src/app/shared/menu/top-menu-dropdown.component.html deleted file mode 100644 index aeaceb662..000000000 --- a/client/src/app/shared/menu/top-menu-dropdown.component.html +++ /dev/null | |||
@@ -1,50 +0,0 @@ | |||
1 | <div class="sub-menu" [ngClass]="{ 'no-scroll': isModalOpened }"> | ||
2 | <ng-container *ngFor="let menuEntry of menuEntries; index as id"> | ||
3 | |||
4 | <a *ngIf="menuEntry.routerLink" [routerLink]="menuEntry.routerLink" routerLinkActive="active" class="title-page title-page-settings">{{ menuEntry.label }}</a> | ||
5 | |||
6 | <div *ngIf="!menuEntry.routerLink" ngbDropdown class="parent-entry" | ||
7 | #dropdown="ngbDropdown" (mouseleave)="closeDropdownIfHovered(dropdown)"> | ||
8 | <span | ||
9 | *ngIf="isInSmallView" | ||
10 | [ngClass]="{ active: !!suffixLabels[menuEntry.label] }" | ||
11 | (click)="openModal(id)" role="button" class="title-page title-page-settings"> | ||
12 | <ng-container i18n>{{ menuEntry.label }}</ng-container> | ||
13 | <ng-container *ngIf="!!suffixLabels[menuEntry.label]"> - {{ suffixLabels[menuEntry.label] }}</ng-container> | ||
14 | </span> | ||
15 | |||
16 | <span | ||
17 | *ngIf="!isInSmallView" | ||
18 | (mouseenter)="openDropdownOnHover(dropdown)" [ngClass]="{ active: !!suffixLabels[menuEntry.label] }" ngbDropdownAnchor | ||
19 | (click)="dropdownAnchorClicked(dropdown)" role="button" class="title-page title-page-settings" | ||
20 | > | ||
21 | <ng-container i18n>{{ menuEntry.label }}</ng-container> | ||
22 | <ng-container *ngIf="!!suffixLabels[menuEntry.label]"> - {{ suffixLabels[menuEntry.label] }}</ng-container> | ||
23 | </span> | ||
24 | |||
25 | <div ngbDropdownMenu> | ||
26 | <a *ngFor="let menuChild of menuEntry.children" class="dropdown-item" [ngClass]="{ icon: hasIcons }" [routerLink]="menuChild.routerLink"> | ||
27 | <my-global-icon *ngIf="menuChild.iconName" [iconName]="menuChild.iconName" aria-hidden="true"></my-global-icon> | ||
28 | |||
29 | {{ menuChild.label }} | ||
30 | </a> | ||
31 | </div> | ||
32 | </div> | ||
33 | </ng-container> | ||
34 | </div> | ||
35 | |||
36 | <ng-template #modal let-close="close" let-dismiss="dismiss"> | ||
37 | <div class="modal-body"> | ||
38 | <ng-container *ngFor="let menuEntry of menuEntries; index as id"> | ||
39 | <div [ngClass]="{ hidden: id !== currentMenuEntryIndex }"> | ||
40 | <a *ngFor="let menuChild of menuEntry.children" | ||
41 | [ngClass]="{ icon: hasIcons }" | ||
42 | [routerLink]="menuChild.routerLink" routerLinkActive="active" (click)="dismissOtherModals()"> | ||
43 | <my-global-icon *ngIf="menuChild.iconName" [iconName]="menuChild.iconName" aria-hidden="true"></my-global-icon> | ||
44 | |||
45 | {{ menuChild.label }} | ||
46 | </a> | ||
47 | </div> | ||
48 | </ng-container> | ||
49 | </div> | ||
50 | </ng-template> | ||
diff --git a/client/src/app/shared/menu/top-menu-dropdown.component.scss b/client/src/app/shared/menu/top-menu-dropdown.component.scss deleted file mode 100644 index 84dd7dce3..000000000 --- a/client/src/app/shared/menu/top-menu-dropdown.component.scss +++ /dev/null | |||
@@ -1,56 +0,0 @@ | |||
1 | @import '_variables'; | ||
2 | @import '_mixins'; | ||
3 | |||
4 | .parent-entry { | ||
5 | span[role=button] { | ||
6 | cursor: pointer; | ||
7 | } | ||
8 | |||
9 | a { | ||
10 | display: block; | ||
11 | } | ||
12 | } | ||
13 | |||
14 | ::ng-deep .dropdown-toggle::after { | ||
15 | position: relative; | ||
16 | top: 2px; | ||
17 | } | ||
18 | |||
19 | ::ng-deep .dropdown-menu { | ||
20 | margin-top: 0 !important; | ||
21 | } | ||
22 | |||
23 | .icon { | ||
24 | @include dropdown-with-icon-item; | ||
25 | |||
26 | top: -1px; | ||
27 | } | ||
28 | |||
29 | .sub-menu.no-scroll { | ||
30 | overflow-x: hidden; | ||
31 | } | ||
32 | |||
33 | .modal-body { | ||
34 | .hidden { | ||
35 | display: none; | ||
36 | } | ||
37 | |||
38 | a { | ||
39 | @include disable-default-a-behaviour; | ||
40 | |||
41 | color: currentColor; | ||
42 | box-sizing: border-box; | ||
43 | display: block; | ||
44 | font-size: 1.2rem; | ||
45 | padding: 9px 12px; | ||
46 | text-align: initial; | ||
47 | text-transform: unset; | ||
48 | width: 100%; | ||
49 | |||
50 | &.active { | ||
51 | color: pvar(--mainBackgroundColor) !important; | ||
52 | background-color: pvar(--mainHoverColor); | ||
53 | opacity: .9; | ||
54 | } | ||
55 | } | ||
56 | } | ||
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 | } | ||