@sunbird-cb/cbp-ai 0.1.50 → 0.1.52

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1200,7 +1200,7 @@ class ApprovalRequestFormComponent {
1200
1200
  request_name: ['', [
1201
1201
  Validators.required,
1202
1202
  Validators.maxLength(100),
1203
- Validators.pattern(/^(?!\s*$)[A-Za-z0-9]+$/)
1203
+ Validators.pattern(/^(?!\s*$)[A-Za-z0-9 ]+$/)
1204
1204
  ]],
1205
1205
  searchmdo: [''],
1206
1206
  });
@@ -1997,8 +1997,10 @@ class EditCbpPlanComponent {
1997
1997
  }));
1998
1998
  // total count may be present in different keys depending on API version.
1999
1999
  // Prefer 'result.result.totalcount' (legacy lower-case) then data.totalCount, then totalCount
2000
- const total = _.get(res, 'result.result.totalcount', _.get(res, 'result.result.data.totalCount', _.get(res, 'result.result.totalCount', 0)));
2001
- this.defaultSearchDesignationCount = total;
2000
+ // const total = _.get(res, 'result.result.totalcount', _.get(res, 'result.result.data.totalCount', _.get(res, 'result.result.totalCount', 0)))
2001
+ // this.defaultSearchDesignationCount = total
2002
+ const total = _.get(res, 'result.result.totalCount', 0);
2003
+ this.defaultSearchDesignationCount = Number(total) || 0;
2002
2004
  // If offset is zero (first page) replace backup, otherwise append + dedupe
2003
2005
  if (!this.masterData['designationBackup'] || reqOffset === 0) {
2004
2006
  this.masterData['designationBackup'] = mapped;
@@ -2016,7 +2018,13 @@ class EditCbpPlanComponent {
2016
2018
  this.noMoreLegacyDesignations = true;
2017
2019
  }
2018
2020
  // Ensure visible list matches the requested display count
2019
- this.masterData['designation'] = (this.masterData['designationBackup'] || []).slice(0, this.designationListLoadCount);
2021
+ this.masterData = {
2022
+ ...this.masterData,
2023
+ designation: [
2024
+ ...(this.masterData['designationBackup'] || [])
2025
+ .slice(0, this.designationListLoadCount)
2026
+ ]
2027
+ };
2020
2028
  // loading flag cleared in finalize()
2021
2029
  this.ensureSelectedDesignationExists();
2022
2030
  this.checkCurrentDesignationPresent();
@@ -2136,45 +2144,50 @@ class EditCbpPlanComponent {
2136
2144
  }, 300);
2137
2145
  }
2138
2146
  onDesignationSelectScroll(event) {
2139
- const panel = event.target;
2140
- const scrollPosition = panel.scrollTop + panel.clientHeight;
2141
- const scrollThreshold = panel.scrollHeight - 50;
2142
- // only trigger near bottom
2143
- if (scrollPosition < scrollThreshold) {
2144
- return;
2145
- }
2146
- // prevent duplicate api calls
2147
- if (this.isLoadingMoreDesignations) {
2147
+ const element = event.target;
2148
+ const atBottom = element.scrollHeight - element.scrollTop <=
2149
+ element.clientHeight + 10;
2150
+ if (!atBottom || this.isLoadingMoreDesignations) {
2148
2151
  return;
2149
2152
  }
2150
- const loadedCount = this.masterData?.designationBackup?.length || 0;
2151
- const visibleCount = this.masterData?.designation?.length || 0;
2152
- console.log('loadedCount', loadedCount, 'visibleCount', visibleCount, 'total', this.defaultSearchDesignationCount);
2153
+ const loaded = this.masterData?.designationBackup?.length || 0;
2154
+ const visible = this.masterData?.designation?.length || 0;
2155
+ console.log({
2156
+ loaded,
2157
+ visible,
2158
+ total: this.defaultSearchDesignationCount
2159
+ });
2153
2160
  /**
2154
2161
  * STEP 1
2155
- * show more from local cache
2162
+ * SHOW MORE FROM LOCAL CACHE
2156
2163
  */
2157
- if (loadedCount > visibleCount) {
2158
- this.isLoadingMoreDesignations = true;
2164
+ if (visible < loaded) {
2165
+ this.designationListLoadCount +=
2166
+ this.designationDefaultLoadCount;
2167
+ // IMPORTANT
2168
+ // create NEW ARRAY reference
2169
+ this.masterData = {
2170
+ ...this.masterData,
2171
+ designation: [
2172
+ ...this.masterData.designationBackup.slice(0, this.designationListLoadCount)
2173
+ ]
2174
+ };
2175
+ // FORCE UI UPDATE
2176
+ this.cdRef.detectChanges();
2177
+ // restore scroll position
2159
2178
  setTimeout(() => {
2160
- this.designationListLoadCount +=
2161
- this.designationDefaultLoadCount;
2162
- this.masterData.designation =
2163
- this.masterData.designationBackup.slice(0, this.designationListLoadCount);
2164
- this.isLoadingMoreDesignations = false;
2165
- }, 200);
2179
+ element.scrollTop = element.scrollTop - 20;
2180
+ });
2166
2181
  return;
2167
2182
  }
2168
2183
  /**
2169
2184
  * STEP 2
2170
- * fetch next page from api
2185
+ * FETCH NEXT PAGE
2171
2186
  */
2172
- if (!this.noMoreLegacyDesignations &&
2173
- loadedCount < this.defaultSearchDesignationCount) {
2174
- this.isLoadingMoreDesignations = true;
2187
+ if (loaded < this.defaultSearchDesignationCount &&
2188
+ !this.noMoreLegacyDesignations) {
2175
2189
  this.designationOffset +=
2176
2190
  this.designationDefaultLoadCount;
2177
- console.log('calling next api page', this.designationOffset);
2178
2191
  this.getDesignation(this.designationSearchText || undefined, this.designationOffset);
2179
2192
  }
2180
2193
  }