src/app/modules/learn/components/batch/update-course-batch/update-course-batch.component.ts
OnInit
OnDestroy
AfterViewInit
selector | app-update-course-batch |
templateUrl | ./update-course-batch.component.html |
constructor(routerNavigationService: RouterNavigationService, activatedRoute: ActivatedRoute, route: Router, resourceService: ResourceService, userService: UserService, courseBatchService: CourseBatchService, toasterService: ToasterService, courseConsumptionService: CourseConsumptionService, navigationhelperService: NavigationHelperService, lazzyLoadScriptService: LazzyLoadScriptService, telemetryService: TelemetryService, csLibInitializerService: CsLibInitializerService, discussionService: DiscussionService)
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Constructor to create injected service(s) object
Parameters :
|
Private addParticipantToBatch | ||||||
addParticipantToBatch(batchId, participants)
|
||||||
Parameters :
Returns :
any
|
checkEnableDiscussions | ||||
checkEnableDiscussions(batchId)
|
||||
Parameters :
Returns :
void
|
checkIssueCertificate | |||||||||
checkIssueCertificate(batchId, batchDetails?: any)
|
|||||||||
Parameters :
Returns :
void
|
disableDiscussionForum | ||||
disableDiscussionForum(batchId)
|
||||
Parameters :
Returns :
void
|
enableDiscussionForum |
enableDiscussionForum()
|
Returns :
void
|
Private fetchBatchDetails |
fetchBatchDetails()
|
Returns :
any
|
fetchForumConfig |
fetchForumConfig()
|
Returns :
void
|
Private fetchParticipantDetails |
fetchParticipantDetails()
|
fetch mentors and participant details of current batch
Returns :
void
|
generateDataForDF |
generateDataForDF()
|
Returns :
void
|
getEnabledForumId |
getEnabledForumId()
|
Returns :
void
|
Private getUserOtherDetail | ||||
getUserOtherDetail(userData)
|
||||
Parameters :
Returns :
string
|
handleInputChange | ||||
handleInputChange(inputId)
|
||||
Parameters :
Returns :
void
|
Private initializeUpdateForm |
initializeUpdateForm()
|
initializes form fields and apply field level validation
Returns :
void
|
Private isSubmitBtnDisable | ||||
isSubmitBtnDisable(batchForm)
|
||||
Parameters :
Returns :
boolean
|
ngAfterViewInit |
ngAfterViewInit()
|
Returns :
void
|
ngOnDestroy |
ngOnDestroy()
|
Returns :
void
|
ngOnInit |
ngOnInit()
|
Initialize form fields and getuserlist
Returns :
void
|
onStartDateChange | ||||||
onStartDateChange(event: MatDatepickerInputEvent
|
||||||
Parameters :
Returns :
void
|
Private processParticipantDetails | ||||
processParticipantDetails(res)
|
||||
Parameters :
Returns :
void
|
Public redirect |
redirect()
|
Returns :
void
|
Private reload |
reload()
|
Returns :
void
|
Private removeParticipantFromBatch | ||||||
removeParticipantFromBatch(batchId, participantId)
|
||||||
Parameters :
Returns :
void
|
resetForm |
resetForm()
|
Returns :
void
|
selectedMultiValues | ||||||
selectedMultiValues(event, field)
|
||||||
Parameters :
Returns :
void
|
setTelemetryCData | ||||||
setTelemetryCData(cdata: [])
|
||||||
Parameters :
Returns :
void
|
setTelemetryInteractData |
setTelemetryInteractData()
|
Returns :
void
|
Private sortUsers | ||||
sortUsers(res)
|
||||
Parameters :
Returns :
{ participantList: any; mentorList: any; }
|
Public updateBatch |
updateBatch()
|
Returns :
void
|
Private activatedRoute |
Type : ActivatedRoute
|
To send activatedRoute.snapshot to router navigation service for redirection to update batch component |
Private batchDetails |
Type : any
|
batchDetails for form |
Private batchId |
Type : string
|
batchId |
Public batchUpdateForm |
Type : UntypedFormGroup
|
form group for batchAddUserForm |
callCreateDiscussion |
Default value : true
|
clearButtonInteractEdata |
Type : IInteractEventEdata
|
Private courseBatchService |
Type : CourseBatchService
|
Refrence of UserService |
Public courseConsumptionService |
Type : CourseConsumptionService
|
Public courseCreator |
Default value : false
|
courseCreator |
Private courseId |
Type : string
|
createForumRequest |
Type : any
|
Public disableSubmitBtn |
Default value : false
|
Private discussionCsService |
Type : any
|
Public enrolmentType |
Type : string
|
fetchForumConfigReq |
Type : Array<IFetchForumConfig>
|
To fetch create-forum request payload for batch |
fetchForumIdReq |
Type : any
|
forumIds |
Type : any
|
isCertificateIssued |
Type : string
|
isEnableDiscussions |
Type : string
|
Public mentorList |
Type : Array<any>
|
Default value : []
|
mentorList for mentors in the batch |
Public navigationhelperService |
Type : NavigationHelperService
|
Public participantList |
Type : []
|
Default value : []
|
participantList for users |
Public pickerMinDate |
Default value : new Date(new Date().setHours(0, 0, 0, 0))
|
Public pickerMinDateForEndDate |
Default value : new Date(this.pickerMinDate.getTime() + (24 * 60 * 60 * 1000))
|
Public pickerMinDateForEnrollmentEndDate |
Private removedUsers |
Type : any
|
Default value : []
|
Public resourceService |
Type : ResourceService
|
To call resource service which helps to use language constant |
Public router |
Type : Router
|
To navigate to other pages |
Public selectedMentors |
Type : any
|
Default value : []
|
Public selectedParticipants |
Type : any
|
Default value : []
|
showDiscussionForum |
Type : string
|
Public showFormInViewMode |
Type : boolean
|
Public showUpdateModal |
Default value : false
|
telemetryCdata |
Type : Array<literal type>
|
Default value : []
|
Public telemetryImpression |
Type : IImpressionEventInput
|
telemetryImpression object for update batch page |
telemetryInteractObject |
Type : IInteractEventObject
|
Private toasterService |
Type : ToasterService
|
To show toaster(error, success etc) after any API calls |
Public unsubscribe |
Default value : new Subject<void>()
|
updateBatchInteractEdata |
Type : IInteractEventEdata
|
Private updateBatchModal |
Private userSearchTime |
Type : any
|
Private userService |
Type : UserService
|
Refrence of UserService |
setBatchModal | ||||
setsetBatchModal(element)
|
||||
Parameters :
Returns :
void
|
import { IInteractEventEdata } from './../../../../telemetry/interfaces/telemetry';
import { Component, OnInit, ViewChild, OnDestroy, AfterViewInit } from '@angular/core';
import { ActivatedRoute, Router } from '@angular/router';
import {combineLatest, Subject, forkJoin} from 'rxjs';
import { takeUntil, mergeMap } from 'rxjs/operators';
import { RouterNavigationService, ResourceService, ToasterService, NavigationHelperService } from '@sunbird/shared';
import { UntypedFormGroup, UntypedFormControl, Validators } from '@angular/forms';
import { UserService } from '@sunbird/core';
import { CourseConsumptionService, CourseBatchService } from './../../../services';
import { IImpressionEventInput, IInteractEventObject, TelemetryService } from '@sunbird/telemetry';
import * as _ from 'lodash-es';
import dayjs from 'dayjs';
import { LazzyLoadScriptService } from 'LazzyLoadScriptService';
import { CsModule } from '@project-sunbird/client-services';
import { CsLibInitializerService } from '../../../../../service/CsLibInitializer/cs-lib-initializer.service';
import { IFetchForumConfig } from '../../../../groups/interfaces';
import { DiscussionService } from '../../../../../../app/modules/discussion/services/discussion/discussion.service';
import { MatDatepickerInputEvent } from '@angular/material/datepicker';
@Component({
selector: 'app-update-course-batch',
templateUrl: './update-course-batch.component.html'
})
export class UpdateCourseBatchComponent implements OnInit, OnDestroy, AfterViewInit {
private updateBatchModal;
@ViewChild('updateBatchModal') set setBatchModal(element) {
if (element) {
this.updateBatchModal = element;
}
// this.initDropDown();
}
/**
* batchId
*/
private batchId: string;
public showUpdateModal = false;
public disableSubmitBtn = false;
private courseId: string;
public selectedParticipants: any = [];
public showFormInViewMode: boolean;
public selectedMentors: any = [];
private userSearchTime: any;
private removedUsers: any = [];
forumIds: any;
fetchForumIdReq: any;
private discussionCsService: any;
createForumRequest: any;
showDiscussionForum: string;
/**
* To fetch create-forum request payload for batch
*/
fetchForumConfigReq: Array<IFetchForumConfig>;
/**
* This variable hepls to show and hide loader.
* It is kept true by default as at first when we comes
* to a popup the loader should be displayed before the
* data is loaded
*/
public showLoader = true;
/**
* courseCreator
*/
public courseCreator = false;
/**
* participantList for users
*/
public participantList = [];
/**
* batchDetails for form
*/
private batchDetails: any;
/**
* mentorList for mentors in the batch
*/
public mentorList: Array<any> = [];
/**
* form group for batchAddUserForm
*/
public batchUpdateForm: UntypedFormGroup;
/**
* To navigate to other pages
*/
public router: Router;
/**
* To send activatedRoute.snapshot to router navigation
* service for redirection to update batch component
*/
private activatedRoute: ActivatedRoute;
/**
* Refrence of UserService
*/
private userService: UserService;
/**
* Refrence of UserService
*/
private courseBatchService: CourseBatchService;
/**
* To call resource service which helps to use language constant
*/
public resourceService: ResourceService;
/**
* To show toaster(error, success etc) after any API calls
*/
private toasterService: ToasterService;
/**
* telemetryImpression object for update batch page
*/
public telemetryImpression: IImpressionEventInput;
public pickerMinDate = new Date(new Date().setHours(0, 0, 0, 0));
public pickerMinDateForEndDate = new Date(this.pickerMinDate.getTime() + (24 * 60 * 60 * 1000));
public pickerMinDateForEnrollmentEndDate;
public courseConsumptionService: CourseConsumptionService;
public unsubscribe = new Subject<void>();
public enrolmentType: string;
updateBatchInteractEdata: IInteractEventEdata;
telemetryInteractObject: IInteractEventObject;
clearButtonInteractEdata: IInteractEventEdata;
telemetryCdata: Array<{}> = [];
isCertificateIssued: string;
isEnableDiscussions: string;
callCreateDiscussion = true;
/**
* Constructor to create injected service(s) object
* @param {RouterNavigationService} routerNavigationService Reference of routerNavigationService
* @param {Router} router Reference of Router
* @param {ActivatedRoute} activatedRoute Reference of ActivatedRoute
* @param {UserService} UserService Reference of UserService
*/
constructor(routerNavigationService: RouterNavigationService,
activatedRoute: ActivatedRoute,
route: Router,
resourceService: ResourceService, userService: UserService,
courseBatchService: CourseBatchService,
toasterService: ToasterService,
courseConsumptionService: CourseConsumptionService,
public navigationhelperService: NavigationHelperService, private lazzyLoadScriptService: LazzyLoadScriptService,
private telemetryService: TelemetryService,
private csLibInitializerService: CsLibInitializerService,
private discussionService: DiscussionService) {
this.resourceService = resourceService;
this.router = route;
this.activatedRoute = activatedRoute;
this.userService = userService;
this.courseBatchService = courseBatchService;
this.toasterService = toasterService;
this.courseConsumptionService = courseConsumptionService;
if (!CsModule.instance.isInitialised) {
this.csLibInitializerService.initializeCs();
}
this.discussionCsService = CsModule.instance.discussionService;
}
/**
* Initialize form fields and getuserlist
*/
ngOnInit() {
combineLatest(this.activatedRoute.params, this.activatedRoute.parent.params,
this.activatedRoute.queryParams,
(params, parentParams, queryParams) => ({ ...params, ...parentParams, ...queryParams })).pipe(
mergeMap((params) => {
this.batchId = params.batchId;
this.courseId = params.courseId;
this.enrolmentType = params.enrollmentType;
this.setTelemetryInteractData();
return this.fetchBatchDetails();
}),
takeUntil(this.unsubscribe)
)
.subscribe((data) => {
this.showDiscussionForum = _.get(data.courseDetails, 'discussionForum.enabled');
this.generateDataForDF();
if (this.showDiscussionForum === 'Yes') {
this.fetchForumConfig();
}
this.showUpdateModal = true;
if (data.courseDetails.createdBy === this.userService.userid) {
this.courseCreator = true;
}
this.batchDetails = data.batchDetails;
if (this.batchDetails.enrollmentType !== 'open' && data.participantList && data.participantList.length > 0) {
this.batchDetails.participants = data.participantList;
}
const userList = this.sortUsers(data.userDetails);
this.participantList = userList.participantList;
this.mentorList = userList.mentorList;
if (_.get(this.batchDetails, 'startDate')) this.pickerMinDateForEndDate = new Date(_.get(this.batchDetails, 'startDate'));
this.initializeUpdateForm();
this.getEnabledForumId();
this.fetchParticipantDetails();
}, (err) => {
if (err?.error && err.error?.params?.errmsg) {
this.toasterService.error(err.error.params.errmsg);
} else {
this.toasterService.error(this.resourceService.messages.fmsg.m0054);
}
this.redirect();
});
}
private fetchBatchDetails() {
if (this.enrolmentType === 'open') {
const requestBody = {
filters: { 'status': '1' },
};
const participantList = {};
return combineLatest(
this.courseBatchService.getUserList(requestBody),
this.courseConsumptionService.getCourseHierarchy(this.courseId),
this.courseBatchService.getUpdateBatchDetails(this.batchId),
(userDetails, courseDetails, batchDetails) => (
{ userDetails, courseDetails, batchDetails, participantList}
));
} else {
const requestBody = {
filters: { 'status': '1' },
};
return combineLatest(
this.courseBatchService.getUserList(requestBody),
this.courseConsumptionService.getCourseHierarchy(this.courseId),
this.courseBatchService.getUpdateBatchDetails(this.batchId),
this.courseBatchService.getParticipantList(
{ 'request': { 'batch': { 'batchId': this.batchId } } }),
(userDetails, courseDetails, batchDetails, participantList) => (
{ userDetails, courseDetails, batchDetails, participantList }
));
}
}
private isSubmitBtnDisable(batchForm): boolean {
const batchFormControls = ['name', 'description', 'enrollmentType', 'mentors', 'startDate', 'endDate', 'users'];
for (let i = 0; i < batchFormControls.length; i++) {
if (batchForm.controls[batchFormControls[i]].status !== 'VALID') {
return true;
}
}
if (batchForm.controls['enrollmentEndDate'].status !== 'VALID' && batchForm.controls['enrollmentEndDate'].pristine) {
return false;
}
return true;
}
/**
* initializes form fields and apply field level validation
*/
private initializeUpdateForm(): void {
this.isCertificateIssued = _.get(this.batchDetails, 'cert_templates') &&
Object.keys(_.get(this.batchDetails, 'cert_templates')).length ? 'yes' : 'no';
const endDate = this.batchDetails.endDate ? new Date(this.batchDetails.endDate) : null;
const enrollmentEndDate = this.batchDetails.enrollmentEndDate ? new Date(this.batchDetails.enrollmentEndDate) : null;
if (!dayjs(this.batchDetails.startDate).isBefore(dayjs(this.pickerMinDate).format('YYYY-MM-DD'))) {
this.pickerMinDateForEnrollmentEndDate = new Date(new Date(this.batchDetails.startDate).setHours(0, 0, 0, 0));
} else {
this.pickerMinDateForEnrollmentEndDate = this.pickerMinDate;
}
this.batchUpdateForm = new UntypedFormGroup({
name: new UntypedFormControl(this.batchDetails.name, [Validators.required]),
description: new UntypedFormControl(this.batchDetails.description),
enrollmentType: new UntypedFormControl(this.batchDetails.enrollmentType, [Validators.required]),
startDate: new UntypedFormControl(new Date(this.batchDetails.startDate), [Validators.required]),
endDate: new UntypedFormControl(endDate),
mentors: new UntypedFormControl(this.batchDetails.mentors || []),
users: new UntypedFormControl(this.batchDetails.participants || []),
enrollmentEndDate: new UntypedFormControl(enrollmentEndDate),
issueCertificate: new UntypedFormControl(this.isCertificateIssued, [Validators.required]),
enableDiscussions: new UntypedFormControl(this.isEnableDiscussions, [Validators.required])
});
this.batchUpdateForm.get('startDate').valueChanges.subscribe(value => {
const startDate: any = dayjs(value);
if (startDate.isValid()) {
if (!dayjs(startDate).isBefore(dayjs(this.pickerMinDate).format('YYYY-MM-DD'))) {
this.pickerMinDateForEnrollmentEndDate = new Date(new Date(startDate).setHours(0, 0, 0, 0));
} else {
this.pickerMinDateForEnrollmentEndDate = this.pickerMinDate;
}
}
});
this.batchUpdateForm.valueChanges.subscribe(val => {
if (this.batchUpdateForm.status === 'VALID') {
this.disableSubmitBtn = false;
} else {
this.disableSubmitBtn = this.isSubmitBtnDisable(this.batchUpdateForm);
}
});
this.disableSubmitBtn = true;
if (this.batchDetails.createdBy !== this.userService.userid) {
this.showFormInViewMode = true;
this.batchUpdateForm.disable();
}
}
/**
* fetch mentors and participant details of current batch
*/
private fetchParticipantDetails() {
let userList = [];
if (this.batchDetails.participants || (this.batchDetails.mentors && this.batchDetails.mentors.length > 0)) {
if (this.batchDetails.enrollmentType !== 'open') {
if (this.batchDetails.participants && this.batchDetails.participants.length > 100) {
userList = this.batchDetails.mentors;
} else {
userList = _.union(this.batchDetails.participants, this.batchDetails.mentors);
}
} else {
userList = this.batchDetails.mentors;
}
if (!userList.length) {
this.showLoader = false;
this.disableSubmitBtn = false;
return ;
}
const request = {
filters: {
identifier: userList
},
limit : userList.length
};
this.courseBatchService.getUserList(request).pipe(takeUntil(this.unsubscribe))
.subscribe((res) => {
this.processParticipantDetails(res);
}, (err) => {
if (err.error && err.error.params.errmsg) {
this.toasterService.error(err.error.params.errmsg);
} else {
this.toasterService.error(this.resourceService.messages.fmsg.m0056);
}
this.redirect();
});
} else {
this.showLoader = false;
this.disableSubmitBtn = false;
}
}
private processParticipantDetails(res) {
const users = this.sortUsers(res);
const participantList = users.participantList;
const mentorList = users.mentorList;
_.forEach(this.batchDetails.participants, (value, key) => {
const user = _.find(participantList, ['id', value]);
if (user) {
this.selectedParticipants.push(`${user.name}${user.otherDetail}`);
}
});
_.forEach(this.batchDetails.mentors, (value, key) => {
const mentor = _.find(mentorList, ['id', value]);
if (mentor) {
this.selectedMentors.push(`${mentor.name}${mentor.otherDetail}`);
}
});
this.disableSubmitBtn = false;
this.showLoader = false;
}
private sortUsers(res) {
const participantList = [];
const mentorList = [];
if (res.result.response.content && res.result.response.content.length > 0) {
_.forEach(res.result.response.content, (userData) => {
if (_.find(this.selectedMentors, { 'id': userData.identifier }) ||
_.find(this.selectedParticipants, { 'id': userData.identifier })) {
return;
}
if (userData.identifier !== this.userService.userid) {
const user = {
id: userData.identifier,
name: userData.firstName + (userData.lastName ? ' ' + userData.lastName : ''),
avatar: userData.avatar,
otherDetail: this.getUserOtherDetail(userData)
};
_.forEach(userData.roles, (roles) => {
if (roles.role === 'COURSE_MENTOR') {
mentorList.push(user);
}
});
participantList.push(user);
}
});
}
return {
participantList: _.uniqBy(participantList, 'id'),
mentorList: _.uniqBy(mentorList, 'id')
};
}
private removeParticipantFromBatch(batchId, participantId) {
const userRequest = {
'request': {
userIds: participantId
}
};
this.courseBatchService.removeUsersFromBatch(batchId, userRequest);
}
private addParticipantToBatch(batchId, participants) {
const userRequest = {
userIds: _.compact(participants)
};
return this.courseBatchService.addUsersToBatch(userRequest, batchId);
}
public updateBatch() {
this.disableSubmitBtn = true;
let participants = [];
const selectedMentors = [];
let mentors = this.batchUpdateForm.value.mentors || [];
if (this.batchUpdateForm.value.enrollmentType !== 'open') {
participants = this.batchUpdateForm.value.users || [];
}
const startDate = dayjs(this.batchUpdateForm.value.startDate).format('YYYY-MM-DD');
const endDate = this.batchUpdateForm.value.endDate && dayjs(this.batchUpdateForm.value.endDate).format('YYYY-MM-DD');
const requestBody = {
id: this.batchId,
courseId: this.courseId,
name: this.batchUpdateForm.value.name,
description: this.batchUpdateForm.value.description,
enrollmentType: this.batchUpdateForm.value.enrollmentType,
startDate: startDate,
endDate: endDate || null,
createdFor: this.userService.userProfile.organisationIds,
mentors: _.compact(mentors)
};
if (this.batchUpdateForm.value.enrollmentType === 'open' && this.batchUpdateForm.value.enrollmentEndDate) {
requestBody['enrollmentEndDate'] = dayjs(this.batchUpdateForm.value.enrollmentEndDate).format('YYYY-MM-DD');
}
const requests = [];
requests.push(this.courseBatchService.updateBatch(requestBody));
if (this.removedUsers && this.removedUsers.length > 0) {
requests.push(this.removeParticipantFromBatch(this.batchId, this.removedUsers));
}
if (participants && participants.length > 0) {
requests.push(this.addParticipantToBatch(this.batchId, participants));
}
forkJoin(requests).subscribe(results => {
// this.disableSubmitBtn = false;
this.toasterService.success(this.resourceService.messages.smsg.m0034);
this.reload();
this.checkIssueCertificate(this.batchId, this.batchDetails);
this.checkEnableDiscussions(this.batchId);
}, (err) => {
this.disableSubmitBtn = false;
if (err.error && err.error.params && err.error.params.errmsg) {
this.toasterService.error(err.error.params.errmsg);
} else {
this.toasterService.error(this.resourceService.messages.fmsg.m0052);
}
});
}
/**
* @since - release-3.2.10
* @param {string} batchId
* @param {Object} batchDetails
* @description - It will emit an event;
*/
checkIssueCertificate(batchId, batchDetails?: any) {
let isCertInBatch = true;
if (batchDetails && _.get(batchDetails, 'cert_templates')) {
isCertInBatch = _.isEmpty(_.get(batchDetails, 'cert_templates')) ? false : true;
}
this.courseBatchService.updateEvent.emit({ event: 'issueCert', value: this.batchUpdateForm.value.issueCertificate,
mode: 'edit', batchId: batchId , isCertInBatch : isCertInBatch});
}
public redirect() {
this.router.navigate(['./'], { relativeTo: this.activatedRoute.parent });
}
private reload() {
setTimeout(() => {
this.courseBatchService.updateEvent.emit({ event: 'update' });
this.router.navigate(['./'], { relativeTo: this.activatedRoute.parent });
}, 1000);
}
private getUserOtherDetail(userData) {
if (userData.maskedEmail && userData.maskedPhone) {
return ' (' + userData.maskedEmail + ', ' + userData.maskedPhone + ')';
}
if (userData.maskedEmail && !userData.maskedPhone) {
return ' (' + userData.maskedEmail + ')';
}
if (!userData.maskedEmail && userData.maskedPhone) {
return ' (' + userData.maskedPhone + ')';
}
}
ngAfterViewInit () {
setTimeout(() => {
this.telemetryImpression = {
context: {
env: this.activatedRoute.snapshot.data.telemetry.env
},
edata: {
type: this.activatedRoute.snapshot.data.telemetry.type,
pageid: this.activatedRoute.snapshot.data.telemetry.pageid,
uri: this.router.url,
duration: this.navigationhelperService.getPageLoadTime()
},
object: {
id: this.activatedRoute.snapshot.params.batchId,
type: this.activatedRoute.snapshot.data.telemetry.object.type,
ver: this.activatedRoute.snapshot.data.telemetry.object.ver,
rollup: {
l1: this.activatedRoute.snapshot.params.courseId,
l2: this.activatedRoute.snapshot.params.batchId
}
}
};
});
}
setTelemetryInteractData() {
this.updateBatchInteractEdata = {
id: 'update-batch',
type: 'click',
pageid: this.activatedRoute.snapshot.data.telemetry.pageid
};
this.clearButtonInteractEdata = {
id: 'clear-button',
type: 'click',
pageid: this.activatedRoute.snapshot.data.telemetry.pageid
};
this.telemetryInteractObject = {
id: this.batchId,
type: this.activatedRoute.snapshot.data.telemetry.object.type,
ver: this.activatedRoute.snapshot.data.telemetry.object.ver
};
}
setTelemetryCData(cdata: []) {
this.telemetryCdata = _.unionBy(this.telemetryCdata, cdata, 'id');
}
ngOnDestroy() {
if (this.updateBatchModal && this.updateBatchModal.deny) {
this.updateBatchModal.deny();
}
this.unsubscribe.next();
this.unsubscribe.complete();
}
resetForm() {
if (this.batchDetails.status === 1) {
this.batchUpdateForm.controls['name'].reset();
this.batchUpdateForm.controls['description'].reset();
this.batchUpdateForm.controls['enrollmentEndDate'].reset();
this.batchUpdateForm.controls['endDate'].reset();
} else {
this.batchUpdateForm.reset();
}
}
getEnabledForumId() {
this.discussionCsService.getForumIds(this.fetchForumIdReq).subscribe(forumDetails => {
this.forumIds = _.map(_.get(forumDetails, 'result'), 'cid');
this.isEnableDiscussions = (this.forumIds && this.forumIds.length > 0) ? 'true' : 'false';
if (this.isEnableDiscussions === 'true') {
this.callCreateDiscussion = false;
}
this.initializeUpdateForm();
}, error => {
this.toasterService.error(this.resourceService.messages.emsg.m0005);
});
}
generateDataForDF() {
this.fetchForumIdReq = {
type: 'batch',
identifier: [this.batchId]
};
}
fetchForumConfig() {
this.fetchForumConfigReq = [{
type: 'batch',
identifier: this.batchId
}];
const subType = 'batch';
this.discussionService.fetchForumConfig(subType).subscribe((formData: any) => {
this.createForumRequest = formData[0];
this.createForumRequest['category']['context'] = this.fetchForumConfigReq;
}, error => {
this.toasterService.error(this.resourceService.messages.emsg.m0005);
});
}
checkEnableDiscussions(batchId) {
if (this.batchUpdateForm.value.enableDiscussions === 'true') {
this.enableDiscussionForum();
} else {
this.disableDiscussionForum(batchId);
}
}
enableDiscussionForum() {
if (this.createForumRequest && this.callCreateDiscussion) {
this.discussionService.createForum(this.createForumRequest).subscribe(resp => {
this.handleInputChange('enable-DF-yes');
this.toasterService.success(_.get(this.resourceService, 'messages.smsg.m0065'));
}, error => {
this.toasterService.error(this.resourceService.messages.emsg.m0005);
});
}
}
disableDiscussionForum(batchId) {
if (this.forumIds && this.forumIds.length > 0) {
const requestBody = {
'sbType': 'batch',
'sbIdentifier': batchId,
'cid': this.forumIds
};
this.discussionService.removeForum(requestBody).subscribe(resp => {
this.handleInputChange('enable-DF-no');
this.toasterService.success(_.get(this.resourceService, 'messages.smsg.m0066'));
}, error => {
this.toasterService.error(this.resourceService.messages.emsg.m0005);
});
}
}
handleInputChange(inputId) {
const telemetryData = {
context: {
env: this.activatedRoute.snapshot.data.telemetry.env,
cdata: [{
id: this.courseId,
type: 'Course'
}, {
id: this.batchId,
type: 'Batch'
}]
},
edata: {
id: inputId,
type: 'click',
pageid: this.activatedRoute.snapshot.data.telemetry.pageid
}
};
this.telemetryService.interact(telemetryData);
}
selectedMultiValues(event, field) {
const selectedValue = event.value;
this.selectedMentors = []
this.selectedParticipants = []
if(selectedValue.length) {
selectedValue.forEach(userID => {
const user = this.mentorList.find(item => item.id === userID)
if (field === 'mentors') {
this.selectedMentors.push(`${user.name}${user.otherDetail}`)
} else {
this.selectedParticipants.push(`${user.name}${user.otherDetail}`)
}
});
}
}
/**
* @param {MatDatepickerInputEvent<Date>} event
* @description - Function to reset the end date picker value on start date change
*/
onStartDateChange(event: MatDatepickerInputEvent<Date>) {
this.pickerMinDateForEndDate = new Date(event.value);
this.batchUpdateForm.controls['endDate'].reset();
}
}
<app-modal-wrapper *ngIf="showUpdateModal"
[config]="{disableClose: false, size: 'normal', panelClass: ['overflow-visible', 'material-modal']}" (dismiss)="redirect()"
#updateBatchModal>
<ng-template sbModalContent>
<div class="sb-mat__modal">
<!--Header-->
<div mat-dialog-title class="mb-0">
<div class="title">
<span *ngIf="!showFormInViewMode">{{resourceService?.frmelmnts?.intxt?.t0007}}</span>
<span *ngIf="showFormInViewMode">{{resourceService?.frmelmnts?.intxt?.t0015}}</span>
</div>
<button aria-label="close dialog" mat-dialog-close class="close-btn"></button>
</div>
<!--Content-->
<div class="sb-mat__modal__content" [appTelemetryImpression]="telemetryImpression">
<form [formGroup]="batchUpdateForm" class="sb-form batchUpdateForm pt-8 px-8">
<div class="sb-color-primary font-weight-bold pb-24">Batch Details</div>
<div class="ui stackable grid">
<div class="eight wide column">
<div class="sb-field-group"
[ngClass]="batchUpdateForm.controls['name'].invalid && batchUpdateForm.controls['name'].errors.required && !batchUpdateForm.controls['name'].pristine ? 'error': ''">
<label class="required">{{resourceService?.frmelmnts?.lbl?.batchname}}</label>
<div class="sb-field">
<input class="sb-form-control" type="text" name="name" formControlName="name"
aria-label="name of batch">
</div>
<div class="mt-0 mb-8 ui pointing red basic label below"
*ngIf="batchUpdateForm.controls.name.invalid && batchUpdateForm.controls['name'].errors.required && !batchUpdateForm.controls['name'].pristine">
{{resourceService?.messages?.stmsg?.m0114}}
</div>
</div>
</div>
<div class="four wide column">
<div>
<label>{{resourceService?.frmelmnts?.cert?.lbl?.issueCertificate}}</label>
<div class="d-flex py-8 flex-w-wrap">
<div class="sb-radio-btn-checkbox sb-radio-btn-primary">
<input (change)="handleInputChange('issue-certificate-yes')" formControlName="issueCertificate"
type="radio" id="yes" value="yes">
<label for="yes">{{resourceService?.frmelmnts?.btn?.yes}}</label>
</div>
<div class="sb-radio-btn-checkbox sb-radio-btn-primary">
<input (change)="handleInputChange('issue-certificate-no')" formControlName="issueCertificate"
type="radio" id="no" value="no">
<label for="no">{{resourceService?.frmelmnts?.btn?.no}}</label>
</div>
</div>
</div>
</div>
</div>
<div class="ui stackable grid">
<div class="eight wide column">
<div class="sb-field-group">
<label>{{resourceService?.frmelmnts?.lbl?.aboutbatch}}</label>
<div class="sb-field">
<textarea class="sb-form-control" rows="4" name="description" formControlName="description"
aria-label="batch description"></textarea>
</div>
</div>
</div>
<div class="four wide column">
<div *ngIf="showDiscussionForum === 'Yes'">
<label>{{resourceService?.frmelmnts?.lbl?.enableDiscussions}}</label>
<div class="d-flex py-8 flex-w-wrap">
<div class="sb-radio-btn-checkbox sb-radio-btn-primary">
<input formControlName="enableDiscussions" type="radio" id="true" value="true">
<label for="true">{{resourceService?.frmelmnts?.btn?.yes}}</label>
</div>
<div class="sb-radio-btn-checkbox sb-radio-btn-primary">
<input formControlName="enableDiscussions" type="radio" id="false" value="false">
<label for="false">{{resourceService?.frmelmnts?.btn?.no}}</label>
</div>
</div>
</div>
<div class="d-flex flex-dc flex-w-wrap" *ngIf="courseCreator">
<div class="mr-8">
<label for="Enrollment Type">{{resourceService?.frmelmnts?.lbl?.natureofbatch}}</label>
</div>
<div class="sb-radio-btn-checkbox sb-radio-btn-primary py-8" *ngIf="courseCreator">
<input id="update-course-open" [attr.disabled]="batchDetails.status !== 0 ? true : null" type="radio"
value='open' name="enrollmentType" formControlName="enrollmentType">
<label for="update-course-open">{{resourceService?.frmelmnts?.lbl?.open}}</label>
</div>
</div>
</div>
</div>
<div class="d-flex flex-w-wrap my-16">
<div class="sb-field-group pr-8"
[ngClass]="batchUpdateForm.controls['startDate'].invalid && batchUpdateForm.controls['startDate'].errors.required && !batchUpdateForm.controls['startDate'].pristine ? 'error': ''">
<label class="required">{{resourceService?.frmelmnts?.lbl?.startdate}}</label>
<div class="ui read-only calendar rangestartAdd" id="rangestartAdd">
<mat-form-field appearance="fill" class="sb-mat__datepicker sb-mat__datepicker--nolabel">
<!-- <mat-label>{{resourceService?.frmelmnts?.lbl?.startdate}}</mat-label> -->
<input [attr.disabled]="(batchDetails.status !== 0 || showFormInViewMode ) ? true : null" matInput
[matDatepicker]="startDatePicker" formControlName="startDate"
[min]='batchDetails.status !== 0 ? batchUpdateForm.controls["startDate"].value : pickerMinDate' (dateChange)="onStartDateChange($event)">
<mat-datepicker-toggle matSuffix [for]="startDatePicker"
[disabled]="(batchDetails.status !== 0 || showFormInViewMode ) ? true : null">
</mat-datepicker-toggle>
<mat-datepicker #startDatePicker></mat-datepicker>
</mat-form-field>
</div>
<div class="mt-0 mb-8 ui pointing red basic label below"
*ngIf="batchUpdateForm.controls.startDate.invalid && batchUpdateForm.controls['startDate'].errors.required && !batchUpdateForm.controls['startDate'].pristine">
{{resourceService?.messages?.stmsg?.m0113}}
</div>
</div>
<div class="sb-field-group">
<label>{{resourceService?.frmelmnts?.lbl?.enddate}}</label>
<div class="ui calendar rangeendAdd" id="rangeendAdd">
<mat-form-field appearance="fill" class="sb-mat__datepicker sb-mat__datepicker--nolabel">
<!-- <mat-label>{{resourceService?.frmelmnts?.lbl?.enddate}}</mat-label> -->
<input [attr.disabled]="(showFormInViewMode) ? true : null" matInput [matDatepicker]="endDatePicker"
formControlName="endDate" [min]='pickerMinDateForEndDate'>
<mat-datepicker-toggle matSuffix [for]="endDatePicker"
[disabled]="(showFormInViewMode) ? true : null"></mat-datepicker-toggle>
<mat-datepicker #endDatePicker></mat-datepicker>
</mat-form-field>
</div>
</div>
<div class="sb-field-group pl-8" *ngIf="batchUpdateForm.value.enrollmentType === 'open'"
[ngClass]="batchUpdateForm.controls['enrollmentEndDate'].invalid && !batchUpdateForm.controls['enrollmentEndDate'].pristine ? 'error': ''">
<label>{{resourceService?.frmelmnts?.lbl?.enrollmentenddate | uppercase}}</label>
<div class="ui read-only calendar rangeenrollMentEnd" id="rangeenrollMentEnd">
<mat-form-field appearance="fill" [ngClass]="{'disabled': !batchUpdateForm.value.startDate}"
class="sb-mat__datepicker sb-mat__datepicker--nolabel">
<!-- <mat-label>{{resourceService?.frmelmnts?.lbl?.startdate}}</mat-label> -->
<input (click)="setTelemetryCData([{id:'course:enrollment:endDate',type:'Feature'},{id:'SB-13073',type:'Task'}])"
matInput [matDatepicker]="enrollmentEndDatePicker" formControlName="enrollmentEndDate"
[min]='pickerMinDateForEnrollmentEndDate' [max]="batchUpdateForm.value.endDate"
aria-label="enrollment End Date">
<mat-datepicker-toggle matSuffix [for]="enrollmentEndDatePicker">
</mat-datepicker-toggle>
<mat-datepicker #enrollmentEndDatePicker></mat-datepicker>
</mat-form-field>
</div>
<div class="mt-0 mb-8 ui pointing red basic label below"
*ngIf="batchUpdateForm.controls['enrollmentEndDate'].invalid && !batchUpdateForm.controls['enrollmentEndDate'].pristine">
{{resourceService?.messages?.stmsg?.m0135}}
</div>
</div>
</div>
<div class="ui tweleve wide column mb-20" *ngIf="showLoader">
<app-loader></app-loader>
</div>
<div class="sb-field-group mb-8">
<label>{{resourceService?.frmelmnts?.lbl?.batchmentors}}</label>
<mat-form-field appearance="fill" class="sb-mat__dropdown w-100 mb-16">
<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] : ''}} </span>
<span *ngIf="selectedMentors?.length >= 2" class="example-additional-selection">
(+{{selectedMentors.length - 1}} {{selectedMentors?.length === 2 ? 'other' : 'others'}})
</span>
</mat-select-trigger>
<mat-option [disabled]="batchDetails.status === 0" 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">
{{mentor.name}}{{mentor.otherDetail}}
</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}}</label>
<mat-form-field appearance="fill" class="sb-mat__dropdown w-100 mb-16">
<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] : ''}} </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]="batchDetails.status === 0" 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="{{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>
</form>
</div>
<!--/Content-->
<!--Actions-->
<div class="sb-mat__modal__actions">
<button class="sb-btn sb-btn-normal sb-btn-outline-primary" tabindex="0" (click)="resetForm()"
[ngClass]="{'sb-btn-disabled': showFormInViewMode}" tabindex="0" appTelemetryInteract
[telemetryInteractObject]="telemetryInteractObject" [telemetryInteractEdata]="clearButtonInteractEdata"
[telemetryInteractCdata]="telemetryCdata">
{{resourceService?.frmelmnts?.btn?.clear}}
</button>
<button class="sb-btn sb-btn-normal sb-btn-primary ml-8"
[ngClass]="{'sb-btn-disabled': disableSubmitBtn || showFormInViewMode}" appTelemetryInteract
[disabled]="disableSubmitBtn || showFormInViewMode" [telemetryInteractObject]="telemetryInteractObject"
[telemetryInteractEdata]="updateBatchInteractEdata" [telemetryInteractCdata]="telemetryCdata" tabindex="0"
tabindex="0" (click)="updateBatch()">
{{resourceService?.frmelmnts?.btn?.update}}
</button>
</div>
<!--/Actions-->
</div>
</ng-template>
</app-modal-wrapper>