Skip to content
This repository was archived by the owner on Jul 6, 2020. It is now read-only.

Commit 99b8f4d

Browse files
Add feature to delete member from participant & handle case for removing owner of team(#288)
* delete_member_draft * delete_member_draft * trash_icon_only_visible_to_team_leader * delete_feature_working * delete_feature_working * build_fail_corrected * delete_host_feature_added * trash_button_and_member_look_updated * removed_package_file_from_commit * edited_travis.yml * removed_extra_files * made_suggested_changes * removed_string_based_access_ * removed_deleteMemeberTitle_from_url * tetsing_build * testing_build_fix * testing_build * removed_changes * changed_chrome_Driver_version * changed_chrome_Driver_version * upgraded_chrome_Driver_version * upgraded_chrome_Driver_version_to_81 * runing_actual_chrome_browser * removed_unnecessary_changes * removed_unnecessary_check * edited travis.yml * Revert unnecessary changes * revert change Co-authored-by: Rishabh Jain <rishabhjain2018@gmail.com>
1 parent 82f3b2f commit 99b8f4d

6 files changed

Lines changed: 114 additions & 17 deletions

File tree

src/app/components/publiclists/teamlist/teamcard/teamcard.component.html

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,17 @@
2929
</div>
3030
</div>
3131
<div class='team-members'>
32-
<div class="title">
33-
<h6><b>Team Members:</b></h6>
32+
<div class="title">
33+
<h6><b>Team Members:</b></h6>
34+
</div>
35+
<div class="col s12 m6" *ngFor="let member of memberArray; let i=index;" class="member-class">
36+
<span class="m1">{{member}}</span>
37+
<span class="trash-icon"><a (click)="deleteTeamMember($event, memberIdArray[i])"
38+
*ngIf="authState.username == teamView['created_by']">
39+
<i class="fa fa-trash list-icon text-highlight w-300 left grey-text" aria-hidden="true"></i>
40+
</a>
41+
</span>
42+
</div>
3443
</div>
35-
<div>
36-
{{teamView['members']}}
37-
</div>
38-
39-
</div>
40-
</div>
44+
</div>
4145
</div>

src/app/components/publiclists/teamlist/teamcard/teamcard.component.scss

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,3 +124,12 @@
124124
height: unset !important;
125125
border-bottom-style: none !important;
126126
}
127+
128+
.member-class{
129+
display: flex;
130+
margin: 2% 0%;
131+
}
132+
.trash-icon {
133+
margin-left: 80%;
134+
position: absolute;
135+
}

src/app/components/publiclists/teamlist/teamcard/teamcard.component.spec.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import { ApiService } from '../../../../services/api.service';
77
import { RouterTestingModule } from '@angular/router/testing';
88
import { HttpClientModule } from '@angular/common/http';
99
import { NO_ERRORS_SCHEMA } from '@angular/core';
10+
import { AuthService } from '../../../../services/auth.service';
11+
import { EndpointsService } from '../../../../services/endpoints.service';
1012

1113
describe('TeamcardComponent', () => {
1214
let component: TeamcardComponent;
@@ -15,7 +17,7 @@ describe('TeamcardComponent', () => {
1517
beforeEach(async(() => {
1618
TestBed.configureTestingModule({
1719
declarations: [ TeamcardComponent ],
18-
providers: [ GlobalService, ApiService ],
20+
providers: [ GlobalService, ApiService, AuthService, EndpointsService ],
1921
imports: [ RouterTestingModule, HttpClientModule ],
2022
schemas: [ NO_ERRORS_SCHEMA ]
2123
})
@@ -29,6 +31,7 @@ describe('TeamcardComponent', () => {
2931
component.selected = false;
3032
component.isOnChallengePage = false;
3133
component.deleteTeamCard = new EventEmitter<any>();
34+
component.deleteMemberCard = new EventEmitter<any>();
3235
component.selectTeamCard = new EventEmitter<any>();
3336
fixture.detectChanges();
3437
});

src/app/components/publiclists/teamlist/teamcard/teamcard.component.ts

Lines changed: 46 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { Component, OnInit, OnChanges, Input, Output, EventEmitter, SimpleChange
22
import { GlobalService } from '../../../../services/global.service';
33
import { ApiService } from '../../../../services/api.service';
44
import { Router, ActivatedRoute } from '@angular/router';
5+
import { AuthService } from '../../../../services/auth.service';
56

67
/**
78
* Component Class
@@ -13,6 +14,16 @@ import { Router, ActivatedRoute } from '@angular/router';
1314
})
1415
export class TeamcardComponent implements OnInit, OnChanges {
1516

17+
/**
18+
* Authentication Service subscription
19+
*/
20+
authServiceSubscription: any;
21+
22+
/**
23+
* Current Authentication state
24+
*/
25+
authState: any;
26+
1627
/**
1728
* Team object
1829
*/
@@ -33,6 +44,11 @@ export class TeamcardComponent implements OnInit, OnChanges {
3344
*/
3445
@Output() deleteTeamCard = new EventEmitter<any>();
3546

47+
/**
48+
* Delete member event
49+
*/
50+
@Output() deleteMemberCard = new EventEmitter<any>();
51+
3652
/**
3753
* Select team event
3854
*/
@@ -58,6 +74,16 @@ export class TeamcardComponent implements OnInit, OnChanges {
5874
*/
5975
teamView = {};
6076

77+
/**
78+
* Team Member Array
79+
*/
80+
memberArray = [];
81+
82+
/**
83+
* Team Member ID Array
84+
*/
85+
memberIdArray = [];
86+
6187
/**
6288
* Is currently selected
6389
*/
@@ -77,6 +103,7 @@ export class TeamcardComponent implements OnInit, OnChanges {
77103
*/
78104
constructor(private globalService: GlobalService,
79105
private apiService: ApiService,
106+
public authService: AuthService,
80107
private router: Router,
81108
private route: ActivatedRoute) { }
82109

@@ -85,6 +112,9 @@ export class TeamcardComponent implements OnInit, OnChanges {
85112
*/
86113
ngOnInit() {
87114
this.updateView();
115+
this.authServiceSubscription = this.authService.change.subscribe((authState) => {
116+
this.authState = authState;
117+
});
88118
}
89119

90120
/**
@@ -132,6 +162,14 @@ export class TeamcardComponent implements OnInit, OnChanges {
132162
this.deleteTeamCard.emit(this.team['id']);
133163
}
134164

165+
/**
166+
* Fires delete member event.
167+
*/
168+
deleteTeamMember(e, participantId) {
169+
e.stopPropagation();
170+
this.deleteMemberCard.emit({teamId: this.team['id'], participantId: participantId});
171+
}
172+
135173
/**
136174
* Fires slect team event.
137175
*/
@@ -155,18 +193,19 @@ export class TeamcardComponent implements OnInit, OnChanges {
155193
this.isSelected = false;
156194
}
157195
const temp = this.team['members'];
158-
let memberString = '';
196+
this.memberArray = [];
197+
this.memberIdArray = [];
159198
for (let i = 0; i < temp.length; i++) {
160199
if (temp[i]['member_name']) {
161-
memberString = memberString + ', ' + temp[i]['member_name'];
200+
this.memberArray.push(temp[i]['member_name']);
201+
this.memberIdArray.push(temp[i]['id']);
162202
} else {
163-
memberString = memberString + ', ' + temp[i]['user'];
203+
this.memberArray.push(temp[i]['user']);
204+
this.memberIdArray.push(temp[i]['id']);
164205
}
165206
}
166-
if (memberString !== '') {
167-
memberString = memberString.slice(2, memberString.length);
168-
}
169-
this.teamView['members'] = memberString;
207+
this.teamView['members'] = this.memberArray;
208+
this.teamView['member_ids'] = this.memberIdArray;
170209
}
171210

172211
}

src/app/components/publiclists/teamlist/teamlist.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
<ul class="collapsible" data-collapsible="accordion">
99
<app-teamcard *ngFor="let team of filteredTeams"
1010
[team]="team" [selected]="team['isSelected']" [isOnChallengePage]="isOnChallengePage"
11-
(deleteTeamCard)="deleteTeamWrapper()($event)" (editTeamCard)="editTeamWrapper()($event)" (addMembersTeamCard)="addMembersToTeamWrapper()($event)"
11+
(deleteTeamCard)="deleteTeamWrapper()($event)" (deleteMemberCard)="deleteTeamMemberWrapper()($event)" (editTeamCard)="editTeamWrapper()($event)" (addMembersTeamCard)="addMembersToTeamWrapper()($event)"
1212
(selectTeamCard)="selectTeamWrapper()($event)">
1313
</app-teamcard>
1414
</ul>

src/app/components/publiclists/teamlist/teamlist.component.ts

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,11 @@ export class TeamlistComponent implements OnInit, OnDestroy {
114114
*/
115115
deleteTeamsPath: any;
116116

117+
/**
118+
* Delete member URL
119+
*/
120+
deleteMembersPath: any;
121+
117122
/**
118123
* Currently selected team
119124
*/
@@ -227,6 +232,7 @@ export class TeamlistComponent implements OnInit, OnDestroy {
227232
this.fetchTeamsPath = 'hosts/challenge_host_team';
228233
this.createTeamsPath = 'hosts/create_challenge_host_team';
229234
this.deleteTeamsPath = 'hosts/remove_self_from_challenge_host';
235+
this.deleteMembersPath = 'hosts/challenge_host_team/<team_id>/challenge_host/';
230236
this.fetchMyTeams(this.fetchTeamsPath);
231237
this.teamCreateTitle = 'Create a New Team';
232238
this.teamSelectTitle = 'Select a Challenge Host Team';
@@ -239,6 +245,7 @@ export class TeamlistComponent implements OnInit, OnDestroy {
239245
this.fetchTeamsPath = 'participants/participant_team';
240246
this.createTeamsPath = this.fetchTeamsPath;
241247
this.deleteTeamsPath = 'participants/remove_self_from_participant_team';
248+
this.deleteMembersPath = 'participants/participant_team/<team_id>/participant/';
242249
this.fetchMyTeams(this.fetchTeamsPath);
243250
this.teamCreateTitle = 'Create a New Participant Team';
244251
this.teamSelectTitle = 'My Existing Participant Teams';
@@ -565,4 +572,39 @@ export class TeamlistComponent implements OnInit, OnDestroy {
565572
};
566573
this.globalService.showTermsAndConditionsModal(PARAMS);
567574
}
575+
576+
/**
577+
* Display confirm dialog before deleting a team member.
578+
*/
579+
deleteTeamMemberWrapper() {
580+
const SELF = this;
581+
const deleteTeamMember = (team) => {
582+
const deleteUrl = SELF.deleteMembersPath.replace('<team_id>', team.teamId);
583+
SELF.apiCall = (params) => {
584+
SELF.apiService.deleteUrl(deleteUrl + team.participantId).subscribe(
585+
data => {
586+
// Success Message in data.message
587+
SELF.globalService.showToast('success', 'Member was removed from the team!', 5);
588+
SELF.fetchMyTeams(SELF.fetchTeamsPath);
589+
SELF.selectedTeam = null;
590+
},
591+
err => {
592+
SELF.globalService.handleApiError(err);
593+
},
594+
() => {}
595+
);
596+
};
597+
const PARAMS = {
598+
title: 'Would you like to remove this member ?',
599+
content: 'Note: This action will remove this member from the team.',
600+
confirm: 'Yes',
601+
deny: 'Cancel',
602+
confirmCallback: SELF.apiCall
603+
};
604+
SELF.globalService.showConfirm(PARAMS);
605+
return false;
606+
};
607+
return deleteTeamMember;
608+
}
609+
568610
}

0 commit comments

Comments
 (0)