added svcapi ui and camunda code
[it/otf.git] / otf-frontend / client / src / app / layout / settings / settings.component.ts
diff --git a/otf-frontend/client/src/app/layout/settings/settings.component.ts b/otf-frontend/client/src/app/layout/settings/settings.component.ts
new file mode 100644 (file)
index 0000000..16312b7
--- /dev/null
@@ -0,0 +1,103 @@
+/*  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 { CookieService } from 'ngx-cookie-service';\r
+import { UserService } from 'app/shared/services/user.service';\r
+import { GroupService } from 'app/shared/services/group.service';\r
+import { routerTransition } from 'app/router.animations';\r
+import { AlertSnackbarComponent } from 'app/shared/modules/alert-snackbar/alert-snackbar.component';\r
+import { Group } from 'app/shared/models/group.model';\r
+import { MatSnackBar } from '@angular/material';\r
+\r
+@Component({\r
+  selector: 'app-settings',\r
+  templateUrl: './settings.component.pug',\r
+  styleUrls: ['./settings.component.scss'],\r
+  animations: [routerTransition()]\r
+})\r
+\r
+export class SettingsComponent implements OnInit {\r
+  defaultGroupEnabled = false;\r
+  private defaultGroup;\r
+  private eligibleGroups;\r
+  private currentUser;\r
+  private defaultGroupId;\r
+\r
+  constructor(private cookie: CookieService,\r
+    private user: UserService,\r
+    private _group: GroupService,\r
+    private snack: MatSnackBar\r
+  ) { }\r
+\r
+  ngOnInit() {\r
+\r
+    this.currentUser = JSON.parse(this.cookie.get('currentUser'));\r
+\r
+    this._group.find({ $limit: -1 }).subscribe((result) => {\r
+      if (result)\r
+        this.eligibleGroups = result;\r
+    });\r
+\r
+    this.user.get(this.currentUser._id).subscribe((result) => {\r
+      if (result)\r
+        this.defaultGroupId = result['defaultGroup'];\r
+        this.defaultGroupEnabled = result['defaultGroupEnabled'];\r
+\r
+        this._group.get(this.defaultGroupId).subscribe((result) => {\r
+        this.defaultGroup = result;\r
+      });\r
+    });\r
+  }\r
+\r
+  changDefaultGroup(group: Group) {\r
+    this.defaultGroup = group;\r
+  }\r
+\r
+  enableDefaultGroup() {\r
+    this.defaultGroupEnabled = true;\r
+  }\r
+\r
+  disableDefaultGroup() {\r
+    this.defaultGroupEnabled = false;\r
+    \r
+  }\r
+\r
+  update() {\r
+\r
+    this.currentUser.defaultGroupEnabled = this.defaultGroupEnabled;\r
+    this.currentUser.defaultGroup = this.defaultGroup;\r
+    this.cookie.set('currentUser', JSON.stringify(this.currentUser));\r
+    \r
+\r
+    \r
+    let userPatch = {\r
+      _id: this.currentUser._id,\r
+      defaultGroup: this.defaultGroup._id,\r
+      defaultGroupEnabled: this.defaultGroupEnabled\r
+    };\r
+\r
+    this.user.patch(userPatch).subscribe((res) => {\r
+      let snackMessage = 'Successfully Updated Settings';\r
+                this.snack.openFromComponent(AlertSnackbarComponent, {\r
+                    duration: 1500,\r
+                    data: {\r
+                        message: snackMessage\r
+                    }\r
+                })\r
+    })\r
+  }\r
+}\r