1 /* Copyright (c) 2019 AT&T Intellectual Property. #
\r
3 # Licensed under the Apache License, Version 2.0 (the "License"); #
\r
4 # you may not use this file except in compliance with the License. #
\r
5 # You may obtain a copy of the License at #
\r
7 # http://www.apache.org/licenses/LICENSE-2.0 #
\r
9 # Unless required by applicable law or agreed to in writing, software #
\r
10 # distributed under the License is distributed on an "AS IS" BASIS, #
\r
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
\r
12 # See the License for the specific language governing permissions and #
\r
13 # limitations under the License. #
\r
14 ##############################################################################*/
\r
17 import { Component, OnInit } from '@angular/core';
\r
18 import { Router, NavigationEnd } from '@angular/router';
\r
19 import { TranslateService } from '@ngx-translate/core';
\r
20 import { AppGlobals } from 'app/app.global';
\r
21 import {CookieService} from "ngx-cookie-service";
\r
22 import { HealthService } from 'app/shared/services/health.service';
\r
23 import { UserService } from 'app/shared/services/user.service';
\r
24 import { GroupService } from 'app/shared/services/group.service';
\r
25 import { Group, Groups } from 'app/shared/models/group.model';
\r
28 selector: 'app-sidebar',
\r
29 templateUrl: './sidebar.component.html',
\r
30 styleUrls: ['./sidebar.component.scss']
\r
32 export class SidebarComponent implements OnInit {
\r
33 isActive: boolean = false;
\r
34 showMenu: string = '';
\r
35 pushRightClass: string = 'push-right';
\r
36 version = AppGlobals.version
\r
39 isAdmin: boolean = false;
\r
41 canManageGroup = false;
\r
45 constructor(private translate: TranslateService, public router: Router, public user: UserService, private health: HealthService, private cookie: CookieService, public group: GroupService) {
\r
46 this.translate.addLangs(['en', 'fr', 'ur', 'es', 'it', 'fa', 'de']);
\r
47 this.translate.setDefaultLang('en');
\r
48 const browserLang = this.translate.getBrowserLang();
\r
49 this.translate.use(browserLang.match(/en|fr|ur|es|it|fa|de/) ? browserLang : 'en');
\r
50 this.checkIsAdmin();
\r
51 this.router.events.subscribe(val => {
\r
53 val instanceof NavigationEnd &&
\r
54 window.innerWidth <= 992 &&
\r
57 this.toggleSidebar();
\r
63 if(this.group.getGroup()){
\r
64 this.checkManage(this.group.getGroup());
\r
66 this.group.groupChange().subscribe(group => {
\r
67 this.checkManage(group);
\r
69 this.setHealthStatus();
\r
73 this.canManageGroup = this.user.ability.can('management', new Groups(group));
\r
77 this.health.get('tcu-api').subscribe(res => {
\r
78 if(res['code'] == 200 || res['statusCode'] == 200){
\r
81 this.tcuapi = false;
\r
84 this.tcuapi = false;
\r
87 this.health.get('tcu-engine').subscribe(res => {
\r
89 if(res['code'] == 200 || res['statusCode'] == 200){
\r
90 this.tcuengine = true;
\r
92 this.tcuengine = false;
\r
96 this.tcuengine = false;
\r
101 this.isActive = !this.isActive;
\r
104 addExpandClass(element: any) {
\r
105 if (element === this.showMenu) {
\r
106 this.showMenu = '0';
\r
108 this.showMenu = element;
\r
112 isToggled(): boolean {
\r
113 const dom: Element = document.querySelector('body');
\r
114 return dom.classList.contains(this.pushRightClass);
\r
118 const dom: any = document.querySelector('body');
\r
119 dom.classList.toggle(this.pushRightClass);
\r
123 const dom: any = document.querySelector('body');
\r
124 dom.classList.toggle('rtl');
\r
127 changeLang(language: string) {
\r
128 this.translate.use(language);
\r
132 localStorage.removeItem('isLoggedin');
\r
136 if (this.cookie.get('access_token') && this.cookie.get('currentUser')) {
\r
137 let currentUser = JSON.parse(this.cookie.get('currentUser'));
\r
138 if (currentUser['permissions'].indexOf('admin') >= 0) {
\r
139 this.isAdmin = true;
\r
143 this.isAdmin = false;
\r