@sunbird-cb/cbp-ai 0.1.89 → 0.1.90

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.
@@ -11376,57 +11376,55 @@ class RoleMappingGenerationComponent {
11376
11376
  }
11377
11377
  getMinistryData() {
11378
11378
  this.apiLoading = true;
11379
- this.sharedService.getMinistryData(this.selectedMinistryType).subscribe((data) => {
11380
- console.log('data--', data);
11381
- this.ministryFullData = data;
11382
- this.apiLoading = false;
11383
- this.ministryData = [];
11384
- if (this.selectedMinistryType === 'ministry') {
11385
- data.forEach((item) => {
11386
- if (item?.sbOrgType === 'ministry') {
11387
- this.ministryData.push(item);
11388
- }
11389
- });
11390
- }
11391
- else if (this.selectedMinistryType === 'state') {
11392
- data.forEach((item) => {
11393
- if (item?.sbOrgType === 'state') {
11394
- this.ministryData.push(item);
11395
- }
11396
- });
11397
- }
11398
- this.getUserProfileData();
11379
+ const requestedType = this.selectedMinistryType;
11380
+ return new Promise((resolve) => {
11381
+ this.sharedService.getMinistryData(requestedType).subscribe((data) => {
11382
+ console.log('data--', data);
11383
+ this.apiLoading = false;
11384
+ // Ignore stale responses from a type that was changed again before this one returned
11385
+ if (requestedType !== this.selectedMinistryType) {
11386
+ resolve();
11387
+ return;
11388
+ }
11389
+ this.ministryFullData = data;
11390
+ this.ministryData = [];
11391
+ if (requestedType === 'ministry') {
11392
+ data.forEach((item) => {
11393
+ if (item?.sbOrgType === 'ministry') {
11394
+ this.ministryData.push(item);
11395
+ }
11396
+ });
11397
+ }
11398
+ else if (requestedType === 'state') {
11399
+ data.forEach((item) => {
11400
+ if (item?.sbOrgType === 'state') {
11401
+ this.ministryData.push(item);
11402
+ }
11403
+ });
11404
+ }
11405
+ this.getUserProfileData(requestedType, resolve);
11406
+ });
11399
11407
  });
11400
11408
  }
11401
11409
  async onMinistryTypeChange(event) {
11402
11410
  console.log('event', event);
11403
- if (this.login) {
11404
- await this.getMinistryData();
11405
- }
11406
11411
  this.sharedService.cbpPlanFinalObj['ministryType'] = event.value;
11407
11412
  this.sharedService.cbpPlanFinalObj['role_mapping_generation'] = [];
11408
11413
  this.selectedMinistryType = event.value;
11409
- localStorage.setItem('cbpPlanFinalObj', JSON.stringify(this.sharedService.cbpPlanFinalObj));
11410
11414
  this.ministryData = [];
11415
+ if (this.login) {
11416
+ await this.getMinistryData();
11417
+ }
11418
+ localStorage.setItem('cbpPlanFinalObj', JSON.stringify(this.sharedService.cbpPlanFinalObj));
11411
11419
  if (event?.value === 'state') {
11412
11420
  this.roleMappingForm.get('ministry')?.setValue(null);
11413
11421
  this.roleMappingForm.get('sectors')?.setValue([]);
11414
11422
  this.roleMappingForm.get('departments')?.setValue([]);
11415
- this.ministryFullData.forEach((item) => {
11416
- if (item?.type === 'state') {
11417
- this.ministryData.push(item);
11418
- }
11419
- });
11420
11423
  }
11421
11424
  else if (event?.value === 'ministry') {
11422
11425
  this.roleMappingForm.get('ministry')?.setValue(null);
11423
11426
  this.roleMappingForm.get('sectors')?.setValue([]);
11424
11427
  this.roleMappingForm.get('departments')?.setValue([]);
11425
- this.ministryFullData.forEach((item) => {
11426
- if (item?.type === 'central') {
11427
- this.ministryData.push(item);
11428
- }
11429
- });
11430
11428
  }
11431
11429
  this.sharedService.cbpPlanFinalObj['ministry'] = '';
11432
11430
  this.sharedService.cbpPlanFinalObj['department_name'] = '';
@@ -11967,20 +11965,26 @@ class RoleMappingGenerationComponent {
11967
11965
  input.value = '';
11968
11966
  }
11969
11967
  }
11970
- getUserProfileData() {
11968
+ getUserProfileData(requestedType, done) {
11971
11969
  this.sharedService.getUserProfile().subscribe((data) => {
11972
11970
  console.log('data--', data);
11973
11971
  localStorage.setItem('userProfile', JSON.stringify(data));
11974
11972
  this.loginUserOrgIds = data?.organization_ids;
11973
+ // Ignore stale responses from a type that was changed again before this one returned
11974
+ if (requestedType && requestedType !== this.selectedMinistryType) {
11975
+ done?.();
11976
+ return;
11977
+ }
11975
11978
  let filteredMinistryData = [];
11976
11979
  this.ministryFullData.map((item) => {
11977
- if (this.loginUserOrgIds.indexOf(item?.identifier) > -1) {
11980
+ if (this.loginUserOrgIds.indexOf(item?.identifier) > -1 && item?.sbOrgType === (requestedType || this.selectedMinistryType)) {
11978
11981
  filteredMinistryData.push(item);
11979
11982
  }
11980
11983
  });
11981
11984
  this.ministryData = filteredMinistryData;
11982
11985
  this.originalMinistryData = filteredMinistryData;
11983
11986
  this.filteredList = filteredMinistryData;
11987
+ done?.();
11984
11988
  });
11985
11989
  }
11986
11990
  onOpened(opened) {
@@ -12057,9 +12061,6 @@ class DeleteRoleMappingComponent {
12057
12061
  this.planData = data;
12058
12062
  }
12059
12063
  deleteRoleMapping() {
12060
- // this.sharedService.deleteRoleMapping(this.planData.id).subscribe(()=>{
12061
- // this.dialogRef.close('saved')
12062
- // })
12063
12064
  this.sharedService.deleteRoleMapping(this.planData.id).subscribe({
12064
12065
  next: () => {
12065
12066
  this.dialogRef.close('saved');
@@ -14374,39 +14375,8 @@ class RoleMappingListComponent {
14374
14375
  });
14375
14376
  dialogRef.afterClosed().subscribe(result => {
14376
14377
  if (result === 'saved') {
14377
- console.log('Changes saved!');
14378
- // Refresh data or show a toast here
14379
- console.log(this.sharedService.cbpPlanFinalObj);
14380
- if (this.sharedService.cbpPlanFinalObj && this.sharedService.cbpPlanFinalObj.ministry && this.sharedService.cbpPlanFinalObj.ministry.identifier &&
14381
- this.sharedService.cbpPlanFinalObj.ministry?.sbOrgType === 'ministry') {
14382
- if (this.sharedService.cbpPlanFinalObj.departments) {
14383
- this.sharedService.getRoleMappingByStateCenterAndDepartment(this.sharedService.cbpPlanFinalObj.ministry.identifier, this.sharedService.cbpPlanFinalObj.departments).subscribe((res) => {
14384
- console.log('res', res);
14385
- this.dataSource = new MatTableDataSource(res);
14386
- this.dataSource.paginator = this.paginator;
14387
- this.originalData = res;
14388
- console.log('this.dataSource', this.dataSource);
14389
- });
14390
- }
14391
- else {
14392
- this.sharedService.getRoleMappingByStateCenter(this.sharedService.cbpPlanFinalObj.ministry.identifier).subscribe((res) => {
14393
- console.log('res', res);
14394
- this.dataSource = new MatTableDataSource(res);
14395
- this.dataSource.paginator = this.paginator;
14396
- this.originalData = res;
14397
- console.log('this.dataSource', this.dataSource);
14398
- });
14399
- }
14400
- }
14401
- else {
14402
- this.sharedService.getRoleMappingByStateCenterAndDepartment(this.sharedService.cbpPlanFinalObj.ministry.identifier, this.sharedService.cbpPlanFinalObj.departments).subscribe((res) => {
14403
- console.log('res', res);
14404
- this.dataSource = new MatTableDataSource(res);
14405
- this.dataSource.paginator = this.paginator;
14406
- this.originalData = res;
14407
- console.log('this.dataSource', this.dataSource);
14408
- });
14409
- }
14378
+ this.selection.clear();
14379
+ this.loadRoleMappingList();
14410
14380
  }
14411
14381
  });
14412
14382
  }