cat-qw-lib 0.43.50 → 0.43.51
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,10 +1381,22 @@ 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
|
}
|
|
1429
1388
|
}
|
|
1389
|
+
ngOnChanges() {
|
|
1390
|
+
this.formStateService.selectIsFormNavigating()
|
|
1391
|
+
.pipe(takeUntil(this.destroy$))
|
|
1392
|
+
.subscribe((res) => {
|
|
1393
|
+
if (res) {
|
|
1394
|
+
console.log("0 unSavedCall", this.initialRecord);
|
|
1395
|
+
console.log("1 unSavedCall", this.initialRecord);
|
|
1396
|
+
this.checkUnsavedChanges();
|
|
1397
|
+
}
|
|
1398
|
+
});
|
|
1399
|
+
}
|
|
1430
1400
|
handleBeforeUnload(event) {
|
|
1431
1401
|
this.formStateService.setIsBrowserEvent(true);
|
|
1432
1402
|
this.formStateService.selectShowBroswerConfirmDialog().subscribe((showConfirmation) => {
|
|
@@ -1436,6 +1406,22 @@ class BaseFormComponent {
|
|
|
1436
1406
|
}
|
|
1437
1407
|
});
|
|
1438
1408
|
}
|
|
1409
|
+
checkUnsavedChanges() {
|
|
1410
|
+
if (!this.initialRecord) {
|
|
1411
|
+
this.initialRecord = JSON.parse(JSON.stringify(this.record)); // Ensure it's assigned
|
|
1412
|
+
console.log("2 initialRecord =>", this.initialRecord);
|
|
1413
|
+
}
|
|
1414
|
+
const hasChanges = JSON.stringify(this.initialRecord) !== JSON.stringify(this.record);
|
|
1415
|
+
const isSaved = this.formStateService.getIsFormSaved(); // Ensure this method exists
|
|
1416
|
+
if (hasChanges && !isSaved) {
|
|
1417
|
+
console.log("3");
|
|
1418
|
+
this.formStateService.setShowConfirmation(true);
|
|
1419
|
+
}
|
|
1420
|
+
else {
|
|
1421
|
+
console.log("4");
|
|
1422
|
+
this.formStateService.setShowConfirmation(false);
|
|
1423
|
+
}
|
|
1424
|
+
}
|
|
1439
1425
|
handleSubmit() {
|
|
1440
1426
|
const validateRecords = this.validatorService
|
|
1441
1427
|
? this.validatorService.handleValidateRecords(this.record)
|
|
@@ -1538,7 +1524,7 @@ class BaseFormComponent {
|
|
|
1538
1524
|
this.formStateService.setIsFormSaved(false);
|
|
1539
1525
|
}
|
|
1540
1526
|
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.0.4", ngImport: i0, type: BaseFormComponent, deps: [{ token: FormStateService }, { token: BaseService }, { token: ValidatorService }, { token: i4$3.Router }, { token: i4$3.ActivatedRoute }, { token: BaseStore }, { token: BaseQuery }], target: i0.ɵɵFactoryTarget.Component });
|
|
1541
|
-
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "19.0.4", type: BaseFormComponent, isStandalone: true, selector: "base-form", outputs: { onSave: "onSave", onFormNavigate: "onFormNavigate", onCancel: "onCancel" }, host: { listeners: { "window:beforeunload": "handleBeforeUnload($event)" } }, providers: [ValidatorService], ngImport: i0, template: "<p>base-form works!</p>\r\n", styles: [""] });
|
|
1527
|
+
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "19.0.4", type: BaseFormComponent, isStandalone: true, selector: "base-form", outputs: { onSave: "onSave", onFormNavigate: "onFormNavigate", onCancel: "onCancel" }, host: { listeners: { "window:beforeunload": "handleBeforeUnload($event)" } }, providers: [ValidatorService], usesOnChanges: true, ngImport: i0, template: "<p>base-form works!</p>\r\n", styles: [""] });
|
|
1542
1528
|
}
|
|
1543
1529
|
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.0.4", ngImport: i0, type: BaseFormComponent, decorators: [{
|
|
1544
1530
|
type: Component,
|