added svcapi ui and camunda code
[it/otf.git] / otf-frontend / client / src / app / layout / components / sidebar / sidebar.component.ts
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 (file)
index 0000000..8034055
--- /dev/null
@@ -0,0 +1,147 @@
+/*  Copyright (c) 2019 AT&T Intellectual Property.                             #\r
+#                                                                              #\r
+#   Licensed under the Apache License, Version 2.0 (the "License");            #\r
+#   you may not use this file except in compliance with the License.           #\r
+#   You may obtain a copy of the License at                                    #\r
+#                                                                              #\r
+#       http://www.apache.org/licenses/LICENSE-2.0                             #\r
+#                                                                              #\r
+#   Unless required by applicable law or agreed to in writing, software        #\r
+#   distributed under the License is distributed on an "AS IS" BASIS,          #\r
+#   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.   #\r
+#   See the License for the specific language governing permissions and        #\r
+#   limitations under the License.                                             #\r
+##############################################################################*/\r
+\r
+\r
+import { Component, OnInit } from '@angular/core';\r
+import { Router, NavigationEnd } from '@angular/router';\r
+import { TranslateService } from '@ngx-translate/core';\r
+import { AppGlobals } from 'app/app.global';\r
+import {CookieService} from "ngx-cookie-service";\r
+import { HealthService } from 'app/shared/services/health.service';\r
+import { UserService } from 'app/shared/services/user.service';\r
+import { GroupService } from 'app/shared/services/group.service';\r
+import { Group, Groups } from 'app/shared/models/group.model';\r
+\r
+@Component({\r
+    selector: 'app-sidebar',\r
+    templateUrl: './sidebar.component.html',\r
+    styleUrls: ['./sidebar.component.scss']\r
+})\r
+export class SidebarComponent implements OnInit {\r
+    isActive: boolean = false;\r
+    showMenu: string = '';\r
+    pushRightClass: string = 'push-right';\r
+    version = AppGlobals.version\r
+    tcuapi: boolean;\r
+    tcuengine: boolean;\r
+    isAdmin: boolean = false;\r
+\r
+    canManageGroup = false;\r
+\r
+    currentGroupId;\r
+\r
+    constructor(private translate: TranslateService, public router: Router, public user: UserService, private health: HealthService, private cookie: CookieService, public group: GroupService) {\r
+        this.translate.addLangs(['en', 'fr', 'ur', 'es', 'it', 'fa', 'de']);\r
+        this.translate.setDefaultLang('en');\r
+        const browserLang = this.translate.getBrowserLang();\r
+        this.translate.use(browserLang.match(/en|fr|ur|es|it|fa|de/) ? browserLang : 'en');\r
+        this.checkIsAdmin();\r
+        this.router.events.subscribe(val => {\r
+            if (\r
+                val instanceof NavigationEnd &&\r
+                window.innerWidth <= 992 &&\r
+                this.isToggled()\r
+            ) {\r
+                this.toggleSidebar();\r
+            }\r
+        });\r
+    }\r
+\r
+    ngOnInit(){\r
+        if(this.group.getGroup()){\r
+            this.checkManage(this.group.getGroup());\r
+        }\r
+        this.group.groupChange().subscribe(group => {\r
+            this.checkManage(group);\r
+        })\r
+        this.setHealthStatus();\r
+    }\r
+\r
+    checkManage(group){\r
+        this.canManageGroup = this.user.ability.can('management', new Groups(group));\r
+    }\r
+\r
+    setHealthStatus(){\r
+        this.health.get('tcu-api').subscribe(res => {\r
+            if(res['code'] == 200 || res['statusCode'] == 200){\r
+                this.tcuapi = true;\r
+            }else{\r
+                this.tcuapi = false;\r
+            }\r
+        }, err => {\r
+            this.tcuapi = false;\r
+        });\r
+\r
+        this.health.get('tcu-engine').subscribe(res => {\r
+            \r
+            if(res['code'] == 200 || res['statusCode'] == 200){\r
+                this.tcuengine = true;\r
+            }else{\r
+                this.tcuengine = false;\r
+            }\r
+        }, err => {\r
+            \r
+            this.tcuengine = false;\r
+        });\r
+    }\r
+\r
+    eventCalled() {\r
+        this.isActive = !this.isActive;\r
+    }\r
+\r
+    addExpandClass(element: any) {\r
+        if (element === this.showMenu) {\r
+            this.showMenu = '0';\r
+        } else {\r
+            this.showMenu = element;\r
+        }\r
+    }\r
+\r
+    isToggled(): boolean {\r
+        const dom: Element = document.querySelector('body');\r
+        return dom.classList.contains(this.pushRightClass);\r
+    }\r
+\r
+    toggleSidebar() {\r
+        const dom: any = document.querySelector('body');\r
+        dom.classList.toggle(this.pushRightClass);\r
+    }\r
+\r
+    rltAndLtr() {\r
+        const dom: any = document.querySelector('body');\r
+        dom.classList.toggle('rtl');\r
+    }\r
+\r
+    changeLang(language: string) {\r
+        this.translate.use(language);\r
+    }\r
+\r
+    onLoggedout() {\r
+        localStorage.removeItem('isLoggedin');\r
+    }\r
+\r
+    checkIsAdmin() {\r
+        if (this.cookie.get('access_token') && this.cookie.get('currentUser')) {\r
+            let currentUser = JSON.parse(this.cookie.get('currentUser'));\r
+            if (currentUser['permissions'].indexOf('admin') >= 0) {\r
+                this.isAdmin = true;\r
+                return true;\r
+            }\r
+        }\r
+        this.isAdmin = false;\r
+        return false;\r
+    }\r
+\r
+}\r