From f4b24df877ddcd1879ddbec067221be98701dff5 Mon Sep 17 00:00:00 2001 From: Thomas Fransolet Date: Fri, 6 Mar 2020 17:13:30 +0100 Subject: [PATCH] CP adding sidebar component --- .../_layouts/sidebar/sidebar.component.scss | 0 .../sidebar/sidebar.component.spec.ts | 25 ++++ src/app/_layouts/sidebar/sidebar.component.ts | 116 ++++++++++++++++++ src/app/_layouts/sidebar/sidebar.module.ts | 14 +++ src/app/app.module.ts | 3 + .../dashboard/dashboard.component.html | 5 +- swagger.json | 2 +- 7 files changed, 162 insertions(+), 3 deletions(-) create mode 100644 src/app/_layouts/sidebar/sidebar.component.scss create mode 100644 src/app/_layouts/sidebar/sidebar.component.spec.ts create mode 100644 src/app/_layouts/sidebar/sidebar.component.ts create mode 100644 src/app/_layouts/sidebar/sidebar.module.ts diff --git a/src/app/_layouts/sidebar/sidebar.component.scss b/src/app/_layouts/sidebar/sidebar.component.scss new file mode 100644 index 0000000..e69de29 diff --git a/src/app/_layouts/sidebar/sidebar.component.spec.ts b/src/app/_layouts/sidebar/sidebar.component.spec.ts new file mode 100644 index 0000000..f29709f --- /dev/null +++ b/src/app/_layouts/sidebar/sidebar.component.spec.ts @@ -0,0 +1,25 @@ +import { async, ComponentFixture, TestBed } from '@angular/core/testing'; + +import { SidebarComponent } from './sidebar.component'; + +describe('SidebarComponent', () => { + let component: SidebarComponent; + let fixture: ComponentFixture; + + beforeEach(async(() => { + TestBed.configureTestingModule({ + declarations: [ SidebarComponent ] + }) + .compileComponents(); + })); + + beforeEach(() => { + fixture = TestBed.createComponent(SidebarComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/src/app/_layouts/sidebar/sidebar.component.ts b/src/app/_layouts/sidebar/sidebar.component.ts new file mode 100644 index 0000000..e132897 --- /dev/null +++ b/src/app/_layouts/sidebar/sidebar.component.ts @@ -0,0 +1,116 @@ +import { Component, OnInit, Input } from '@angular/core'; +import { LayoutService } from '../../_api/services'; +import { PanelSection } from '../../_api/models'; +import { Router } from '@angular/router'; + +@Component({ + selector: 'app-sidebar', + template: ` + `, + styleUrls: ['./sidebar.component.scss'] +}) +export class SidebarComponent implements OnInit { + public navigation: Array; + + public hasChildren(item) { + return item.children != null && item.children.length > 0 ? true : false; + } + + constructor(private _layoutService: LayoutService) { } + + ngOnInit() { + this.LoadMenu(); + } + + private LoadMenu(): void { + this._layoutService.Get().subscribe(items => { + this.navigation = items; + }); + } + +} + +@Component({ + selector: 'app-sidebar-nav-root-item', + template: `` +}) +export class SidebarNavRootItemComponent { + @Input() item; + + public hasBadge() { + return this.item.badge ? true : false; + } +} + +@Component({ + selector: 'app-sidebar-nav-item', + template: `` +}) +export class SidebarNavItemComponent { + @Input() item; + + public hasBadge() { + return this.item.badge ? true : false; + } +} + +@Component({ + selector: 'app-sidebar-nav-dropdown-item', + template: `` +}) +export class SidebarNavDropItemComponent { + @Input() item; + isOpen = false; + + constructor( + protected _router: Router + ) { + } + + public isActive() { + return this.isOpen; + } + + public toggleOpen(route: string) { + this.isOpen = this.isOpen ? false : true; + if (route != null && route !== '') { + this._router.navigate([route]); + } + } + + public hasChildren(item) { + return item.children != null && item.children.length > 0 ? true : false; + } +} diff --git a/src/app/_layouts/sidebar/sidebar.module.ts b/src/app/_layouts/sidebar/sidebar.module.ts new file mode 100644 index 0000000..c0f81b0 --- /dev/null +++ b/src/app/_layouts/sidebar/sidebar.module.ts @@ -0,0 +1,14 @@ +import { NgModule } from '@angular/core'; +import { CommonModule } from '@angular/common'; +import { RouterModule } from '@angular/router'; +import { SidebarComponent, SidebarNavRootItemComponent, SidebarNavDropItemComponent, SidebarNavItemComponent } from './sidebar.component'; + +@NgModule({ + imports: [CommonModule, RouterModule], + declarations: [SidebarComponent, SidebarNavItemComponent, SidebarNavRootItemComponent, SidebarNavDropItemComponent], + exports: [SidebarComponent], + providers: [ ] +}) +export class SidebarModule { + +} diff --git a/src/app/app.module.ts b/src/app/app.module.ts index 20a325e..0c36616 100644 --- a/src/app/app.module.ts +++ b/src/app/app.module.ts @@ -42,6 +42,8 @@ import { DashboardComponent } from './control-panel/profile/dashboard/dashboard. import { BetComponent } from './control-panel/bet/bet.component'; import { PanelMenuModule } from 'primeng/panelmenu'; import { EnergyComponent } from './control-panel/profile/dashboard/energy/energy.component'; +import { SidebarComponent } from './_layouts/sidebar/sidebar.component'; +import { SidebarModule } from './_layouts/sidebar/sidebar.module'; @@ -100,6 +102,7 @@ export function HttpLoaderFactory(http: HttpClient) { ToastModule, DropdownModule, PanelMenuModule, + SidebarModule, TranslateModule.forRoot({ loader: { provide: TranslateLoader, diff --git a/src/app/control-panel/profile/dashboard/dashboard.component.html b/src/app/control-panel/profile/dashboard/dashboard.component.html index 912e6ec..105eca4 100644 --- a/src/app/control-panel/profile/dashboard/dashboard.component.html +++ b/src/app/control-panel/profile/dashboard/dashboard.component.html @@ -1,9 +1,10 @@
-