cat-qw-lib 0.43.41 → 0.43.43

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.
@@ -598,10 +598,12 @@ class FormStateService {
598
598
  formChangesSubject$;
599
599
  isFormNavigating$;
600
600
  isShowConfirmation$;
601
+ initialRecord$;
601
602
  constructor() {
602
603
  this.formChangesSubject$ = new BehaviorSubject(false);
603
604
  this.isFormNavigating$ = new BehaviorSubject(false);
604
605
  this.isShowConfirmation$ = new BehaviorSubject(false);
606
+ this.initialRecord$ = new BehaviorSubject({});
605
607
  }
606
608
  setIsFormNavigating(isNavigation) {
607
609
  this.isFormNavigating$.next(isNavigation);
@@ -627,6 +629,12 @@ class FormStateService {
627
629
  selectShowConfirmation() {
628
630
  return this.isShowConfirmation$.asObservable();
629
631
  }
632
+ setInitialRecord(value) {
633
+ return this.initialRecord$.next(value);
634
+ }
635
+ selectInitialRecord() {
636
+ return this.initialRecord$.asObservable();
637
+ }
630
638
  static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.0.4", ngImport: i0, type: FormStateService, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
631
639
  static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "19.0.4", ngImport: i0, type: FormStateService, providedIn: 'root' });
632
640
  }
@@ -683,13 +691,19 @@ class BaseControlComponent {
683
691
  });
684
692
  }
685
693
  ngOnChanges(changes) {
686
- if (this.store) {
694
+ if (changes['store'] && this.store) {
687
695
  this.query = new BaseQuery(this.store);
688
696
  }
689
- if (changes['record'] && changes['record'].currentValue) {
690
- // Only update initialRecord when a new record is received from the server
691
- this.initialRecord = structuredClone(changes['record'].currentValue);
692
- console.log("onchange initialRecord=>", this.initialRecord);
697
+ if (changes['record'] && this.record) {
698
+ console.log('🔄 Updating initialRecord with:', this.record);
699
+ this.setInitialRecord(this.record);
700
+ }
701
+ }
702
+ setInitialRecord(record) {
703
+ if (record) {
704
+ console.log('🔄 Setting Initial Record:', record);
705
+ this.initialRecord = structuredClone(record);
706
+ this.formStateService.setInitialRecord(this.initialRecord);
693
707
  }
694
708
  }
695
709
  handleModelChange(event, valid, val) {
@@ -720,26 +734,24 @@ class BaseControlComponent {
720
734
  return this.record[this.attributeModel.name];
721
735
  }
722
736
  checkUnsavedChanges() {
723
- console.log("1=> initialRecord", this.initialRecord);
724
- console.log("2=> Record", this.record);
725
- const sanitizedInitialRecord = this.normalizeRecord(this.initialRecord);
726
- const sanitizedCurrentRecord = this.normalizeRecord(this.record);
727
- console.log("3=> currentRecord", sanitizedCurrentRecord);
728
- console.log("4=> Initial Record", sanitizedInitialRecord);
729
- const hasChanges = JSON.stringify(sanitizedInitialRecord) !== JSON.stringify(sanitizedCurrentRecord);
730
- this.formStateService.selectIsFormSaved().subscribe((res) => {
737
+ this.formStateService.selectInitialRecord().subscribe((res) => {
731
738
  if (res) {
732
- this.formStateService.setShowConfirmation(false);
733
- }
734
- else {
735
- if (!res && hasChanges) {
736
- console.log("hasChange");
737
- this.formStateService.setShowConfirmation(true);
738
- }
739
- if (!res && !hasChanges) {
740
- console.log("No hasChange");
741
- this.formStateService.setShowConfirmation(false);
742
- }
739
+ const sanitizedInitialRecord = this.normalizeRecord(res);
740
+ const sanitizedCurrentRecord = this.normalizeRecord(this.record);
741
+ const hasChanges = JSON.stringify(sanitizedInitialRecord) !== JSON.stringify(sanitizedCurrentRecord);
742
+ this.formStateService.selectIsFormSaved().subscribe((res) => {
743
+ if (res) {
744
+ this.formStateService.setShowConfirmation(false);
745
+ }
746
+ else {
747
+ if (!res && hasChanges) {
748
+ this.formStateService.setShowConfirmation(true);
749
+ }
750
+ if (!res && !hasChanges) {
751
+ this.formStateService.setShowConfirmation(false);
752
+ }
753
+ }
754
+ });
743
755
  }
744
756
  });
745
757
  }
@@ -749,7 +761,7 @@ class BaseControlComponent {
749
761
  return Object.keys(record).reduce((acc, key) => {
750
762
  let value = record[key];
751
763
  if (value === undefined || value === SHARED.EMPTY) {
752
- value = null;
764
+ value = undefined;
753
765
  }
754
766
  acc[key] = value;
755
767
  return acc;