@gisce/react-ooui 1.5.15-rc.1 → 1.5.15
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
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
display: flex;
|
|
33
33
|
align-items: center;
|
|
34
34
|
justify-content: center;
|
|
35
|
-
`,_a=({numberOfVisibleSelectedRows:t,totalRecords:r,numberOfTotalRows:n,onSelectAllRecords:s,numberOfRealSelectedRows:o})=>{const[i,a]=l.useState(!1),{t:c}=l.useContext(he),h={recordsSelected:c("recordsSelected"),selectAllRecords:c("selectAllRecords"),allRecordsSelected:c("allRecordsSelected")};if(n===0||t<n&&o<=n||r===t)return null;const d=async g=>{g.preventDefault(),g.stopPropagation(),a(!0),await s(),a(!1)},u=e.jsxs("span",{children:[h.recordsSelected.replace("{numberOfSelectedRows}",t.toString())+" ",i?e.jsx(p.Spin,{}):e.jsx(Mo.default,{onClick:d,style:{fontWeight:600},children:h.selectAllRecords.replace("{totalRecords}",r.toString())})]}),f=e.jsx("span",{style:{fontWeight:600},children:h.allRecordsSelected.replace("{totalRecords}",o.toString())+" "});return e.jsx(Oa,{children:o>n?f:u})},Da=t=>e.jsx("div",{style:{display:"flex",justifyContent:"center",alignContent:"center"},children:e.jsx(p.Checkbox,{checked:t,disabled:!0})}),ka=t=>e.jsx(wa,{m2oField:t}),Ma=t=>e.jsx(Kt.Interweave,{content:t==null?void 0:t.toString().replace(/(?:\r\n|\r|\n)/g,"<br>")}),Va=t=>{if(!t||t&&t.length===0)return e.jsx(e.Fragment,{});const r=Ze(t,et.date.dateInternalFormat).format(et.date.dateDisplayFormat);return e.jsx(e.Fragment,{children:r})},Ea=t=>{if(!t||t&&t.length===0)return e.jsx(e.Fragment,{});const r=Ze(t,et.time.dateInternalFormat).format(et.time.dateDisplayFormat);return e.jsx(e.Fragment,{children:r})},mn=t=>{const r=Array.isArray(t==null?void 0:t.items)?t==null?void 0:t.items.length:0;return e.jsx(e.Fragment,{children:`( ${r} )`})},Ia=t=>e.jsx(dn,{value:t}),Aa=t=>e.jsx(e.Fragment,{children:ln(t)}),yn=t=>e.jsx("div",{style:{textAlign:"right"},children:t}),$a=t=>e.jsx("img",{src:`data:image/*;base64,${t}`,style:{maxWidth:"50px",padding:"5px"}}),La=(t,r,n,s)=>e.jsx(Qr,{ooui:n,value:t}),Na=(t,r,n,s)=>{const[o,i]=l.useState([]),{relation:a,field:c}=n;l.useEffect(()=>{t&&(async()=>{try{const u=await K.getHandler().search({model:a,params:[["id","in",t.items.map(f=>f.id)]],fields:[c],context:s});i(u.map(f=>f.name))}catch(u){console.log("Error loading data",u)}})()},[]);const h=o.map(d=>{const u=St(d);return e.jsx(Xt,{color:u,children:d})});return e.jsx("div",{style:{maxWidth:"300px",whiteSpace:"break-spaces"},children:h})},Pa=(t,r,n,s)=>e.jsx(e.Fragment,{children:n.selectionValues.get(t)}),Ba=(t,r,n,s)=>e.jsx(e.Fragment,{children:e.jsx(Sa,{value:t,selectionValues:n.selectionValues,context:s})}),Ha=(t,r,n,s)=>e.jsx(Ca,{ooui:n,value:t});function Ft(t){var Z;const{page:r=1,limit:n,total:s,treeView:o,results:i,onRequestPageChange:a,loading:c,onRowClicked:h,showPagination:d=!0,rowSelection:u,scrollY:f,colorsForResults:g={},statusForResults:w={},onChangeSort:y,sorter:m,onFetchChildrenForRecord:v,childField:S,rootTree:T=!1,context:E,readonly:b,onSelectAllRecords:V}=t,[F,L]=l.useState([]),[x,O]=l.useState([]),_=l.useRef(!1),C=l.useRef(null),{t:P}=l.useContext(he),I=l.useRef(n),D=l.useContext(Ge),{title:$=void 0,setTitle:A=void 0}=(T?D:{})||{};l.useEffect(()=>{C.current=at(o);const B=di(C.current,{boolean:Da,many2one:ka,text:Ma,one2many:mn,many2many:mn,progressbar:Ia,float_time:Aa,image:$a,integer:yn,float:yn,reference:Ba,tag:La,selection:Pa,date:Va,datetime:Ea,avatar:Ha,tags:Na},E);O(B),C.current.string&&$!==C.current.string&&(A==null||A(C.current.string))},[o]),l.useEffect(()=>{_.current=!1;const B=Gr(C.current,i);L(B),I.current=n},[i]);const M=(r-1)*I.current+1,N=M-1+F.length,k=s===void 0?null:s===0?P("no_results"):P("summary").replace("{from}",M==null?void 0:M.toString()).replace("{to}",N==null?void 0:N.toString()).replace("{total}",s==null?void 0:s.toString()),Y=()=>{var W;if(!d||o.isExpandable)return null;const B=F==null?void 0:F.filter(R=>(u==null?void 0:u.selectedRowKeys)&&(u==null?void 0:u.selectedRowKeys.includes(R.id))).length;return c?null:s===void 0?e.jsx(p.Spin,{className:"pb-4"}):e.jsxs(p.Row,{align:"bottom",className:"pb-4",children:[e.jsx(p.Col,{span:V?8:12,children:e.jsx(p.Pagination,{total:s,pageSize:I.current===0?s:I.current,current:r,showSizeChanger:!1,onChange:a})}),V&&e.jsx(p.Col,{span:8,className:"text-center",children:e.jsx(_a,{numberOfVisibleSelectedRows:B,numberOfRealSelectedRows:((W=u==null?void 0:u.selectedRowKeys)==null?void 0:W.length)||0,numberOfTotalRows:F.length,totalRecords:s||0,onSelectAllRecords:V})}),e.jsx(p.Col,{span:V?8:12,className:"text-right",children:k})]})};function z(){var ce;const W=C.current.columns.filter(X=>X.sum!==void 0).map(X=>({label:X.sum,field:X.id}));if(!W||W.length===0)return null;let R=[],re=((ce=u==null?void 0:u.selectedRowKeys)==null?void 0:ce.length)>0?F.filter(X=>u==null?void 0:u.selectedRowKeys.includes(X.id)):F;return W.forEach(X=>{const Q=re.reduce((ue,pe)=>pe[X.field]&&!isNaN(pe[X.field])?ue+pe[X.field]:ue,0);R.push(`${X.label}: ${Math.round(Q*100)/100}`)}),e.jsx("div",{className:"p-1 pb-0 pl-2 mt-2 ",children:R.join(", ")})}let j,U=f;if(C.current!==null){j=ma(x,F,600);const W=C.current;f&&W.columns.some(R=>R.sum!==void 0)&&(U=f-30)}return C.current===null||!j||((Z=j.columns)==null?void 0:Z.length)===0?e.jsx(p.Spin,{style:{padding:"2rem"}}):e.jsxs("div",{children:[Y(),c&&e.jsx(p.Spin,{className:"pb-4"}),e.jsx(wo.Table,{height:U,columns:j.columns,dataSource:F,loading:!1,loadingComponent:e.jsx(p.Spin,{}),onRowStyle:B=>{if(g[B.id])return{color:g[B.id]}},onRowStatus:ui(w)?B=>{if(w[B.id])return e.jsx(p.Badge,{color:w[B.id]})}:void 0,onRowDoubleClick:h,selectionRowKeys:u==null?void 0:u.selectedRowKeys,onRowSelectionChange:u==null?void 0:u.onChange,onChangeSort:y,sorter:m,readonly:b,expandableOpts:v?{expandIcon:H.PlusSquareOutlined,collapseIcon:H.MinusSquareOutlined,loadingIcon:H.LoadingOutlined,onFetchChildrenForRecord:v,childField:S}:void 0}),z()]})}function Ka(t,r){const{model:n,formView:s,treeView:o,onRowClicked:i,nameSearch:a,treeScrollY:c,domain:h=[],visible:d=!0,rootTree:u=!1,parentContext:f={},onChangeSelectedRowKeys:g}=t,[w,y]=l.useState(!1),[m,v]=l.useState(!1),S=l.useRef(!1),[T,E]=l.useState(),[b,V]=l.useState(),[F,L]=l.useState(),[x,O]=l.useState(),[_,C]=l.useState(200),P=l.useRef(),{height:I}=kt(),D=l.useContext(ut),{processAction:$}=D||{},A=l.useContext(Ge),{setResults:M=void 0,setCurrentItemIndex:N=void 0,currentId:k=void 0,results:Y=void 0,selectedRowItems:z=void 0,setSelectedRowItems:j=void 0,searchParams:U=[],setSearchParams:Z=void 0,searchVisible:B=!0,setSearchVisible:W=void 0,sorter:R=void 0,setSorter:re=void 0,setTotalItems:ce=void 0,setSearchTreeNameSearch:X=void 0,setTreeIsLoading:Q=void 0,searchValues:ue={},setSearchValues:pe=void 0,limit:ke=xt,setLimit:Fe=void 0}=(u?A:{})||{},{submit:Ee,clear:Be,fetchResults:Se,tableRefreshing:ie,searchFilterLoading:Me,searchError:ve,page:Ve,offset:$e,getResults:te,requestPageChange:we,changeSort:_e,fetchChildrenForRecord:Ie,colorsForResults:ae,statusForResults:fe,totalItems:Ae,getAllIds:de}=nn({model:T,setSearchTreeNameSearch:X,setSelectedRowItems:ye,setSearchParams:Z,setSearchValues:pe,searchParams:U,setSearchVisible:W,setTreeIsLoading:Q,nameSearch:a,searchNameGetDoneRef:S,context:f,formView:F,treeView:b,sorter:R,setSorter:re,setCurrentItemIndex:N,setResultsActionView:M,resultsActionView:Y,domain:h,currentId:k,setActionViewTotalItems:ce,limit:ke,setLimit:Fe});l.useImperativeHandle(r,()=>({refreshResults:()=>{S.current=!1,Se()},getFields:()=>b==null?void 0:b.fields,getDomain:()=>h})),l.useEffect(()=>{!m||d&&(S.current=!1,Se())},[Ve,$e,m,d,a]);const qe=async()=>{v(!1),y(!0),O(void 0),Q==null||Q(!0);try{await Le(),v(!0)}catch(Oe){O(Oe),Q==null||Q(!1)}finally{y(!1)}},Le=async()=>{E(n);let Oe=s;s||(Oe=await K.getHandler().getView({model:n,type:"form",context:f}));let Ne=o;o||(Ne=await K.getHandler().getView({model:n,type:"tree",context:f})),L(Oe),V(Ne)};l.useEffect(()=>{qe()},[n]);const ee=Oe=>{Fe==null||Fe(Oe)},le=async Oe=>{const{id:Ne}=Oe;P.current||(P.current=await K.getHandler().treeButOpen({id:b.view_id,model:T,context:f}));const yt=P.current[0][2];await($==null?void 0:$({actionData:yt,fields:b.fields,values:{active_id:Ne,...Oe},context:f}))},Ce=async Oe=>{const{id:Ne}=Oe;if(b!=null&&b.isExpandable){try{await le(Oe)}catch(yt){Pe(yt)}return}i({id:Ne,model:T,formView:F,treeView:b})};function ye(Oe){j==null||j(Oe.map(Ne=>({id:Ne}))),g==null||g(Oe)}async function be(){const Oe=await de();j==null||j(Oe.map(Ne=>({id:Ne}))),g==null||g(Oe)}function Te(){return b!=null&&b.isExpandable?I-160:I-(_+210)}const je=()=>!b||!F?null:e.jsxs(e.Fragment,{children:[e.jsx(er,{fields:{...F.fields,...b.fields},searchFields:Jr([F.search_fields,b.search_fields]),onClear:Be,limit:ke,offset:$e,isSearching:Me,onSubmit:Ee,onLimitChange:ee,setSearchFilterHeight:C,searchError:ve,searchVisible:B,searchValues:ue}),e.jsx(Ft,{context:f,total:Ae,limit:ke,page:Ve,treeView:b,results:te(),onRequestPageChange:we,loading:ie,onRowClicked:Ce,scrollY:c||Te(),colorsForResults:ae,statusForResults:fe,rowSelection:{selectedRowKeys:z==null?void 0:z.map(Oe=>Oe.id),onChange:ye},sorter:R,onChangeSort:_e,onFetchChildrenForRecord:b.isExpandable?Ie:void 0,childField:b.field_parent,rootTree:u,onSelectAllRecords:be})]}),He=x||ve;return He?e.jsx(p.Alert,{className:"mt-10",message:He,type:"error",banner:!0}):e.jsx("div",{style:d?{}:{display:"none"},children:w?e.jsx(p.Spin,{}):je()})}const rr=l.forwardRef(Ka),nr=t=>{const{visible:r,onCloseModal:n,onSelectValues:s,model:o,nameSearch:i,domain:a,context:c={}}=t,[h,d]=l.useState(!1),{modalWidth:u,modalHeight:f}=kt(),{t:g}=l.useContext(he),[w,y]=l.useState([]),m=async()=>{await new Promise(E=>setTimeout(E,5)),n()},v=async E=>{const{id:b}=E;s([b])};function S(){if(w.length===0){m();return}s(w)}const T=()=>e.jsxs(e.Fragment,{children:[e.jsx(rr,{model:o,nameSearch:i,onRowClicked:v,treeScrollY:f*.3,domain:a,parentContext:c,onChangeSelectedRowKeys:E=>{y(E)}}),e.jsx(p.Divider,{}),e.jsx(p.Row,{justify:"end",children:e.jsxs(p.Space,{children:[e.jsx(p.Button,{icon:e.jsx(H.FileAddOutlined,{}),onClick:()=>{d(!0)},children:g("new")}),e.jsx(p.Button,{icon:e.jsx(H.CheckOutlined,{}),onClick:()=>{S()},type:"primary",children:g("ok")}),e.jsx(p.Button,{icon:e.jsx(H.CloseOutlined,{}),onClick:m,children:g("cancel")})]})})]});return e.jsxs(e.Fragment,{children:[e.jsx(p.Modal,{title:g("search"),centered:!0,width:u,open:r&&!h,closable:!0,onCancel:m,footer:null,destroyOnClose:!0,maskClosable:!1,children:T()}),e.jsx(ht,{model:o,visible:h,parentContext:c,onSubmitSucceed:E=>{d(!1),m(),s([E])},onCancel:()=>{d(!1),m()}})]})},{error:Wa}=p.Modal,Et=t=>{Wa({title:"Error",icon:e.jsx(H.ExclamationCircleOutlined,{}),centered:!0,content:t})},{defaultAlgorithm:Ya,defaultSeed:qa}=p.theme,vn=Ya(qa),wn=t=>{const{ooui:r}=t,{required:n}=r,s=async(o,i)=>{if(!i)throw new Error;if(!Array.isArray(i))throw new Error;if(Array.isArray(i)&&!i[0])throw new Error};return e.jsx(me,{required:n,type:"array",validator:s,...t,children:e.jsx(Sn,{ooui:r})})},Sn=t=>{const{value:r,onChange:n,ooui:s}=t,{required:o,relation:i,readOnly:a,context:c,id:h,domain:d}=s,u=o&&!a?{backgroundColor:vn.colorPrimaryBg}:void 0,[f,g]=l.useState(!1),[w,y]=l.useState(!1),[m,v]=l.useState(!1),[S,T]=l.useState(),E=l.useRef(!1),[b,V]=l.useState(""),F=l.useRef(),L=l.useContext(De),{domain:x,getValues:O,getFields:_,getContext:C,elementHasLostFocus:P}=L||{},I=l.useRef([]),[D,$]=l.useState([]),A=r&&r[0]||void 0,M=r&&r[1]||"";l.useEffect(()=>{!Array.isArray(r)&&r&&j(r)},[r]),l.useEffect(()=>{A&&M.length===0?j(A):A&&M.length>0?V(M):!A&&!M&&V(F.current||"")},[r]);const N=W=>{n==null||n(W),P==null||P()},k=W=>{F.current=W.target.value,N([void 0,""])},Y=async()=>{if(!m&&b!==M){if(await new Promise(W=>setTimeout(W,100)),E.current){N([void 0,""]);return}v(!0);try{if(I.current&&I.current.length>0)z(F.current);else{const W=await K.getHandler().nameSearch({model:i,payload:F.current,context:{...C==null?void 0:C(),...c}});W.length===1?(F.current=void 0,N(W[0])):z(F.current)}}catch(W){Et(W)}finally{v(!1)}}},z=async W=>{if(await U(),I.current&&I.current.length>0){const R=await K.getHandler().searchAllIds({params:I.current,model:i,context:{...C==null?void 0:C(),...c},totalItems:2});R.length===1?j(R[0]):(T(W),g(!0));return}T(W),g(!0)},j=async W=>{v(!0);try{const R=await K.getHandler().execute({action:"name_get",payload:[W],model:i,context:{...C==null?void 0:C(),...c}});N([W,R[0][1]])}catch(R){Et(R)}finally{v(!1)}};async function U(){d&&(I.current=await K.getHandler().evalDomain({domain:d,values:dt({fields:_(),values:O()}),fields:_(),context:C()})),x&&x.length>0&&(I.current=I.current.concat(se.transformDomainForChildWidget({domain:x,widgetFieldName:h}))),$(I.current)}async function Z(W){W.keyCode===13?(W.preventDefault(),W.stopPropagation(),await Y()):W.code==="Backspace"&&A!==void 0&&(W.preventDefault(),W.stopPropagation(),N([void 0,""]))}const B=o&&!a?Ua:p.Input;return e.jsxs(p.Row,{gutter:8,wrap:!1,children:[e.jsx(p.Col,{flex:"auto",children:e.jsx(B,{type:"text",value:b,disabled:a,onChange:k,style:u,onBlur:Y,onKeyDown:Z,suffix:e.jsx(tr,{id:A,model:i,context:{...C==null?void 0:C(),...c}})})}),e.jsx(p.Col,{flex:"32px",style:{paddingRight:0},children:e.jsx(p.Button,{icon:e.jsx(H.FolderOpenOutlined,{}),disabled:A===void 0||M===""||b===void 0,onClick:()=>{y(!0)},style:{borderTopRightRadius:0,borderBottomRightRadius:0},tabIndex:-1})}),e.jsx(p.Col,{flex:"32px",style:{paddingLeft:0},children:e.jsx(p.Button,{icon:m?e.jsx(H.LoadingOutlined,{}):e.jsx(H.SearchOutlined,{}),disabled:a||m,onClick:()=>{E.current=!0,z(M)},style:{borderTopLeftRadius:0,borderBottomLeftRadius:0},tabIndex:-1})}),e.jsx(nr,{model:i,domain:D,context:{...C==null?void 0:C(),...c},visible:f,nameSearch:A?void 0:S,onSelectValues:W=>{g(!1),j(W[0]),E.current=!1,F.current=void 0},onCloseModal:()=>{g(!1),E.current=!1}}),e.jsx(ht,{model:i,parentContext:{...C==null?void 0:C(),...c},id:r&&r[0],visible:w,onSubmitSucceed:W=>{y(!1),j(W)},onCancel:()=>{y(!1)},mustClearAfterSave:!0,readOnly:a})]})},Ua=ot.default(p.Input)`
|
|
35
|
+
`,_a=({numberOfVisibleSelectedRows:t,totalRecords:r,numberOfTotalRows:n,onSelectAllRecords:s,numberOfRealSelectedRows:o})=>{const[i,a]=l.useState(!1),{t:c}=l.useContext(he),h={recordsSelected:c("recordsSelected"),selectAllRecords:c("selectAllRecords"),allRecordsSelected:c("allRecordsSelected")};if(n===0||t<n&&o<=n||r===t)return null;const d=async g=>{g.preventDefault(),g.stopPropagation(),a(!0),await s(),a(!1)},u=e.jsxs("span",{children:[h.recordsSelected.replace("{numberOfSelectedRows}",t.toString())+" ",i?e.jsx(p.Spin,{}):e.jsx(Mo.default,{onClick:d,style:{fontWeight:600},children:h.selectAllRecords.replace("{totalRecords}",r.toString())})]}),f=e.jsx("span",{style:{fontWeight:600},children:h.allRecordsSelected.replace("{totalRecords}",o.toString())+" "});return e.jsx(Oa,{children:o>n?f:u})},Da=t=>e.jsx("div",{style:{display:"flex",justifyContent:"center",alignContent:"center"},children:e.jsx(p.Checkbox,{checked:t,disabled:!0})}),ka=t=>e.jsx(wa,{m2oField:t}),Ma=t=>e.jsx(Kt.Interweave,{content:t==null?void 0:t.toString().replace(/(?:\r\n|\r|\n)/g,"<br>")}),Va=t=>{if(!t||t&&t.length===0)return e.jsx(e.Fragment,{});const r=Ze(t,et.date.dateInternalFormat).format(et.date.dateDisplayFormat);return e.jsx(e.Fragment,{children:r})},Ea=t=>{if(!t||t&&t.length===0)return e.jsx(e.Fragment,{});const r=Ze(t,et.time.dateInternalFormat).format(et.time.dateDisplayFormat);return e.jsx(e.Fragment,{children:r})},mn=t=>{const r=Array.isArray(t==null?void 0:t.items)?t==null?void 0:t.items.length:0;return e.jsx(e.Fragment,{children:`( ${r} )`})},Ia=t=>e.jsx(dn,{value:t}),Aa=t=>e.jsx(e.Fragment,{children:ln(t)}),yn=t=>e.jsx("div",{style:{textAlign:"right"},children:t}),$a=t=>e.jsx("img",{src:`data:image/*;base64,${t}`,style:{maxWidth:"50px",padding:"5px"}}),La=(t,r,n,s)=>e.jsx(Qr,{ooui:n,value:t}),Na=(t,r,n,s)=>{const[o,i]=l.useState([]),{relation:a,field:c}=n;l.useEffect(()=>{t&&(async()=>{try{const u=await K.getHandler().search({model:a,params:[["id","in",t.items.map(f=>f.id)]],fields:[c],context:s});i(u.map(f=>f.name))}catch(u){console.log("Error loading data",u)}})()},[]);const h=o.map(d=>{const u=St(d);return e.jsx(Xt,{color:u,children:d})});return e.jsx("div",{style:{maxWidth:"300px",whiteSpace:"break-spaces"},children:h})},Pa=(t,r,n,s)=>{let o=t;return Array.isArray(t)&&t.length===2&&(o=t[0]),e.jsx(e.Fragment,{children:n.selectionValues.get(o)})},Ba=(t,r,n,s)=>e.jsx(e.Fragment,{children:e.jsx(Sa,{value:t,selectionValues:n.selectionValues,context:s})}),Ha=(t,r,n,s)=>e.jsx(Ca,{ooui:n,value:t});function Ft(t){var Z;const{page:r=1,limit:n,total:s,treeView:o,results:i,onRequestPageChange:a,loading:c,onRowClicked:h,showPagination:d=!0,rowSelection:u,scrollY:f,colorsForResults:g={},statusForResults:w={},onChangeSort:y,sorter:m,onFetchChildrenForRecord:v,childField:S,rootTree:T=!1,context:E,readonly:b,onSelectAllRecords:V}=t,[F,L]=l.useState([]),[x,O]=l.useState([]),_=l.useRef(!1),C=l.useRef(null),{t:P}=l.useContext(he),I=l.useRef(n),D=l.useContext(Ge),{title:$=void 0,setTitle:A=void 0}=(T?D:{})||{};l.useEffect(()=>{C.current=at(o);const B=di(C.current,{boolean:Da,many2one:ka,text:Ma,one2many:mn,many2many:mn,progressbar:Ia,float_time:Aa,image:$a,integer:yn,float:yn,reference:Ba,tag:La,selection:Pa,date:Va,datetime:Ea,avatar:Ha,tags:Na},E);O(B),C.current.string&&$!==C.current.string&&(A==null||A(C.current.string))},[o]),l.useEffect(()=>{_.current=!1;const B=Gr(C.current,i);L(B),I.current=n},[i]);const M=(r-1)*I.current+1,N=M-1+F.length,k=s===void 0?null:s===0?P("no_results"):P("summary").replace("{from}",M==null?void 0:M.toString()).replace("{to}",N==null?void 0:N.toString()).replace("{total}",s==null?void 0:s.toString()),Y=()=>{var W;if(!d||o.isExpandable)return null;const B=F==null?void 0:F.filter(R=>(u==null?void 0:u.selectedRowKeys)&&(u==null?void 0:u.selectedRowKeys.includes(R.id))).length;return c?null:s===void 0?e.jsx(p.Spin,{className:"pb-4"}):e.jsxs(p.Row,{align:"bottom",className:"pb-4",children:[e.jsx(p.Col,{span:V?8:12,children:e.jsx(p.Pagination,{total:s,pageSize:I.current===0?s:I.current,current:r,showSizeChanger:!1,onChange:a})}),V&&e.jsx(p.Col,{span:8,className:"text-center",children:e.jsx(_a,{numberOfVisibleSelectedRows:B,numberOfRealSelectedRows:((W=u==null?void 0:u.selectedRowKeys)==null?void 0:W.length)||0,numberOfTotalRows:F.length,totalRecords:s||0,onSelectAllRecords:V})}),e.jsx(p.Col,{span:V?8:12,className:"text-right",children:k})]})};function z(){var ce;const W=C.current.columns.filter(X=>X.sum!==void 0).map(X=>({label:X.sum,field:X.id}));if(!W||W.length===0)return null;let R=[],re=((ce=u==null?void 0:u.selectedRowKeys)==null?void 0:ce.length)>0?F.filter(X=>u==null?void 0:u.selectedRowKeys.includes(X.id)):F;return W.forEach(X=>{const Q=re.reduce((ue,pe)=>pe[X.field]&&!isNaN(pe[X.field])?ue+pe[X.field]:ue,0);R.push(`${X.label}: ${Math.round(Q*100)/100}`)}),e.jsx("div",{className:"p-1 pb-0 pl-2 mt-2 ",children:R.join(", ")})}let j,U=f;if(C.current!==null){j=ma(x,F,600);const W=C.current;f&&W.columns.some(R=>R.sum!==void 0)&&(U=f-30)}return C.current===null||!j||((Z=j.columns)==null?void 0:Z.length)===0?e.jsx(p.Spin,{style:{padding:"2rem"}}):e.jsxs("div",{children:[Y(),c&&e.jsx(p.Spin,{className:"pb-4"}),e.jsx(wo.Table,{height:U,columns:j.columns,dataSource:F,loading:!1,loadingComponent:e.jsx(p.Spin,{}),onRowStyle:B=>{if(g[B.id])return{color:g[B.id]}},onRowStatus:ui(w)?B=>{if(w[B.id])return e.jsx(p.Badge,{color:w[B.id]})}:void 0,onRowDoubleClick:h,selectionRowKeys:u==null?void 0:u.selectedRowKeys,onRowSelectionChange:u==null?void 0:u.onChange,onChangeSort:y,sorter:m,readonly:b,expandableOpts:v?{expandIcon:H.PlusSquareOutlined,collapseIcon:H.MinusSquareOutlined,loadingIcon:H.LoadingOutlined,onFetchChildrenForRecord:v,childField:S}:void 0}),z()]})}function Ka(t,r){const{model:n,formView:s,treeView:o,onRowClicked:i,nameSearch:a,treeScrollY:c,domain:h=[],visible:d=!0,rootTree:u=!1,parentContext:f={},onChangeSelectedRowKeys:g}=t,[w,y]=l.useState(!1),[m,v]=l.useState(!1),S=l.useRef(!1),[T,E]=l.useState(),[b,V]=l.useState(),[F,L]=l.useState(),[x,O]=l.useState(),[_,C]=l.useState(200),P=l.useRef(),{height:I}=kt(),D=l.useContext(ut),{processAction:$}=D||{},A=l.useContext(Ge),{setResults:M=void 0,setCurrentItemIndex:N=void 0,currentId:k=void 0,results:Y=void 0,selectedRowItems:z=void 0,setSelectedRowItems:j=void 0,searchParams:U=[],setSearchParams:Z=void 0,searchVisible:B=!0,setSearchVisible:W=void 0,sorter:R=void 0,setSorter:re=void 0,setTotalItems:ce=void 0,setSearchTreeNameSearch:X=void 0,setTreeIsLoading:Q=void 0,searchValues:ue={},setSearchValues:pe=void 0,limit:ke=xt,setLimit:Fe=void 0}=(u?A:{})||{},{submit:Ee,clear:Be,fetchResults:Se,tableRefreshing:ie,searchFilterLoading:Me,searchError:ve,page:Ve,offset:$e,getResults:te,requestPageChange:we,changeSort:_e,fetchChildrenForRecord:Ie,colorsForResults:ae,statusForResults:fe,totalItems:Ae,getAllIds:de}=nn({model:T,setSearchTreeNameSearch:X,setSelectedRowItems:ye,setSearchParams:Z,setSearchValues:pe,searchParams:U,setSearchVisible:W,setTreeIsLoading:Q,nameSearch:a,searchNameGetDoneRef:S,context:f,formView:F,treeView:b,sorter:R,setSorter:re,setCurrentItemIndex:N,setResultsActionView:M,resultsActionView:Y,domain:h,currentId:k,setActionViewTotalItems:ce,limit:ke,setLimit:Fe});l.useImperativeHandle(r,()=>({refreshResults:()=>{S.current=!1,Se()},getFields:()=>b==null?void 0:b.fields,getDomain:()=>h})),l.useEffect(()=>{!m||d&&(S.current=!1,Se())},[Ve,$e,m,d,a]);const qe=async()=>{v(!1),y(!0),O(void 0),Q==null||Q(!0);try{await Le(),v(!0)}catch(Oe){O(Oe),Q==null||Q(!1)}finally{y(!1)}},Le=async()=>{E(n);let Oe=s;s||(Oe=await K.getHandler().getView({model:n,type:"form",context:f}));let Ne=o;o||(Ne=await K.getHandler().getView({model:n,type:"tree",context:f})),L(Oe),V(Ne)};l.useEffect(()=>{qe()},[n]);const ee=Oe=>{Fe==null||Fe(Oe)},le=async Oe=>{const{id:Ne}=Oe;P.current||(P.current=await K.getHandler().treeButOpen({id:b.view_id,model:T,context:f}));const yt=P.current[0][2];await($==null?void 0:$({actionData:yt,fields:b.fields,values:{active_id:Ne,...Oe},context:f}))},Ce=async Oe=>{const{id:Ne}=Oe;if(b!=null&&b.isExpandable){try{await le(Oe)}catch(yt){Pe(yt)}return}i({id:Ne,model:T,formView:F,treeView:b})};function ye(Oe){j==null||j(Oe.map(Ne=>({id:Ne}))),g==null||g(Oe)}async function be(){const Oe=await de();j==null||j(Oe.map(Ne=>({id:Ne}))),g==null||g(Oe)}function Te(){return b!=null&&b.isExpandable?I-160:I-(_+210)}const je=()=>!b||!F?null:e.jsxs(e.Fragment,{children:[e.jsx(er,{fields:{...F.fields,...b.fields},searchFields:Jr([F.search_fields,b.search_fields]),onClear:Be,limit:ke,offset:$e,isSearching:Me,onSubmit:Ee,onLimitChange:ee,setSearchFilterHeight:C,searchError:ve,searchVisible:B,searchValues:ue}),e.jsx(Ft,{context:f,total:Ae,limit:ke,page:Ve,treeView:b,results:te(),onRequestPageChange:we,loading:ie,onRowClicked:Ce,scrollY:c||Te(),colorsForResults:ae,statusForResults:fe,rowSelection:{selectedRowKeys:z==null?void 0:z.map(Oe=>Oe.id),onChange:ye},sorter:R,onChangeSort:_e,onFetchChildrenForRecord:b.isExpandable?Ie:void 0,childField:b.field_parent,rootTree:u,onSelectAllRecords:be})]}),He=x||ve;return He?e.jsx(p.Alert,{className:"mt-10",message:He,type:"error",banner:!0}):e.jsx("div",{style:d?{}:{display:"none"},children:w?e.jsx(p.Spin,{}):je()})}const rr=l.forwardRef(Ka),nr=t=>{const{visible:r,onCloseModal:n,onSelectValues:s,model:o,nameSearch:i,domain:a,context:c={}}=t,[h,d]=l.useState(!1),{modalWidth:u,modalHeight:f}=kt(),{t:g}=l.useContext(he),[w,y]=l.useState([]),m=async()=>{await new Promise(E=>setTimeout(E,5)),n()},v=async E=>{const{id:b}=E;s([b])};function S(){if(w.length===0){m();return}s(w)}const T=()=>e.jsxs(e.Fragment,{children:[e.jsx(rr,{model:o,nameSearch:i,onRowClicked:v,treeScrollY:f*.3,domain:a,parentContext:c,onChangeSelectedRowKeys:E=>{y(E)}}),e.jsx(p.Divider,{}),e.jsx(p.Row,{justify:"end",children:e.jsxs(p.Space,{children:[e.jsx(p.Button,{icon:e.jsx(H.FileAddOutlined,{}),onClick:()=>{d(!0)},children:g("new")}),e.jsx(p.Button,{icon:e.jsx(H.CheckOutlined,{}),onClick:()=>{S()},type:"primary",children:g("ok")}),e.jsx(p.Button,{icon:e.jsx(H.CloseOutlined,{}),onClick:m,children:g("cancel")})]})})]});return e.jsxs(e.Fragment,{children:[e.jsx(p.Modal,{title:g("search"),centered:!0,width:u,open:r&&!h,closable:!0,onCancel:m,footer:null,destroyOnClose:!0,maskClosable:!1,children:T()}),e.jsx(ht,{model:o,visible:h,parentContext:c,onSubmitSucceed:E=>{d(!1),m(),s([E])},onCancel:()=>{d(!1),m()}})]})},{error:Wa}=p.Modal,Et=t=>{Wa({title:"Error",icon:e.jsx(H.ExclamationCircleOutlined,{}),centered:!0,content:t})},{defaultAlgorithm:Ya,defaultSeed:qa}=p.theme,vn=Ya(qa),wn=t=>{const{ooui:r}=t,{required:n}=r,s=async(o,i)=>{if(!i)throw new Error;if(!Array.isArray(i))throw new Error;if(Array.isArray(i)&&!i[0])throw new Error};return e.jsx(me,{required:n,type:"array",validator:s,...t,children:e.jsx(Sn,{ooui:r})})},Sn=t=>{const{value:r,onChange:n,ooui:s}=t,{required:o,relation:i,readOnly:a,context:c,id:h,domain:d}=s,u=o&&!a?{backgroundColor:vn.colorPrimaryBg}:void 0,[f,g]=l.useState(!1),[w,y]=l.useState(!1),[m,v]=l.useState(!1),[S,T]=l.useState(),E=l.useRef(!1),[b,V]=l.useState(""),F=l.useRef(),L=l.useContext(De),{domain:x,getValues:O,getFields:_,getContext:C,elementHasLostFocus:P}=L||{},I=l.useRef([]),[D,$]=l.useState([]),A=r&&r[0]||void 0,M=r&&r[1]||"";l.useEffect(()=>{!Array.isArray(r)&&r&&j(r)},[r]),l.useEffect(()=>{A&&M.length===0?j(A):A&&M.length>0?V(M):!A&&!M&&V(F.current||"")},[r]);const N=W=>{n==null||n(W),P==null||P()},k=W=>{F.current=W.target.value,N([void 0,""])},Y=async()=>{if(!m&&b!==M){if(await new Promise(W=>setTimeout(W,100)),E.current){N([void 0,""]);return}v(!0);try{if(I.current&&I.current.length>0)z(F.current);else{const W=await K.getHandler().nameSearch({model:i,payload:F.current,context:{...C==null?void 0:C(),...c}});W.length===1?(F.current=void 0,N(W[0])):z(F.current)}}catch(W){Et(W)}finally{v(!1)}}},z=async W=>{if(await U(),I.current&&I.current.length>0){const R=await K.getHandler().searchAllIds({params:I.current,model:i,context:{...C==null?void 0:C(),...c},totalItems:2});R.length===1?j(R[0]):(T(W),g(!0));return}T(W),g(!0)},j=async W=>{v(!0);try{const R=await K.getHandler().execute({action:"name_get",payload:[W],model:i,context:{...C==null?void 0:C(),...c}});N([W,R[0][1]])}catch(R){Et(R)}finally{v(!1)}};async function U(){d&&(I.current=await K.getHandler().evalDomain({domain:d,values:dt({fields:_(),values:O()}),fields:_(),context:C()})),x&&x.length>0&&(I.current=I.current.concat(se.transformDomainForChildWidget({domain:x,widgetFieldName:h}))),$(I.current)}async function Z(W){W.keyCode===13?(W.preventDefault(),W.stopPropagation(),await Y()):W.code==="Backspace"&&A!==void 0&&(W.preventDefault(),W.stopPropagation(),N([void 0,""]))}const B=o&&!a?Ua:p.Input;return e.jsxs(p.Row,{gutter:8,wrap:!1,children:[e.jsx(p.Col,{flex:"auto",children:e.jsx(B,{type:"text",value:b,disabled:a,onChange:k,style:u,onBlur:Y,onKeyDown:Z,suffix:e.jsx(tr,{id:A,model:i,context:{...C==null?void 0:C(),...c}})})}),e.jsx(p.Col,{flex:"32px",style:{paddingRight:0},children:e.jsx(p.Button,{icon:e.jsx(H.FolderOpenOutlined,{}),disabled:A===void 0||M===""||b===void 0,onClick:()=>{y(!0)},style:{borderTopRightRadius:0,borderBottomRightRadius:0},tabIndex:-1})}),e.jsx(p.Col,{flex:"32px",style:{paddingLeft:0},children:e.jsx(p.Button,{icon:m?e.jsx(H.LoadingOutlined,{}):e.jsx(H.SearchOutlined,{}),disabled:a||m,onClick:()=>{E.current=!0,z(M)},style:{borderTopLeftRadius:0,borderBottomLeftRadius:0},tabIndex:-1})}),e.jsx(nr,{model:i,domain:D,context:{...C==null?void 0:C(),...c},visible:f,nameSearch:A?void 0:S,onSelectValues:W=>{g(!1),j(W[0]),E.current=!1,F.current=void 0},onCloseModal:()=>{g(!1),E.current=!1}}),e.jsx(ht,{model:i,parentContext:{...C==null?void 0:C(),...c},id:r&&r[0],visible:w,onSubmitSucceed:W=>{y(!1),j(W)},onCancel:()=>{y(!1)},mustClearAfterSave:!0,readOnly:a})]})},Ua=ot.default(p.Input)`
|
|
36
36
|
.ant-input {
|
|
37
37
|
background-color: ${vn.colorPrimaryBg};
|
|
38
38
|
}
|