added svcapi ui and camunda code
[it/otf.git] / otf-frontend / client / src / app / shared / modules / user-select / user-select.component.ts
diff --git a/otf-frontend/client/src/app/shared/modules/user-select/user-select.component.ts b/otf-frontend/client/src/app/shared/modules/user-select/user-select.component.ts
new file mode 100644 (file)
index 0000000..5cbfa0b
--- /dev/null
@@ -0,0 +1,117 @@
+/*  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 { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material';\r
+import { UserService } from 'app/shared/services/user.service';\r
+import { GroupService } from 'app/shared/services/group.service';\r
+\r
+@Component({\r
+  selector: 'app-user-select',\r
+  templateUrl: './user-select.component.pug',\r
+  styleUrls: ['./user-select.component.scss']\r
+})\r
+export class UserSelectComponent implements OnInit {\r
+\r
+  \r
+  public data; \r
+  public users; \r
+  public group;\r
+  public search;\r
+  public selectedUsers;\r
+\r
+  constructor(\r
+    public dialogRef: MatDialogRef<UserSelectComponent>,\r
+    private userService: UserService,\r
+    private groupService: GroupService,\r
+    @Inject(MAT_DIALOG_DATA) public input_data\r
+  ) {\r
+    this.data = {};\r
+   }\r
+  \r
+  onNoClick(): void {\r
+    this.dialogRef.close();\r
+  }\r
+\r
+  selectUser(user){\r
+    //this.unselectUser();\r
+    if(user.isSelected){\r
+      this.selectedUsers.push(user);\r
+    }else{\r
+      //user.isSelected = false;\r
+      this.unselectUser(user);\r
+    }\r
+    \r
+\r
+  }\r
+\r
+  unselectUser(user){\r
+    // this.selectedUsers = this.selectedUsers.filter(user => user.isSelected);\r
+    this.selectedUsers.splice(this.selectedUsers.findIndex(function(userN){ return userN._id.toString() === user._id.toString(); }), 1);\r
+    \r
+  }\r
+\r
+  addUsers(){\r
+    let usersToAdd = this.selectedUsers;\r
+\r
+    //filters users that are already in the group to avoid duplicates\r
+    if(this.group.members){\r
+      usersToAdd = this.selectedUsers.filter(user =>\r
+        this.group.members.filter(member => member.userId.toString() == user._id.toString()).length <= 0\r
+      );\r
+    }\r
+   \r
+    //populates the users roles and userId field\r
+    for(let i = 0; i < usersToAdd.length; i++){\r
+        usersToAdd[i] = {\r
+          userId : usersToAdd[i]._id,\r
+          roles : ["user"]\r
+        }\r
+    }\r
+    //sets up patch object\r
\r
+    let groupPatch = {\r
+      _id : this.input_data.groupId,\r
+      $push : { members: { $each : usersToAdd } }\r
+      \r
+    }\r
+    this.groupService.patch(groupPatch).subscribe((results) => {\r
+      this.dialogRef.close(usersToAdd);\r
+    });\r
+    \r
+  }\r
+\r
+  ngOnInit() {\r
+    this.users = [];\r
+    this.selectedUsers = [];\r
+    this.userService.find({$limit: -1, $select: ['firstName', 'lastName', 'email']})\r
+      .subscribe(\r
+        (result) => {\r
+            this.users = result;\r
+        },\r
+        (error) => {\r
+            console.log(error);\r
+      });\r
+      this.groupService.get(this.input_data.groupId).subscribe((res) => {\r
+        this.group = res;\r
+      })\r
+    \r
+    this.search = {};\r
+    this.search.email = ""; \r
+    this.input_data.testDefinition = {};\r
+  }\r
+\r
+}\r