Service-CZKEboqO.js 12 KB

1
  1. import{s as O,E as b,G as S,V as _,X as y,an as x,aE as M,ck as E,ds as k,cj as T,c7 as j,aK as R,a3 as C,y as D,dt as I,aM as U,f as A,x as B,O as W,z as F,P,Q as l,T as Q,D as z,d0 as K,K as N,av as V,a5 as H,at as G}from"./index-DT8qTvyx.js";var w=["inited","onApiFetched","onSchemaApiFetched","onWsFetched"],L=function(m){O(n,m);function n(t){var e=m.call(this,t)||this;return e.dataProviders=e.initDataProviders(t.dataProvider),e.handleQuery=e.handleQuery.bind(e),e.handleAction=e.handleAction.bind(e),e.handleChange=e.handleChange.bind(e),e.reload=e.reload.bind(e),e.silentReload=e.silentReload.bind(e),e.initInterval=e.initInterval.bind(e),e.afterDataFetch=e.afterDataFetch.bind(e),e.afterSchemaFetch=e.afterSchemaFetch.bind(e),e.runDataProvider=e.runDataProvider.bind(e),e.dataProviderSetData=e.dataProviderSetData.bind(e),e}return n.prototype.componentDidMount=function(){return b(this,void 0,void 0,function(){var t,e,a,r;return S(this,function(i){switch(i.label){case 0:return t=this.props,e=t.data,a=t.dispatchEvent,this.mounted=!0,[4,a("init",e,this)];case 1:return r=i.sent(),r!=null&&r.prevented?[2]:(this.initFetch(),[2])}})})},n.prototype.componentDidUpdate=function(t){var e=this,a,r=this.props,i=r.store,o=r.messages,s=o.fetchSuccess,c=o.fetchFailed;r.dataProvider!==t.dataProvider&&(this.dataProviders=this.initDataProviders(r.dataProvider),this.dataProviders&&(!((a=this.dataProviders)===null||a===void 0)&&a.inited)&&this.runDataProvider("inited")),_(t.api,r.api,t.data,r.data)&&y(r.api,i.data)&&i.fetchData(r.api,i.data,{successMessage:s,errorMessage:c}).then(function(d){e.runDataProvider("onApiFetched"),e.afterDataFetch(d)}),_(t.schemaApi,r.schemaApi,t.data,r.data)&&y(r.schemaApi,i.data)&&i.fetchSchema(r.schemaApi,i.data,{successMessage:s,errorMessage:c}).then(function(d){e.runDataProvider("onSchemaApiFetched"),e.afterSchemaFetch(d)}),r.ws&&t.ws!==r.ws&&(this.socket&&this.socket.close(),this.socket=this.fetchWSData(r.ws,i.data)),x(t.defaultData,r.defaultData)&&i.reInitData(r.defaultData)},n.prototype.componentWillUnmount=function(){this.mounted=!1,this.runDataProviderUnsubscribe(),clearTimeout(this.timer),this.socket&&this.socket.close&&this.socket.close()},n.prototype.doAction=function(t,e,a,r){if((t==null?void 0:t.actionType)==="rebuild"){var i=this.props,o=i.schemaApi,s=i.store,c=i.dataProvider,d=i.messages,h=d.fetchSuccess,u=d.fetchFailed;s.updateData(r),clearTimeout(this.timer),y(o,s.data)&&s.fetchSchema(o,s.data,{successMessage:h,errorMessage:u}).then(this.afterSchemaFetch),c&&this.runDataProvider("inited")}},n.prototype.initFetch=function(){var t=this,e=this.props,a=e.schemaApi,r=e.initFetchSchema,i=e.api,o=e.ws,s=e.initFetch,c=e.initFetchOn,d=e.dataProvider,h=e.store,u=e.messages,f=u.fetchSuccess,p=u.fetchFailed;y(a,h.data,r)&&h.fetchSchema(a,h.data,{successMessage:f,errorMessage:p}).then(function(v){t.runDataProvider("onSchemaApiFetched"),t.afterSchemaFetch(v)}),y(i,h.data,s,c)&&h.fetchInitData(i,h.data,{successMessage:f,errorMessage:p}).then(function(v){t.runDataProvider("onApiFetched"),t.afterDataFetch(v)}),o&&(this.socket=this.fetchWSData(o,h.data)),d&&this.runDataProvider("inited")},n.prototype.initDataProviders=function(t){var e=this,a=M(t)?E(t):t,r={};if(a)if(M(a))Object.keys(a).forEach(function(o){var s=e.normalizeProvider(a[o],o);r=k(r,s||{})});else{var i=this.normalizeProvider(a,"inited");r=k(r,i||{})}return r},n.prototype.normalizeProvider=function(t,e){var a,r;if(e===void 0&&(e="inited"),!~w.indexOf(e))return null;if(typeof t=="function")return a={},a[e]=t,a;if(typeof t=="string"){var i=T(t,"data","setData","env");return i?(r={},r[e]=i,r):null}return null},n.prototype.runDataProvider=function(t){return b(this,void 0,void 0,function(){var e,a,r,i;return S(this,function(o){switch(o.label){case 0:return this.runDataProviderUnsubscribe(t),e=this.props.store,a=this.dataProviders,a&&~w.indexOf(t)?(r=a[t],r&&typeof r=="function"?[4,r(e.data,this.dataProviderSetData,this.props.env)]:[3,2]):[3,2];case 1:i=o.sent(),typeof i=="function"&&(this.dataProviderUnsubscribe||(this.dataProviderUnsubscribe={}),this.dataProviderUnsubscribe[t]=i),o.label=2;case 2:return[2]}})})},n.prototype.runDataProviderUnsubscribe=function(t){var e,a=this.dataProviderUnsubscribe;if(a)if(t){var r=a[t];try{r&&typeof r=="function"&&r()}catch(i){console.error(i)}}else(e=Object.keys(a))===null||e===void 0||e.forEach(function(i){var o=a[i];try{o&&typeof o=="function"&&o()}catch(s){console.error(s)}})},n.prototype.dataProviderSetData=function(t){if(this.mounted){var e=this.props.store;e.updateData(t,void 0,!1),e.setHasRemoteData()}},n.prototype.fetchWSData=function(t,e){var a=this,r=this.props,i=r.env,o=r.store,s=j(t,e);i.wsFetcher(s,function(c){var d,h,u,f,p=c;if("status"in c&&"data"in c&&(p=c.data,c.status!==0)){o.updateMessage((h=(d=s==null?void 0:s.messages)===null||d===void 0?void 0:d.failed)!==null&&h!==void 0?h:c.msg,!0),i.notify("error",(f=(u=s==null?void 0:s.messages)===null||u===void 0?void 0:u.failed)!==null&&f!==void 0?f:c.msg);return}o.updateData(p,void 0,!1,s.concatDataFields),o.setHasRemoteData(),a.runDataProvider("onWsFetched"),a.afterDataFetch({ok:!0,data:p})},function(c){o.updateMessage(c,!0),i.notify("error",c)})},n.prototype.afterDataFetch=function(t){var e,a=t!=null&&t.hasOwnProperty("ok")?(e=t.data)!==null&&e!==void 0?e:{}:t,r=this.props,i=r.onBulkChange,o=r.dispatchEvent,s=r.store,c=r.formStore;R(s)&&(o==null||o("fetchInited",C(this.props.data,D(D({},a),{__response:{msg:s.msg,error:s.error},responseData:a,responseStatus:(t==null?void 0:t.status)===void 0?s.error?1:0:t==null?void 0:t.status,responseMsg:s.msg}))),!I(a)&&i&&c&&i(a,!1,{type:"api"}),t!=null&&t.ok&&this.initInterval(a))},n.prototype.afterSchemaFetch=function(t){var e=this.props,a=e.onBulkChange,r=e.formStore,i=e.dispatchEvent,o=e.store;i==null||i("fetchSchemaInited",D(D({},t),{__response:{msg:o.msg,error:o.error},responseData:t,responseStatus:(t==null?void 0:t.status)===void 0?o.error?1:0:t==null?void 0:t.status,responseMsg:o.msg})),r&&(t!=null&&t.data)&&a&&a&&a(t.data),this.initInterval(t)},n.prototype.initInterval=function(t){var e=this.props,a=e.interval,r=e.silentPolling,i=e.stopAutoRefreshWhen,o=e.data;return clearTimeout(this.timer),a&&this.mounted&&(!i||!U(i,C(o,t)))&&(this.timer=setTimeout(r?this.silentReload:this.reload,Math.max(a,1e3))),t},n.prototype.reload=function(t,e,a,r,i){return b(this,void 0,void 0,function(){var o,s,c,d,h,u,f,p,v,v;return S(this,function(g){switch(g.label){case 0:return e?[2,this.receive(e,void 0,i)]:(o=this.props,s=o.schemaApi,o.initFetchSchema,c=o.api,o.initFetch,o.initFetchOn,d=o.store,h=o.dataProvider,u=o.messages,f=u.fetchSuccess,p=u.fetchFailed,clearTimeout(this.timer),y(s,d.data)?[4,d.fetchSchema(s,d.data,{successMessage:f,errorMessage:p})]:[3,3]);case 1:return v=g.sent(),[4,this.runDataProvider("onApiFetched")];case 2:g.sent(),this.afterSchemaFetch(v),g.label=3;case 3:return y(c,d.data)?[4,d.fetchData(c,d.data,{silent:r,successMessage:f,errorMessage:p})]:[3,6];case 4:return v=g.sent(),[4,this.runDataProvider("onSchemaApiFetched")];case 5:g.sent(),this.afterDataFetch(v),g.label=6;case 6:return h?[4,this.runDataProvider("inited")]:[3,8];case 7:g.sent(),g.label=8;case 8:return[2,d.data]}})})},n.prototype.silentReload=function(t,e){this.reload(t,e,void 0,!0)},n.prototype.receive=function(t,e,a){return b(this,void 0,void 0,function(){var r;return S(this,function(i){return r=this.props.store,r.updateData(t,void 0,a),[2,this.reload()]})})},n.prototype.handleQuery=function(t){var e=this;if(this.props.api||this.props.schemaApi){if(t!=null&&t.hasOwnProperty("orderBy")&&[this.props.api,this.props.schemaApi].every(function(a){return!a||!_(a,a,e.props.store.data,C(e.props.store.data,t))}))return!1;this.receive(t);return}return this.props.onQuery?this.props.onQuery(t):!1},n.prototype.reloadTarget=function(t,e){},n.prototype.handleDialogConfirm=function(t,e,a,r){var i=this.props.store;i.closeDialog(!0,t)},n.prototype.handleDialogClose=function(t){t===void 0&&(t=!1);var e=this.props.store;e.closeDialog(t)},n.prototype.openFeedback=function(t,e){var a=this;return new Promise(function(r){var i=a.props.store;i.setCurrentAction({type:"button",actionType:"dialog",dialog:t},a.props.resolveDefinitions),i.openDialog(e,void 0,function(o){r(o)},a.context)})},n.prototype.handleAction=function(t,e,a,r,i){var o=this;r===void 0&&(r=!1);var s=this.props,c=s.onAction,d=s.store,h=s.env,u=s.api,f=s.translate;u&&e.actionType==="ajax"?(d.setCurrentAction(e,this.props.resolveDefinitions),d.saveRemote(e.api,a,{successMessage:f(e.messages&&e.messages.success),errorMessage:f(e.messages&&e.messages.failed)}).then(function(p){return b(o,void 0,void 0,function(){var v;return S(this,function(g){switch(g.label){case 0:return this.afterDataFetch(p),e.feedback&&H(e.feedback,d.data)?[4,this.openFeedback(e.feedback,d.data)]:[3,2];case 1:g.sent(),g.label=2;case 2:return v=e.redirect&&N(e.redirect,d.data),v&&h.jumpTo(v,e,d.data),e.reload&&this.reloadTarget(V(e.reload,d.data),d.data),[2]}})})}).catch(function(p){if(r||e.countDown)throw p})):c(t,e,a,r,i||this.context)},n.prototype.handleChange=function(t,e,a,r){var i,o,s=this.props,c=s.store,d=s.formStore,h=s.onChange;typeof e=="string"&&((o=(i=c).changeValue)===null||o===void 0||o.call(i,e,t),d&&(h==null||h(t,e,a,r)))},n.prototype.renderBody=function(){var t=this.props,e=t.render,a=t.store,r=t.body;return t.classnames,e("body",a.schema||r,{key:a.schemaKey||"body",loading:a.loading,onQuery:this.handleQuery,onAction:this.handleAction,onChange:this.handleChange})},n.prototype.render=function(){var t=this.props,e=t.className,a=t.style,r=t.store,i=t.render,o=t.env,s=t.classPrefix,c=t.classnames,d=t.loadingConfig,h=t.showErrorMsg,u=t.testIdBuilder;return A.createElement("div",D({className:c("".concat(s,"Service"),e),style:a},u==null?void 0:u.getTestId()),!o.forceSilenceInsideError&&r.error&&h!==!1?A.createElement(B,{level:"danger",showCloseButton:!0,onClose:function(){return r.updateMessage("")}},r.msg):null,this.renderBody(),A.createElement(W,{size:"lg",overlay:!0,key:"info",show:r.loading,loadingConfig:d}),i("modal",D(D({},r.action&&r.action.dialog),{type:"dialog"}),{key:"dialog",data:r.dialogData,onConfirm:this.handleDialogConfirm,onClose:this.handleDialogClose,show:r.dialogOpen}))},n.defaultProps={messages:{fetchFailed:"fetchFailed"},showErrorMsg:!0},n.propsList=[],F([P,l("design:type",Function),l("design:paramtypes",[]),l("design:returntype",void 0)],n.prototype,"initFetch",null),F([P,l("design:type",Function),l("design:paramtypes",[Object]),l("design:returntype",void 0)],n.prototype,"initDataProviders",null),F([P,l("design:type",Function),l("design:paramtypes",[Object,String]),l("design:returntype",Object)],n.prototype,"normalizeProvider",null),F([P,l("design:type",Function),l("design:paramtypes",[Array,Object,Object,Array]),l("design:returntype",void 0)],n.prototype,"handleDialogConfirm",null),F([P,l("design:type",Function),l("design:paramtypes",[Object]),l("design:returntype",void 0)],n.prototype,"handleDialogClose",null),n}(A.Component),$=function(m){O(n,m);function n(t,e){var a=m.call(this,t)||this,r=e;return r.registerComponent(a),a}return n.prototype.reload=function(t,e,a,r,i){return b(this,void 0,void 0,function(){var o;return S(this,function(s){return o=this.context,t?[2,o.reload(e?"".concat(t,"?").concat(G(e)):t,a)]:[2,m.prototype.reload.call(this,t,e,a,r,i)]})})},n.prototype.receive=function(t,e,a){return b(this,void 0,void 0,function(){var r;return S(this,function(i){return r=this.context,e?[2,r.send(e,t)]:[2,m.prototype.receive.call(this,t,e,a)]})})},n.prototype.componentWillUnmount=function(){m.prototype.componentWillUnmount.call(this);var t=this.context;t.unRegisterComponent(this)},n.prototype.reloadTarget=function(t,e){var a=this.context;a.reload(t,e)},n.prototype.setData=function(t,e){return this.props.store.updateData(t,void 0,e)},n.prototype.getData=function(){var t=this.props.store;return t.data},n.contextType=Q,n=F([z({type:"service",storeType:K.name,isolateScope:!0,storeExtendsData:function(t){return!t.formStore}}),l("design:paramtypes",[Object,Object])],n),n}(L);export{$ as ServiceRenderer,L as default,w as eventTypes};