Commit 075138cc5c6115c0242aebe6cf4dcfd1c99c08db
Committed by
GitHub
Merge pull request #3463 from vvlladd28/improvement/menu/trackBy
Improvement draw menu and breadCrumb
Showing
9 changed files
with
47 additions
and
7 deletions
... | ... | @@ -14,9 +14,11 @@ |
14 | 14 | /// limitations under the License. |
15 | 15 | /// |
16 | 16 | |
17 | +import { HasUUID } from '@shared/models/id/has-uuid'; | |
18 | + | |
17 | 19 | export declare type MenuSectionType = 'link' | 'toggle'; |
18 | 20 | |
19 | -export class MenuSection { | |
21 | +export interface MenuSection extends HasUUID{ | |
20 | 22 | name: string; |
21 | 23 | type: MenuSectionType; |
22 | 24 | path: string; |
... | ... | @@ -26,12 +28,12 @@ export class MenuSection { |
26 | 28 | pages?: Array<MenuSection>; |
27 | 29 | } |
28 | 30 | |
29 | -export class HomeSection { | |
31 | +export interface HomeSection { | |
30 | 32 | name: string; |
31 | 33 | places: Array<HomeSectionPlace>; |
32 | 34 | } |
33 | 35 | |
34 | -export class HomeSectionPlace { | |
36 | +export interface HomeSectionPlace { | |
35 | 37 | name: string; |
36 | 38 | icon: string; |
37 | 39 | isMdiIcon?: boolean; | ... | ... |
... | ... | @@ -24,6 +24,7 @@ import { HomeSection, MenuSection } from '@core/services/menu.models'; |
24 | 24 | import { BehaviorSubject, Observable, Subject } from 'rxjs'; |
25 | 25 | import { Authority } from '@shared/models/authority.enum'; |
26 | 26 | import { AuthUser } from '@shared/models/user.model'; |
27 | +import { guid } from '@core/utils'; | |
27 | 28 | |
28 | 29 | @Injectable({ |
29 | 30 | providedIn: 'root' |
... | ... | @@ -74,24 +75,28 @@ export class MenuService { |
74 | 75 | const sections: Array<MenuSection> = []; |
75 | 76 | sections.push( |
76 | 77 | { |
78 | + id: guid(), | |
77 | 79 | name: 'home.home', |
78 | 80 | type: 'link', |
79 | 81 | path: '/home', |
80 | 82 | icon: 'home' |
81 | 83 | }, |
82 | 84 | { |
85 | + id: guid(), | |
83 | 86 | name: 'tenant.tenants', |
84 | 87 | type: 'link', |
85 | 88 | path: '/tenants', |
86 | 89 | icon: 'supervisor_account' |
87 | 90 | }, |
88 | 91 | { |
92 | + id: guid(), | |
89 | 93 | name: 'widget.widget-library', |
90 | 94 | type: 'link', |
91 | 95 | path: '/widgets-bundles', |
92 | 96 | icon: 'now_widgets' |
93 | 97 | }, |
94 | 98 | { |
99 | + id: guid(), | |
95 | 100 | name: 'admin.system-settings', |
96 | 101 | type: 'toggle', |
97 | 102 | path: '/settings', |
... | ... | @@ -99,18 +104,21 @@ export class MenuService { |
99 | 104 | icon: 'settings', |
100 | 105 | pages: [ |
101 | 106 | { |
107 | + id: guid(), | |
102 | 108 | name: 'admin.general', |
103 | 109 | type: 'link', |
104 | 110 | path: '/settings/general', |
105 | 111 | icon: 'settings_applications' |
106 | 112 | }, |
107 | 113 | { |
114 | + id: guid(), | |
108 | 115 | name: 'admin.outgoing-mail', |
109 | 116 | type: 'link', |
110 | 117 | path: '/settings/outgoing-mail', |
111 | 118 | icon: 'mail' |
112 | 119 | }, |
113 | 120 | { |
121 | + id: guid(), | |
114 | 122 | name: 'admin.security-settings', |
115 | 123 | type: 'link', |
116 | 124 | path: '/settings/security-settings', |
... | ... | @@ -173,54 +181,63 @@ export class MenuService { |
173 | 181 | const sections: Array<MenuSection> = []; |
174 | 182 | sections.push( |
175 | 183 | { |
184 | + id: guid(), | |
176 | 185 | name: 'home.home', |
177 | 186 | type: 'link', |
178 | 187 | path: '/home', |
179 | 188 | icon: 'home' |
180 | 189 | }, |
181 | 190 | { |
191 | + id: guid(), | |
182 | 192 | name: 'rulechain.rulechains', |
183 | 193 | type: 'link', |
184 | 194 | path: '/ruleChains', |
185 | 195 | icon: 'settings_ethernet' |
186 | 196 | }, |
187 | 197 | { |
198 | + id: guid(), | |
188 | 199 | name: 'customer.customers', |
189 | 200 | type: 'link', |
190 | 201 | path: '/customers', |
191 | 202 | icon: 'supervisor_account' |
192 | 203 | }, |
193 | 204 | { |
205 | + id: guid(), | |
194 | 206 | name: 'asset.assets', |
195 | 207 | type: 'link', |
196 | 208 | path: '/assets', |
197 | 209 | icon: 'domain' |
198 | 210 | }, |
199 | 211 | { |
212 | + id: guid(), | |
200 | 213 | name: 'device.devices', |
201 | 214 | type: 'link', |
202 | 215 | path: '/devices', |
203 | 216 | icon: 'devices_other' |
204 | 217 | }, |
205 | 218 | { |
219 | + id: guid(), | |
206 | 220 | name: 'entity-view.entity-views', |
207 | 221 | type: 'link', |
208 | 222 | path: '/entityViews', |
209 | 223 | icon: 'view_quilt' |
210 | 224 | }, |
211 | 225 | { |
226 | + id: guid(), | |
212 | 227 | name: 'widget.widget-library', |
213 | 228 | type: 'link', |
214 | 229 | path: '/widgets-bundles', |
215 | 230 | icon: 'now_widgets' |
216 | 231 | }, |
217 | 232 | { |
233 | + id: guid(), | |
218 | 234 | name: 'dashboard.dashboards', |
219 | 235 | type: 'link', |
220 | 236 | path: '/dashboards', |
221 | 237 | icon: 'dashboards' |
222 | 238 | }, |
223 | 239 | { |
240 | + id: guid(), | |
224 | 241 | name: 'audit-log.audit-logs', |
225 | 242 | type: 'link', |
226 | 243 | path: '/auditLogs', |
... | ... | @@ -316,30 +333,35 @@ export class MenuService { |
316 | 333 | const sections: Array<MenuSection> = []; |
317 | 334 | sections.push( |
318 | 335 | { |
336 | + id: guid(), | |
319 | 337 | name: 'home.home', |
320 | 338 | type: 'link', |
321 | 339 | path: '/home', |
322 | 340 | icon: 'home' |
323 | 341 | }, |
324 | 342 | { |
343 | + id: guid(), | |
325 | 344 | name: 'asset.assets', |
326 | 345 | type: 'link', |
327 | 346 | path: '/assets', |
328 | 347 | icon: 'domain' |
329 | 348 | }, |
330 | 349 | { |
350 | + id: guid(), | |
331 | 351 | name: 'device.devices', |
332 | 352 | type: 'link', |
333 | 353 | path: '/devices', |
334 | 354 | icon: 'devices_other' |
335 | 355 | }, |
336 | 356 | { |
357 | + id: guid(), | |
337 | 358 | name: 'entity-view.entity-views', |
338 | 359 | type: 'link', |
339 | 360 | path: '/entityViews', |
340 | 361 | icon: 'view_quilt' |
341 | 362 | }, |
342 | 363 | { |
364 | + id: guid(), | |
343 | 365 | name: 'dashboard.dashboards', |
344 | 366 | type: 'link', |
345 | 367 | path: '/dashboards', | ... | ... |
... | ... | @@ -24,7 +24,7 @@ |
24 | 24 | [ngClass]="{'tb-toggled' : sectionActive()}"></span> |
25 | 25 | </a> |
26 | 26 | <ul id="docs-menu-{{section.name | nospace}}" class="tb-menu-toggle-list" [ngStyle]="{height: sectionHeight()}"> |
27 | - <li *ngFor="let page of section.pages"> | |
27 | + <li *ngFor="let page of section.pages; trackBy: trackBySectionPages"> | |
28 | 28 | <tb-menu-link [section]="page"></tb-menu-link> |
29 | 29 | </li> |
30 | 30 | </ul> | ... | ... |
... | ... | @@ -16,7 +16,7 @@ |
16 | 16 | |
17 | 17 | --> |
18 | 18 | <ul fxFlex fxLayout="column" fxLayoutAlign="start stretch" class="tb-side-menu"> |
19 | - <li *ngFor="let section of menuSections$| async" [ngSwitch]="section.type === 'link'"> | |
19 | + <li *ngFor="let section of menuSections$ | async; trackBy: trackByMenuSection" [ngSwitch]="section.type === 'link'"> | |
20 | 20 | <tb-menu-link *ngSwitchCase="true" [section]="section"></tb-menu-link> |
21 | 21 | <tb-menu-toggle *ngSwitchCase="false" [section]="section"></tb-menu-toggle> |
22 | 22 | </li> | ... | ... |
... | ... | @@ -16,6 +16,7 @@ |
16 | 16 | |
17 | 17 | import { Component, OnInit } from '@angular/core'; |
18 | 18 | import { MenuService } from '@core/services/menu.service'; |
19 | +import { MenuSection } from '@core/services/menu.models'; | |
19 | 20 | |
20 | 21 | @Component({ |
21 | 22 | selector: 'tb-side-menu', |
... | ... | @@ -29,6 +30,10 @@ export class SideMenuComponent implements OnInit { |
29 | 30 | constructor(private menuService: MenuService) { |
30 | 31 | } |
31 | 32 | |
33 | + trackByMenuSection(index: number, section: MenuSection){ | |
34 | + return section.id; | |
35 | + } | |
36 | + | |
32 | 37 | ngOnInit() { |
33 | 38 | } |
34 | 39 | ... | ... |
... | ... | @@ -19,7 +19,7 @@ |
19 | 19 | <h1 fxFlex fxHide.gt-sm *ngIf="lastBreadcrumb$ | async; let breadcrumb"> |
20 | 20 | {{ breadcrumb.ignoreTranslate ? (breadcrumb.labelFunction ? breadcrumb.labelFunction() : breadcrumb.label) : (breadcrumb.label | translate) }} |
21 | 21 | </h1> |
22 | - <span fxHide.lt-md fxLayout="row" *ngFor="let breadcrumb of breadcrumbs$ | async; last as isLast;" [ngSwitch]="isLast"> | |
22 | + <span fxHide.lt-md fxLayout="row" *ngFor="let breadcrumb of breadcrumbs$ | async; trackBy: trackByBreadcrumbs; last as isLast;" [ngSwitch]="isLast"> | |
23 | 23 | <a *ngSwitchCase="false" [routerLink]="breadcrumb.link" [queryParams]="breadcrumb.queryParams"> |
24 | 24 | <mat-icon *ngIf="breadcrumb.isMdiIcon" [svgIcon]="breadcrumb.icon"> |
25 | 25 | </mat-icon> | ... | ... |
... | ... | @@ -20,6 +20,7 @@ import { BreadCrumb, BreadCrumbConfig } from './breadcrumb'; |
20 | 20 | import { ActivatedRoute, ActivatedRouteSnapshot, NavigationEnd, Router } from '@angular/router'; |
21 | 21 | import { distinctUntilChanged, filter, map } from 'rxjs/operators'; |
22 | 22 | import { TranslateService } from '@ngx-translate/core'; |
23 | +import { guid } from '@core/utils'; | |
23 | 24 | |
24 | 25 | @Component({ |
25 | 26 | selector: 'tb-breadcrumb', |
... | ... | @@ -94,6 +95,7 @@ export class BreadcrumbComponent implements OnInit, OnDestroy { |
94 | 95 | const isMdiIcon = icon.startsWith('mdi:'); |
95 | 96 | const link = [ route.pathFromRoot.map(v => v.url.map(segment => segment.toString()).join('/')).join('/') ]; |
96 | 97 | const breadcrumb = { |
98 | + id: guid(), | |
97 | 99 | label, |
98 | 100 | labelFunction, |
99 | 101 | ignoreTranslate, |
... | ... | @@ -110,4 +112,8 @@ export class BreadcrumbComponent implements OnInit, OnDestroy { |
110 | 112 | } |
111 | 113 | return newBreadcrumbs; |
112 | 114 | } |
115 | + | |
116 | + trackByBreadcrumbs(index: number, breadcrumb: BreadCrumb){ | |
117 | + return breadcrumb.id; | |
118 | + } | |
113 | 119 | } | ... | ... |
... | ... | @@ -16,8 +16,9 @@ |
16 | 16 | |
17 | 17 | import { ActivatedRouteSnapshot, Params } from '@angular/router'; |
18 | 18 | import { TranslateService } from '@ngx-translate/core'; |
19 | +import { HasUUID } from '@shared/models/id/has-uuid'; | |
19 | 20 | |
20 | -export interface BreadCrumb { | |
21 | +export interface BreadCrumb extends HasUUID{ | |
21 | 22 | label: string; |
22 | 23 | labelFunction?: () => string; |
23 | 24 | ignoreTranslate: boolean; | ... | ... |