cat-qw-lib 0.43.50 → 0.43.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.
package/fesm2022/cat-qw-lib.mjs
CHANGED
|
@@ -689,10 +689,9 @@ class BaseControlComponent {
|
|
|
689
689
|
query;
|
|
690
690
|
destroy$ = new Subject();
|
|
691
691
|
attributeDestroy$ = new Subject();
|
|
692
|
-
sanitizedInitialRecord;
|
|
693
|
-
sanitizedCurrentRecord;
|
|
694
692
|
ngOnInit() {
|
|
695
693
|
this.addToAttributeList();
|
|
694
|
+
// this.initialRecord = structuredClone(this.record); // Reset initial state after saving
|
|
696
695
|
this.baseQuery.getIsFormSubmitted()
|
|
697
696
|
.pipe(takeUntil(this.destroy$))
|
|
698
697
|
.subscribe((res) => {
|
|
@@ -703,36 +702,19 @@ class BaseControlComponent {
|
|
|
703
702
|
this.baseStore.setIsFormSubmitted(false);
|
|
704
703
|
}
|
|
705
704
|
});
|
|
706
|
-
this.formStateService.selectIsFormNavigating()
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
});
|
|
713
|
-
this.formStateService.selectIsBrowserEvent()
|
|
714
|
-
.pipe(takeUntil(this.destroy$))
|
|
715
|
-
.subscribe((res) => {
|
|
716
|
-
if (res) {
|
|
717
|
-
this.checkUnsavedChangesforBrowser(true);
|
|
718
|
-
}
|
|
719
|
-
});
|
|
705
|
+
// this.formStateService.selectIsFormNavigating()
|
|
706
|
+
// .pipe(takeUntil(this.destroy$))
|
|
707
|
+
// .subscribe((res) => {
|
|
708
|
+
// if (res) {
|
|
709
|
+
// this.checkUnsavedChanges();
|
|
710
|
+
// }
|
|
711
|
+
// });
|
|
720
712
|
}
|
|
721
|
-
ngOnChanges(
|
|
722
|
-
if (
|
|
713
|
+
ngOnChanges() {
|
|
714
|
+
if (this.store) {
|
|
723
715
|
this.query = new BaseQuery(this.store);
|
|
724
716
|
}
|
|
725
|
-
|
|
726
|
-
console.log('🔄 Updating initialRecord with:', this.record);
|
|
727
|
-
this.setInitialRecord(this.record);
|
|
728
|
-
}
|
|
729
|
-
}
|
|
730
|
-
setInitialRecord(record) {
|
|
731
|
-
if (record) {
|
|
732
|
-
console.log('🔄 Setting Initial Record:', record);
|
|
733
|
-
this.initialRecord = structuredClone(record);
|
|
734
|
-
this.formStateService.setInitialRecord(this.initialRecord);
|
|
735
|
-
}
|
|
717
|
+
// this.initialRecord = structuredClone(this.record);;
|
|
736
718
|
}
|
|
737
719
|
handleModelChange(event, valid, val) {
|
|
738
720
|
if (this.attributeModel?.name) {
|
|
@@ -761,60 +743,34 @@ class BaseControlComponent {
|
|
|
761
743
|
getValue() {
|
|
762
744
|
return this.record[this.attributeModel.name];
|
|
763
745
|
}
|
|
764
|
-
checkUnsavedChanges(
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
this.sanitizedInitialRecord = this.normalizeRecord(res);
|
|
793
|
-
this.sanitizedCurrentRecord = this.normalizeRecord(this.record);
|
|
794
|
-
console.log("1 sanitizedInitialRecord", this.sanitizedInitialRecord);
|
|
795
|
-
console.log("2 sanitizedCurrentRecord", this.sanitizedCurrentRecord);
|
|
796
|
-
}
|
|
797
|
-
});
|
|
798
|
-
const hasChanges = JSON.stringify(this.sanitizedInitialRecord) !== JSON.stringify(this.sanitizedCurrentRecord);
|
|
799
|
-
if (isBrowserEvent && hasChanges) {
|
|
800
|
-
this.formStateService.setShowBroswerConfirmDialog(true);
|
|
801
|
-
}
|
|
802
|
-
else {
|
|
803
|
-
this.formStateService.setShowBroswerConfirmDialog(false);
|
|
804
|
-
}
|
|
805
|
-
}
|
|
806
|
-
normalizeRecord(record) {
|
|
807
|
-
if (!record)
|
|
808
|
-
return {};
|
|
809
|
-
return Object.keys(record).reduce((acc, key) => {
|
|
810
|
-
let value = record[key];
|
|
811
|
-
if (value === undefined || value === SHARED.EMPTY) {
|
|
812
|
-
value = undefined;
|
|
813
|
-
}
|
|
814
|
-
acc[key] = value;
|
|
815
|
-
return acc;
|
|
816
|
-
}, {});
|
|
817
|
-
}
|
|
746
|
+
// checkUnsavedChanges() {
|
|
747
|
+
// const sanitizedInitialRecord = this.normalizeRecord(this.initialRecord);
|
|
748
|
+
// const sanitizedCurrentRecord = this.normalizeRecord(this.record);
|
|
749
|
+
// const hasChanges = JSON.stringify(sanitizedInitialRecord) !== JSON.stringify(sanitizedCurrentRecord);
|
|
750
|
+
// this.formStateService.selectIsFormSaved().subscribe((res: boolean) => {
|
|
751
|
+
// if (res) {
|
|
752
|
+
// this.formStateService.setShowConfirmation(false);
|
|
753
|
+
// } else {
|
|
754
|
+
// if (!res && hasChanges) {
|
|
755
|
+
// this.formStateService.setShowConfirmation(true);
|
|
756
|
+
// }
|
|
757
|
+
// if (!res && !hasChanges) {
|
|
758
|
+
// this.formStateService.setShowConfirmation(false);
|
|
759
|
+
// }
|
|
760
|
+
// }
|
|
761
|
+
// })
|
|
762
|
+
// }
|
|
763
|
+
// private normalizeRecord(record: any): Record<string, any> {
|
|
764
|
+
// if (!record) return {};
|
|
765
|
+
// return Object.keys(record).reduce((acc, key) => {
|
|
766
|
+
// let value = record[key];
|
|
767
|
+
// if (value === undefined || value === SHARED.EMPTY) {
|
|
768
|
+
// value = null;
|
|
769
|
+
// }
|
|
770
|
+
// acc[key] = value;
|
|
771
|
+
// return acc;
|
|
772
|
+
// }, {} as Record<string, any>);
|
|
773
|
+
// }
|
|
818
774
|
ngOnDestroy() {
|
|
819
775
|
this.destroy$.next();
|
|
820
776
|
this.destroy$.complete();
|
|
@@ -1399,6 +1355,8 @@ class BaseFormComponent {
|
|
|
1399
1355
|
onSave = new EventEmitter();
|
|
1400
1356
|
onFormNavigate = new EventEmitter();
|
|
1401
1357
|
onCancel = new EventEmitter();
|
|
1358
|
+
sanitizedInitialRecord;
|
|
1359
|
+
sanitizedCurrentRecord;
|
|
1402
1360
|
constructor(formStateService, service, validatorService, router, activatedRoute, baseStore, baseQuery) {
|
|
1403
1361
|
this.formStateService = formStateService;
|
|
1404
1362
|
this.service = service;
|
|
@@ -1423,9 +1381,19 @@ class BaseFormComponent {
|
|
|
1423
1381
|
this.service.getById(id).subscribe((res) => {
|
|
1424
1382
|
this.record = JSON.parse(JSON.stringify(res));
|
|
1425
1383
|
this.baseStore?.setRecordChange(res);
|
|
1384
|
+
this.initialRecord = JSON.parse(JSON.stringify(res));
|
|
1426
1385
|
this.recordChange.next(res);
|
|
1427
1386
|
});
|
|
1428
1387
|
}
|
|
1388
|
+
this.formStateService.selectIsFormNavigating()
|
|
1389
|
+
.pipe(takeUntil(this.destroy$))
|
|
1390
|
+
.subscribe((res) => {
|
|
1391
|
+
if (res) {
|
|
1392
|
+
console.log("0 unSavedCall", this.initialRecord);
|
|
1393
|
+
console.log("1 unSavedCall", this.initialRecord);
|
|
1394
|
+
this.checkUnsavedChanges();
|
|
1395
|
+
}
|
|
1396
|
+
});
|
|
1429
1397
|
}
|
|
1430
1398
|
handleBeforeUnload(event) {
|
|
1431
1399
|
this.formStateService.setIsBrowserEvent(true);
|
|
@@ -1436,6 +1404,22 @@ class BaseFormComponent {
|
|
|
1436
1404
|
}
|
|
1437
1405
|
});
|
|
1438
1406
|
}
|
|
1407
|
+
checkUnsavedChanges() {
|
|
1408
|
+
if (!this.initialRecord) {
|
|
1409
|
+
this.initialRecord = JSON.parse(JSON.stringify(this.record)); // Ensure it's assigned
|
|
1410
|
+
console.log("2 initialRecord =>", this.initialRecord);
|
|
1411
|
+
}
|
|
1412
|
+
const hasChanges = JSON.stringify(this.initialRecord) !== JSON.stringify(this.record);
|
|
1413
|
+
const isSaved = this.formStateService.getIsFormSaved(); // Ensure this method exists
|
|
1414
|
+
if (hasChanges && !isSaved) {
|
|
1415
|
+
console.log("3");
|
|
1416
|
+
this.formStateService.setShowConfirmation(true);
|
|
1417
|
+
}
|
|
1418
|
+
else {
|
|
1419
|
+
console.log("4");
|
|
1420
|
+
this.formStateService.setShowConfirmation(false);
|
|
1421
|
+
}
|
|
1422
|
+
}
|
|
1439
1423
|
handleSubmit() {
|
|
1440
1424
|
const validateRecords = this.validatorService
|
|
1441
1425
|
? this.validatorService.handleValidateRecords(this.record)
|