1 /* Copyright (c) 2019 AT&T Intellectual Property. #
\r
3 # Licensed under the Apache License, Version 2.0 (the "License"); #
\r
4 # you may not use this file except in compliance with the License. #
\r
5 # You may obtain a copy of the License at #
\r
7 # http://www.apache.org/licenses/LICENSE-2.0 #
\r
9 # Unless required by applicable law or agreed to in writing, software #
\r
10 # distributed under the License is distributed on an "AS IS" BASIS, #
\r
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
\r
12 # See the License for the specific language governing permissions and #
\r
13 # limitations under the License. #
\r
14 ##############################################################################*/
\r
17 import { Component, OnInit, Inject } from '@angular/core';
\r
18 import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material';
\r
19 import { UserService } from 'app/shared/services/user.service';
\r
20 import { GroupService } from 'app/shared/services/group.service';
\r
23 selector: 'app-user-select',
\r
24 templateUrl: './user-select.component.pug',
\r
25 styleUrls: ['./user-select.component.scss']
\r
27 export class UserSelectComponent implements OnInit {
\r
34 public selectedUsers;
\r
37 public dialogRef: MatDialogRef<UserSelectComponent>,
\r
38 private userService: UserService,
\r
39 private groupService: GroupService,
\r
40 @Inject(MAT_DIALOG_DATA) public input_data
\r
46 this.dialogRef.close();
\r
50 //this.unselectUser();
\r
51 if(user.isSelected){
\r
52 this.selectedUsers.push(user);
\r
54 //user.isSelected = false;
\r
55 this.unselectUser(user);
\r
62 // this.selectedUsers = this.selectedUsers.filter(user => user.isSelected);
\r
63 this.selectedUsers.splice(this.selectedUsers.findIndex(function(userN){ return userN._id.toString() === user._id.toString(); }), 1);
\r
68 let usersToAdd = this.selectedUsers;
\r
70 //filters users that are already in the group to avoid duplicates
\r
71 if(this.group.members){
\r
72 usersToAdd = this.selectedUsers.filter(user =>
\r
73 this.group.members.filter(member => member.userId.toString() == user._id.toString()).length <= 0
\r
77 //populates the users roles and userId field
\r
78 for(let i = 0; i < usersToAdd.length; i++){
\r
80 userId : usersToAdd[i]._id,
\r
84 //sets up patch object
\r
87 _id : this.input_data.groupId,
\r
88 $push : { members: { $each : usersToAdd } }
\r
91 this.groupService.patch(groupPatch).subscribe((results) => {
\r
92 this.dialogRef.close(usersToAdd);
\r
99 this.selectedUsers = [];
\r
100 this.userService.find({$limit: -1, $select: ['firstName', 'lastName', 'email']})
\r
103 this.users = result;
\r
106 console.log(error);
\r
108 this.groupService.get(this.input_data.groupId).subscribe((res) => {
\r
113 this.search.email = "";
\r
114 this.input_data.testDefinition = {};
\r