@elite.framework/ng.core 1.0.15 → 1.0.17

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.
@@ -3744,16 +3744,6 @@ class GenericSelectorTypeComponent extends FieldType {
3744
3744
  this.injector = injector;
3745
3745
  this.cdr = cdr;
3746
3746
  }
3747
- onSelectionChange(val) {
3748
- this.selectedItem = val;
3749
- const vf = this.to['valueField'] || 'id';
3750
- if (this.to['multiple']) {
3751
- this.formControl.setValue(Array.isArray(val) ? val.map((c) => c[vf]) : []);
3752
- }
3753
- else {
3754
- this.formControl.setValue(val?.[vf] ?? null);
3755
- }
3756
- }
3757
3747
  ngOnInit() {
3758
3748
  this.api = this.svc;
3759
3749
  this.dialog = this.injector.get(DialogService);
@@ -3813,6 +3803,48 @@ class GenericSelectorTypeComponent extends FieldType {
3813
3803
  this.valueChangeSubscription.unsubscribe();
3814
3804
  }
3815
3805
  }
3806
+ loadDefaultValue() {
3807
+ this.loading = true;
3808
+ const vf = this.to['valueField'] || 'id';
3809
+ const fixedFilters = this.to['fixedFilters'] || {};
3810
+ const searchParams = {
3811
+ isDefault: true,
3812
+ ...fixedFilters,
3813
+ };
3814
+ this.api.getList(searchParams)
3815
+ .subscribe({
3816
+ next: (res) => {
3817
+ // Assuming the API returns a list and you want to select the first one
3818
+ if (res && res.items && res.items.length > 0) {
3819
+ if (this.to['multiple']) {
3820
+ this.formControl.setValue(res.items.map((c) => c[vf]));
3821
+ }
3822
+ else {
3823
+ const defaultValue = res.items[0];
3824
+ this.formControl.setValue(defaultValue?.[vf]);
3825
+ }
3826
+ }
3827
+ this.loading = false;
3828
+ // this.initOnlineSelection(); // Proceed with online selection after setting the value
3829
+ },
3830
+ error: (err) => {
3831
+ console.error("Failed to load default value from API:", err);
3832
+ this.loading = false;
3833
+ // this.initOnlineSelection(); // Fallback to local selection if API fails
3834
+ }
3835
+ });
3836
+ }
3837
+ // New method to handle loading the default value from the API
3838
+ onSelectionChange(val) {
3839
+ this.selectedItem = val;
3840
+ const vf = this.to['valueField'] || 'id';
3841
+ if (this.to['multiple']) {
3842
+ this.formControl.setValue(Array.isArray(val) ? val.map((c) => c[vf]) : []);
3843
+ }
3844
+ else {
3845
+ this.formControl.setValue(val?.[vf] ?? null);
3846
+ }
3847
+ }
3816
3848
  initOfflineSelection(withSetValue = true) {
3817
3849
  const val = this.formControl.value;
3818
3850
  const vf = this.to['valueField'] || 'id';
@@ -3843,7 +3875,12 @@ class GenericSelectorTypeComponent extends FieldType {
3843
3875
  const vf = this.to['valueField'] || 'id';
3844
3876
  if (val == null || (Array.isArray(val) && val.length === 0)) {
3845
3877
  this.selectedItem = this.to['multiple'] ? [] : null;
3846
- return;
3878
+ if (this.props['loadDefault'] == true) {
3879
+ this.loadDefaultValue();
3880
+ }
3881
+ else {
3882
+ return;
3883
+ }
3847
3884
  }
3848
3885
  if (this.to['multiple'] && Array.isArray(val) && val.length) {
3849
3886
  const calls = val.map((id) => this.api.get(id));