@gisce/react-ooui 1.0.18 → 1.0.20
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:F}=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,_=b-1+g.length,T=o===void 0?null:o===0?F("no_results"):F("summary").replace("{from}",b==null?void 0:b.toString()).replace("{to}",_==null?void 0:_.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 U=O.current.columns.filter(K=>K.sum!==void 0).map(K=>({label:K.sum,field:K.id}));if(!U||U.length===0)return null;let q=[],B=((V=d==null?void 0:d.selectedRowKeys)==null?void 0:V.length)>0?g.filter(K=>d==null?void 0:d.selectedRowKeys.includes(K.id)):g;return U.forEach(K=>{const G=B.reduce((H,Y)=>Y[K.field]&&!isNaN(Y[K.field])?H+Y[K.field]:H,0);q.push(`${K.label}: ${Math.round(G*100)/100}`)}),jsxRuntime.jsx("div",{className:"p-1 pb-0 pl-2 mt-2 bg-gray-50",children:q.join(", ")})}let D,P=f;if(O.current!==null){D=calculateColumnsWidth(y,g,600);const U=O.current;f&&U.columns.some(q=>q.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: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,F]=React.useState(),[b,_]=React.useState(),[T,k]=React.useState(1),[L,D]=React.useState(0),[P,j]=React.useState(DEFAULT_SEARCH_LIMIT$1),[U,q]=React.useState(),B=React.useRef([]),[V,K]=React.useState(),[G,H]=React.useState([]),[Y,N]=React.useState(void 0),[z,M]=React.useState(!1),[A,$]=React.useState(),[Z,Q]=React.useState(),[E,S]=React.useState(!1),W=React.useRef([]),[X,oe]=React.useState(200),ee=React.useRef([]),re=React.useRef(),{height:le}=useWindowDimensions(),de=React.useContext(ActionViewContext),{setResults:ae=void 0,setCurrentItemIndex:pe=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:fe=void 0,setSearchTreeNameSearch:me=void 0,setTreeIsLoading:te=void 0}=(f?de:{})||{},he=React.useContext(ContentRootContext),{processAction:Ce}=he||{};React.useImperativeHandle(n,()=>({refreshResults:()=>{h.current=!1,Ne()}}));const be=ue=>{S(!0),k(ue),D((ue-1)*P)};function Te(ue){ae==null||ae([...ue]),H([...ue])}const Se=React.useCallback(()=>_e||G,[_e,G]),Pe=async()=>{const ue=await ConnectionProvider.getHandler().nameSearch({model:x,payload:l,limit:y.current,attrs:W.current.length>0?W.current:u,context:m});if(K(ue.length),fe==null||fe(ue.length),ue.length>0){const ve=ue.map(se=>se==null?void 0:se[0]),{colors:we}=getTree(O),Ae=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=Ae[0];ee.current=[...J],N(getColorMap(Ae[1]));const ne=J.map(se=>se.id),ce=Ee!==void 0?sortResults({resultsToSort:J,sorter:Ee,fields:{...O.fields,...b.fields}}):[...ee.current];Te(ce),ne.length>0?pe==null||pe(0):pe==null||pe(void 0)}else Te([]),pe==null||pe(void 0);h.current=!0},je=ue=>{const ve={};return ue.forEach(we=>{Array.isArray(we)&&we[0]?ve[we[0]]=!0:ve[we]=!0}),Object.keys(ve)},Le=(ue,ve)=>{const we=ue,Ae=je(ue);return ve.forEach(J=>{Array.isArray(J)&&J[0]?Ae.includes(J[0])||we.push(J):Ae.includes(J)||we.push(J)}),we},Me=async()=>{const ue=W.current.length>0?W.current:u,ve=Le(B.current,ue),{colors:we}=getTree(O),{totalItems:Ae,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}});N(getColorMap(ne)),ee.current=[...J];const ce=Ee!==void 0?sortResults({resultsToSort:J,sorter:Ee,fields:{...O.fields,...b.fields}}):[...ee.current];if(Ae.then(se=>{K(se),fe==null||fe(se)}),Te(ce),_e&&ce.length>0){const se=ce.findIndex(Oe=>ge===Oe.id);se===-1?pe==null||pe(0):pe==null||pe(se)}else pe==null||pe(void 0)},Ne=async()=>{try{S(!0),te==null||te(!0),l&&!h.current?await Pe():await Me()}catch(ue){$(ue)}finally{S(!1),M(!1),te==null||te(!1)}};async function Ve(ue){const ve=ue[(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())},[T,P,L,C,d,l]);const qe=async ue=>{g(!1),v(!0),Q(void 0),te==null||te(!0);try{ue==="action"?await De():await Be(),g(!0)}catch(ve){Q(ve)}finally{v(!1),te==null||te(!1)}},De=async()=>{const ue=await ConnectionProvider.getHandler().getViewsForAction({action:t,context:m});W.current=ue.domain,_(ue.views.get("form")),F(ue.views.get("tree")),w(ue.model),q(ue.limit),j(ue.limit)},Be=async()=>{w(o);let ue=r;r||(ue=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})),_(ue),F(ve),q(void 0),j(DEFAULT_SEARCH_LIMIT$1)};React.useEffect(()=>{t?qe("action"):o&&qe("model")},[t,o]);const $e=()=>{E||(me==null||me(void 0),B.current=[],ye==null||ye([]),$(void 0),D(0),k(1),j(U||DEFAULT_SEARCH_LIMIT$1))},He=({params:ue,limit:ve,offset:we})=>{E||(B.current=ue,me==null||me(void 0),Re==null||Re([]),ye==null||ye(ue),xe==null||xe(!1),M(!0),$(void 0),k(1),ve&&j(ve),we&&D(we),Ne())},We=ue=>{y.current=ue},ze=async ue=>{const{id:ve}=ue;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,...ue},context:m}))},Ge=async ue=>{const{id:ve}=ue;if(O!=null&&O.isExpandable){try{await ze(ue)}catch(we){showDialog$8(we)}return}s({id:ve,model:x,formView:b,treeView:O})};function Ye(ue){const ve=Se().filter(we=>ue.includes(we.id));Re==null||Re(ve),p==null||p(ue)}function Ke(){return O!=null&&O.isExpandable?le-160:le-(X+210)}const Ue=()=>!O||!b?null:jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx(Measure__default.default,{bounds:!0,onResize:ue=>{var ve;oe((ve=ue.bounds)==null?void 0:ve.height)},children:({measureRef:ue})=>jsxRuntime.jsx("div",{ref:ue,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:z,onSubmit:He,onLimitChange:We}),A&&jsxRuntime.jsx(antd.Alert,{className:"mt-10",message:A,type:"error",banner:!0}),jsxRuntime.jsx("div",{className:"pb-5"})]})})}),jsxRuntime.jsx(Tree,{total:V,limit:P,page:T,treeView:O,results:Se(),onRequestPageChange:be,loading:E,onRowClicked:Ge,scrollY:c||Ke(),colorsForResults:Y,rowSelection:{selectedRowKeys:Ie==null?void 0:Ie.map(ue=>ue.id),onChange:Ye},sorter:Ee,onChangeSort:ue=>{ie==null||ie(ue);const ve=ue!==void 0?sortResults({resultsToSort:Se(),sorter:ue,fields:{...O.fields,...b.fields}}):[...ee.current];Te(ve)},onFetchChildrenForRecord:O.isExpandable?Ve: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,{}):Ue()})}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(),F=React.useContext(FormContext$1),{domain:b,getValues:_,getFields:T,getContext:k,setOriginalValue:L,elementHasLostFocus:D}=F||{},P=React.useRef([]),[j,U]=React.useState([]),q=n&&n[0],B=n&&n[1]||"";React.useEffect(()=>{!Array.isArray(n)&&!isNaN(n)&&Y(n)},[n]),React.useEffect(()=>{q&&B.length===0?Y(q):q&&B.length>0?w(B):!q&&!B&&w(O.current||"")},[n]);const V=A=>{t==null||t(A),D==null||D()},K=A=>{O.current=A.target.value,V([void 0,""])},G=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?Y($[0],!0):(h(A),m(!0));return}h(A),m(!0)},Y=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:_()}),context:k()})),b&&b.length>0&&(P.current=P.current.concat(ooui.transformDomainForChildWidget({domain:b,widgetFieldName:c}))),U(P.current)}async function z(A){A.code==="Enter"?(A.preventDefault(),A.stopPropagation(),await G()):A.code==="Backspace"&&q!==void 0&&(A.preventDefault(),A.stopPropagation(),V([void 0,""]))}const M=r&&!s?RequiredInput:antd.Input;return jsxRuntime.jsxs(antd.Row,{gutter:8,wrap:!1,children:[jsxRuntime.jsx(antd.Col,{flex:"auto",children:jsxRuntime.jsx(M,{type:"text",value:x,disabled:s,onChange:K,className:d,onBlur:G,onKeyDown:z,suffix:jsxRuntime.jsx(Many2oneSuffix,{id:q,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:q===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,H(B)},tabIndex:-1})}),jsxRuntime.jsx(SearchModal,{model:a,domain:j,context:{...k==null?void 0:k(),...l},visible:f,nameSearch:q?void 0:g,onSelectValues:A=>{m(!1),Y(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),Y(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:F}=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,_=b-1+g.length,T=o===void 0?null:o===0?F("no_results"):F("summary").replace("{from}",b==null?void 0:b.toString()).replace("{to}",_==null?void 0:_.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 U=O.current.columns.filter(K=>K.sum!==void 0).map(K=>({label:K.sum,field:K.id}));if(!U||U.length===0)return null;let q=[],B=((V=d==null?void 0:d.selectedRowKeys)==null?void 0:V.length)>0?g.filter(K=>d==null?void 0:d.selectedRowKeys.includes(K.id)):g;return U.forEach(K=>{const G=B.reduce((H,Y)=>Y[K.field]&&!isNaN(Y[K.field])?H+Y[K.field]:H,0);q.push(`${K.label}: ${Math.round(G*100)/100}`)}),jsxRuntime.jsx("div",{className:"p-1 pb-0 pl-2 mt-2 bg-gray-50",children:q.join(", ")})}let D,P=f;if(O.current!==null){D=calculateColumnsWidth(y,g,600);const U=O.current;f&&U.columns.some(q=>q.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: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,F]=React.useState(),[b,_]=React.useState(),[T,k]=React.useState(1),[L,D]=React.useState(0),[P,j]=React.useState(DEFAULT_SEARCH_LIMIT$1),[U,q]=React.useState(),B=React.useRef([]),[V,K]=React.useState(),[G,H]=React.useState([]),[Y,N]=React.useState(void 0),[z,M]=React.useState(!1),[A,$]=React.useState(),[Z,Q]=React.useState(),[E,S]=React.useState(!1),W=React.useRef([]),[X,oe]=React.useState(200),ee=React.useRef([]),re=React.useRef(),{height:le}=useWindowDimensions(),de=React.useContext(ActionViewContext),{setResults:ae=void 0,setCurrentItemIndex:pe=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:fe=void 0,setSearchTreeNameSearch:me=void 0,setTreeIsLoading:te=void 0}=(f?de:{})||{},he=React.useContext(ContentRootContext),{processAction:Ce}=he||{};React.useImperativeHandle(n,()=>({refreshResults:()=>{h.current=!1,Ne()}}));const be=ue=>{S(!0),k(ue),D((ue-1)*P)};function Te(ue){ae==null||ae([...ue]),H([...ue])}const Se=React.useCallback(()=>_e||G,[_e,G]),Pe=async()=>{const ue=await ConnectionProvider.getHandler().nameSearch({model:x,payload:l,limit:y.current,attrs:W.current.length>0?W.current:u,context:m});if(K(ue.length),fe==null||fe(ue.length),ue.length>0){const ve=ue.map(se=>se==null?void 0:se[0]),{colors:we}=getTree(O),Ae=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=Ae[0];ee.current=[...J],N(getColorMap(Ae[1]));const ne=J.map(se=>se.id),ce=Ee!==void 0?sortResults({resultsToSort:J,sorter:Ee,fields:{...O.fields,...b.fields}}):[...ee.current];Te(ce),ne.length>0?pe==null||pe(0):pe==null||pe(void 0)}else Te([]),pe==null||pe(void 0);h.current=!0},je=ue=>{const ve={};return ue.forEach(we=>{Array.isArray(we)&&we[0]?ve[we[0]]=!0:ve[we]=!0}),Object.keys(ve)},Le=(ue,ve)=>{const we=ue,Ae=je(ue);return ve.forEach(J=>{Array.isArray(J)&&J[0]?Ae.includes(J[0])||we.push(J):Ae.includes(J)||we.push(J)}),we},Me=async()=>{const ue=W.current.length>0?W.current:u,ve=Le(B.current,ue),{colors:we}=getTree(O),{totalItems:Ae,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}});N(getColorMap(ne)),ee.current=[...J];const ce=Ee!==void 0?sortResults({resultsToSort:J,sorter:Ee,fields:{...O.fields,...b.fields}}):[...ee.current];if(Ae.then(se=>{K(se),fe==null||fe(se)}),Te(ce),_e&&ce.length>0){const se=ce.findIndex(Oe=>ge===Oe.id);se===-1?pe==null||pe(0):pe==null||pe(se)}else pe==null||pe(void 0)},Ne=async()=>{try{S(!0),te==null||te(!0),l&&!h.current?await Pe():await Me()}catch(ue){$(ue)}finally{S(!1),M(!1),te==null||te(!1)}};async function Ve(ue){const ve=ue[(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())},[T,P,L,C,d,l]);const qe=async ue=>{g(!1),v(!0),Q(void 0),te==null||te(!0);try{ue==="action"?await De():await Be(),g(!0)}catch(ve){Q(ve)}finally{v(!1),te==null||te(!1)}},De=async()=>{const ue=await ConnectionProvider.getHandler().getViewsForAction({action:t,context:m});W.current=ue.domain,_(ue.views.get("form")),F(ue.views.get("tree")),w(ue.model),q(ue.limit),j(ue.limit)},Be=async()=>{w(o);let ue=r;r||(ue=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})),_(ue),F(ve),q(void 0),j(DEFAULT_SEARCH_LIMIT$1)};React.useEffect(()=>{t?qe("action"):o&&qe("model")},[t,o]);const $e=()=>{E||(me==null||me(void 0),B.current=[],ye==null||ye([]),$(void 0),D(0),k(1),j(U||DEFAULT_SEARCH_LIMIT$1))},He=({params:ue,limit:ve,offset:we})=>{E||(B.current=ue,me==null||me(void 0),Re==null||Re([]),ye==null||ye(ue),xe==null||xe(!1),M(!0),$(void 0),k(1),ve&&j(ve),we&&D(we),Ne())},We=ue=>{y.current=ue},ze=async ue=>{const{id:ve}=ue;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,...ue},context:m}))},Ge=async ue=>{const{id:ve}=ue;if(O!=null&&O.isExpandable){try{await ze(ue)}catch(we){showDialog$8(we)}return}s({id:ve,model:x,formView:b,treeView:O})};function Ye(ue){const ve=Se().filter(we=>ue.includes(we.id));Re==null||Re(ve),p==null||p(ue)}function Ke(){return O!=null&&O.isExpandable?le-160:le-(X+210)}const Ue=()=>!O||!b?null:jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx(Measure__default.default,{bounds:!0,onResize:ue=>{var ve;oe((ve=ue.bounds)==null?void 0:ve.height)},children:({measureRef:ue})=>jsxRuntime.jsx("div",{ref:ue,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:z,onSubmit:He,onLimitChange:We}),A&&jsxRuntime.jsx(antd.Alert,{className:"mt-10",message:A,type:"error",banner:!0}),jsxRuntime.jsx("div",{className:"pb-5"})]})})}),jsxRuntime.jsx(Tree,{total:V,limit:P,page:T,treeView:O,results:Se(),onRequestPageChange:be,loading:E,onRowClicked:Ge,scrollY:c||Ke(),colorsForResults:Y,rowSelection:{selectedRowKeys:Ie==null?void 0:Ie.map(ue=>ue.id),onChange:Ye},sorter:Ee,onChangeSort:ue=>{ie==null||ie(ue);const ve=ue!==void 0?sortResults({resultsToSort:Se(),sorter:ue,fields:{...O.fields,...b.fields}}):[...ee.current];Te(ve)},onFetchChildrenForRecord:O.isExpandable?Ve: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,{}):Ue()})}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(),F=React.useContext(FormContext$1),{domain:b,getValues:_,getFields:T,getContext:k,setOriginalValue:L,elementHasLostFocus:D}=F||{},P=React.useRef([]),[j,U]=React.useState([]),q=n&&n[0]||void 0,B=n&&n[1]||"";React.useEffect(()=>{!Array.isArray(n)&&n&&Y(n)},[n]),React.useEffect(()=>{q&&B.length===0?Y(q):q&&B.length>0?w(B):!q&&!B&&w(O.current||"")},[n]);const V=A=>{t==null||t(A),D==null||D()},K=A=>{O.current=A.target.value,V([void 0,""])},G=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?Y($[0],!0):(h(A),m(!0));return}h(A),m(!0)},Y=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:_()}),context:k()})),b&&b.length>0&&(P.current=P.current.concat(ooui.transformDomainForChildWidget({domain:b,widgetFieldName:c}))),U(P.current)}async function z(A){A.code==="Enter"?(A.preventDefault(),A.stopPropagation(),await G()):A.code==="Backspace"&&q!==void 0&&(A.preventDefault(),A.stopPropagation(),V([void 0,""]))}const M=r&&!s?RequiredInput:antd.Input;return jsxRuntime.jsxs(antd.Row,{gutter:8,wrap:!1,children:[jsxRuntime.jsx(antd.Col,{flex:"auto",children:jsxRuntime.jsx(M,{type:"text",value:x,disabled:s,onChange:K,className:d,onBlur:G,onKeyDown:z,suffix:jsxRuntime.jsx(Many2oneSuffix,{id:q,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:q===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,H(B)},tabIndex:-1})}),jsxRuntime.jsx(SearchModal,{model:a,domain:j,context:{...k==null?void 0:k(),...l},visible:f,nameSearch:q?void 0:g,onSelectValues:A=>{m(!1),Y(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),Y(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
|
}
|