cat-qw-lib 0.43.43 → 0.43.46
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 +101 -33
- package/fesm2022/cat-qw-lib.mjs.map +1 -1
- package/lib/shared/_base/base-control/base-control.component.d.ts +5 -2
- package/lib/shared/services/check-unsaved-changes.service.d.ts +12 -0
- package/lib/shared/services/form-state.service.d.ts +7 -0
- package/package.json +1 -1
package/fesm2022/cat-qw-lib.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as i0 from '@angular/core';
|
|
2
|
-
import { EventEmitter, Component, Input, Output, Injectable, ViewChild, ViewEncapsulation, HostListener, Pipe, Directive, NgModule, APP_INITIALIZER } from '@angular/core';
|
|
2
|
+
import { EventEmitter, Component, Input, Output, Injectable, inject, ViewChild, ViewEncapsulation, HostListener, Pipe, Directive, NgModule, APP_INITIALIZER } from '@angular/core';
|
|
3
3
|
import * as i1 from '@angular/common';
|
|
4
4
|
import { CommonModule } from '@angular/common';
|
|
5
5
|
import * as i3$1 from '@angular/forms';
|
|
@@ -23,7 +23,7 @@ import * as i3$2 from 'primeng/checkbox';
|
|
|
23
23
|
import { CheckboxModule } from 'primeng/checkbox';
|
|
24
24
|
import { EntityStore, StoreConfig, QueryEntity } from '@datorama/akita';
|
|
25
25
|
import { __decorate } from 'tslib';
|
|
26
|
-
import { BehaviorSubject, Subject, takeUntil, firstValueFrom, of, tap as tap$1, map, debounceTime, distinctUntilChanged, catchError, Subscription } from 'rxjs';
|
|
26
|
+
import { BehaviorSubject, take, Subject, takeUntil, firstValueFrom, of, tap as tap$1, map, debounceTime, distinctUntilChanged, catchError, Subscription } from 'rxjs';
|
|
27
27
|
import { DragDropModule } from 'primeng/dragdrop';
|
|
28
28
|
import * as i5 from 'primeng/confirmdialog';
|
|
29
29
|
import { ConfirmDialogModule } from 'primeng/confirmdialog';
|
|
@@ -597,20 +597,33 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.0.4", ngImpor
|
|
|
597
597
|
class FormStateService {
|
|
598
598
|
formChangesSubject$;
|
|
599
599
|
isFormNavigating$;
|
|
600
|
+
isBrowserEvent$;
|
|
600
601
|
isShowConfirmation$;
|
|
602
|
+
isShowBrowserConfirmation$;
|
|
601
603
|
initialRecord$;
|
|
602
604
|
constructor() {
|
|
603
605
|
this.formChangesSubject$ = new BehaviorSubject(false);
|
|
604
606
|
this.isFormNavigating$ = new BehaviorSubject(false);
|
|
607
|
+
this.isBrowserEvent$ = new BehaviorSubject(false);
|
|
605
608
|
this.isShowConfirmation$ = new BehaviorSubject(false);
|
|
609
|
+
this.isShowBrowserConfirmation$ = new BehaviorSubject(false);
|
|
606
610
|
this.initialRecord$ = new BehaviorSubject({});
|
|
607
611
|
}
|
|
608
612
|
setIsFormNavigating(isNavigation) {
|
|
609
613
|
this.isFormNavigating$.next(isNavigation);
|
|
610
614
|
}
|
|
615
|
+
setIsBrowserEvent(isNavigation) {
|
|
616
|
+
this.isFormNavigating$.next(isNavigation);
|
|
617
|
+
}
|
|
618
|
+
getIsBrowserEvent() {
|
|
619
|
+
return this.isBrowserEvent$.getValue();
|
|
620
|
+
}
|
|
611
621
|
getIsFormNavigating() {
|
|
612
622
|
return this.isFormNavigating$.getValue();
|
|
613
623
|
}
|
|
624
|
+
selectIsBrowserEvent() {
|
|
625
|
+
return this.isBrowserEvent$.asObservable();
|
|
626
|
+
}
|
|
614
627
|
selectIsFormNavigating() {
|
|
615
628
|
return this.isFormNavigating$.asObservable();
|
|
616
629
|
}
|
|
@@ -635,6 +648,12 @@ class FormStateService {
|
|
|
635
648
|
selectInitialRecord() {
|
|
636
649
|
return this.initialRecord$.asObservable();
|
|
637
650
|
}
|
|
651
|
+
setShowBroswerConfirmDialog(value) {
|
|
652
|
+
return this.isShowBrowserConfirmation$.next(value);
|
|
653
|
+
}
|
|
654
|
+
selectShowBroswerConfirmDialog() {
|
|
655
|
+
return this.isShowBrowserConfirmation$.asObservable();
|
|
656
|
+
}
|
|
638
657
|
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.0.4", ngImport: i0, type: FormStateService, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
|
|
639
658
|
static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "19.0.4", ngImport: i0, type: FormStateService, providedIn: 'root' });
|
|
640
659
|
}
|
|
@@ -645,6 +664,72 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.0.4", ngImpor
|
|
|
645
664
|
}]
|
|
646
665
|
}], ctorParameters: () => [] });
|
|
647
666
|
|
|
667
|
+
class CheckUnsavedChangesService {
|
|
668
|
+
formStateService;
|
|
669
|
+
sanitizedInitialRecord;
|
|
670
|
+
sanitizedCurrentRecord;
|
|
671
|
+
constructor(formStateService) {
|
|
672
|
+
this.formStateService = formStateService;
|
|
673
|
+
}
|
|
674
|
+
// checkUnsavedChanges(initialRecord: any, currentRecord: any, isBrowserEvent?: boolean) {
|
|
675
|
+
// this.sanitizedInitialRecord = this.normalizeRecord(initialRecord);
|
|
676
|
+
// this.sanitizedCurrentRecord = this.normalizeRecord(currentRecord);
|
|
677
|
+
// console.log('1 sanitizedInitialRecord', this.sanitizedInitialRecord);
|
|
678
|
+
// console.log('2 sanitizedCurrentRecord', this.sanitizedCurrentRecord);
|
|
679
|
+
// const hasChanges = JSON.stringify(this.sanitizedInitialRecord) !== JSON.stringify(this.sanitizedCurrentRecord);
|
|
680
|
+
// if (isBrowserEvent && hasChanges) {
|
|
681
|
+
// this.formStateService.setShowBroswerConfirmDialog(true);
|
|
682
|
+
// } else {
|
|
683
|
+
// this.formStateService.setShowBroswerConfirmDialog(false);
|
|
684
|
+
// }
|
|
685
|
+
// this.formStateService.selectIsFormSaved().subscribe((res: boolean) => {
|
|
686
|
+
// if (res) {
|
|
687
|
+
// this.formStateService.setShowConfirmation(false);
|
|
688
|
+
// console.log('3 isFormSaved');
|
|
689
|
+
// } else {
|
|
690
|
+
// console.log(hasChanges ? '4 not saved but hasChanges' : '5 not saved and not hasChanges');
|
|
691
|
+
// this.formStateService.setShowConfirmation(hasChanges);
|
|
692
|
+
// }
|
|
693
|
+
// });
|
|
694
|
+
// }
|
|
695
|
+
// private normalizeRecord(record: any): Record<string, any> {
|
|
696
|
+
// if (!record) return {};
|
|
697
|
+
// return Object.keys(record).reduce((acc, key) => {
|
|
698
|
+
// let value = record[key];
|
|
699
|
+
// acc[key] = value === undefined || value === SHARED.EMPTY ? undefined : value;
|
|
700
|
+
// return acc;
|
|
701
|
+
// }, {} as Record<string, any>);
|
|
702
|
+
// }
|
|
703
|
+
checkUnsavedChanges(initialRecord, currentRecord, isBrowserEvent) {
|
|
704
|
+
const sanitizedInitialRecord = this.normalizeRecord(initialRecord);
|
|
705
|
+
const sanitizedCurrentRecord = this.normalizeRecord(currentRecord);
|
|
706
|
+
console.log('1 sanitizedInitialRecord', sanitizedInitialRecord);
|
|
707
|
+
console.log('2 sanitizedCurrentRecord', sanitizedCurrentRecord);
|
|
708
|
+
const hasChanges = JSON.stringify(sanitizedInitialRecord) !== JSON.stringify(sanitizedCurrentRecord);
|
|
709
|
+
if (isBrowserEvent) {
|
|
710
|
+
console.log("3 for browser event");
|
|
711
|
+
this.formStateService.setShowBroswerConfirmDialog(hasChanges);
|
|
712
|
+
}
|
|
713
|
+
this.formStateService.selectIsFormSaved().pipe(take(1)).subscribe((isFormSaved) => {
|
|
714
|
+
this.formStateService.setShowConfirmation(!isFormSaved && hasChanges);
|
|
715
|
+
console.log(isFormSaved ? '3 isFormSaved' : hasChanges ? '4 not saved but hasChanges' : '5 not saved and not hasChanges');
|
|
716
|
+
});
|
|
717
|
+
}
|
|
718
|
+
normalizeRecord(record) {
|
|
719
|
+
if (!record)
|
|
720
|
+
return {};
|
|
721
|
+
return Object.fromEntries(Object.entries(record).map(([key, value]) => [key, value === undefined || value === SHARED.EMPTY ? undefined : value]));
|
|
722
|
+
}
|
|
723
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.0.4", ngImport: i0, type: CheckUnsavedChangesService, deps: [{ token: FormStateService }], target: i0.ɵɵFactoryTarget.Injectable });
|
|
724
|
+
static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "19.0.4", ngImport: i0, type: CheckUnsavedChangesService, providedIn: 'root' });
|
|
725
|
+
}
|
|
726
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.0.4", ngImport: i0, type: CheckUnsavedChangesService, decorators: [{
|
|
727
|
+
type: Injectable,
|
|
728
|
+
args: [{
|
|
729
|
+
providedIn: 'root'
|
|
730
|
+
}]
|
|
731
|
+
}], ctorParameters: () => [{ type: FormStateService }] });
|
|
732
|
+
|
|
648
733
|
class BaseControlComponent {
|
|
649
734
|
baseStore;
|
|
650
735
|
baseQuery;
|
|
@@ -665,11 +750,14 @@ class BaseControlComponent {
|
|
|
665
750
|
textboxField;
|
|
666
751
|
dropdown;
|
|
667
752
|
textArea;
|
|
753
|
+
unsavedChangesService = inject(CheckUnsavedChangesService);
|
|
668
754
|
initialRecord = {};
|
|
669
755
|
static allAttributes = [];
|
|
670
756
|
query;
|
|
671
757
|
destroy$ = new Subject();
|
|
672
758
|
attributeDestroy$ = new Subject();
|
|
759
|
+
sanitizedInitialRecord;
|
|
760
|
+
sanitizedCurrentRecord;
|
|
673
761
|
ngOnInit() {
|
|
674
762
|
this.addToAttributeList();
|
|
675
763
|
this.baseQuery.getIsFormSubmitted()
|
|
@@ -689,6 +777,13 @@ class BaseControlComponent {
|
|
|
689
777
|
this.checkUnsavedChanges();
|
|
690
778
|
}
|
|
691
779
|
});
|
|
780
|
+
this.formStateService.selectIsBrowserEvent()
|
|
781
|
+
.pipe(takeUntil(this.destroy$))
|
|
782
|
+
.subscribe((res) => {
|
|
783
|
+
if (res) {
|
|
784
|
+
this.checkUnsavedChanges(true);
|
|
785
|
+
}
|
|
786
|
+
});
|
|
692
787
|
}
|
|
693
788
|
ngOnChanges(changes) {
|
|
694
789
|
if (changes['store'] && this.store) {
|
|
@@ -733,40 +828,13 @@ class BaseControlComponent {
|
|
|
733
828
|
getValue() {
|
|
734
829
|
return this.record[this.attributeModel.name];
|
|
735
830
|
}
|
|
736
|
-
checkUnsavedChanges() {
|
|
831
|
+
checkUnsavedChanges(isBrowserEvent) {
|
|
737
832
|
this.formStateService.selectInitialRecord().subscribe((res) => {
|
|
738
833
|
if (res) {
|
|
739
|
-
|
|
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
|
-
});
|
|
834
|
+
this.unsavedChangesService.checkUnsavedChanges(res, this.record, isBrowserEvent);
|
|
755
835
|
}
|
|
756
836
|
});
|
|
757
837
|
}
|
|
758
|
-
normalizeRecord(record) {
|
|
759
|
-
if (!record)
|
|
760
|
-
return {};
|
|
761
|
-
return Object.keys(record).reduce((acc, key) => {
|
|
762
|
-
let value = record[key];
|
|
763
|
-
if (value === undefined || value === SHARED.EMPTY) {
|
|
764
|
-
value = undefined;
|
|
765
|
-
}
|
|
766
|
-
acc[key] = value;
|
|
767
|
-
return acc;
|
|
768
|
-
}, {});
|
|
769
|
-
}
|
|
770
838
|
ngOnDestroy() {
|
|
771
839
|
this.destroy$.next();
|
|
772
840
|
this.destroy$.complete();
|
|
@@ -1380,8 +1448,8 @@ class BaseFormComponent {
|
|
|
1380
1448
|
}
|
|
1381
1449
|
}
|
|
1382
1450
|
handleBeforeUnload(event) {
|
|
1383
|
-
this.formStateService.
|
|
1384
|
-
this.formStateService.
|
|
1451
|
+
this.formStateService.setIsBrowserEvent(true);
|
|
1452
|
+
this.formStateService.selectShowBroswerConfirmDialog().subscribe((showConfirmation) => {
|
|
1385
1453
|
if (showConfirmation) {
|
|
1386
1454
|
event.preventDefault();
|
|
1387
1455
|
event.returnValue = SHARED.BROWSER_WARNING;
|