@gisce/react-ooui 1.0.10 → 1.0.12
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/react-ooui.umd.js
CHANGED
|
@@ -112,7 +112,7 @@ In order to be iterable, non-array objects must have a [Symbol.iterator]() metho
|
|
|
112
112
|
.ant-progress-text {
|
|
113
113
|
display: none;
|
|
114
114
|
}
|
|
115
|
-
`,booleanComponentFn=e=>jsxRuntime.jsx("div",{style:{display:"flex",justifyContent:"center",alignContent:"center"},children:jsxRuntime.jsx(antd.Checkbox,{checked:e,disabled:!0})}),many2OneComponentFn=e=>e?jsxRuntime.jsxs(antd.Space,{children:[jsxRuntime.jsx(jsxRuntime.Fragment,{children:e.value}),jsxRuntime.jsx(Many2oneSuffix,{id:e.id,model:e.model})]}):jsxRuntime.jsx(jsxRuntime.Fragment,{}),textComponentFn=e=>jsxRuntime.jsx("div",{style:{whiteSpace:"pre-line"},children:e}),one2ManyComponentFn=e=>{const n=Array.isArray(e==null?void 0:e.items)?e==null?void 0:e.items.length:0;return jsxRuntime.jsx(jsxRuntime.Fragment,{children:`( ${n} )`})},progressBarComponentFn=e=>jsxRuntime.jsx(ProgressBarInput,{value:e}),floatTimeComponent=e=>jsxRuntime.jsx(jsxRuntime.Fragment,{children:parseFloatToString(e)}),numberComponent=e=>jsxRuntime.jsx("div",{style:{textAlign:"right"},children:e}),imageComponent=e=>jsxRuntime.jsx("img",{src:`data:image/*;base64,${e}`,style:{maxWidth:"50px",padding:"5px"}});function Tree(e){const{page:n=1,limit:t,total:o,treeView:r,results:a,onRequestPageChange:s,loading:l,onRowClicked:c,showPagination:u=!0,rowSelection:d,scrollY:f,colorsForResults:m={},onChangeSort:p,sorter:I,onFetchChildrenForRecord:v,childField:C}=e,[g,h]=React.useState([]),[y,x]=React.useState([]),w=React.useRef(!1),O=React.useRef(null),{t:_}=React.useContext(LocaleContext);React.useEffect(()=>{O.current=getTree(r);const j=getTableColumns(O.current,{boolean:booleanComponentFn,many2one:many2OneComponentFn,text:textComponentFn,one2many:one2ManyComponentFn,many2many:one2ManyComponentFn,progressbar:progressBarComponentFn,float_time:floatTimeComponent,image:imageComponent,integer:numberComponent,float:numberComponent});x(j)},[r]),React.useEffect(()=>{w.current=!1;const j=getTableItems(O.current,a);h(j)},[a]);const b=(n-1)*t+1,T=b-1+g.length,F=o?o===0?_("no_results"):_("summary").replace("{from}",b==null?void 0:b.toString()).replace("{to}",T==null?void 0:T.toString()).replace("{total}",o==null?void 0:o.toString()):null,k=()=>!u||r.isExpandable||l?null:o?jsxRuntime.jsxs(antd.Row,{align:"bottom",className:"pb-4",children:[jsxRuntime.jsx(antd.Col,{span:12,children:jsxRuntime.jsx(antd.Pagination,{total:o,pageSize:t,current:n,showSizeChanger:!1,onChange:s})}),jsxRuntime.jsx(antd.Col,{span:12,className:"text-right",children:F})]}):jsxRuntime.jsx(antd.Spin,{});function L(){var H;const q=O.current.columns.filter(K=>K.sum!==void 0).map(K=>({label:K.sum,field:K.id}));if(!q||q.length===0)return null;let $=[],B=((H=d==null?void 0:d.selectedRowKeys)==null?void 0:H.length)>0?g.filter(K=>d==null?void 0:d.selectedRowKeys.includes(K.id)):g;return q.forEach(K=>{const G=B.reduce((z,V)=>V[K.field]&&!isNaN(V[K.field])?z+V[K.field]:z,0);$.push(`${K.label}: ${Math.round(G*100)/100}`)}),jsxRuntime.jsx("div",{className:"p-1 pb-0 pl-2 mt-2 bg-gray-50",children:$.join(", ")})}let M,P=f;if(O.current!==null){M=calculateColumnsWidth(y,g,600);const q=O.current;f&&q.columns.some($=>$.sum!==void 0)&&(P=f-30)}return O.current===null?jsxRuntime.jsx(antd.Spin,{style:{padding:"2rem"}}):jsxRuntime.jsxs("div",{children:[k(),jsxRuntime.jsx(reactFormigaTable.Table,{height:P,columns:M.columns,dataSource:g,loading:l,loadingComponent:jsxRuntime.jsx(antd.Spin,{}),onRowStyle:j=>{if(m[j.id])return{color:m[j.id]}},onRowDoubleClick:c,onRowSelectionChange:d==null?void 0:d.onChange,onChangeSort:p,sorter:I,expandableOpts:v?{expandIcon:Icon.PlusSquareOutlined,collapseIcon:Icon.MinusSquareOutlined,loadingIcon:Icon.LoadingOutlined,onFetchChildrenForRecord:v,childField:C}:void 0}),L()]})}const DEFAULT_SEARCH_LIMIT$1=80;function SearchTree(e,n){const{action:t,model:o,formView:r,treeView:a,onRowClicked:s,nameSearch:l,treeScrollY:c,domain:u=[],visible:d=!0,rootTree:f=!1,parentContext:m={},onChangeSelectedRowKeys:p}=e,[I,v]=React.useState(!1),[C,g]=React.useState(!1),h=React.useRef(!1),y=React.useRef(80),[x,w]=React.useState(),[O,_]=React.useState(),[b,T]=React.useState(),[F,k]=React.useState(1),[L,M]=React.useState(0),[P,j]=React.useState(DEFAULT_SEARCH_LIMIT$1),[q,$]=React.useState(),B=React.useRef([]),[H,K]=React.useState(),[G,z]=React.useState([]),[V,U]=React.useState(void 0),[Y,D]=React.useState(!1),[A,N]=React.useState(),[Z,Q]=React.useState(),[E,S]=React.useState(!1),W=React.useRef([]),[X,te]=React.useState(200),ee=React.useRef([]),re=React.useRef(),{height:ce}=useWindowDimensions(),ue=React.useContext(ActionViewContext),{setResults:se=void 0,setCurrentItemIndex:fe=void 0,currentId:ge=void 0,results:_e=void 0,selectedRowItems:Ie=void 0,setSelectedRowItems:Re=void 0,setSearchParams:ye=void 0,searchVisible:Fe=!0,setSearchVisible:xe=void 0,sorter:Ee=void 0,setSorter:ie=void 0,setTotalItems:de=void 0,setSearchTreeNameSearch:me=void 0,setTreeIsLoading:oe=void 0}=(f?ue:{})||{},he=React.useContext(ContentRootContext),{processAction:Ce}=he||{};React.useImperativeHandle(n,()=>({refreshResults:()=>{h.current=!1,Ne()}}));const be=le=>{S(!0),k(le),M((le-1)*P)};function Te(le){se==null||se([...le]),z([...le])}const Se=React.useCallback(()=>_e||G,[_e,G]),Ae=async()=>{const le=await ConnectionProvider.getHandler().nameSearch({model:x,payload:l,limit:y.current,attrs:W.current.length>0?W.current:u,context:m});if(K(le.length),de==null||de(le.length),le.length>0){const ve=le.map(pe=>pe==null?void 0:pe[0]),{colors:we}=getTree(O),ke=await ConnectionProvider.getHandler().readEvalUiObjects({model:x,ids:ve,arch:O==null?void 0:O.arch,fields:O.field_parent?{...O.fields,[O.field_parent]:{}}:O.fields,context:m,attrs:we&&{colors:we}}),J=ke[0];ee.current=[...J],U(getColorMap(ke[1]));const ne=J.map(pe=>pe.id),ae=Ee!==void 0?sortResults({resultsToSort:J,sorter:Ee,fields:{...O.fields,...b.fields}}):[...ee.current];Te(ae),ne.length>0?fe==null||fe(0):fe==null||fe(void 0)}else Te([]),fe==null||fe(void 0);h.current=!0},je=le=>{const ve={};return le.forEach(we=>{Array.isArray(we)&&we[0]?ve[we[0]]=!0:ve[we]=!0}),Object.keys(ve)},Le=(le,ve)=>{const we=le,ke=je(le);return ve.forEach(J=>{Array.isArray(J)&&J[0]?ke.includes(J[0])||we.push(J):ke.includes(J)||we.push(J)}),we},Me=async()=>{const le=W.current.length>0?W.current:u,ve=Le(B.current,le),{colors:we}=getTree(O),{totalItems:ke,results:J,attrsEvaluated:ne}=await ConnectionProvider.getHandler().searchForTree({params:ve,limit:P,offset:L,model:x,fields:O.field_parent?{...O.fields,[O.field_parent]:{}}:O.fields,context:m,attrs:we&&{colors:we}});U(getColorMap(ne)),ee.current=[...J];const ae=Ee!==void 0?sortResults({resultsToSort:J,sorter:Ee,fields:{...O.fields,...b.fields}}):[...ee.current];if(ke.then(pe=>{K(pe),de==null||de(pe)}),Te(ae),_e&&ae.length>0){const pe=ae.findIndex(Oe=>ge===Oe.id);pe===-1?fe==null||fe(0):fe==null||fe(pe)}else fe==null||fe(void 0)},Ne=async()=>{try{S(!0),oe==null||oe(!0),l&&!h.current?await Ae():await Me()}catch(le){N(le)}finally{S(!1),D(!1),oe==null||oe(!1)}};async function He(le){const ve=le[(O==null?void 0:O.field_parent)||"child_id"],we=await ConnectionProvider.getHandler().readObjects({model:x,ids:ve,fields:O.field_parent?{...O.fields,[O.field_parent]:{}}:O.fields,context:m});return Te([...Se(),...we]),getTableItems(getTree(O),we)}React.useEffect(()=>{!C||d&&(h.current=!1,Ne())},[F,P,L,C,d,l]);const Ue=async le=>{g(!1),v(!0),Q(void 0),oe==null||oe(!0);try{le==="action"?await De():await Be(),g(!0)}catch(ve){Q(ve)}finally{v(!1),oe==null||oe(!1)}},De=async()=>{const le=await ConnectionProvider.getHandler().getViewsForAction({action:t,context:m});W.current=le.domain,T(le.views.get("form")),_(le.views.get("tree")),w(le.model),$(le.limit),j(le.limit)},Be=async()=>{w(o);let le=r;r||(le=await ConnectionProvider.getHandler().getView({model:o,type:"form",context:m}));let ve=a;a||(ve=await ConnectionProvider.getHandler().getView({model:o,type:"tree",context:m})),T(le),_(ve),$(void 0),j(DEFAULT_SEARCH_LIMIT$1)};React.useEffect(()=>{t?Ue("action"):o&&Ue("model")},[t,o]);const $e=()=>{E||(me==null||me(void 0),B.current=[],ye==null||ye([]),N(void 0),M(0),k(1),j(q||DEFAULT_SEARCH_LIMIT$1))},We=({params:le,limit:ve,offset:we})=>{E||(B.current=le,me==null||me(void 0),Re==null||Re([]),ye==null||ye(le),xe==null||xe(!1),D(!0),N(void 0),k(1),ve&&j(ve),we&&M(we),Ne())},ze=le=>{y.current=le},Ge=async le=>{const{id:ve}=le;re.current||(re.current=await ConnectionProvider.getHandler().treeButOpen({id:O.view_id,model:x,context:m}));const we=re.current[0][2];await(Ce==null?void 0:Ce({actionData:we,fields:O.fields,values:{active_id:ve,...le},context:m}))},Ye=async le=>{const{id:ve}=le;if(O!=null&&O.isExpandable){try{await Ge(le)}catch(we){showDialog$8(we)}return}s({id:ve,model:x,formView:b,treeView:O})};function Ke(le){const ve=Se().filter(we=>le.includes(we.id));Re==null||Re(ve),p==null||p(le)}function Ze(){return O!=null&&O.isExpandable?ce-160:ce-(X+210)}const Ve=()=>!O||!b?null:jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx(Measure__default.default,{bounds:!0,onResize:le=>{var ve;te((ve=le.bounds)==null?void 0:ve.height)},children:({measureRef:le})=>jsxRuntime.jsx("div",{ref:le,children:jsxRuntime.jsxs("div",{style:{display:Fe?"block":"none"},children:[jsxRuntime.jsx(SearchFilter,{fields:{...O.fields,...b.fields},searchFields:mergeSearchFields([b.search_fields,O.search_fields]),onClear:$e,limit:P,offset:L,isSearching:Y,onSubmit:We,onLimitChange:ze}),A&&jsxRuntime.jsx(antd.Alert,{className:"mt-10",message:A,type:"error",banner:!0}),jsxRuntime.jsx("div",{className:"pb-5"})]})})}),jsxRuntime.jsx(Tree,{total:H,limit:P,page:F,treeView:O,results:Se(),onRequestPageChange:be,loading:E,onRowClicked:Ye,scrollY:c||Ze(),colorsForResults:V,rowSelection:{selectedRowKeys:Ie==null?void 0:Ie.map(le=>le.id),onChange:Ke},sorter:Ee,onChangeSort:le=>{ie==null||ie(le);const ve=le!==void 0?sortResults({resultsToSort:Se(),sorter:le,fields:{...O.fields,...b.fields}}):[...ee.current];Te(ve)},onFetchChildrenForRecord:O.isExpandable?He:void 0,childField:O.field_parent})]});return Z?jsxRuntime.jsx(antd.Alert,{className:"mt-10",message:Z,type:"error",banner:!0}):jsxRuntime.jsx("div",{style:d?{}:{display:"none"},children:I?jsxRuntime.jsx(antd.Spin,{}):Ve()})}const SearchTree$1=React.forwardRef(SearchTree),SearchModal=e=>{const{visible:n,onCloseModal:t,onSelectValues:o,model:r,nameSearch:a,domain:s,context:l={}}=e,[c,u]=React.useState(!1),{modalWidth:d,modalHeight:f}=useWindowDimensions(),{t:m}=React.useContext(LocaleContext),[p,I]=React.useState([]),v=async()=>{await new Promise(y=>setTimeout(y,5)),t()},C=async y=>{const{id:x}=y;o([x])};function g(){if(p.length===0){v();return}o(p)}const h=()=>jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx(SearchTree$1,{model:r,nameSearch:a,onRowClicked:C,treeScrollY:f*.3,domain:s,parentContext:l,onChangeSelectedRowKeys:y=>{I(y)}}),jsxRuntime.jsx(antd.Divider,{}),jsxRuntime.jsx(antd.Row,{justify:"end",children:jsxRuntime.jsxs(antd.Space,{children:[jsxRuntime.jsx(antd.Button,{icon:jsxRuntime.jsx(Icon.FileAddOutlined,{}),onClick:()=>{u(!0)},children:m("new")}),jsxRuntime.jsx(antd.Button,{icon:jsxRuntime.jsx(Icon.CheckOutlined,{}),onClick:()=>{g()},type:"primary",children:m("ok")}),jsxRuntime.jsx(antd.Button,{icon:jsxRuntime.jsx(Icon.CloseOutlined,{}),onClick:v,children:m("cancel")})]})})]});return jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx(antd.Modal,{title:m("search"),centered:!0,width:d,visible:n&&!c,closable:!0,onCancel:v,footer:null,destroyOnClose:!0,maskClosable:!1,children:h()}),jsxRuntime.jsx(FormModal,{model:r,visible:c,parentContext:l,onSubmitSucceed:y=>{u(!1),v(),o([y])},onCancel:()=>{u(!1),v()}})]})},{error}=antd.Modal,showDialog$3=e=>{error({title:"Error",icon:jsxRuntime.jsx(Icon.ExclamationCircleOutlined,{}),centered:!0,content:e})},Many2one=e=>{const{ooui:n}=e,{required:t}=n,o=async(r,a)=>{if(!a)throw new Error;if(!Array.isArray(a))throw new Error;if(Array.isArray(a)&&!a[0])throw new Error};return jsxRuntime.jsx(Field$1,{required:t,type:"array",validator:o,...e,children:jsxRuntime.jsx(Many2oneInput,{ooui:n})})},Many2oneInput=e=>{const{value:n,onChange:t,ooui:o}=e,{required:r,relation:a,readOnly:s,context:l,id:c,domain:u}=o,d=r&&!s?Config.requiredClass:void 0,[f,m]=React.useState(!1),[p,I]=React.useState(!1),[v,C]=React.useState(!1),[g,h]=React.useState(),y=React.useRef(!1),[x,w]=React.useState(""),O=React.useRef(),_=React.useContext(FormContext$1),{domain:b,getValues:T,getFields:F,getContext:k,setOriginalValue:L,elementHasLostFocus:M}=_||{},P=React.useRef([]),[j,q]=React.useState([]),$=n&&n[0],B=n&&n[1]||"";React.useEffect(()=>{!Array.isArray(n)&&!isNaN(n)&&V(n)},[n]),React.useEffect(()=>{$&&B.length===0?V($):$&&B.length>0?w(B):!$&&!B&&w(O.current||"")},[n]);const H=A=>{t==null||t(A),M==null||M()},K=A=>{O.current=A.target.value,H([void 0,""])},G=async()=>{if(!v&&x!==B){if(await new Promise(A=>setTimeout(A,100)),y.current){H([void 0,""]);return}C(!0);try{if(P.current&&P.current.length>0)z(O.current);else{const A=await ConnectionProvider.getHandler().nameSearch({model:a,payload:O.current,context:{...k==null?void 0:k(),...l}});A.length===1?(O.current=void 0,H(A[0])):z(O.current)}}catch(A){showDialog$3(A)}finally{C(!1)}}},z=async A=>{if(await U(),P.current&&P.current.length>0){const N=await ConnectionProvider.getHandler().searchAllIds({params:P.current,model:a,context:{...k==null?void 0:k(),...l},totalItems:2});N.length===1?V(N[0],!0):(h(A),m(!0));return}h(A),m(!0)},V=async(A,N)=>{C(!0);try{const Z=await ConnectionProvider.getHandler().execute({action:"name_get",payload:[A],model:a,context:{...k==null?void 0:k(),...l}});H([A,Z[0][1]]),N&&L(o.id,[A,Z[0][1]])}catch(Z){showDialog$3(Z)}finally{C(!1)}};async function U(){u&&(P.current=await ConnectionProvider.getHandler().evalDomain({domain:u,values:transformPlainMany2Ones({fields:F(),values:T()}),context:k()})),b&&b.length>0&&(P.current=P.current.concat(ooui.transformDomainForChildWidget({domain:b,widgetFieldName:c}))),q(P.current)}async function Y(A){A.code==="Enter"?(A.preventDefault(),A.stopPropagation(),await G()):A.code==="Backspace"&&$!==void 0&&(A.preventDefault(),A.stopPropagation(),H([void 0,""]))}const D=r&&!s?RequiredInput:antd.Input;return jsxRuntime.jsxs(antd.Row,{gutter:8,wrap:!1,children:[jsxRuntime.jsx(antd.Col,{flex:"auto",children:jsxRuntime.jsx(D,{type:"text",value:x,disabled:s,onChange:K,className:d,onBlur:G,onKeyDown:Y,suffix:jsxRuntime.jsx(Many2oneSuffix,{id:$,model:a,context:{...k==null?void 0:k(),...l}})})}),jsxRuntime.jsx(antd.Col,{flex:"32px",children:jsxRuntime.jsx(antd.Button,{icon:jsxRuntime.jsx(Icon.FolderOpenOutlined,{}),disabled:$===void 0||B===""||x===void 0,onClick:()=>{I(!0)},tabIndex:-1})}),jsxRuntime.jsx(antd.Col,{flex:"32px",children:jsxRuntime.jsx(antd.Button,{icon:v?jsxRuntime.jsx(Icon.LoadingOutlined,{}):jsxRuntime.jsx(Icon.SearchOutlined,{}),disabled:s||v,onClick:()=>{y.current=!0,z(B)},tabIndex:-1})}),jsxRuntime.jsx(SearchModal,{model:a,domain:j,context:{...k==null?void 0:k(),...l},visible:f,nameSearch:$?void 0:g,onSelectValues:A=>{m(!1),V(A[0]),y.current=!1,O.current=void 0},onCloseModal:()=>{m(!1),y.current=!1}}),jsxRuntime.jsx(FormModal,{model:a,parentContext:{...k==null?void 0:k(),...l},id:n&&n[0],visible:p,onSubmitSucceed:A=>{I(!1),V(A)},onCancel:()=>{I(!1)},mustClearAfterSave:!0,readOnly:s})]})},RequiredInput=styled__default.default(antd.Input)`
|
|
115
|
+
`,booleanComponentFn=e=>jsxRuntime.jsx("div",{style:{display:"flex",justifyContent:"center",alignContent:"center"},children:jsxRuntime.jsx(antd.Checkbox,{checked:e,disabled:!0})}),many2OneComponentFn=e=>e?jsxRuntime.jsxs(antd.Space,{children:[jsxRuntime.jsx(jsxRuntime.Fragment,{children:e.value}),jsxRuntime.jsx(Many2oneSuffix,{id:e.id,model:e.model})]}):jsxRuntime.jsx(jsxRuntime.Fragment,{}),textComponentFn=e=>jsxRuntime.jsx("div",{style:{whiteSpace:"pre-line"},children:e}),one2ManyComponentFn=e=>{const n=Array.isArray(e==null?void 0:e.items)?e==null?void 0:e.items.length:0;return jsxRuntime.jsx(jsxRuntime.Fragment,{children:`( ${n} )`})},progressBarComponentFn=e=>jsxRuntime.jsx(ProgressBarInput,{value:e}),floatTimeComponent=e=>jsxRuntime.jsx(jsxRuntime.Fragment,{children:parseFloatToString(e)}),numberComponent=e=>jsxRuntime.jsx("div",{style:{textAlign:"right"},children:e}),imageComponent=e=>jsxRuntime.jsx("img",{src:`data:image/*;base64,${e}`,style:{maxWidth:"50px",padding:"5px"}});function Tree(e){const{page:n=1,limit:t,total:o,treeView:r,results:a,onRequestPageChange:s,loading:l,onRowClicked:c,showPagination:u=!0,rowSelection:d,scrollY:f,colorsForResults:m={},onChangeSort:p,sorter:I,onFetchChildrenForRecord:v,childField:C}=e,[g,h]=React.useState([]),[y,x]=React.useState([]),w=React.useRef(!1),O=React.useRef(null),{t:_}=React.useContext(LocaleContext);React.useEffect(()=>{O.current=getTree(r);const j=getTableColumns(O.current,{boolean:booleanComponentFn,many2one:many2OneComponentFn,text:textComponentFn,one2many:one2ManyComponentFn,many2many:one2ManyComponentFn,progressbar:progressBarComponentFn,float_time:floatTimeComponent,image:imageComponent,integer:numberComponent,float:numberComponent});x(j)},[r]),React.useEffect(()=>{w.current=!1;const j=getTableItems(O.current,a);h(j)},[a]);const b=(n-1)*t+1,T=b-1+g.length,F=o===void 0?null:o===0?_("no_results"):_("summary").replace("{from}",b==null?void 0:b.toString()).replace("{to}",T==null?void 0:T.toString()).replace("{total}",o==null?void 0:o.toString()),k=()=>!u||r.isExpandable||l?null:o===void 0?jsxRuntime.jsx(antd.Spin,{}):jsxRuntime.jsxs(antd.Row,{align:"bottom",className:"pb-4",children:[jsxRuntime.jsx(antd.Col,{span:12,children:jsxRuntime.jsx(antd.Pagination,{total:o,pageSize:t,current:n,showSizeChanger:!1,onChange:s})}),jsxRuntime.jsx(antd.Col,{span:12,className:"text-right",children:F})]});function L(){var H;const q=O.current.columns.filter(K=>K.sum!==void 0).map(K=>({label:K.sum,field:K.id}));if(!q||q.length===0)return null;let $=[],B=((H=d==null?void 0:d.selectedRowKeys)==null?void 0:H.length)>0?g.filter(K=>d==null?void 0:d.selectedRowKeys.includes(K.id)):g;return q.forEach(K=>{const G=B.reduce((z,V)=>V[K.field]&&!isNaN(V[K.field])?z+V[K.field]:z,0);$.push(`${K.label}: ${Math.round(G*100)/100}`)}),jsxRuntime.jsx("div",{className:"p-1 pb-0 pl-2 mt-2 bg-gray-50",children:$.join(", ")})}let M,P=f;if(O.current!==null){M=calculateColumnsWidth(y,g,600);const q=O.current;f&&q.columns.some($=>$.sum!==void 0)&&(P=f-30)}return O.current===null?jsxRuntime.jsx(antd.Spin,{style:{padding:"2rem"}}):jsxRuntime.jsxs("div",{children:[k(),jsxRuntime.jsx(reactFormigaTable.Table,{height:P,columns:M.columns,dataSource:g,loading:l,loadingComponent:jsxRuntime.jsx(antd.Spin,{}),onRowStyle:j=>{if(m[j.id])return{color:m[j.id]}},onRowDoubleClick:c,onRowSelectionChange:d==null?void 0:d.onChange,onChangeSort:p,sorter:I,expandableOpts:v?{expandIcon:Icon.PlusSquareOutlined,collapseIcon:Icon.MinusSquareOutlined,loadingIcon:Icon.LoadingOutlined,onFetchChildrenForRecord:v,childField:C}:void 0}),L()]})}const DEFAULT_SEARCH_LIMIT$1=80;function SearchTree(e,n){const{action:t,model:o,formView:r,treeView:a,onRowClicked:s,nameSearch:l,treeScrollY:c,domain:u=[],visible:d=!0,rootTree:f=!1,parentContext:m={},onChangeSelectedRowKeys:p}=e,[I,v]=React.useState(!1),[C,g]=React.useState(!1),h=React.useRef(!1),y=React.useRef(80),[x,w]=React.useState(),[O,_]=React.useState(),[b,T]=React.useState(),[F,k]=React.useState(1),[L,M]=React.useState(0),[P,j]=React.useState(DEFAULT_SEARCH_LIMIT$1),[q,$]=React.useState(),B=React.useRef([]),[H,K]=React.useState(),[G,z]=React.useState([]),[V,U]=React.useState(void 0),[Y,D]=React.useState(!1),[A,N]=React.useState(),[Z,Q]=React.useState(),[E,S]=React.useState(!1),W=React.useRef([]),[X,te]=React.useState(200),ee=React.useRef([]),re=React.useRef(),{height:ce}=useWindowDimensions(),ue=React.useContext(ActionViewContext),{setResults:se=void 0,setCurrentItemIndex:fe=void 0,currentId:ge=void 0,results:_e=void 0,selectedRowItems:Ie=void 0,setSelectedRowItems:Re=void 0,setSearchParams:ye=void 0,searchVisible:Fe=!0,setSearchVisible:xe=void 0,sorter:Ee=void 0,setSorter:ie=void 0,setTotalItems:de=void 0,setSearchTreeNameSearch:me=void 0,setTreeIsLoading:oe=void 0}=(f?ue:{})||{},he=React.useContext(ContentRootContext),{processAction:Ce}=he||{};React.useImperativeHandle(n,()=>({refreshResults:()=>{h.current=!1,Ne()}}));const be=le=>{S(!0),k(le),M((le-1)*P)};function Te(le){se==null||se([...le]),z([...le])}const Se=React.useCallback(()=>_e||G,[_e,G]),Ae=async()=>{const le=await ConnectionProvider.getHandler().nameSearch({model:x,payload:l,limit:y.current,attrs:W.current.length>0?W.current:u,context:m});if(K(le.length),de==null||de(le.length),le.length>0){const ve=le.map(pe=>pe==null?void 0:pe[0]),{colors:we}=getTree(O),ke=await ConnectionProvider.getHandler().readEvalUiObjects({model:x,ids:ve,arch:O==null?void 0:O.arch,fields:O.field_parent?{...O.fields,[O.field_parent]:{}}:O.fields,context:m,attrs:we&&{colors:we}}),J=ke[0];ee.current=[...J],U(getColorMap(ke[1]));const ne=J.map(pe=>pe.id),ae=Ee!==void 0?sortResults({resultsToSort:J,sorter:Ee,fields:{...O.fields,...b.fields}}):[...ee.current];Te(ae),ne.length>0?fe==null||fe(0):fe==null||fe(void 0)}else Te([]),fe==null||fe(void 0);h.current=!0},je=le=>{const ve={};return le.forEach(we=>{Array.isArray(we)&&we[0]?ve[we[0]]=!0:ve[we]=!0}),Object.keys(ve)},Le=(le,ve)=>{const we=le,ke=je(le);return ve.forEach(J=>{Array.isArray(J)&&J[0]?ke.includes(J[0])||we.push(J):ke.includes(J)||we.push(J)}),we},Me=async()=>{const le=W.current.length>0?W.current:u,ve=Le(B.current,le),{colors:we}=getTree(O),{totalItems:ke,results:J,attrsEvaluated:ne}=await ConnectionProvider.getHandler().searchForTree({params:ve,limit:P,offset:L,model:x,fields:O.field_parent?{...O.fields,[O.field_parent]:{}}:O.fields,context:m,attrs:we&&{colors:we}});U(getColorMap(ne)),ee.current=[...J];const ae=Ee!==void 0?sortResults({resultsToSort:J,sorter:Ee,fields:{...O.fields,...b.fields}}):[...ee.current];if(ke.then(pe=>{K(pe),de==null||de(pe)}),Te(ae),_e&&ae.length>0){const pe=ae.findIndex(Oe=>ge===Oe.id);pe===-1?fe==null||fe(0):fe==null||fe(pe)}else fe==null||fe(void 0)},Ne=async()=>{try{S(!0),oe==null||oe(!0),l&&!h.current?await Ae():await Me()}catch(le){N(le)}finally{S(!1),D(!1),oe==null||oe(!1)}};async function He(le){const ve=le[(O==null?void 0:O.field_parent)||"child_id"],we=await ConnectionProvider.getHandler().readObjects({model:x,ids:ve,fields:O.field_parent?{...O.fields,[O.field_parent]:{}}:O.fields,context:m});return Te([...Se(),...we]),getTableItems(getTree(O),we)}React.useEffect(()=>{!C||d&&(h.current=!1,Ne())},[F,P,L,C,d,l]);const Ue=async le=>{g(!1),v(!0),Q(void 0),oe==null||oe(!0);try{le==="action"?await De():await Be(),g(!0)}catch(ve){Q(ve)}finally{v(!1),oe==null||oe(!1)}},De=async()=>{const le=await ConnectionProvider.getHandler().getViewsForAction({action:t,context:m});W.current=le.domain,T(le.views.get("form")),_(le.views.get("tree")),w(le.model),$(le.limit),j(le.limit)},Be=async()=>{w(o);let le=r;r||(le=await ConnectionProvider.getHandler().getView({model:o,type:"form",context:m}));let ve=a;a||(ve=await ConnectionProvider.getHandler().getView({model:o,type:"tree",context:m})),T(le),_(ve),$(void 0),j(DEFAULT_SEARCH_LIMIT$1)};React.useEffect(()=>{t?Ue("action"):o&&Ue("model")},[t,o]);const $e=()=>{E||(me==null||me(void 0),B.current=[],ye==null||ye([]),N(void 0),M(0),k(1),j(q||DEFAULT_SEARCH_LIMIT$1))},We=({params:le,limit:ve,offset:we})=>{E||(B.current=le,me==null||me(void 0),Re==null||Re([]),ye==null||ye(le),xe==null||xe(!1),D(!0),N(void 0),k(1),ve&&j(ve),we&&M(we),Ne())},ze=le=>{y.current=le},Ge=async le=>{const{id:ve}=le;re.current||(re.current=await ConnectionProvider.getHandler().treeButOpen({id:O.view_id,model:x,context:m}));const we=re.current[0][2];await(Ce==null?void 0:Ce({actionData:we,fields:O.fields,values:{active_id:ve,...le},context:m}))},Ye=async le=>{const{id:ve}=le;if(O!=null&&O.isExpandable){try{await Ge(le)}catch(we){showDialog$8(we)}return}s({id:ve,model:x,formView:b,treeView:O})};function Ke(le){const ve=Se().filter(we=>le.includes(we.id));Re==null||Re(ve),p==null||p(le)}function Ze(){return O!=null&&O.isExpandable?ce-160:ce-(X+210)}const Ve=()=>!O||!b?null:jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx(Measure__default.default,{bounds:!0,onResize:le=>{var ve;te((ve=le.bounds)==null?void 0:ve.height)},children:({measureRef:le})=>jsxRuntime.jsx("div",{ref:le,children:jsxRuntime.jsxs("div",{style:{display:Fe?"block":"none"},children:[jsxRuntime.jsx(SearchFilter,{fields:{...O.fields,...b.fields},searchFields:mergeSearchFields([b.search_fields,O.search_fields]),onClear:$e,limit:P,offset:L,isSearching:Y,onSubmit:We,onLimitChange:ze}),A&&jsxRuntime.jsx(antd.Alert,{className:"mt-10",message:A,type:"error",banner:!0}),jsxRuntime.jsx("div",{className:"pb-5"})]})})}),jsxRuntime.jsx(Tree,{total:H,limit:P,page:F,treeView:O,results:Se(),onRequestPageChange:be,loading:E,onRowClicked:Ye,scrollY:c||Ze(),colorsForResults:V,rowSelection:{selectedRowKeys:Ie==null?void 0:Ie.map(le=>le.id),onChange:Ke},sorter:Ee,onChangeSort:le=>{ie==null||ie(le);const ve=le!==void 0?sortResults({resultsToSort:Se(),sorter:le,fields:{...O.fields,...b.fields}}):[...ee.current];Te(ve)},onFetchChildrenForRecord:O.isExpandable?He:void 0,childField:O.field_parent})]});return Z?jsxRuntime.jsx(antd.Alert,{className:"mt-10",message:Z,type:"error",banner:!0}):jsxRuntime.jsx("div",{style:d?{}:{display:"none"},children:I?jsxRuntime.jsx(antd.Spin,{}):Ve()})}const SearchTree$1=React.forwardRef(SearchTree),SearchModal=e=>{const{visible:n,onCloseModal:t,onSelectValues:o,model:r,nameSearch:a,domain:s,context:l={}}=e,[c,u]=React.useState(!1),{modalWidth:d,modalHeight:f}=useWindowDimensions(),{t:m}=React.useContext(LocaleContext),[p,I]=React.useState([]),v=async()=>{await new Promise(y=>setTimeout(y,5)),t()},C=async y=>{const{id:x}=y;o([x])};function g(){if(p.length===0){v();return}o(p)}const h=()=>jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx(SearchTree$1,{model:r,nameSearch:a,onRowClicked:C,treeScrollY:f*.3,domain:s,parentContext:l,onChangeSelectedRowKeys:y=>{I(y)}}),jsxRuntime.jsx(antd.Divider,{}),jsxRuntime.jsx(antd.Row,{justify:"end",children:jsxRuntime.jsxs(antd.Space,{children:[jsxRuntime.jsx(antd.Button,{icon:jsxRuntime.jsx(Icon.FileAddOutlined,{}),onClick:()=>{u(!0)},children:m("new")}),jsxRuntime.jsx(antd.Button,{icon:jsxRuntime.jsx(Icon.CheckOutlined,{}),onClick:()=>{g()},type:"primary",children:m("ok")}),jsxRuntime.jsx(antd.Button,{icon:jsxRuntime.jsx(Icon.CloseOutlined,{}),onClick:v,children:m("cancel")})]})})]});return jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx(antd.Modal,{title:m("search"),centered:!0,width:d,visible:n&&!c,closable:!0,onCancel:v,footer:null,destroyOnClose:!0,maskClosable:!1,children:h()}),jsxRuntime.jsx(FormModal,{model:r,visible:c,parentContext:l,onSubmitSucceed:y=>{u(!1),v(),o([y])},onCancel:()=>{u(!1),v()}})]})},{error}=antd.Modal,showDialog$3=e=>{error({title:"Error",icon:jsxRuntime.jsx(Icon.ExclamationCircleOutlined,{}),centered:!0,content:e})},Many2one=e=>{const{ooui:n}=e,{required:t}=n,o=async(r,a)=>{if(!a)throw new Error;if(!Array.isArray(a))throw new Error;if(Array.isArray(a)&&!a[0])throw new Error};return jsxRuntime.jsx(Field$1,{required:t,type:"array",validator:o,...e,children:jsxRuntime.jsx(Many2oneInput,{ooui:n})})},Many2oneInput=e=>{const{value:n,onChange:t,ooui:o}=e,{required:r,relation:a,readOnly:s,context:l,id:c,domain:u}=o,d=r&&!s?Config.requiredClass:void 0,[f,m]=React.useState(!1),[p,I]=React.useState(!1),[v,C]=React.useState(!1),[g,h]=React.useState(),y=React.useRef(!1),[x,w]=React.useState(""),O=React.useRef(),_=React.useContext(FormContext$1),{domain:b,getValues:T,getFields:F,getContext:k,setOriginalValue:L,elementHasLostFocus:M}=_||{},P=React.useRef([]),[j,q]=React.useState([]),$=n&&n[0],B=n&&n[1]||"";React.useEffect(()=>{!Array.isArray(n)&&!isNaN(n)&&V(n)},[n]),React.useEffect(()=>{$&&B.length===0?V($):$&&B.length>0?w(B):!$&&!B&&w(O.current||"")},[n]);const H=A=>{t==null||t(A),M==null||M()},K=A=>{O.current=A.target.value,H([void 0,""])},G=async()=>{if(!v&&x!==B){if(await new Promise(A=>setTimeout(A,100)),y.current){H([void 0,""]);return}C(!0);try{if(P.current&&P.current.length>0)z(O.current);else{const A=await ConnectionProvider.getHandler().nameSearch({model:a,payload:O.current,context:{...k==null?void 0:k(),...l}});A.length===1?(O.current=void 0,H(A[0])):z(O.current)}}catch(A){showDialog$3(A)}finally{C(!1)}}},z=async A=>{if(await U(),P.current&&P.current.length>0){const N=await ConnectionProvider.getHandler().searchAllIds({params:P.current,model:a,context:{...k==null?void 0:k(),...l},totalItems:2});N.length===1?V(N[0],!0):(h(A),m(!0));return}h(A),m(!0)},V=async(A,N)=>{C(!0);try{const Z=await ConnectionProvider.getHandler().execute({action:"name_get",payload:[A],model:a,context:{...k==null?void 0:k(),...l}});H([A,Z[0][1]]),N&&L(o.id,[A,Z[0][1]])}catch(Z){showDialog$3(Z)}finally{C(!1)}};async function U(){u&&(P.current=await ConnectionProvider.getHandler().evalDomain({domain:u,values:transformPlainMany2Ones({fields:F(),values:T()}),context:k()})),b&&b.length>0&&(P.current=P.current.concat(ooui.transformDomainForChildWidget({domain:b,widgetFieldName:c}))),q(P.current)}async function Y(A){A.code==="Enter"?(A.preventDefault(),A.stopPropagation(),await G()):A.code==="Backspace"&&$!==void 0&&(A.preventDefault(),A.stopPropagation(),H([void 0,""]))}const D=r&&!s?RequiredInput:antd.Input;return jsxRuntime.jsxs(antd.Row,{gutter:8,wrap:!1,children:[jsxRuntime.jsx(antd.Col,{flex:"auto",children:jsxRuntime.jsx(D,{type:"text",value:x,disabled:s,onChange:K,className:d,onBlur:G,onKeyDown:Y,suffix:jsxRuntime.jsx(Many2oneSuffix,{id:$,model:a,context:{...k==null?void 0:k(),...l}})})}),jsxRuntime.jsx(antd.Col,{flex:"32px",children:jsxRuntime.jsx(antd.Button,{icon:jsxRuntime.jsx(Icon.FolderOpenOutlined,{}),disabled:$===void 0||B===""||x===void 0,onClick:()=>{I(!0)},tabIndex:-1})}),jsxRuntime.jsx(antd.Col,{flex:"32px",children:jsxRuntime.jsx(antd.Button,{icon:v?jsxRuntime.jsx(Icon.LoadingOutlined,{}):jsxRuntime.jsx(Icon.SearchOutlined,{}),disabled:s||v,onClick:()=>{y.current=!0,z(B)},tabIndex:-1})}),jsxRuntime.jsx(SearchModal,{model:a,domain:j,context:{...k==null?void 0:k(),...l},visible:f,nameSearch:$?void 0:g,onSelectValues:A=>{m(!1),V(A[0]),y.current=!1,O.current=void 0},onCloseModal:()=>{m(!1),y.current=!1}}),jsxRuntime.jsx(FormModal,{model:a,parentContext:{...k==null?void 0:k(),...l},id:n&&n[0],visible:p,onSubmitSucceed:A=>{I(!1),V(A)},onCancel:()=>{I(!1)},mustClearAfterSave:!0,readOnly:s})]})},RequiredInput=styled__default.default(antd.Input)`
|
|
116
116
|
.ant-input {
|
|
117
117
|
background-color: ${Config.requiredColor};
|
|
118
118
|
}
|