@elite.framework/ng.core 1.0.14 → 1.0.16
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.
|
@@ -3729,6 +3729,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.1.4", ngImpor
|
|
|
3729
3729
|
class GenericSelectorTypeComponent extends FieldType {
|
|
3730
3730
|
svc;
|
|
3731
3731
|
injector;
|
|
3732
|
+
cdr;
|
|
3732
3733
|
autoComp;
|
|
3733
3734
|
options_ = [];
|
|
3734
3735
|
selectedItem;
|
|
@@ -3737,20 +3738,11 @@ class GenericSelectorTypeComponent extends FieldType {
|
|
|
3737
3738
|
api;
|
|
3738
3739
|
dialog;
|
|
3739
3740
|
valueChangeSubscription; // Add a subscription to manage the observable
|
|
3740
|
-
constructor(svc, injector) {
|
|
3741
|
+
constructor(svc, injector, cdr) {
|
|
3741
3742
|
super();
|
|
3742
3743
|
this.svc = svc;
|
|
3743
3744
|
this.injector = injector;
|
|
3744
|
-
|
|
3745
|
-
onSelectionChange(val) {
|
|
3746
|
-
this.selectedItem = val;
|
|
3747
|
-
const vf = this.to['valueField'] || 'id';
|
|
3748
|
-
if (this.to['multiple']) {
|
|
3749
|
-
this.formControl.setValue(Array.isArray(val) ? val.map((c) => c[vf]) : []);
|
|
3750
|
-
}
|
|
3751
|
-
else {
|
|
3752
|
-
this.formControl.setValue(val?.[vf] ?? null);
|
|
3753
|
-
}
|
|
3745
|
+
this.cdr = cdr;
|
|
3754
3746
|
}
|
|
3755
3747
|
ngOnInit() {
|
|
3756
3748
|
this.api = this.svc;
|
|
@@ -3811,6 +3803,44 @@ class GenericSelectorTypeComponent extends FieldType {
|
|
|
3811
3803
|
this.valueChangeSubscription.unsubscribe();
|
|
3812
3804
|
}
|
|
3813
3805
|
}
|
|
3806
|
+
loadDefaultValue() {
|
|
3807
|
+
this.loading = true;
|
|
3808
|
+
const defaultFilter = { isDefault: true };
|
|
3809
|
+
const vf = this.to['valueField'] || 'id';
|
|
3810
|
+
this.api.getList(defaultFilter)
|
|
3811
|
+
.subscribe({
|
|
3812
|
+
next: (res) => {
|
|
3813
|
+
// Assuming the API returns a list and you want to select the first one
|
|
3814
|
+
if (res && res.data && res.data.length > 0) {
|
|
3815
|
+
if (this.to['multiple']) {
|
|
3816
|
+
this.formControl.setValue(res.data.map((c) => c[vf]));
|
|
3817
|
+
}
|
|
3818
|
+
else {
|
|
3819
|
+
const defaultValue = res.data[0];
|
|
3820
|
+
this.formControl.setValue(defaultValue?.[vf]);
|
|
3821
|
+
}
|
|
3822
|
+
}
|
|
3823
|
+
this.loading = false;
|
|
3824
|
+
// this.initOnlineSelection(); // Proceed with online selection after setting the value
|
|
3825
|
+
},
|
|
3826
|
+
error: (err) => {
|
|
3827
|
+
console.error("Failed to load default value from API:", err);
|
|
3828
|
+
this.loading = false;
|
|
3829
|
+
// this.initOnlineSelection(); // Fallback to local selection if API fails
|
|
3830
|
+
}
|
|
3831
|
+
});
|
|
3832
|
+
}
|
|
3833
|
+
// New method to handle loading the default value from the API
|
|
3834
|
+
onSelectionChange(val) {
|
|
3835
|
+
this.selectedItem = val;
|
|
3836
|
+
const vf = this.to['valueField'] || 'id';
|
|
3837
|
+
if (this.to['multiple']) {
|
|
3838
|
+
this.formControl.setValue(Array.isArray(val) ? val.map((c) => c[vf]) : []);
|
|
3839
|
+
}
|
|
3840
|
+
else {
|
|
3841
|
+
this.formControl.setValue(val?.[vf] ?? null);
|
|
3842
|
+
}
|
|
3843
|
+
}
|
|
3814
3844
|
initOfflineSelection(withSetValue = true) {
|
|
3815
3845
|
const val = this.formControl.value;
|
|
3816
3846
|
const vf = this.to['valueField'] || 'id';
|
|
@@ -3830,6 +3860,7 @@ class GenericSelectorTypeComponent extends FieldType {
|
|
|
3830
3860
|
else {
|
|
3831
3861
|
if (this.props.change) {
|
|
3832
3862
|
this.props.change(this.field, { item: this.selectedItem });
|
|
3863
|
+
this.cdr.detectChanges();
|
|
3833
3864
|
}
|
|
3834
3865
|
}
|
|
3835
3866
|
}
|
|
@@ -3840,7 +3871,12 @@ class GenericSelectorTypeComponent extends FieldType {
|
|
|
3840
3871
|
const vf = this.to['valueField'] || 'id';
|
|
3841
3872
|
if (val == null || (Array.isArray(val) && val.length === 0)) {
|
|
3842
3873
|
this.selectedItem = this.to['multiple'] ? [] : null;
|
|
3843
|
-
|
|
3874
|
+
if (this.props['loadDefault'] == true) {
|
|
3875
|
+
this.loadDefaultValue();
|
|
3876
|
+
}
|
|
3877
|
+
else {
|
|
3878
|
+
return;
|
|
3879
|
+
}
|
|
3844
3880
|
}
|
|
3845
3881
|
if (this.to['multiple'] && Array.isArray(val) && val.length) {
|
|
3846
3882
|
const calls = val.map((id) => this.api.get(id));
|
|
@@ -3854,6 +3890,7 @@ class GenericSelectorTypeComponent extends FieldType {
|
|
|
3854
3890
|
else {
|
|
3855
3891
|
if (this.props.change) {
|
|
3856
3892
|
this.props.change(this.field, { item: this.selectedItem });
|
|
3893
|
+
this.cdr.detectChanges();
|
|
3857
3894
|
}
|
|
3858
3895
|
}
|
|
3859
3896
|
});
|
|
@@ -3871,6 +3908,7 @@ class GenericSelectorTypeComponent extends FieldType {
|
|
|
3871
3908
|
else {
|
|
3872
3909
|
if (this.props.change) {
|
|
3873
3910
|
this.props.change(this.field, { item: this.selectedItem });
|
|
3911
|
+
this.cdr.detectChanges();
|
|
3874
3912
|
}
|
|
3875
3913
|
}
|
|
3876
3914
|
});
|
|
@@ -3945,7 +3983,7 @@ class GenericSelectorTypeComponent extends FieldType {
|
|
|
3945
3983
|
return Array.isArray(this.selectedItem) &&
|
|
3946
3984
|
this.selectedItem.some((sel) => sel[vf] === item[vf]);
|
|
3947
3985
|
}
|
|
3948
|
-
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.1.4", ngImport: i0, type: GenericSelectorTypeComponent, deps: [{ token: BaseService }, { token: i0.Injector }], target: i0.ɵɵFactoryTarget.Component });
|
|
3986
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.1.4", ngImport: i0, type: GenericSelectorTypeComponent, deps: [{ token: BaseService }, { token: i0.Injector }, { token: i0.ChangeDetectorRef }], target: i0.ɵɵFactoryTarget.Component });
|
|
3949
3987
|
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "20.1.4", type: GenericSelectorTypeComponent, isStandalone: true, selector: "formly-generic-selector", providers: [DialogService, BaseService], viewQueries: [{ propertyName: "autoComp", first: true, predicate: ["autoComp"], descendants: true }], usesInheritance: true, ngImport: i0, template: `
|
|
3950
3988
|
<p-autoComplete
|
|
3951
3989
|
#autoComp
|
|
@@ -4027,7 +4065,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.1.4", ngImpor
|
|
|
4027
4065
|
CheckboxModule
|
|
4028
4066
|
]
|
|
4029
4067
|
}]
|
|
4030
|
-
}], ctorParameters: () => [{ type: BaseService }, { type: i0.Injector }], propDecorators: { autoComp: [{
|
|
4068
|
+
}], ctorParameters: () => [{ type: BaseService }, { type: i0.Injector }, { type: i0.ChangeDetectorRef }], propDecorators: { autoComp: [{
|
|
4031
4069
|
type: ViewChild,
|
|
4032
4070
|
args: ['autoComp']
|
|
4033
4071
|
}] } });
|