@xuda.io/runtime-bundle 1.0.1384 → 1.0.1385

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.
@@ -3655,6 +3655,36 @@ func.datasource.execute = async function (SESSION_ID, dataSourceSession, IS_DATA
3655
3655
  _dataSourceFilterModelType,
3656
3656
  );
3657
3657
 
3658
+ if (_dataSourceFilterModelType === 'index' && _ds?.progDataSource?.sortModel) {
3659
+ function sortByKeys(array, sortConfig) {
3660
+ return array.sort((a, b) => {
3661
+ for (let config of sortConfig) {
3662
+ const key = config.field_id;
3663
+ const direction = config.sort_dir === 'desc' ? -1 : 1;
3664
+
3665
+ const valA = a.value[key];
3666
+ const valB = b.value[key];
3667
+
3668
+ // Handle numeric comparison
3669
+ if (typeof valA === 'number' && typeof valB === 'number') {
3670
+ if (valA !== valB) {
3671
+ return (valA - valB) * direction;
3672
+ }
3673
+ }
3674
+ // Handle string comparison
3675
+ else if (typeof valA === 'string' && typeof valB === 'string') {
3676
+ if (valA !== valB) {
3677
+ return valA.localeCompare(valB) * direction;
3678
+ }
3679
+ }
3680
+ }
3681
+ return 0;
3682
+ });
3683
+ }
3684
+ const sorted = sortByKeys(_ds.v.raw_data.rows, _ds.progDataSource.sortModel);
3685
+ _ds.v.raw_data.rows = sorted;
3686
+ }
3687
+
3658
3688
  if (_ds?.progDataSource?.dataSourceLimit) {
3659
3689
  const ret_rows_found = await func.db.get_query(SESSION_ID, _ds._dataSourceTableId, _ds.v.couchView, dataSourceSession, _ds.viewSourceDesc, 'datasource table', prog_obj.progDataSource.dataSourceReduce, null, null, true, null, null, null, filterModel, _dataSourceFilterModelType);
3660
3690
  _ds.rows_found = ret_rows_found?.rows?.[0]?.value || 0;
@@ -3673,17 +3703,8 @@ func.datasource.execute = async function (SESSION_ID, dataSourceSession, IS_DATA
3673
3703
  data = [];
3674
3704
  }
3675
3705
 
3676
- // let _KEY = 0;
3677
- // for (const _VAL of data) {
3678
- // _ds.data_feed.rows[_KEY] = { _KEY, _VAL };
3679
- // _KEY++;
3680
- // }
3681
-
3682
3706
  _ds.rows_found = data?.length || 0;
3683
3707
 
3684
- // if (!_ds.v.raw_data) {
3685
- // _ds.v.raw_data = { rows: [] };
3686
- // }
3687
3708
  let _KEY = 0;
3688
3709
  for (const _VAL of data) {
3689
3710
  _ds.v.raw_data.rows.push({ id: _KEY, value: { _KEY, _VAL } });
@@ -3698,13 +3719,7 @@ func.datasource.execute = async function (SESSION_ID, dataSourceSession, IS_DATA
3698
3719
  data = {};
3699
3720
  }
3700
3721
 
3701
- // for (let [_KEY, _VAL] of Object.keys(data)) {
3702
- // _ds.data_feed.rows[_KEY] = { _KEY, _VAL };
3703
- // }
3704
3722
  _ds.rows_found = Object.keys(data)?.length || 0;
3705
- // if (!_ds.v.raw_data) {
3706
- // _ds.v.raw_data = { rows: [] };
3707
- // }
3708
3723
 
3709
3724
  for (let [_KEY, _VAL] of Object.keys(data)) {
3710
3725
  _ds.v.raw_data.rows.push({ id: _KEY, value: { _KEY, _VAL } });
@@ -3719,21 +3734,6 @@ func.datasource.execute = async function (SESSION_ID, dataSourceSession, IS_DATA
3719
3734
  data = '';
3720
3735
  }
3721
3736
 
3722
- // if (!_ds.v.raw_data) {
3723
- // _ds.v.raw_data = { rows: [] };
3724
- // }
3725
-
3726
- // let _KEY = 0;
3727
- // let arr = data.split(",");
3728
- // for (const _VAL of arr) {
3729
- // _ds.data_feed.rows[_KEY] = { _KEY, _VAL };
3730
- // _KEY++;
3731
- // }
3732
- // _ds.rows_found = arr?.length || 0;
3733
- // if (!_ds.v.raw_data) {
3734
- // _ds.v.raw_data = { rows: [] };
3735
- // }
3736
-
3737
3737
  let _KEY = 0;
3738
3738
  let arr = data.split(',');
3739
3739
  for (const _VAL of arr) {
@@ -3656,6 +3656,36 @@ func.datasource.execute = async function (SESSION_ID, dataSourceSession, IS_DATA
3656
3656
  _dataSourceFilterModelType,
3657
3657
  );
3658
3658
 
3659
+ if (_dataSourceFilterModelType === 'index' && _ds?.progDataSource?.sortModel) {
3660
+ function sortByKeys(array, sortConfig) {
3661
+ return array.sort((a, b) => {
3662
+ for (let config of sortConfig) {
3663
+ const key = config.field_id;
3664
+ const direction = config.sort_dir === 'desc' ? -1 : 1;
3665
+
3666
+ const valA = a.value[key];
3667
+ const valB = b.value[key];
3668
+
3669
+ // Handle numeric comparison
3670
+ if (typeof valA === 'number' && typeof valB === 'number') {
3671
+ if (valA !== valB) {
3672
+ return (valA - valB) * direction;
3673
+ }
3674
+ }
3675
+ // Handle string comparison
3676
+ else if (typeof valA === 'string' && typeof valB === 'string') {
3677
+ if (valA !== valB) {
3678
+ return valA.localeCompare(valB) * direction;
3679
+ }
3680
+ }
3681
+ }
3682
+ return 0;
3683
+ });
3684
+ }
3685
+ const sorted = sortByKeys(_ds.v.raw_data.rows, _ds.progDataSource.sortModel);
3686
+ _ds.v.raw_data.rows = sorted;
3687
+ }
3688
+
3659
3689
  if (_ds?.progDataSource?.dataSourceLimit) {
3660
3690
  const ret_rows_found = await func.db.get_query(SESSION_ID, _ds._dataSourceTableId, _ds.v.couchView, dataSourceSession, _ds.viewSourceDesc, 'datasource table', prog_obj.progDataSource.dataSourceReduce, null, null, true, null, null, null, filterModel, _dataSourceFilterModelType);
3661
3691
  _ds.rows_found = ret_rows_found?.rows?.[0]?.value || 0;
@@ -3674,17 +3704,8 @@ func.datasource.execute = async function (SESSION_ID, dataSourceSession, IS_DATA
3674
3704
  data = [];
3675
3705
  }
3676
3706
 
3677
- // let _KEY = 0;
3678
- // for (const _VAL of data) {
3679
- // _ds.data_feed.rows[_KEY] = { _KEY, _VAL };
3680
- // _KEY++;
3681
- // }
3682
-
3683
3707
  _ds.rows_found = data?.length || 0;
3684
3708
 
3685
- // if (!_ds.v.raw_data) {
3686
- // _ds.v.raw_data = { rows: [] };
3687
- // }
3688
3709
  let _KEY = 0;
3689
3710
  for (const _VAL of data) {
3690
3711
  _ds.v.raw_data.rows.push({ id: _KEY, value: { _KEY, _VAL } });
@@ -3699,13 +3720,7 @@ func.datasource.execute = async function (SESSION_ID, dataSourceSession, IS_DATA
3699
3720
  data = {};
3700
3721
  }
3701
3722
 
3702
- // for (let [_KEY, _VAL] of Object.keys(data)) {
3703
- // _ds.data_feed.rows[_KEY] = { _KEY, _VAL };
3704
- // }
3705
3723
  _ds.rows_found = Object.keys(data)?.length || 0;
3706
- // if (!_ds.v.raw_data) {
3707
- // _ds.v.raw_data = { rows: [] };
3708
- // }
3709
3724
 
3710
3725
  for (let [_KEY, _VAL] of Object.keys(data)) {
3711
3726
  _ds.v.raw_data.rows.push({ id: _KEY, value: { _KEY, _VAL } });
@@ -3720,21 +3735,6 @@ func.datasource.execute = async function (SESSION_ID, dataSourceSession, IS_DATA
3720
3735
  data = '';
3721
3736
  }
3722
3737
 
3723
- // if (!_ds.v.raw_data) {
3724
- // _ds.v.raw_data = { rows: [] };
3725
- // }
3726
-
3727
- // let _KEY = 0;
3728
- // let arr = data.split(",");
3729
- // for (const _VAL of arr) {
3730
- // _ds.data_feed.rows[_KEY] = { _KEY, _VAL };
3731
- // _KEY++;
3732
- // }
3733
- // _ds.rows_found = arr?.length || 0;
3734
- // if (!_ds.v.raw_data) {
3735
- // _ds.v.raw_data = { rows: [] };
3736
- // }
3737
-
3738
3738
  let _KEY = 0;
3739
3739
  let arr = data.split(',');
3740
3740
  for (const _VAL of arr) {