Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue #SB-30707 fix: Mentor and participant list dropdown migration #8235

Merged
merged 1 commit into from
Aug 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -138,23 +138,46 @@
</div>
</div>
<div class="sb-field-group mb-8">
<label>{{resourceService?.frmelmnts?.lbl?.batchmentors}}</label>
<div class="createbatchdropdown ui fluid multiple search selection dropdown" id="mentors">
<input id="mentorSelList" aria-label="mentor list">
<i class="dropdown icon"></i>
<div class="default text">{{resourceService?.frmelmnts?.intxt?.t0005}}</div>
<div class="menu">
<div class="item" [attr.data-value]="mentor.id" *ngFor="let mentor of mentorList">
<mat-form-field appearance="fill" class="sb-mat__dropdown w-100 mb-16">
<mat-label>{{resourceService?.frmelmnts?.lbl?.batchmentors}}</mat-label>
<mat-select formControlName="mentors" role="listbox" multiple aria-label="mentor list"
class="selection" (selectionChange)="selectedMultiValues($event, 'mentors')">
<mat-select-trigger>
<span>{{selectedMentorList ? selectedMentorList[0] : ''}} </span>
<span *ngIf="selectedMentorList?.length >= 2" class="example-additional-selection">
(+{{selectedMentorList.length - 1}} {{selectedMentorList?.length === 2 ? 'other' : 'others'}})
</span>
</mat-select-trigger>
<mat-option class="mat-dropdown__options" role="option" *ngFor="let mentor of mentorList" [value]="mentor.id"
attr.aria-label="{{mentor.name}}">
<img class="ui mini avatar image"
src="{{mentor.avatar || 'assets/images/user_logo.png' | cdnprefixurl}}" alt="avatar image">
src="{{mentor.avatar || 'assets/images/user_logo.png' | cdnprefixurl}}" alt="avatar image">
{{mentor.name}}{{mentor.otherDetail}}
</div>
</div>
</div>
</mat-option>
</mat-select>
</mat-form-field>
</div>

<div class="sb-field-group " *ngIf="createBatchForm.value.enrollmentType !== 'open'">
<label>{{resourceService?.frmelmnts?.lbl?.bacthmembers}}</label>
<mat-form-field appearance="fill" class="sb-mat__dropdown w-100 mb-16">
<mat-label>{{resourceService?.frmelmnts?.lbl?.bacthmembers}}</mat-label>
<mat-select formControlName="users" role="listbox" multiple aria-label="participant list"
class="selection" (selectionChange)="selectedMultiValues($event, 'participant')">
<mat-select-trigger>
<span>{{selectedParticipantList ? selectedParticipantList[0] : ''}} </span>
<span *ngIf="selectedParticipantList?.length >= 2" class="example-additional-selection">
(+{{selectedParticipantList.length - 1}} {{selectedParticipantList?.length === 2 ? 'other' : 'others'}})
</span>
</mat-select-trigger>
<mat-option class="mat-dropdown__options" role="option" *ngFor="let participant of participantList" [value]="participant.id"
attr.aria-label="{{participant.name}}">
<img class="ui mini avatar image"
src="{{mentor.avatar || 'assets/images/user_logo.png' | cdnprefixurl}}" alt="avatar image">
{{participant.name}}{{participant.otherDetail}}
</mat-option>
</mat-select>
</mat-form-field>

<div class="createbatchdropdown ui fluid multiple search selection dropdown" id="participants">
<input id="userSelList">
<i class="dropdown icon"></i>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@ export class CreateBatchComponent implements OnInit, OnDestroy, AfterViewInit {
private discussionCsService: any;
createForumRequest: any;
showDiscussionForum: string;
selectedMentorList: Array<any> = []
selectedParticipantList: Array<any> = []

/**
* Constructor to create injected service(s) object
Expand Down Expand Up @@ -157,7 +159,6 @@ export class CreateBatchComponent implements OnInit, OnDestroy, AfterViewInit {
// const userList = this.sortUsers(data.userDetails);
// this.participantList = userList.participantList;
// this.mentorList = userList.mentorList;
this.initDropDown();
}, (err) => {
if (err.error && err.error?.params?.errmsg) {
this.toasterService.error(err.error.params.errmsg);
Expand All @@ -180,6 +181,22 @@ export class CreateBatchComponent implements OnInit, OnDestroy, AfterViewInit {
});
}

selectedMultiValues(event, field) {
const selectedValue = event.value;
this.selectedMentorList = []
this.selectedParticipantList = []
if(selectedValue.length) {
selectedValue.forEach(userID => {
const user = this.mentorList.find(item => item.id === userID)
if (field === 'mentors') {
this.selectedMentorList.push(`${user.name}${user.otherDetail}`)
} else {
this.selectedParticipantList.push(`${user.name}${user.otherDetail}`)
}
});
}
}

private fetchBatchDetails() {
const requestBody = {
filters: {'status': '1'},
Expand Down Expand Up @@ -241,12 +258,8 @@ export class CreateBatchComponent implements OnInit, OnDestroy, AfterViewInit {

public createBatch() {
this.disableSubmitBtn = true;
let participants = [];
let mentors = [];
mentors = $('#mentors').dropdown('get value') ? $('#mentors').dropdown('get value').split(',') : [];
if (this.createBatchForm.value.enrollmentType !== 'open') {
participants = $('#participants').dropdown('get value') ? $('#participants').dropdown('get value').split(',') : [];
}
let participants = this.createBatchForm.value.users || [];
let mentors = this.createBatchForm.value.mentors || [];
const startDate = dayjs(this.createBatchForm.value.startDate).format('YYYY-MM-DD');
const endDate = this.createBatchForm.value.endDate && dayjs(this.createBatchForm.value.endDate).format('YYYY-MM-DD');
const requestBody = {
Expand Down Expand Up @@ -330,63 +343,7 @@ export class CreateBatchComponent implements OnInit, OnDestroy, AfterViewInit {
return ' (' + userData.maskedPhone + ')';
}
}
private initDropDown() {
this.lazzyLoadScriptService.loadScript('semanticDropdown.js').subscribe(() => {
$('#participants').dropdown({
forceSelection: false,
fullTextSearch: true,
onAdd: () => {
}
});
$('#mentors').dropdown({
fullTextSearch: true,
forceSelection: false,
onAdd: () => {
}
});
$('#participants input.search').on('keyup', (e) => {
this.getUserListWithQuery($('#participants input.search').val(), 'participant');
});
$('#mentors input.search').on('keyup', (e) => {
this.getUserListWithQuery($('#mentors input.search').val(), 'mentor');
});
});
}
private getUserListWithQuery(query, type) {
if (this.userSearchTime) {
clearTimeout(this.userSearchTime);
}
this.userSearchTime = setTimeout(() => {
this.getUserList(query, type);
}, 1000);
}
/**
* api call to get user list
*/
private getUserList(query: string = '', type) {
this.selectedParticipants = $('#participants').dropdown('get value') ? $('#participants').dropdown('get value').split(',') : [];
this.selectedMentors = $('#mentors').dropdown('get value') ? $('#mentors').dropdown('get value').split(',') : [];
const requestBody = {
filters: {'status': '1'},
query: query
};
this.courseBatchService.getUserList(requestBody).pipe(takeUntil(this.unsubscribe))
.subscribe((res) => {
const list = this.sortUsers(res);
if (type === 'participant') {
this.participantList = list.participantList;
} else {
this.mentorList = list.mentorList;
}
},
(err) => {
if (err.error && err.error.params.errmsg) {
this.toasterService.error(err.error.params.errmsg);
} else {
this.toasterService.error(this.resourceService.messages.fmsg.m0056);
}
});
}

ngAfterViewInit () {
setTimeout(() => {
this.telemetryImpression = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,64 +149,48 @@
<app-loader></app-loader>
</div>
<div class="sb-field-group mb-8">
<label>{{resourceService?.frmelmnts?.lbl?.batchmentors}}</label>
<div class="createbatchdropdown ui fluid multiple search selection dropdown" id="mentors"
[ngClass]="{ 'disabled' : showFormInViewMode }">
<input id="mentorSelList" aria-label="mentor list">
<i class="dropdown icon"></i>
<div class="default text">{{resourceService?.frmelmnts?.intxt?.t0005}}</div>
<div class="menu">
<div class="item" [attr.data-value]="mentor.id" *ngFor="let mentor of mentorList">
<mat-form-field appearance="fill" class="sb-mat__dropdown w-100 mb-16">
<mat-label>{{resourceService?.frmelmnts?.lbl?.batchmentors}}</mat-label>
<mat-select formControlName="mentors" role="listbox" multiple aria-label="mentor list"
class="selection" [disabled]="showFormInViewMode" (selectionChange)="selectedMultiValues($event, 'mentors')">
<mat-select-trigger>
<span>{{selectedMentors ? selectedMentors[0].name : ''}} </span>
<span *ngIf="selectedMentorList?.length > 2" class="example-additional-selection">
(+{{selectedMentorList.length - 1}} {{selectedMentorList?.length === 2 ? 'other' : 'others'}})
</span>
</mat-select-trigger>
<mat-option [disabled]="true" class="mat-dropdown__options" role="option" *ngFor="let mentor of mentorList" [value]="mentor.id"
attr.aria-label="{{mentor.name}}">
<img class="ui mini avatar image"
src="{{mentor.avatar || 'assets/images/user_logo.png' | cdnprefixurl}}" alt="avatar-img">
src="{{mentor.avatar || 'assets/images/user_logo.png' | cdnprefixurl}}" alt="avatar image">
{{mentor.name}}{{mentor.otherDetail}}
</div>
</div>
</div>
</div>
<div class="sb-field-group mb-8" *ngIf="selectedMentors.length > 0">
<label>{{resourceService?.frmelmnts?.lbl?.batchselmentors}}</label>
<a class="ui label mt-5" *ngFor="let selectmentor of selectedMentors">
<img class="ui right spaced avatar image"
src="{{selectmentor.avatar || 'assets/images/user_logo.png' | cdnprefixurl}}" alt="avatar-img">
{{selectmentor.name}}{{selectmentor.otherDetail}}
<i class="delete icon" *ngIf="batchDetails.status === 0" tabindex="0"
(click)="removeMentor(selectmentor)"></i>
</a>
</mat-option>
</mat-select>
</mat-form-field>
</div>

<div class="sb-field-group mb-8" *ngIf="batchUpdateForm.value.enrollmentType !== 'open'">
<label>{{resourceService?.frmelmnts?.lbl?.bacthmembers}}
<i *ngIf="batchDetails.participants && batchDetails.participants.length >= 100"
matTooltip="{{resourceService?.frmelmnts?.lbl?.contactStateAdmin}}" [matTooltipPosition]="'right'"
class="sb-icon-info info-icon"></i>
</label>
<div class="createbatchdropdown ui fluid multiple search selection dropdown" id="participant"
[ngClass]="{'disabled' : showFormInViewMode || (batchDetails.participants && batchDetails.participants.length >= 100)}">
<input id="userSelList">
<i class="dropdown icon"></i>
<div class="default text">{{resourceService?.frmelmnts?.intxt?.t0006}}</div>
<div class="menu">
<div class="item" *ngFor="let user of participantList" [attr.data-value]="user.id">
<mat-form-field appearance="fill" class="sb-mat__dropdown w-100 mb-16">
<mat-label>{{resourceService?.frmelmnts?.lbl?.bacthmembers}}</mat-label>
<mat-select formControlName="users" role="listbox" multiple aria-label="participant list"
class="selection" [disabled]="showFormInViewMode || (batchDetails.participants && batchDetails.participants.length >= 100)" (selectionChange)="selectedMultiValues($event, 'participant')">
<mat-select-trigger>
<span>{{selectedParticipants ? selectedParticipants[0].name : ''}} </span>
<span *ngIf="selectedMentorList?.length > 2" class="example-additional-selection">
(+{{selectedParticipants.length - 1}} {{selectedParticipants?.length === 2 ? 'other' : 'others'}})
</span>
</mat-select-trigger>
<mat-option [disabled]="true" class="mat-dropdown__options" role="option" *ngFor="let participant of participantList" [value]="participant.id"
attr.aria-label="{{participant.name}}">
<img class="ui mini avatar image"
src="{{user.avatar || 'assets/images/user_logo.png' | cdnprefixurl}}" alt="avatar-image">
{{user.name}}{{user.otherDetail}}
</div>
</div>
</div>
src="{{participant.avatar || 'assets/images/user_logo.png' | cdnprefixurl}}" alt="avatar image">
{{participant.name}}{{participant.otherDetail}}
</mat-option>
</mat-select>
</mat-form-field>
<small *ngIf="batchDetails.participants && batchDetails.participants.length > 100"
class="sb-color-primary d-flex pt-4">{{resourceService?.frmelmnts?.lbl?.contactStateAdmin}}</small>
</div>
<div class="sb-field-group mb-8"
*ngIf="batchUpdateForm.value.enrollmentType !== 'open' && selectedParticipants.length > 0 && (batchDetails.participants && batchDetails.participants.length <= 100)">
<label>{{resourceService?.frmelmnts?.lbl?.batchparticipants}}</label>
<a class="ui label mt-5" *ngFor="let user of selectedParticipants">
<img class="ui right spaced avatar image"
src="{{user.avatar || 'assets/images/user_logo.png' | cdnprefixurl}}" alt="avatar-image">
{{user.name}}{{user.otherDetail}}
<!-- TODO: Will be enabled in future
<i class="delete icon" *ngIf="batchDetails.status === 0" (click)="removeParticipant(user)"></i>-->
</a>
</div>
</form>
</div>
<!--/Content-->
Expand Down
Loading