@gisce/react-ooui 1.0.26-rc.0 → 1.0.26
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:g,onFetchChildrenForRecord:v,childField:C}=e,[I,h]=React.useState([]),[y,x]=React.useState([]),w=React.useRef(!1),O=React.useRef(null),{t:F}=React.useContext(LocaleContext);React.useEffect(()=>{O.current=getTree(r);const M=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(M)},[r]),React.useEffect(()=>{w.current=!1;const M=getTableItems(O.current,a);h(M)},[a]);const b=(n-1)*t+1,S=b-1+I.length,T=o===void 0?null:o===0?F("no_results"):F("summary").replace("{from}",b==null?void 0:b.toString()).replace("{to}",S==null?void 0:S.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:T})]});function L(){var V;const q=O.current.columns.filter(G=>G.sum!==void 0).map(G=>({label:G.sum,field:G.id}));if(!q||q.length===0)return null;let U=[],B=((V=d==null?void 0:d.selectedRowKeys)==null?void 0:V.length)>0?I.filter(G=>d==null?void 0:d.selectedRowKeys.includes(G.id)):I;return q.forEach(G=>{const Y=B.reduce((H,K)=>K[G.field]&&!isNaN(K[G.field])?H+K[G.field]:H,0);U.push(`${G.label}: ${Math.round(Y*100)/100}`)}),jsxRuntime.jsx("div",{className:"p-1 pb-0 pl-2 mt-2 bg-gray-50",children:U.join(", ")})}let D,P=f;if(O.current!==null){D=calculateColumnsWidth(y,I,600);const q=O.current;f&&q.columns.some(U=>U.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:D.columns,dataSource:I,loading:l,loadingComponent:jsxRuntime.jsx(antd.Spin,{}),onRowStyle:M=>{if(m[M.id])return{color:m[M.id]}},onRowDoubleClick:c,onRowSelectionChange:d==null?void 0:d.onChange,onChangeSort:p,sorter:g,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{model:t,formView:o,treeView:r,onRowClicked:a,nameSearch:s,treeScrollY:l,domain:c=[],visible:u=!0,rootTree:d=!1,parentContext:f={},onChangeSelectedRowKeys:m,limit:p}=e,[g,v]=React.useState(!1),[C,I]=React.useState(!1),h=React.useRef(!1),y=React.useRef(p||DEFAULT_SEARCH_LIMIT$1),[x,w]=React.useState(),[O,F]=React.useState(),[b,S]=React.useState(),[T,k]=React.useState(1),[L,D]=React.useState(0),[P,M]=React.useState(p||DEFAULT_SEARCH_LIMIT$1),q=React.useRef([]),[U,B]=React.useState(),[V,G]=React.useState([]),[Y,H]=React.useState(void 0),[K,N]=React.useState(!1),[W,j]=React.useState(),[A,$]=React.useState(),[Z,Q]=React.useState(!1),E=React.useRef([]),[_,z]=React.useState(200),X=React.useRef([]),ne=React.useRef(),{height:ee}=useWindowDimensions(),oe=React.useContext(ActionViewContext),{setResults:se=void 0,setCurrentItemIndex:ie=void 0,currentId:ce=void 0,results:pe=void 0,selectedRowItems:ve=void 0,setSelectedRowItems:Re=void 0,setSearchParams:he=void 0,searchVisible:Fe=!0,setSearchVisible:ye=void 0,sorter:_e=void 0,setSorter:xe=void 0,setTotalItems:Ee=void 0,setSearchTreeNameSearch:re=void 0,setTreeIsLoading:ae=void 0}=(d?oe:{})||{},Ie=React.useContext(ContentRootContext),{processAction:me}=Ie||{};React.useImperativeHandle(n,()=>({refreshResults:()=>{h.current=!1,De()}}));const ue=de=>{Q(!0),k(de),D((de-1)*P)};function ge(de){se==null||se([...de]),G([...de])}const be=React.useCallback(()=>pe||V,[pe,V]),Te=async()=>{const de=await ConnectionProvider.getHandler().nameSearch({model:x,payload:s,limit:y.current,attrs:E.current.length>0?E.current:c,context:f});if(B(de.length),Ee==null||Ee(de.length),de.length>0){const Ce=de.map(J=>J==null?void 0:J[0]),{colors:Oe}=getTree(O),ke=await ConnectionProvider.getHandler().readEvalUiObjects({model:x,ids:Ce,arch:O==null?void 0:O.arch,fields:O.field_parent?{...O.fields,[O.field_parent]:{}}:O.fields,context:f,attrs:Oe&&{colors:Oe}}),Ae=ke[0];X.current=[...Ae],H(getColorMap(ke[1]));const Ue=Ae.map(J=>J.id),Be=_e!==void 0?sortResults({resultsToSort:Ae,sorter:_e,fields:{...O.fields,...b.fields}}):[...X.current];ge(Be),Ue.length>0?ie==null||ie(0):ie==null||ie(void 0)}else ge([]),ie==null||ie(void 0);h.current=!0},Se=de=>{const Ce={};return de.forEach(Oe=>{Array.isArray(Oe)&&Oe[0]?Ce[Oe[0]]=!0:Ce[Oe]=!0}),Object.keys(Ce)},Pe=(de,Ce)=>{const Oe=de,ke=Se(de);return Ce.forEach(Ae=>{Array.isArray(Ae)&&Ae[0]?ke.includes(Ae[0])||Oe.push(Ae):ke.includes(Ae)||Oe.push(Ae)}),Oe},Me=async()=>{const de=E.current.length>0?E.current:c,Ce=Pe(q.current,de),{colors:Oe}=getTree(O),{totalItems:ke,results:Ae,attrsEvaluated:Ue}=await ConnectionProvider.getHandler().searchForTree({params:Ce,limit:P,offset:L,model:x,fields:O.field_parent?{...O.fields,[O.field_parent]:{}}:O.fields,context:f,attrs:Oe&&{colors:Oe}});H(getColorMap(Ue)),X.current=[...Ae];const Be=_e!==void 0?sortResults({resultsToSort:Ae,sorter:_e,fields:{...O.fields,...b.fields}}):[...X.current];if(ke.then(J=>{B(J),Ee==null||Ee(J)}),ge(Be),pe&&Be.length>0){const J=Be.findIndex(te=>ce===te.id);J===-1?ie==null||ie(0):ie==null||ie(J)}else ie==null||ie(void 0)},De=async()=>{try{Q(!0),ae==null||ae(!0),s&&!h.current?await Te():await Me()}catch(de){j(de)}finally{Q(!1),N(!1),ae==null||ae(!1)}};async function je(de){const Ce=de[(O==null?void 0:O.field_parent)||"child_id"],Oe=await ConnectionProvider.getHandler().readObjects({model:x,ids:Ce,fields:O.field_parent?{...O.fields,[O.field_parent]:{}}:O.fields,context:f});return ge([...be(),...Oe]),getTableItems(getTree(O),Oe)}React.useEffect(()=>{!C||u&&(h.current=!1,De())},[T,P,L,C,u,s]);const Ve=async()=>{I(!1),v(!0),$(void 0),ae==null||ae(!0);try{await He(),I(!0)}catch(de){$(de)}finally{v(!1),ae==null||ae(!1)}},He=async()=>{w(t);let de=o;o||(de=await ConnectionProvider.getHandler().getView({model:t,type:"form",context:f}));let Ce=r;r||(Ce=await ConnectionProvider.getHandler().getView({model:t,type:"tree",context:f})),S(de),F(Ce),M(p||DEFAULT_SEARCH_LIMIT$1)};React.useEffect(()=>{Ve()},[t]);const We=()=>{Z||(re==null||re(void 0),q.current=[],he==null||he([]),j(void 0),D(0),k(1),M(p||DEFAULT_SEARCH_LIMIT$1))},Ne=({params:de,limit:Ce,offset:Oe})=>{Z||(q.current=de,re==null||re(void 0),Re==null||Re([]),he==null||he(de),ye==null||ye(!1),N(!0),j(void 0),k(1),Ce&&M(Ce),Oe&&D(Oe),De())},$e=de=>{y.current=de},qe=async de=>{const{id:Ce}=de;ne.current||(ne.current=await ConnectionProvider.getHandler().treeButOpen({id:O.view_id,model:x,context:f}));const Oe=ne.current[0][2];await(me==null?void 0:me({actionData:Oe,fields:O.fields,values:{active_id:Ce,...de},context:f}))},ze=async de=>{const{id:Ce}=de;if(O!=null&&O.isExpandable){try{await qe(de)}catch(Oe){showDialog$8(Oe)}return}a({id:Ce,model:x,formView:b,treeView:O})};function Ge(de){const Ce=be().filter(Oe=>de.includes(Oe.id));Re==null||Re(Ce),m==null||m(de)}function Ye(){return O!=null&&O.isExpandable?ee-160:ee-(_+210)}const Ke=()=>!O||!b?null:jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx(Measure__default.default,{bounds:!0,onResize:de=>{var Ce;z((Ce=de.bounds)==null?void 0:Ce.height)},children:({measureRef:de})=>jsxRuntime.jsx("div",{ref:de,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:We,limit:P,offset:L,isSearching:K,onSubmit:Ne,onLimitChange:$e}),W&&jsxRuntime.jsx(antd.Alert,{className:"mt-10",message:W,type:"error",banner:!0}),jsxRuntime.jsx("div",{className:"pb-5"})]})})}),jsxRuntime.jsx(Tree,{total:U,limit:P,page:T,treeView:O,results:be(),onRequestPageChange:ue,loading:Z,onRowClicked:ze,scrollY:l||Ye(),colorsForResults:Y,rowSelection:{selectedRowKeys:ve==null?void 0:ve.map(de=>de.id),onChange:Ge},sorter:_e,onChangeSort:de=>{xe==null||xe(de);const Ce=de!==void 0?sortResults({resultsToSort:be(),sorter:de,fields:{...O.fields,...b.fields}}):[...X.current];ge(Ce)},onFetchChildrenForRecord:O.isExpandable?je:void 0,childField:O.field_parent})]});return A?jsxRuntime.jsx(antd.Alert,{className:"mt-10",message:A,type:"error",banner:!0}):jsxRuntime.jsx("div",{style:u?{}:{display:"none"},children:g?jsxRuntime.jsx(antd.Spin,{}):Ke()})}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,g]=React.useState([]),v=async()=>{await new Promise(y=>setTimeout(y,5)),t()},C=async y=>{const{id:x}=y;o([x])};function I(){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=>{g(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:()=>{I()},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,g]=React.useState(!1),[v,C]=React.useState(!1),[I,h]=React.useState(),y=React.useRef(!1),[x,w]=React.useState(""),O=React.useRef(),F=React.useContext(FormContext$1),{domain:b,getValues:S,getFields:T,getContext:k,setOriginalValue:L,elementHasLostFocus:D}=F||{},P=React.useRef([]),[M,q]=React.useState([]),U=n&&n[0]||void 0,B=n&&n[1]||"";React.useEffect(()=>{!Array.isArray(n)&&n&&K(n)},[n]),React.useEffect(()=>{U&&B.length===0?K(U):U&&B.length>0?w(B):!U&&!B&&w(O.current||"")},[n]);const V=A=>{t==null||t(A),D==null||D()},G=A=>{O.current=A.target.value,V([void 0,""])},Y=async()=>{if(!v&&x!==B){if(await new Promise(A=>setTimeout(A,100)),y.current){V([void 0,""]);return}C(!0);try{if(P.current&&P.current.length>0)H(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,V(A[0])):H(O.current)}}catch(A){showDialog$3(A)}finally{C(!1)}}},H=async A=>{if(await N(),P.current&&P.current.length>0){const $=await ConnectionProvider.getHandler().searchAllIds({params:P.current,model:a,context:{...k==null?void 0:k(),...l},totalItems:2});$.length===1?K($[0],!0):(h(A),m(!0));return}h(A),m(!0)},K=async(A,$)=>{C(!0);try{const Z=await ConnectionProvider.getHandler().execute({action:"name_get",payload:[A],model:a,context:{...k==null?void 0:k(),...l}});V([A,Z[0][1]]),$&&L(o.id,[A,Z[0][1]])}catch(Z){showDialog$3(Z)}finally{C(!1)}};async function N(){u&&(P.current=await ConnectionProvider.getHandler().evalDomain({domain:u,values:transformPlainMany2Ones({fields:T(),values:S()}),context:k()})),b&&b.length>0&&(P.current=P.current.concat(ooui.transformDomainForChildWidget({domain:b,widgetFieldName:c}))),q(P.current)}async function W(A){A.code==="Enter"?(A.preventDefault(),A.stopPropagation(),await Y()):A.code==="Backspace"&&U!==void 0&&(A.preventDefault(),A.stopPropagation(),V([void 0,""]))}const j=r&&!s?RequiredInput:antd.Input;return jsxRuntime.jsxs(antd.Row,{gutter:8,wrap:!1,children:[jsxRuntime.jsx(antd.Col,{flex:"auto",children:jsxRuntime.jsx(j,{type:"text",value:x,disabled:s,onChange:G,className:d,onBlur:Y,onKeyDown:W,suffix:jsxRuntime.jsx(Many2oneSuffix,{id:U,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:U===void 0||B===""||x===void 0,onClick:()=>{g(!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,H(B)},tabIndex:-1})}),jsxRuntime.jsx(SearchModal,{model:a,domain:M,context:{...k==null?void 0:k(),...l},visible:f,nameSearch:U?void 0:I,onSelectValues:A=>{m(!1),K(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=>{g(!1),K(A)},onCancel:()=>{g(!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:g,onFetchChildrenForRecord:v,childField:C}=e,[I,h]=React.useState([]),[y,x]=React.useState([]),w=React.useRef(!1),O=React.useRef(null),{t:F}=React.useContext(LocaleContext);React.useEffect(()=>{O.current=getTree(r);const M=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(M)},[r]),React.useEffect(()=>{w.current=!1;const M=getTableItems(O.current,a);h(M)},[a]);const b=(n-1)*t+1,S=b-1+I.length,T=o===void 0?null:o===0?F("no_results"):F("summary").replace("{from}",b==null?void 0:b.toString()).replace("{to}",S==null?void 0:S.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:T})]});function L(){var V;const q=O.current.columns.filter(G=>G.sum!==void 0).map(G=>({label:G.sum,field:G.id}));if(!q||q.length===0)return null;let U=[],B=((V=d==null?void 0:d.selectedRowKeys)==null?void 0:V.length)>0?I.filter(G=>d==null?void 0:d.selectedRowKeys.includes(G.id)):I;return q.forEach(G=>{const Y=B.reduce((H,K)=>K[G.field]&&!isNaN(K[G.field])?H+K[G.field]:H,0);U.push(`${G.label}: ${Math.round(Y*100)/100}`)}),jsxRuntime.jsx("div",{className:"p-1 pb-0 pl-2 mt-2 bg-gray-50",children:U.join(", ")})}let D,P=f;if(O.current!==null){D=calculateColumnsWidth(y,I,600);const q=O.current;f&&q.columns.some(U=>U.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:D.columns,dataSource:I,loading:l,loadingComponent:jsxRuntime.jsx(antd.Spin,{}),onRowStyle:M=>{if(m[M.id])return{color:m[M.id]}},onRowDoubleClick:c,onRowSelectionChange:d==null?void 0:d.onChange,onChangeSort:p,sorter:g,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{model:t,formView:o,treeView:r,onRowClicked:a,nameSearch:s,treeScrollY:l,domain:c=[],visible:u=!0,rootTree:d=!1,parentContext:f={},onChangeSelectedRowKeys:m,limit:p}=e,[g,v]=React.useState(!1),[C,I]=React.useState(!1),h=React.useRef(!1),y=React.useRef(p||DEFAULT_SEARCH_LIMIT$1),[x,w]=React.useState(),[O,F]=React.useState(),[b,S]=React.useState(),[T,k]=React.useState(1),[L,D]=React.useState(0),[P,M]=React.useState(p||DEFAULT_SEARCH_LIMIT$1),q=React.useRef([]),[U,B]=React.useState(),[V,G]=React.useState([]),[Y,H]=React.useState(void 0),[K,N]=React.useState(!1),[W,j]=React.useState(),[A,$]=React.useState(),[Z,Q]=React.useState(!1),E=React.useRef([]),[_,z]=React.useState(200),X=React.useRef([]),ne=React.useRef(),{height:ee}=useWindowDimensions(),oe=React.useContext(ActionViewContext),{setResults:se=void 0,setCurrentItemIndex:ie=void 0,currentId:ce=void 0,results:pe=void 0,selectedRowItems:ve=void 0,setSelectedRowItems:Re=void 0,setSearchParams:he=void 0,searchVisible:Fe=!0,setSearchVisible:ye=void 0,sorter:_e=void 0,setSorter:xe=void 0,setTotalItems:Ee=void 0,setSearchTreeNameSearch:re=void 0,setTreeIsLoading:ae=void 0}=(d?oe:{})||{},Ie=React.useContext(ContentRootContext),{processAction:me}=Ie||{};React.useImperativeHandle(n,()=>({refreshResults:()=>{h.current=!1,De()}}));const ue=de=>{Q(!0),k(de),D((de-1)*P)};function ge(de){se==null||se([...de]),G([...de])}const be=React.useCallback(()=>pe||V,[pe,V]),Te=async()=>{const de=await ConnectionProvider.getHandler().nameSearch({model:x,payload:s,limit:y.current,attrs:E.current.length>0?E.current:c,context:f});if(B(de.length),Ee==null||Ee(de.length),de.length>0){const Ce=de.map(J=>J==null?void 0:J[0]),{colors:Oe}=getTree(O),ke=await ConnectionProvider.getHandler().readEvalUiObjects({model:x,ids:Ce,arch:O==null?void 0:O.arch,fields:O.field_parent?{...O.fields,[O.field_parent]:{}}:O.fields,context:f,attrs:Oe&&{colors:Oe}}),Ae=ke[0];X.current=[...Ae],H(getColorMap(ke[1]));const Ue=Ae.map(J=>J.id),Be=_e!==void 0?sortResults({resultsToSort:Ae,sorter:_e,fields:{...O.fields,...b.fields}}):[...X.current];ge(Be),Ue.length>0?ie==null||ie(0):ie==null||ie(void 0)}else ge([]),ie==null||ie(void 0);h.current=!0},Se=de=>{const Ce={};return de.forEach(Oe=>{Array.isArray(Oe)&&Oe[0]?Ce[Oe[0]]=!0:Ce[Oe]=!0}),Object.keys(Ce)},Pe=(de,Ce)=>{const Oe=de,ke=Se(de);return Ce.forEach(Ae=>{Array.isArray(Ae)&&Ae[0]?ke.includes(Ae[0])||Oe.push(Ae):ke.includes(Ae)||Oe.push(Ae)}),Oe},Me=async()=>{const de=E.current.length>0?E.current:c,Ce=Pe(q.current,de),{colors:Oe}=getTree(O),{totalItems:ke,results:Ae,attrsEvaluated:Ue}=await ConnectionProvider.getHandler().searchForTree({params:Ce,limit:P,offset:L,model:x,fields:O.field_parent?{...O.fields,[O.field_parent]:{}}:O.fields,context:f,attrs:Oe&&{colors:Oe}});H(getColorMap(Ue)),X.current=[...Ae];const Be=_e!==void 0?sortResults({resultsToSort:Ae,sorter:_e,fields:{...O.fields,...b.fields}}):[...X.current];if(ke.then(J=>{B(J),Ee==null||Ee(J)}),ge(Be),pe&&Be.length>0){const J=Be.findIndex(te=>ce===te.id);J===-1?ie==null||ie(0):ie==null||ie(J)}else ie==null||ie(void 0)},De=async()=>{try{Q(!0),ae==null||ae(!0),s&&!h.current?await Te():await Me()}catch(de){j(de)}finally{Q(!1),N(!1),ae==null||ae(!1)}};async function je(de){const Ce=de[(O==null?void 0:O.field_parent)||"child_id"],Oe=await ConnectionProvider.getHandler().readObjects({model:x,ids:Ce,fields:O.field_parent?{...O.fields,[O.field_parent]:{}}:O.fields,context:f});return ge([...be(),...Oe]),getTableItems(getTree(O),Oe)}React.useEffect(()=>{!C||u&&(h.current=!1,De())},[T,P,L,C,u,s]);const Ve=async()=>{I(!1),v(!0),$(void 0),ae==null||ae(!0);try{await He(),I(!0)}catch(de){$(de)}finally{v(!1),ae==null||ae(!1)}},He=async()=>{w(t);let de=o;o||(de=await ConnectionProvider.getHandler().getView({model:t,type:"form",context:f}));let Ce=r;r||(Ce=await ConnectionProvider.getHandler().getView({model:t,type:"tree",context:f})),S(de),F(Ce),M(p||DEFAULT_SEARCH_LIMIT$1)};React.useEffect(()=>{Ve()},[t]);const We=()=>{Z||(re==null||re(void 0),q.current=[],he==null||he([]),j(void 0),D(0),k(1),M(p||DEFAULT_SEARCH_LIMIT$1))},Ne=({params:de,limit:Ce,offset:Oe})=>{Z||(q.current=de,re==null||re(void 0),Re==null||Re([]),he==null||he(de),ye==null||ye(!1),N(!0),j(void 0),k(1),Ce&&M(Ce),Oe&&D(Oe),De())},$e=de=>{y.current=de},qe=async de=>{const{id:Ce}=de;ne.current||(ne.current=await ConnectionProvider.getHandler().treeButOpen({id:O.view_id,model:x,context:f}));const Oe=ne.current[0][2];await(me==null?void 0:me({actionData:Oe,fields:O.fields,values:{active_id:Ce,...de},context:f}))},ze=async de=>{const{id:Ce}=de;if(O!=null&&O.isExpandable){try{await qe(de)}catch(Oe){showDialog$8(Oe)}return}a({id:Ce,model:x,formView:b,treeView:O})};function Ge(de){const Ce=be().filter(Oe=>de.includes(Oe.id));Re==null||Re(Ce),m==null||m(de)}function Ye(){return O!=null&&O.isExpandable?ee-160:ee-(_+210)}const Ke=()=>!O||!b?null:jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx(Measure__default.default,{bounds:!0,onResize:de=>{var Ce;z((Ce=de.bounds)==null?void 0:Ce.height)},children:({measureRef:de})=>jsxRuntime.jsx("div",{ref:de,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:We,limit:P,offset:L,isSearching:K,onSubmit:Ne,onLimitChange:$e}),W&&jsxRuntime.jsx(antd.Alert,{className:"mt-10",message:W,type:"error",banner:!0}),jsxRuntime.jsx("div",{className:"pb-5"})]})})}),jsxRuntime.jsx(Tree,{total:U,limit:P,page:T,treeView:O,results:be(),onRequestPageChange:ue,loading:Z,onRowClicked:ze,scrollY:l||Ye(),colorsForResults:Y,rowSelection:{selectedRowKeys:ve==null?void 0:ve.map(de=>de.id),onChange:Ge},sorter:_e,onChangeSort:de=>{xe==null||xe(de);const Ce=de!==void 0?sortResults({resultsToSort:be(),sorter:de,fields:{...O.fields,...b.fields}}):[...X.current];ge(Ce)},onFetchChildrenForRecord:O.isExpandable?je:void 0,childField:O.field_parent})]});return A?jsxRuntime.jsx(antd.Alert,{className:"mt-10",message:A,type:"error",banner:!0}):jsxRuntime.jsx("div",{style:u?{}:{display:"none"},children:g?jsxRuntime.jsx(antd.Spin,{}):Ke()})}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,g]=React.useState([]),v=async()=>{await new Promise(y=>setTimeout(y,5)),t()},C=async y=>{const{id:x}=y;o([x])};function I(){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=>{g(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:()=>{I()},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,g]=React.useState(!1),[v,C]=React.useState(!1),[I,h]=React.useState(),y=React.useRef(!1),[x,w]=React.useState(""),O=React.useRef(),F=React.useContext(FormContext$1),{domain:b,getValues:S,getFields:T,getContext:k,setOriginalValue:L,elementHasLostFocus:D}=F||{},P=React.useRef([]),[M,q]=React.useState([]),U=n&&n[0],B=n&&n[1]||"";React.useEffect(()=>{!Array.isArray(n)&&!isNaN(n)&&K(n)},[n]),React.useEffect(()=>{U&&B.length===0?K(U):U&&B.length>0?w(B):!U&&!B&&w(O.current||"")},[n]);const V=A=>{t==null||t(A),D==null||D()},G=A=>{O.current=A.target.value,V([void 0,""])},Y=async()=>{if(!v&&x!==B){if(await new Promise(A=>setTimeout(A,100)),y.current){V([void 0,""]);return}C(!0);try{if(P.current&&P.current.length>0)H(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,V(A[0])):H(O.current)}}catch(A){showDialog$3(A)}finally{C(!1)}}},H=async A=>{if(await N(),P.current&&P.current.length>0){const $=await ConnectionProvider.getHandler().searchAllIds({params:P.current,model:a,context:{...k==null?void 0:k(),...l},totalItems:2});$.length===1?K($[0],!0):(h(A),m(!0));return}h(A),m(!0)},K=async(A,$)=>{C(!0);try{const Z=await ConnectionProvider.getHandler().execute({action:"name_get",payload:[A],model:a,context:{...k==null?void 0:k(),...l}});V([A,Z[0][1]]),$&&L(o.id,[A,Z[0][1]])}catch(Z){showDialog$3(Z)}finally{C(!1)}};async function N(){u&&(P.current=await ConnectionProvider.getHandler().evalDomain({domain:u,values:transformPlainMany2Ones({fields:T(),values:S()}),context:k()})),b&&b.length>0&&(P.current=P.current.concat(ooui.transformDomainForChildWidget({domain:b,widgetFieldName:c}))),q(P.current)}async function W(A){A.code==="Enter"?(A.preventDefault(),A.stopPropagation(),await Y()):A.code==="Backspace"&&U!==void 0&&(A.preventDefault(),A.stopPropagation(),V([void 0,""]))}const j=r&&!s?RequiredInput:antd.Input;return jsxRuntime.jsxs(antd.Row,{gutter:8,wrap:!1,children:[jsxRuntime.jsx(antd.Col,{flex:"auto",children:jsxRuntime.jsx(j,{type:"text",value:x,disabled:s,onChange:G,className:d,onBlur:Y,onKeyDown:W,suffix:jsxRuntime.jsx(Many2oneSuffix,{id:U,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:U===void 0||B===""||x===void 0,onClick:()=>{g(!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,H(B)},tabIndex:-1})}),jsxRuntime.jsx(SearchModal,{model:a,domain:M,context:{...k==null?void 0:k(),...l},visible:f,nameSearch:U?void 0:I,onSelectValues:A=>{m(!1),K(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=>{g(!1),K(A)},onCancel:()=>{g(!1)},mustClearAfterSave:!0,readOnly:s})]})},RequiredInput=styled__default.default(antd.Input)`
|
|
116
116
|
.ant-input {
|
|
117
117
|
background-color: ${Config.requiredColor};
|
|
118
118
|
}
|