added svcapi ui and camunda code
[it/otf.git] / otf-frontend / client / src / app / layout / manage-group / dropdown-multiselect.component.ts
diff --git a/otf-frontend/client/src/app/layout/manage-group/dropdown-multiselect.component.ts b/otf-frontend/client/src/app/layout/manage-group/dropdown-multiselect.component.ts
new file mode 100644 (file)
index 0000000..df065cb
--- /dev/null
@@ -0,0 +1,96 @@
+/*  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, Inject } from '@angular/core';\r
+import { GroupService } from 'app/shared/services/group.service';\r
+import { MatDialogRef, MAT_DIALOG_DATA } from '@angular/material';\r
+import { UserService } from 'app/shared/services/user.service';\r
+\r
+\r
+@Component({\r
+  selector: 'app-dropdown-multiselect',\r
+  templateUrl: './dropdown-multiselect.component.pug',\r
+  styleUrls: ['./dropdown-multiselect.component.scss']\r
+})\r
+export class DropdownMultiselectComponent implements OnInit {\r
+\r
+  public group;\r
+  public memberRoles;\r
+  private params;\r
+  public roles;\r
+  public user;\r
+  public userId;\r
+  public search;\r
+  constructor(private groupService: GroupService, public dialogRef: MatDialogRef<DropdownMultiselectComponent>,\r
+    private userService: UserService,\r
+    @Inject(MAT_DIALOG_DATA) public input_data\r
+  ) {\r
+   \r
+   }\r
+\r
+  ngOnInit() {\r
+    this.search = {};\r
+    this.userId = this.input_data["user"][0]["_id"];\r
+    this.group = this.input_data["group"];\r
+    this.memberRoles = this.group["members"].filter(member => member.userId == this.userId)["roles"];\r
+    this.userService.get(this.userId).subscribe((result) => {\r
+      this.user = result;\r
+    });\r
+    this.roles = this.group.roles;\r
+    \r
+    this.memberRoles = this.group.members.filter(member => member.userId.toString() == this.userId.toString())[0].roles;\r
+    if(this.memberRoles){\r
+      for(let i = 0; i < this.roles.length; i++){\r
+        this.roles[i].isSelected = false;\r
+        for(let j = 0; j < this.memberRoles.length; j++){\r
+          if(this.roles[i].roleName == this.memberRoles[j]){\r
+            this.roles[i].isSelected = true;\r
+          }\r
+        }\r
+      }\r
+    }\r
+  }\r
+\r
+  saveRoles(){\r
+    let member = {\r
+      userId : this.userId,\r
+      roles : []\r
+    }\r
+    \r
+    member.roles = this.roles.filter(role => role.isSelected).map(item => {return item.roleName});\r
+    \r
+    // the logic to remove the one member from the array of members and then push the new member roles\r
+    this.groupService.get(this.group._id).subscribe((res) => {\r
+      let group = res;\r
+      \r
+      let newMembers = [];\r
+      if(group["members"]){\r
+        newMembers = group["members"].filter(member => member.userId.toString() != this.userId.toString());\r
+      }\r
+      newMembers.push(member)\r
+      let groupPatch = {\r
+        _id : this.group._id,\r
+        members : newMembers\r
+      }\r
+      this.groupService.patch(groupPatch).subscribe((response) => {\r
+        this.dialogRef.close();\r
+      });\r
+    });\r
+    \r
+    \r
+  }\r
+\r
+}\r