@fctc/widget-logic 1.8.4 → 1.8.6

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/dist/index.js CHANGED
@@ -6535,33 +6535,21 @@ var import_constants3 = require("@fctc/interface-logic/constants");
6535
6535
  var import_utils6 = require("@fctc/interface-logic/utils");
6536
6536
  var import_moment = __toESM(require_moment());
6537
6537
  var import_react18 = require("react");
6538
-
6539
- // src/provider.ts
6540
- var provider_exports = {};
6541
- __reExport(provider_exports, require("@fctc/interface-logic/provider"));
6542
-
6543
- // src/widget/advance/search/controller.ts
6544
6538
  var searchController = ({
6545
6539
  viewData,
6546
6540
  actionData,
6547
6541
  fieldsList,
6548
- setDomain
6542
+ contextSearch,
6543
+ setSearchMap,
6544
+ searchMap
6549
6545
  }) => {
6550
- const { env } = (0, provider_exports.useEnv)();
6551
- const { context } = actionData || {};
6552
- const actionContext = typeof context === "string" ? (0, import_utils6.evalJSONContext)(context) : context;
6553
- const contextSearch = { ...env.context, ...actionContext };
6554
6546
  const [filterBy, setFilterBy] = (0, import_react18.useState)(null);
6555
6547
  const [searchBy, setSearchBy] = (0, import_react18.useState)(null);
6556
6548
  const [groupBy, setGroupBy] = (0, import_react18.useState)(null);
6557
6549
  const [selectedTags, setSelectedTags] = (0, import_react18.useState)(null);
6558
6550
  const [searchString, setSearchString] = (0, import_react18.useState)("");
6559
- const [searchMap, setSearchMap] = (0, import_react18.useState)({});
6560
- const [isReadyFormatDomain, setIsReadyFormatDomain] = (0, import_react18.useState)(false);
6561
- const [didInit, setDidInit] = (0, import_react18.useState)(false);
6562
6551
  const aid = actionData?.id;
6563
6552
  const model = actionData?.res_model;
6564
- const domainAction = actionData?.domain ? Array.isArray(actionData?.domain) ? [...actionData?.domain] : (0, import_utils6.evalJSONDomain)(actionData?.domain, contextSearch) : [];
6565
6553
  const clearSearch = () => {
6566
6554
  setFilterBy([]);
6567
6555
  setGroupBy([]);
@@ -6643,6 +6631,52 @@ var searchController = ({
6643
6631
  const addSearchItems = (key, newItem) => {
6644
6632
  updateSearchMap({ key, item: newItem });
6645
6633
  };
6634
+ const domainAction = actionData?.domain ? Array.isArray(actionData?.domain) ? [...actionData?.domain] : (0, import_utils6.evalJSONDomain)(actionData?.domain, contextSearch) : [];
6635
+ const formatDomain = () => {
6636
+ if (domainAction) {
6637
+ const domain = [];
6638
+ if (domainAction?.length > 0) {
6639
+ if (Object.keys(searchMap).length > 0) {
6640
+ domain.push("&");
6641
+ }
6642
+ domainAction.forEach((domainItem) => {
6643
+ domain.push(domainItem);
6644
+ });
6645
+ }
6646
+ Object.keys(searchMap).forEach((key, keyIndex, keys) => {
6647
+ if (!key?.includes(import_constants3.SearchType.GROUP)) {
6648
+ if (keys.length > 1 && keyIndex < keys.length - 1) {
6649
+ domain.push("&");
6650
+ }
6651
+ const valuesOfKey = searchMap[key];
6652
+ valuesOfKey.forEach((value, index) => {
6653
+ if (index < valuesOfKey.length - 1) {
6654
+ domain.push("|");
6655
+ }
6656
+ if (value.domain) {
6657
+ domain.push(...value.domain);
6658
+ return;
6659
+ }
6660
+ let valueDomainItem = value?.value;
6661
+ if (value?.modelType === "date") {
6662
+ valueDomainItem = (0, import_utils6.validateAndParseDate)(value?.value);
6663
+ } else if (value?.modelType === "datetime") {
6664
+ if (value?.operator === "<=" || value?.operator === "<") {
6665
+ const parsedDate = (0, import_utils6.validateAndParseDate)(value?.value, true);
6666
+ const hasTime = (0, import_moment.default)(value?.value).format("HH:mm:ss") !== "00:00:00";
6667
+ valueDomainItem = hasTime ? (0, import_moment.default)(parsedDate).format("YYYY-MM-DD HH:mm:ss") : (0, import_moment.default)(parsedDate).add(1, "day").subtract(1, "second").format("YYYY-MM-DD HH:mm:ss");
6668
+ } else {
6669
+ valueDomainItem = (0, import_utils6.validateAndParseDate)(value?.value, true);
6670
+ }
6671
+ }
6672
+ const operator = value?.modelType === "date" || value?.modelType === "datetime" || value?.modelType === "boolean" || value?.modelType === "integer" ? value?.operator ?? "=" : value.operator ?? "ilike";
6673
+ domain.push([value.name, operator, valueDomainItem]);
6674
+ });
6675
+ }
6676
+ });
6677
+ return [...domain];
6678
+ }
6679
+ };
6646
6680
  const setTagSearch = (0, import_react18.useCallback)(
6647
6681
  (updatedMap) => {
6648
6682
  if (!updatedMap) return;
@@ -6671,16 +6705,16 @@ var searchController = ({
6671
6705
  const contexts = [];
6672
6706
  let groupValues = [];
6673
6707
  objValues?.forEach((objValue) => {
6674
- const { context: context2, value, active, groupIndex: groupIndex2, isDefault } = objValue;
6708
+ const { context, value, active, groupIndex: groupIndex2, isDefault } = objValue;
6675
6709
  const indexAppend = groupIndex2 != null ? groupIndex2 : viewData?.views?.search?.filters_by?.length ?? 0;
6676
6710
  contexts.push(
6677
- ...Array.isArray(context2?.group_by) ? context2.group_by.map((item) => ({ group_by: item })) : [context2]
6711
+ ...Array.isArray(context?.group_by) ? context.group_by.map((item) => ({ group_by: item })) : [context]
6678
6712
  );
6679
6713
  groupValues[indexAppend] = {
6680
6714
  contexts: [
6681
- ...Array.isArray(context2?.group_by) ? context2.group_by.map((item) => ({
6715
+ ...Array.isArray(context?.group_by) ? context.group_by.map((item) => ({
6682
6716
  group_by: item
6683
- })) : [context2]
6717
+ })) : [context]
6684
6718
  ],
6685
6719
  strings: isDefault ? [value] : [...groupValues[indexAppend]?.strings ?? [], value]
6686
6720
  };
@@ -6710,51 +6744,6 @@ var searchController = ({
6710
6744
  setSelectedTags(null);
6711
6745
  setTagSearch(searchMap);
6712
6746
  }, [searchMap]);
6713
- const formatDomain = () => {
6714
- if (domainAction) {
6715
- const domain = [];
6716
- if (domainAction?.length > 0) {
6717
- if (Object.keys(searchMap).length > 0) {
6718
- domain.push("&");
6719
- }
6720
- domainAction.forEach((domainItem) => {
6721
- domain.push(domainItem);
6722
- });
6723
- }
6724
- Object.keys(searchMap).forEach((key, keyIndex, keys) => {
6725
- if (!key?.includes(import_constants3.SearchType.GROUP)) {
6726
- if (keys.length > 1 && keyIndex < keys.length - 1) {
6727
- domain.push("&");
6728
- }
6729
- const valuesOfKey = searchMap[key];
6730
- valuesOfKey.forEach((value, index) => {
6731
- if (index < valuesOfKey.length - 1) {
6732
- domain.push("|");
6733
- }
6734
- if (value.domain) {
6735
- domain.push(...value.domain);
6736
- return;
6737
- }
6738
- let valueDomainItem = value?.value;
6739
- if (value?.modelType === "date") {
6740
- valueDomainItem = (0, import_utils6.validateAndParseDate)(value?.value);
6741
- } else if (value?.modelType === "datetime") {
6742
- if (value?.operator === "<=" || value?.operator === "<") {
6743
- const parsedDate = (0, import_utils6.validateAndParseDate)(value?.value, true);
6744
- const hasTime = (0, import_moment.default)(value?.value).format("HH:mm:ss") !== "00:00:00";
6745
- valueDomainItem = hasTime ? (0, import_moment.default)(parsedDate).format("YYYY-MM-DD HH:mm:ss") : (0, import_moment.default)(parsedDate).add(1, "day").subtract(1, "second").format("YYYY-MM-DD HH:mm:ss");
6746
- } else {
6747
- valueDomainItem = (0, import_utils6.validateAndParseDate)(value?.value, true);
6748
- }
6749
- }
6750
- const operator = value?.modelType === "date" || value?.modelType === "datetime" || value?.modelType === "boolean" || value?.modelType === "integer" ? value?.operator ?? "=" : value.operator ?? "ilike";
6751
- domain.push([value.name, operator, valueDomainItem]);
6752
- });
6753
- }
6754
- });
6755
- return [...domain];
6756
- }
6757
- };
6758
6747
  const handleAddTagSearch = (tag) => {
6759
6748
  const {
6760
6749
  domain,
@@ -6762,7 +6751,7 @@ var searchController = ({
6762
6751
  value,
6763
6752
  type,
6764
6753
  title,
6765
- context: context2,
6754
+ context,
6766
6755
  active,
6767
6756
  dataIndex
6768
6757
  } = tag;
@@ -6770,13 +6759,13 @@ var searchController = ({
6770
6759
  if (type === import_constants3.SearchType.FILTER) {
6771
6760
  addSearchItems(`${import_constants3.SearchType.FILTER}_${groupIndex}`, {
6772
6761
  ...tag,
6773
- domain: domain ? domainFormat.toList(context2) : null
6762
+ domain: domain ? domainFormat.toList(context) : null
6774
6763
  });
6775
6764
  } else if (type === import_constants3.SearchType.SEARCH) {
6776
6765
  addSearchItems(`${import_constants3.SearchType.SEARCH}_${String(dataIndex)}`, {
6777
6766
  ...tag,
6778
6767
  domain: domain ? domainFormat.toList({
6779
- ...context2,
6768
+ ...context,
6780
6769
  self: value
6781
6770
  }) : null
6782
6771
  });
@@ -6784,73 +6773,12 @@ var searchController = ({
6784
6773
  addSearchItems(`${import_constants3.SearchType.GROUP}`, {
6785
6774
  ...tag,
6786
6775
  domain: domain ? domainFormat.toList({
6787
- context: context2,
6776
+ context,
6788
6777
  self: value
6789
6778
  }) : null
6790
6779
  });
6791
6780
  }
6792
6781
  };
6793
- (0, import_react18.useEffect)(() => {
6794
- if (isReadyFormatDomain) {
6795
- (0, store_exports.setPage)(0);
6796
- (0, store_exports.setSelectedRowKeys)([]);
6797
- const containSearchFilter = selectedTags?.length > 0 && selectedTags?.find(
6798
- (item) => item?.type === import_constants3.SearchType.FILTER || item?.type === import_constants3.SearchType.SEARCH || item?.type === import_constants3.SearchType.GROUP
6799
- );
6800
- if (containSearchFilter || Array.isArray(selectedTags) && selectedTags?.length === 0) {
6801
- setDomain(formatDomain());
6802
- }
6803
- }
6804
- return () => {
6805
- setDidInit(false);
6806
- setIsReadyFormatDomain(false);
6807
- };
6808
- }, [selectedTags, isReadyFormatDomain]);
6809
- (0, import_react18.useEffect)(() => {
6810
- if (didInit || selectedTags?.length > 0 || !fieldsList || fieldsList?.length === 0)
6811
- return;
6812
- const searchDefaults = Object.entries(actionContext || {}).filter(
6813
- ([key]) => key.startsWith("search_default_")
6814
- );
6815
- const hasGroupBy = viewData?.views?.search?.filters_by?.length > 0;
6816
- if (searchDefaults.length === 0 && !hasGroupBy) {
6817
- setIsReadyFormatDomain(true);
6818
- setDidInit(true);
6819
- return;
6820
- }
6821
- const updatedFilter = filterBy?.map((item) => {
6822
- const matched = searchDefaults.find(
6823
- ([key]) => key.split("search_default_")[1] === item.name
6824
- );
6825
- if (matched && !item.active) {
6826
- handleAddTagSearch?.({
6827
- name: item?.name,
6828
- value: item?.string ?? item?.help,
6829
- domain: item?.domain,
6830
- groupIndex: item?.group_index,
6831
- type: import_constants3.SearchType.FILTER
6832
- });
6833
- return { ...item, active: true };
6834
- }
6835
- return item;
6836
- });
6837
- if (updatedFilter) setFilterBy(updatedFilter);
6838
- if (hasGroupBy) {
6839
- viewData?.views?.search?.filters_by?.forEach((item, idx) => {
6840
- const groupCtx = (0, import_utils6.evalJSONContext)(item?.context);
6841
- handleAddTagSearch?.({
6842
- name: item?.name,
6843
- value: item?.display_name,
6844
- type: import_constants3.SearchType.GROUP,
6845
- context: groupCtx,
6846
- groupIndex: idx,
6847
- isDefault: true
6848
- });
6849
- });
6850
- setDidInit(true);
6851
- }
6852
- setIsReadyFormatDomain(true);
6853
- }, [aid, fieldsList]);
6854
6782
  return {
6855
6783
  groupBy,
6856
6784
  searchBy,
@@ -6864,13 +6792,14 @@ var searchController = ({
6864
6792
  setSelectedTags,
6865
6793
  removeSearchItems,
6866
6794
  onSearchString: onChangeSearchInput,
6867
- handleAddTagSearch
6795
+ handleAddTagSearch,
6796
+ domain: formatDomain()
6868
6797
  };
6869
6798
  };
6870
6799
 
6871
6800
  // src/widget/basic/many2many-field/controller.ts
6872
6801
  var import_environment8 = require("@fctc/interface-logic/environment");
6873
- var import_store13 = require("@fctc/interface-logic/store");
6802
+ var import_store12 = require("@fctc/interface-logic/store");
6874
6803
  var import_utils7 = require("@fctc/interface-logic/utils");
6875
6804
  var many2manyFieldController = (props) => {
6876
6805
  const {
@@ -6880,7 +6809,7 @@ var many2manyFieldController = (props) => {
6880
6809
  tab,
6881
6810
  model,
6882
6811
  aid,
6883
- setSelectedRowKeys: setSelectedRowKeys5,
6812
+ setSelectedRowKeys: setSelectedRowKeys4,
6884
6813
  fields,
6885
6814
  setFields,
6886
6815
  groupByDomain,
@@ -6888,14 +6817,14 @@ var many2manyFieldController = (props) => {
6888
6817
  options,
6889
6818
  sessionStorageUtils
6890
6819
  } = props;
6891
- const appDispatch = (0, import_store13.useAppDispatch)();
6820
+ const appDispatch = (0, import_store12.useAppDispatch)();
6892
6821
  const actionData = sessionStorageUtils.getActionData();
6893
6822
  const [debouncedPage] = useDebounce(page, 500);
6894
6823
  const [order, setOrder] = (0, import_react19.useState)();
6895
6824
  const [isLoadedData, setIsLoadedData] = (0, import_react19.useState)(false);
6896
6825
  const [domainMany2Many, setDomainMany2Many] = (0, import_react19.useState)(domain);
6897
6826
  const env = (0, import_environment8.getEnv)();
6898
- const { selectedTags } = (0, import_store13.useAppSelector)(import_store13.selectSearch);
6827
+ const { selectedTags } = (0, import_store12.useAppSelector)(import_store12.selectSearch);
6899
6828
  const viewParams = {
6900
6829
  model: relation,
6901
6830
  views: [
@@ -6938,8 +6867,8 @@ var many2manyFieldController = (props) => {
6938
6867
  const fetchData = async () => {
6939
6868
  try {
6940
6869
  setDomainMany2Many(domain);
6941
- appDispatch((0, import_store13.setFirstDomain)(domain));
6942
- appDispatch((0, import_store13.setViewDataStore)(viewResponse));
6870
+ appDispatch((0, import_store12.setFirstDomain)(domain));
6871
+ appDispatch((0, import_store12.setViewDataStore)(viewResponse));
6943
6872
  const modalData = viewResponse?.views?.list?.fields.map((field) => ({
6944
6873
  ...viewResponse?.models?.[String(model)]?.[field?.name],
6945
6874
  ...field
@@ -6950,7 +6879,7 @@ var many2manyFieldController = (props) => {
6950
6879
  [`${aid}_${relation}_popupmany2many`]: modalData
6951
6880
  });
6952
6881
  }
6953
- appDispatch((0, import_store13.setPage)(0));
6882
+ appDispatch((0, import_store12.setPage)(0));
6954
6883
  } catch (err) {
6955
6884
  console.log(err);
6956
6885
  }
@@ -6986,13 +6915,13 @@ var many2manyFieldController = (props) => {
6986
6915
  fetchData();
6987
6916
  }
6988
6917
  return () => {
6989
- appDispatch((0, import_store13.setGroupByDomain)(null));
6918
+ appDispatch((0, import_store12.setGroupByDomain)(null));
6990
6919
  setFields((prevFields) => ({
6991
6920
  ...prevFields,
6992
6921
  [`${aid}_${relation}_popupmany2many`]: null
6993
6922
  }));
6994
- appDispatch((0, import_store13.setPage)(0));
6995
- setSelectedRowKeys5([]);
6923
+ appDispatch((0, import_store12.setPage)(0));
6924
+ setSelectedRowKeys4([]);
6996
6925
  setDomainMany2Many(null);
6997
6926
  setIsLoadedData(false);
6998
6927
  };
@@ -7104,7 +7033,7 @@ var many2manyTagsController = (props) => {
7104
7033
  // src/widget/basic/status-bar-field/controller.ts
7105
7034
  var import_react21 = require("react");
7106
7035
  var import_hooks16 = require("@fctc/interface-logic/hooks");
7107
- var import_store14 = require("@fctc/interface-logic/store");
7036
+ var import_store13 = require("@fctc/interface-logic/store");
7108
7037
  var import_utils9 = require("@fctc/interface-logic/utils");
7109
7038
  var durationController = (props) => {
7110
7039
  const {
@@ -7124,7 +7053,7 @@ var durationController = (props) => {
7124
7053
  };
7125
7054
  const [disabled, setDisabled] = (0, import_react21.useState)(false);
7126
7055
  const [modelStatus, setModalStatus] = (0, import_react21.useState)(false);
7127
- const { context } = (0, import_store14.useAppSelector)(import_store14.selectEnv);
7056
+ const { context } = (0, import_store13.useAppSelector)(import_store13.selectEnv);
7128
7057
  const queryKey = [`data-status-duration`, specification];
7129
7058
  const listDataProps = {
7130
7059
  model: relation,
@@ -7787,6 +7716,12 @@ __reExport(constants_exports, require("@fctc/interface-logic/constants"));
7787
7716
  // src/index.ts
7788
7717
  __reExport(index_exports, constants_exports, module.exports);
7789
7718
  __reExport(index_exports, environment_exports, module.exports);
7719
+
7720
+ // src/provider.ts
7721
+ var provider_exports = {};
7722
+ __reExport(provider_exports, require("@fctc/interface-logic/provider"));
7723
+
7724
+ // src/index.ts
7790
7725
  __reExport(index_exports, provider_exports, module.exports);
7791
7726
 
7792
7727
  // src/services.ts