/* * ============LICENSE_START========================================== * ONAP Portal SDK * =================================================================== * Copyright © 2019 AT&T Intellectual Property. All rights reserved. * =================================================================== * * Unless otherwise specified, all software contained herein is licensed * under the Apache License, Version 2.0 (the "License"); * you may not use this software except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * * Unless otherwise specified, all documentation contained herein is licensed * under the Creative Commons License, Attribution 4.0 Intl. (the "License"); * you may not use this documentation except in compliance with the License. * You may obtain a copy of the License at * * https://creativecommons.org/licenses/by/4.0/ * * Unless required by applicable law or agreed to in writing, documentation * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * * ============LICENSE_END============================================ * * */ import { Component, Output, EventEmitter, OnInit } from '@angular/core'; import { Router, NavigationEnd } from '@angular/router'; import { SidebarService} from '../../../shared/services/index' import { CookieService } from 'ngx-cookie-service'; @Component({ selector: 'app-sidebar', templateUrl: './sidebar.component.html', styleUrls: ['./sidebar.component.scss'] }) export class SidebarComponent implements OnInit { isActive: boolean; collapsed: boolean; showMenu: string; pushRightClass: string; result:any; leftParentData; leftChildData; hash:string="#"; menuData:Array = []; page; showHeader:boolean = true; @Output() collapsedEvent = new EventEmitter(); constructor(public router: Router, public sidebarService: SidebarService,public cookieService: CookieService) { this.router.events.subscribe(val => { if ( val instanceof NavigationEnd && window.innerWidth <= 992 && this.isToggled() ) { this.toggleSidebar(); } }); } ngOnInit() { if(this.cookieService.get('show_app_header') == 'false'){ this.showHeader = false; } this.isActive = false; this.collapsed = false; this.showMenu = ''; this.pushRightClass = 'push-right'; this.sidebarService.getLeftMenu() .subscribe(data => { this.result = data; this.leftParentData = JSON.parse(this.result.data); this.leftChildData = JSON.parse(this.result.data2); for (let i = 0; i < this.leftParentData.length; i++) { let parentItem={ name:null, imageSrc:null, href:null, target : null, menuItems:[] }; parentItem.name = this.leftParentData[i].label; parentItem.imageSrc = this.leftParentData[i].imageSrc; // Add link to items with no subitems if (this.leftChildData[i].length === 0){ parentItem.href = this.leftParentData[i].action; parentItem.target = this.leftParentData[i].target; }else{ for (let j = 0; j < this.leftChildData[i].length; j++) { let childItem={ name:null, href:null, target : null, router:null }; if (this.leftChildData[i][j].label != null && this.leftChildData[i][j].label.length > 0) { childItem.name = this.leftChildData[i][j].label; if(null!==this.leftChildData[i][j].action){ if(this.leftChildData[i][j].action.match('v2/*')) childItem.router = '/'+ this.leftChildData[i][j].action; else childItem.href = this.leftChildData[i][j].action; childItem.target = this.leftChildData[i][j].target; parentItem.menuItems.push(childItem) } } } } this.menuData.push(parentItem); } }); } eventCalled() { this.isActive = !this.isActive; } addExpandClass(element: any) { if (element === this.showMenu) { this.showMenu = '0'; } else { this.showMenu = element; } this.collapsed=false; this.collapsedEvent.emit(false); } toggleCollapsed() { this.collapsed = !this.collapsed; this.collapsedEvent.emit(this.collapsed); } isToggled(): boolean { const dom: Element = document.querySelector('body'); return dom.classList.contains(this.pushRightClass); } toggleSidebar() { const dom: any = document.querySelector('body'); dom.classList.toggle(this.pushRightClass); } onLoggedout() { localStorage.removeItem('isLoggedin'); } }