added svcapi ui and camunda code
[it/otf.git] / otf-frontend / client / src / app / layout / components / header / header.component.ts
diff --git a/otf-frontend/client/src/app/layout/components/header/header.component.ts b/otf-frontend/client/src/app/layout/components/header/header.component.ts
new file mode 100644 (file)
index 0000000..924d50e
--- /dev/null
@@ -0,0 +1,205 @@
+/*  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, ViewChild } from '@angular/core';\r
+import { Router, NavigationEnd } from '@angular/router';\r
+import { TranslateService } from '@ngx-translate/core';\r
+import { AuthService } from 'app/shared/services/auth.service';\r
+import { CookieService } from 'ngx-cookie-service';\r
+import { GroupService } from 'app/shared/services/group.service';\r
+import { UserService } from 'app/shared/services/user.service';\r
+//import { group } from '@angular/animations';\r
+import { CreateGroupModalComponent } from 'app/shared/modules/create-group-modal/create-group-modal.component';\r
+import { MatDialog } from '@angular/material/dialog';\r
+import { NavItem } from 'app/shared/components/menu-item/menu-item.component';\r
+import { MatMenuTrigger } from '@angular/material';\r
+\r
+\r
+@Component({\r
+    selector: 'app-header',\r
+    templateUrl: './header.component.html',\r
+    styleUrls: ['./header.component.scss']\r
+})\r
+\r
+export class HeaderComponent implements OnInit {\r
+    pushRightClass: string = 'push-right';\r
+    myStyle: object = {};\r
+    myParams: object = {};\r
+    width: number = 100;\r
+    height: number = 100;\r
+\r
+    public groups: Array<NavItem>;\r
+    public selectedGroup;\r
+\r
+    @ViewChild('goupMenuTrigger') groupMenu: MatMenuTrigger;\r
+    \r
+\r
+    constructor(\r
+        private translate: TranslateService,\r
+        public router: Router,\r
+        private auth: AuthService,\r
+        private cookie: CookieService,\r
+        public _groups: GroupService,\r
+        private user: UserService,\r
+        private modal: MatDialog\r
+        \r
+    ) {\r
+\r
+        this.translate.addLangs(['en', 'fr', 'ur', 'es', 'it', 'fa', 'de', 'zh-CHS']);\r
+        this.translate.setDefaultLang('en');\r
+        const browserLang = this.translate.getBrowserLang();\r
+        this.translate.use(browserLang.match(/en|fr|ur|es|it|fa|de|zh-CHS/) ? browserLang : 'en');\r
+\r
+\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
+    public currentUser;// = {};\r
+    public username;\r
+\r
+\r
+    ngOnInit() {\r
+       \r
+       \r
+        this.currentUser = JSON.parse(this.cookie.get('currentUser'));\r
+        this.username = this.currentUser["firstName"] + " " + this.currentUser["lastName"];\r
+        \r
+       \r
+\r
+        this._groups.setUp();\r
+\r
+        this._groups.listChange().subscribe(res => {\r
+            this.groups = res;\r
+        });\r
+       \r
+        // if (!window.localStorage.getItem("currentGroupId"))\r
+        // {\r
+        //     if (!(this.currentUser.defaultGroup)){\r
+        //         let userPatch = {\r
+        //             _id : this.currentUser._id,\r
+        //            defaultGroup : this.currentUser.groups[0].groupId,\r
+        //            defaultGroupEnabled: false  \r
+        //         };\r
+    \r
+        //         this.user.patch(userPatch).subscribe((res) => {\r
+        //             console.log(res)\r
+        //             console.log("Created first default group for user. Default group has been added!")\r
+        //         })\r
+            \r
+        //     }\r
+        //     else {\r
+    \r
+        //         this._groups.setGroup({_id: this.currentUser.defaultGroup})\r
+    \r
+        //     }\r
+        // }\r
+\r
+        //this._groups.setUp();\r
+\r
+        this._groups.listChange().subscribe(res => {\r
+            res = this._groups.format(res);\r
+            //set menu fields\r
+            this.setNavFields(res);\r
+            this.groups = res as Array<NavItem>;\r
+        });\r
+\r
+        this._groups.groupChange().subscribe(res => {\r
+            \r
+            this.selectedGroup = res;\r
+        });\r
+\r
+    }\r
+\r
+    setNavFields(groups){\r
+        groups.forEach((elem, val) => {\r
+            groups[val].displayName = elem.groupName;\r
+            this.setNavFields(groups[val].children);\r
+        });\r
+    }\r
+\r
+    print(){\r
+        \r
+    }\r
+\r
+    changeGroup(group) {\r
+        this.groupMenu.closeMenu();\r
+       // Patch to add update Default Group\r
+\r
+       // If the Default Group Enabled does not exist (users havent saved a default group)\r
+        if (!this.currentUser.defaultGroupEnabled)\r
+        {\r
+            let userPatch = {\r
+                _id : this.currentUser._id,\r
+                defaultGroup: group._id\r
+            };\r
+\r
+            this.user.patch(userPatch).subscribe((res) =>{\r
+                \r
+                \r
+            })\r
+        }\r
+        // If the default Group Enabled exists (Users saved a default group)\r
+        else{\r
+            \r
+            //Take the default group from the user input\r
+        }\r
+\r
+    \r
+        \r
+        this._groups.setGroup(group);\r
+   \r
+    }\r
+\r
+    createGroup(){\r
+        this.modal.open(CreateGroupModalComponent, {\r
+            width: '50%'\r
+        }).afterClosed().subscribe((result) => {\r
+            if(result){\r
+                this.groups.push(result);\r
+            }\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
+    onLoggedout() {\r
+        this.auth.logout();\r
+    }\r
+\r
+    changeLang(language: string) {\r
+        this.translate.use(language);\r
+    }\r
+}\r