X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?p=it%2Fotf.git;a=blobdiff_plain;f=otf-frontend%2Fclient%2Fsrc%2Fapp%2Flayout%2Fcomponents%2Fsidebar%2Fsidebar.component.ts;fp=otf-frontend%2Fclient%2Fsrc%2Fapp%2Flayout%2Fcomponents%2Fsidebar%2Fsidebar.component.ts;h=80340553b6bb8bb5407fd946b03397603d40479f;hp=0000000000000000000000000000000000000000;hb=14f6f95c84a4a1fa8774190db4a03fd0214ec55f;hpb=f49bd1efeaaddd4891c1f329b18d8cfb28b3e75b diff --git a/otf-frontend/client/src/app/layout/components/sidebar/sidebar.component.ts b/otf-frontend/client/src/app/layout/components/sidebar/sidebar.component.ts new file mode 100644 index 0000000..8034055 --- /dev/null +++ b/otf-frontend/client/src/app/layout/components/sidebar/sidebar.component.ts @@ -0,0 +1,147 @@ +/* Copyright (c) 2019 AT&T Intellectual Property. # +# # +# Licensed under the Apache License, Version 2.0 (the "License"); # +# you may not use this file 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. # +##############################################################################*/ + + +import { Component, OnInit } from '@angular/core'; +import { Router, NavigationEnd } from '@angular/router'; +import { TranslateService } from '@ngx-translate/core'; +import { AppGlobals } from 'app/app.global'; +import {CookieService} from "ngx-cookie-service"; +import { HealthService } from 'app/shared/services/health.service'; +import { UserService } from 'app/shared/services/user.service'; +import { GroupService } from 'app/shared/services/group.service'; +import { Group, Groups } from 'app/shared/models/group.model'; + +@Component({ + selector: 'app-sidebar', + templateUrl: './sidebar.component.html', + styleUrls: ['./sidebar.component.scss'] +}) +export class SidebarComponent implements OnInit { + isActive: boolean = false; + showMenu: string = ''; + pushRightClass: string = 'push-right'; + version = AppGlobals.version + tcuapi: boolean; + tcuengine: boolean; + isAdmin: boolean = false; + + canManageGroup = false; + + currentGroupId; + + constructor(private translate: TranslateService, public router: Router, public user: UserService, private health: HealthService, private cookie: CookieService, public group: GroupService) { + this.translate.addLangs(['en', 'fr', 'ur', 'es', 'it', 'fa', 'de']); + this.translate.setDefaultLang('en'); + const browserLang = this.translate.getBrowserLang(); + this.translate.use(browserLang.match(/en|fr|ur|es|it|fa|de/) ? browserLang : 'en'); + this.checkIsAdmin(); + this.router.events.subscribe(val => { + if ( + val instanceof NavigationEnd && + window.innerWidth <= 992 && + this.isToggled() + ) { + this.toggleSidebar(); + } + }); + } + + ngOnInit(){ + if(this.group.getGroup()){ + this.checkManage(this.group.getGroup()); + } + this.group.groupChange().subscribe(group => { + this.checkManage(group); + }) + this.setHealthStatus(); + } + + checkManage(group){ + this.canManageGroup = this.user.ability.can('management', new Groups(group)); + } + + setHealthStatus(){ + this.health.get('tcu-api').subscribe(res => { + if(res['code'] == 200 || res['statusCode'] == 200){ + this.tcuapi = true; + }else{ + this.tcuapi = false; + } + }, err => { + this.tcuapi = false; + }); + + this.health.get('tcu-engine').subscribe(res => { + + if(res['code'] == 200 || res['statusCode'] == 200){ + this.tcuengine = true; + }else{ + this.tcuengine = false; + } + }, err => { + + this.tcuengine = false; + }); + } + + eventCalled() { + this.isActive = !this.isActive; + } + + addExpandClass(element: any) { + if (element === this.showMenu) { + this.showMenu = '0'; + } else { + this.showMenu = element; + } + } + + 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); + } + + rltAndLtr() { + const dom: any = document.querySelector('body'); + dom.classList.toggle('rtl'); + } + + changeLang(language: string) { + this.translate.use(language); + } + + onLoggedout() { + localStorage.removeItem('isLoggedin'); + } + + checkIsAdmin() { + if (this.cookie.get('access_token') && this.cookie.get('currentUser')) { + let currentUser = JSON.parse(this.cookie.get('currentUser')); + if (currentUser['permissions'].indexOf('admin') >= 0) { + this.isAdmin = true; + return true; + } + } + this.isAdmin = false; + return false; + } + +}