cat-qw-lib 0.43.49 → 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.
@@ -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
- .pipe(takeUntil(this.destroy$))
708
- .subscribe((res) => {
709
- if (res) {
710
- this.checkUnsavedChanges();
711
- }
712
- });
713
- this.formStateService.selectIsBrowserEvent()
714
- .pipe(takeUntil(this.destroy$))
715
- .subscribe((res) => {
716
- if (res) {
717
- this.checkUnsavedChanges(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(changes) {
722
- if (changes['store'] && this.store) {
713
+ ngOnChanges() {
714
+ if (this.store) {
723
715
  this.query = new BaseQuery(this.store);
724
716
  }
725
- if (changes['record'] && this.record) {
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,51 +743,34 @@ class BaseControlComponent {
761
743
  getValue() {
762
744
  return this.record[this.attributeModel.name];
763
745
  }
764
- checkUnsavedChanges(isBrowserEvent) {
765
- this.formStateService.selectInitialRecord().subscribe((res) => {
766
- if (res) {
767
- this.sanitizedInitialRecord = this.normalizeRecord(res);
768
- this.sanitizedCurrentRecord = this.normalizeRecord(this.record);
769
- console.log("1 sanitizedInitialRecord", this.sanitizedInitialRecord);
770
- console.log("2 sanitizedCurrentRecord", this.sanitizedCurrentRecord);
771
- }
772
- });
773
- const hasChanges = JSON.stringify(this.sanitizedInitialRecord) !== JSON.stringify(this.sanitizedCurrentRecord);
774
- if (isBrowserEvent && hasChanges) {
775
- this.formStateService.setShowBroswerConfirmDialog(true);
776
- }
777
- else {
778
- this.formStateService.setShowBroswerConfirmDialog(false);
779
- }
780
- this.formStateService.selectIsFormSaved().subscribe((res) => {
781
- if (res) {
782
- this.formStateService.setShowConfirmation(false);
783
- console.log("3 isFormSaved");
784
- }
785
- else {
786
- if (!res && hasChanges) {
787
- console.log("4 not saved but hasChanges");
788
- this.formStateService.setShowConfirmation(true);
789
- }
790
- if (!res && !hasChanges) {
791
- console.log("5 not saved and not hasChanges");
792
- this.formStateService.setShowConfirmation(false);
793
- }
794
- }
795
- });
796
- }
797
- normalizeRecord(record) {
798
- if (!record)
799
- return {};
800
- return Object.keys(record).reduce((acc, key) => {
801
- let value = record[key];
802
- if (value === undefined || value === SHARED.EMPTY) {
803
- value = undefined;
804
- }
805
- acc[key] = value;
806
- return acc;
807
- }, {});
808
- }
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
+ // }
809
774
  ngOnDestroy() {
810
775
  this.destroy$.next();
811
776
  this.destroy$.complete();
@@ -1390,6 +1355,8 @@ class BaseFormComponent {
1390
1355
  onSave = new EventEmitter();
1391
1356
  onFormNavigate = new EventEmitter();
1392
1357
  onCancel = new EventEmitter();
1358
+ sanitizedInitialRecord;
1359
+ sanitizedCurrentRecord;
1393
1360
  constructor(formStateService, service, validatorService, router, activatedRoute, baseStore, baseQuery) {
1394
1361
  this.formStateService = formStateService;
1395
1362
  this.service = service;
@@ -1414,10 +1381,22 @@ class BaseFormComponent {
1414
1381
  this.service.getById(id).subscribe((res) => {
1415
1382
  this.record = JSON.parse(JSON.stringify(res));
1416
1383
  this.baseStore?.setRecordChange(res);
1384
+ this.initialRecord = JSON.parse(JSON.stringify(res));
1417
1385
  this.recordChange.next(res);
1418
1386
  });
1419
1387
  }
1420
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
+ }
1421
1400
  handleBeforeUnload(event) {
1422
1401
  this.formStateService.setIsBrowserEvent(true);
1423
1402
  this.formStateService.selectShowBroswerConfirmDialog().subscribe((showConfirmation) => {
@@ -1427,6 +1406,22 @@ class BaseFormComponent {
1427
1406
  }
1428
1407
  });
1429
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
+ }
1430
1425
  handleSubmit() {
1431
1426
  const validateRecords = this.validatorService
1432
1427
  ? this.validatorService.handleValidateRecords(this.record)
@@ -1529,7 +1524,7 @@ class BaseFormComponent {
1529
1524
  this.formStateService.setIsFormSaved(false);
1530
1525
  }
1531
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 });
1532
- 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: [""] });
1533
1528
  }
1534
1529
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.0.4", ngImport: i0, type: BaseFormComponent, decorators: [{
1535
1530
  type: Component,