From 3cff25d7c8e5818fabc5b8d934c158b7f605dde7 Mon Sep 17 00:00:00 2001
From: raghuv45 <raghavendrav444@gmail.com>
Date: Thu, 7 Feb 2019 20:52:47 +0530
Subject: [PATCH] Issue #SB-9932 fix : ability to add mentors for open batches
 (#1404)

---
 .../batch/create-batch/create-batch.component.html |  2 +-
 .../batch/create-batch/create-batch.component.ts   |  2 +-
 .../update-course-batch.component.html             |  4 ++--
 .../update-course-batch.component.ts               | 14 ++++++--------
 .../update-batch/update-batch.component.html       |  4 ++--
 .../update-batch/update-batch.component.ts         | 14 ++++++--------
 6 files changed, 18 insertions(+), 22 deletions(-)

diff --git a/src/app/client/src/app/modules/learn/components/batch/create-batch/create-batch.component.html b/src/app/client/src/app/modules/learn/components/batch/create-batch/create-batch.component.html
index c4540a625c..adf543cf36 100644
--- a/src/app/client/src/app/modules/learn/components/batch/create-batch/create-batch.component.html
+++ b/src/app/client/src/app/modules/learn/components/batch/create-batch/create-batch.component.html
@@ -80,7 +80,7 @@
           </sui-select-option>
         </sui-multi-select>
       </div> -->
-      <div class="one field " *ngIf="createBatchForm.value.enrollmentType !== 'open'">
+      <div class="one field ">
         <label>{{resourceService?.frmelmnts?.lbl?.batchmentors}}</label>
         <div class="createbatchdropdown ui fluid multiple search selection dropdown" id="mentors" ng-class="batch.isUserSearch === 1 ? 'loading' : undefined">
           <input id="mentorSelList">
diff --git a/src/app/client/src/app/modules/learn/components/batch/create-batch/create-batch.component.ts b/src/app/client/src/app/modules/learn/components/batch/create-batch/create-batch.component.ts
index d9a9a6a476..c2feee05ac 100644
--- a/src/app/client/src/app/modules/learn/components/batch/create-batch/create-batch.component.ts
+++ b/src/app/client/src/app/modules/learn/components/batch/create-batch/create-batch.component.ts
@@ -202,9 +202,9 @@ export class CreateBatchComponent implements OnInit, OnDestroy {
     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(',') : [];
-      mentors = $('#mentors').dropdown('get value') ? $('#mentors').dropdown('get value').split(',') : [];
     }
     const startDate = moment(this.createBatchForm.value.startDate).format('YYYY-MM-DD');
     const endDate = this.createBatchForm.value.endDate && moment(this.createBatchForm.value.endDate).format('YYYY-MM-DD');
diff --git a/src/app/client/src/app/modules/learn/components/batch/update-course-batch/update-course-batch.component.html b/src/app/client/src/app/modules/learn/components/batch/update-course-batch/update-course-batch.component.html
index 11274c4b3a..b5a18d8b12 100644
--- a/src/app/client/src/app/modules/learn/components/batch/update-course-batch/update-course-batch.component.html
+++ b/src/app/client/src/app/modules/learn/components/batch/update-course-batch/update-course-batch.component.html
@@ -83,7 +83,7 @@
             </sui-select-option>
           </sui-multi-select>
         </div> -->
-      <div class="one field " *ngIf="batchUpdateForm.value.enrollmentType !== 'open'">
+      <div class="one field ">
         <label>{{resourceService?.frmelmnts?.lbl?.batchmentors}}</label>
         <div class="createbatchdropdown ui fluid multiple search selection dropdown" id="mentors" 
         [ngClass]="{ 'disabled' : showFormInViewMode }">
@@ -97,7 +97,7 @@
           </div>
         </div>
       </div>
-      <div class="one field" *ngIf="batchUpdateForm.value.enrollmentType !== 'open' && selectedMentors.length > 0">
+      <div class="one field" *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}}"> {{selectmentor.name}}{{selectmentor.otherDetail}}
diff --git a/src/app/client/src/app/modules/learn/components/batch/update-course-batch/update-course-batch.component.ts b/src/app/client/src/app/modules/learn/components/batch/update-course-batch/update-course-batch.component.ts
index b6ab40dc66..02f4f12a71 100644
--- a/src/app/client/src/app/modules/learn/components/batch/update-course-batch/update-course-batch.component.ts
+++ b/src/app/client/src/app/modules/learn/components/batch/update-course-batch/update-course-batch.component.ts
@@ -319,9 +319,9 @@ export class UpdateCourseBatchComponent implements OnInit, OnDestroy {
     this.disableSubmitBtn = true;
     let participants = [];
     let mentors = [];
+    mentors = $('#mentors').dropdown('get value') ? $('#mentors').dropdown('get value').split(',') : [];
     if (this.batchUpdateForm.value.enrollmentType !== 'open') {
       participants = $('#participant').dropdown('get value') ? $('#participant').dropdown('get value').split(',') : [];
-      mentors = $('#mentors').dropdown('get value') ? $('#mentors').dropdown('get value').split(',') : [];
     }
     const startDate = moment(this.batchUpdateForm.value.startDate).format('YYYY-MM-DD');
     const endDate = this.batchUpdateForm.value.endDate && moment(this.batchUpdateForm.value.endDate).format('YYYY-MM-DD');
@@ -335,13 +335,11 @@ export class UpdateCourseBatchComponent implements OnInit, OnDestroy {
       createdFor: this.userService.userProfile.organisationIds,
       mentors: _.compact(mentors)
     };
-    if (this.batchUpdateForm.value.enrollmentType !== 'open') {
-      const selected = [];
-      _.forEach(this.selectedMentors, (value) => {
-        selected.push(value.id);
-      });
-      requestBody['mentors'] = _.concat(_.compact(requestBody['mentors']), selected);
-    }
+    const selected = [];
+    _.forEach(this.selectedMentors, (value) => {
+      selected.push(value.id);
+    });
+    requestBody['mentors'] = _.concat(_.compact(requestBody['mentors']), selected);
     this.courseBatchService.updateBatch(requestBody).pipe(takeUntil(this.unsubscribe))
       .subscribe((response) => {
         if (participants && participants.length > 0) {
diff --git a/src/app/client/src/app/modules/workspace/components/update-batch/update-batch.component.html b/src/app/client/src/app/modules/workspace/components/update-batch/update-batch.component.html
index 3bef7be1d7..11f52fabde 100644
--- a/src/app/client/src/app/modules/workspace/components/update-batch/update-batch.component.html
+++ b/src/app/client/src/app/modules/workspace/components/update-batch/update-batch.component.html
@@ -67,7 +67,7 @@
           </div>
         </div>
       </div>
-      <div class="one field " *ngIf="batchUpdateForm.value.enrollmentType !== 'open'">
+      <div class="one field ">
         <label>{{resourceService?.frmelmnts?.lbl?.batchmentors}}</label>
         <div class="createbatchdropdown ui fluid multiple search selection dropdown" id="mentors" [ngClass]="{ 'disabled': batchDetails.status === 2 }">
           <input id="mentorSelList">
@@ -81,7 +81,7 @@
           </div>
         </div>
       </div>
-      <div class="one field" *ngIf="batchUpdateForm.value.enrollmentType !== 'open' && selectedMentors.length > 0">
+      <div class="one field" *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}}">
diff --git a/src/app/client/src/app/modules/workspace/components/update-batch/update-batch.component.ts b/src/app/client/src/app/modules/workspace/components/update-batch/update-batch.component.ts
index 4e0ee7ca3c..8b5bfc83c3 100644
--- a/src/app/client/src/app/modules/workspace/components/update-batch/update-batch.component.ts
+++ b/src/app/client/src/app/modules/workspace/components/update-batch/update-batch.component.ts
@@ -306,9 +306,9 @@ export class UpdateBatchComponent implements OnInit, OnDestroy {
     this.disableSubmitBtn = true;
     let participants = [];
     let mentors = [];
+    mentors = $('#mentors').dropdown('get value') ? $('#mentors').dropdown('get value').split(',') : [];
     if (this.batchUpdateForm.value.enrollmentType !== 'open') {
       participants = $('#participant').dropdown('get value') ? $('#participant').dropdown('get value').split(',') : [];
-      mentors = $('#mentors').dropdown('get value') ? $('#mentors').dropdown('get value').split(',') : [];
     }
     const startDate = moment(this.batchUpdateForm.value.startDate).format('YYYY-MM-DD');
     const endDate = this.batchUpdateForm.value.endDate && moment(this.batchUpdateForm.value.endDate).format('YYYY-MM-DD');
@@ -322,13 +322,11 @@ export class UpdateBatchComponent implements OnInit, OnDestroy {
       createdFor: this.userService.userProfile.organisationIds,
       mentors: _.compact(mentors)
     };
-    if (this.batchUpdateForm.value.enrollmentType !== 'open') {
-      const selected = [];
-      _.forEach(this.selectedMentors, (value) => {
-        selected.push(value.id);
-      });
-      requestBody['mentors'] = _.concat(_.compact(requestBody['mentors']), selected);
-    }
+    const selected = [];
+    _.forEach(this.selectedMentors, (value) => {
+      selected.push(value.id);
+    });
+    requestBody['mentors'] = _.concat(_.compact(requestBody['mentors']), selected);
     this.batchService.updateBatch(requestBody).pipe(takeUntil(this.unsubscribe))
       .subscribe((response) => {
         if (participants && participants.length > 0) {
-- 
GitLab