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 { GroupService } from 'app/shared/services/group.service';
\r
19 import { MatDialogRef, MAT_DIALOG_DATA } from '@angular/material';
\r
20 import { UserService } from 'app/shared/services/user.service';
\r
24 selector: 'app-dropdown-multiselect',
\r
25 templateUrl: './dropdown-multiselect.component.pug',
\r
26 styleUrls: ['./dropdown-multiselect.component.scss']
\r
28 export class DropdownMultiselectComponent implements OnInit {
\r
37 constructor(private groupService: GroupService, public dialogRef: MatDialogRef<DropdownMultiselectComponent>,
\r
38 private userService: UserService,
\r
39 @Inject(MAT_DIALOG_DATA) public input_data
\r
46 this.userId = this.input_data["user"][0]["_id"];
\r
47 this.group = this.input_data["group"];
\r
48 this.memberRoles = this.group["members"].filter(member => member.userId == this.userId)["roles"];
\r
49 this.userService.get(this.userId).subscribe((result) => {
\r
52 this.roles = this.group.roles;
\r
54 this.memberRoles = this.group.members.filter(member => member.userId.toString() == this.userId.toString())[0].roles;
\r
55 if(this.memberRoles){
\r
56 for(let i = 0; i < this.roles.length; i++){
\r
57 this.roles[i].isSelected = false;
\r
58 for(let j = 0; j < this.memberRoles.length; j++){
\r
59 if(this.roles[i].roleName == this.memberRoles[j]){
\r
60 this.roles[i].isSelected = true;
\r
69 userId : this.userId,
\r
73 member.roles = this.roles.filter(role => role.isSelected).map(item => {return item.roleName});
\r
75 // the logic to remove the one member from the array of members and then push the new member roles
\r
76 this.groupService.get(this.group._id).subscribe((res) => {
\r
79 let newMembers = [];
\r
80 if(group["members"]){
\r
81 newMembers = group["members"].filter(member => member.userId.toString() != this.userId.toString());
\r
83 newMembers.push(member)
\r
85 _id : this.group._id,
\r
86 members : newMembers
\r
88 this.groupService.patch(groupPatch).subscribe((response) => {
\r
89 this.dialogRef.close();
\r