X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?p=it%2Fotf.git;a=blobdiff_plain;f=otf-frontend%2Fclient%2Fsrc%2Fapp%2Flayout%2Fmanage-group%2Fdropdown-multiselect.component.ts;fp=otf-frontend%2Fclient%2Fsrc%2Fapp%2Flayout%2Fmanage-group%2Fdropdown-multiselect.component.ts;h=df065cb67b0bf845054d42f09a84847e52b7a266;hp=0000000000000000000000000000000000000000;hb=14f6f95c84a4a1fa8774190db4a03fd0214ec55f;hpb=f49bd1efeaaddd4891c1f329b18d8cfb28b3e75b 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 index 0000000..df065cb --- /dev/null +++ b/otf-frontend/client/src/app/layout/manage-group/dropdown-multiselect.component.ts @@ -0,0 +1,96 @@ +/* Copyright (c) 2019 AT&T Intellectual Property. # +# # +# Licensed under the Apache License, Version 2.0 (the "License"); # +# you may not use this file except in compliance with the License. # +# You may obtain a copy of the License at # +# # +# http://www.apache.org/licenses/LICENSE-2.0 # +# # +# Unless required by applicable law or agreed to in writing, software # +# distributed under the License is distributed on an "AS IS" BASIS, # +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # +# See the License for the specific language governing permissions and # +# limitations under the License. # +##############################################################################*/ + + +import { Component, OnInit, Inject } from '@angular/core'; +import { GroupService } from 'app/shared/services/group.service'; +import { MatDialogRef, MAT_DIALOG_DATA } from '@angular/material'; +import { UserService } from 'app/shared/services/user.service'; + + +@Component({ + selector: 'app-dropdown-multiselect', + templateUrl: './dropdown-multiselect.component.pug', + styleUrls: ['./dropdown-multiselect.component.scss'] +}) +export class DropdownMultiselectComponent implements OnInit { + + public group; + public memberRoles; + private params; + public roles; + public user; + public userId; + public search; + constructor(private groupService: GroupService, public dialogRef: MatDialogRef, + private userService: UserService, + @Inject(MAT_DIALOG_DATA) public input_data + ) { + + } + + ngOnInit() { + this.search = {}; + this.userId = this.input_data["user"][0]["_id"]; + this.group = this.input_data["group"]; + this.memberRoles = this.group["members"].filter(member => member.userId == this.userId)["roles"]; + this.userService.get(this.userId).subscribe((result) => { + this.user = result; + }); + this.roles = this.group.roles; + + this.memberRoles = this.group.members.filter(member => member.userId.toString() == this.userId.toString())[0].roles; + if(this.memberRoles){ + for(let i = 0; i < this.roles.length; i++){ + this.roles[i].isSelected = false; + for(let j = 0; j < this.memberRoles.length; j++){ + if(this.roles[i].roleName == this.memberRoles[j]){ + this.roles[i].isSelected = true; + } + } + } + } + } + + saveRoles(){ + let member = { + userId : this.userId, + roles : [] + } + + member.roles = this.roles.filter(role => role.isSelected).map(item => {return item.roleName}); + + // the logic to remove the one member from the array of members and then push the new member roles + this.groupService.get(this.group._id).subscribe((res) => { + let group = res; + + let newMembers = []; + if(group["members"]){ + newMembers = group["members"].filter(member => member.userId.toString() != this.userId.toString()); + } + newMembers.push(member) + let groupPatch = { + _id : this.group._id, + members : newMembers + } + this.groupService.patch(groupPatch).subscribe((response) => { + this.dialogRef.close(); + }); + }); + + + } + +}