-
Notifications
You must be signed in to change notification settings - Fork 4
/
index.js
1 lines (1 loc) · 13.3 KB
/
index.js
1
(function(){"use strict";function i(t,e,s,n,r,c,u,xe){var a=typeof t=="function"?t.options:t;e&&(a.render=e,a.staticRenderFns=s,a._compiled=!0),n&&(a.functional=!0),c&&(a._scopeId="data-v-"+c);var l;if(u?(l=function(o){o=o||this.$vnode&&this.$vnode.ssrContext||this.parent&&this.parent.$vnode&&this.parent.$vnode.ssrContext,!o&&typeof __VUE_SSR_CONTEXT__<"u"&&(o=__VUE_SSR_CONTEXT__),r&&r.call(this,o),o&&o._registeredComponents&&o._registeredComponents.add(u)},a._ssrRegister=l):r&&(l=xe?function(){r.call(this,(a.functional?this.parent:this).$root.$options.shadowRoot)}:r),l)if(a.functional){a._injectStyles=l;var De=a.render;a.render=function(Se,d){return l.call(d),De(Se,d)}}else{var v=a.beforeCreate;a.beforeCreate=v?[].concat(v,l):[l]}return{exports:t,options:a}}const _={props:{changes:Object}};var f=function(){var e=this,s=e._self._c;return s("ul",{staticClass:"lbvs-changes"},e._l(e.changes,function(n,r){return s("li",{key:r},[s("span",{attrs:{"data-status":n,title:e.$t("versions.label.status."+n)}},[e._v(" "+e._s(n)+" ")]),e._v(" "+e._s(r)+" ")])}),0)},h=[],b=i(_,f,h,!1,null,null,null,null);const p=b.exports,m={data(){return{error:{message:null,details:{lockedModels:{}}}}},methods:{open(t){this.error=t,this.$refs.dialog.open()}}};var g=function(){var e=this,s=e._self._c;return s("k-dialog",{ref:"dialog",staticClass:"lbvs-create-error-dialog",attrs:{"cancel-button":e.$t("close"),"submit-button":!1}},[s("p",{staticClass:"lbvs-create-error-dialog-message"},[e._v(" "+e._s(e.error.message)+" ")]),s("ul",{staticClass:"lbvs-create-error-dialog-list"},e._l(e.error.details.lockedModels,function(n,r){return s("li",{key:r},[e._v(" "+e._s(r)+" "),s("span",[e._v("("+e._s(n.join(", "))+")")])])}),0)])},$=[],y=i(m,g,$,!1,null,null,null,null);const C=y.exports,k={data(){return{instance:null,inProgress:!1,stagedChanges:{}}},computed:{fields(){return{label:{autofocus:!0,icon:"title",label:this.$t("versions.label.label"),type:"text"}}}},methods:{async onSubmit(){if(this.inProgress!==!0)try{this.inProgress=!0;let t=this.$refs.form.value.label;if(!t)throw this.$t("field.required");await this.$store.dispatch({type:"versions/createVersion",instance:this.instance,label:t}),this.$store.dispatch("notification/success",":)"),this.$refs.dialog.close()}catch(t){this.$refs.dialog.error(t.message||t)}finally{this.inProgress=!1}},async open(t){this.instance=t;try{this.stagedChanges=await this.$store.dispatch({type:"versions/prepareVersionCreation",instance:this.instance})}catch(e){if(e.key==="error.versions.lockFiles")return this.$refs.errorDialog.open(e);throw e}this.$refs.dialog.open()}}};var w=function(){var e=this,s=e._self._c;return s("div",[s("k-dialog",{ref:"dialog",attrs:{size:"large","submit-button":e.$t("versions.button.create"),theme:"positive"},on:{submit:e.onSubmit}},[s("k-form",{ref:"form",attrs:{fields:e.fields},on:{submit:e.onSubmit},scopedSlots:e._u([{key:"header",fn:function(){return[s("k-field",{staticClass:"lbvs-create-changes",attrs:{label:e.$t("versions.label.changes")}},[s("lbvs-changes",{attrs:{changes:e.stagedChanges}})],1)]},proxy:!0}])})],1),s("lbvs-create-error-dialog",{ref:"errorDialog"})],1)},x=[],D=i(k,w,x,!1,null,null,null,null);const S=D.exports,R={data(){return{inProgress:!1,version:null}},methods:{async onSubmit(){if(this.inProgress!==!0)try{this.inProgress=!0,await this.$store.dispatch({type:"versions/deleteVersion",version:this.version.name}),this.$store.dispatch("notification/success",":)"),this.$refs.dialog.close()}catch(t){this.$refs.dialog.error(t.message||t)}finally{this.inProgress=!1}},open(t){this.version=t,this.$refs.dialog.open()}}};var T=function(){var e=this,s=e._self._c;return s("k-dialog",{ref:"dialog",staticClass:"lbvs-version-dialog lbvs-version-delete-dialog",attrs:{icon:"trash","submit-button":e.$t("versions.button.delete"),theme:"negative"},on:{submit:e.onSubmit}},[e.version?s("lbvs-version",{attrs:{version:e.version}}):e._e(),s("p",[e._v(e._s(e.$t("versions.message.delete")))])],1)},V=[],F=i(R,T,V,!1,null,null,null,null);const O=F.exports,A={data(){return{inProgress:!1,version:null}},computed:{fields(){let t=this.$store.getters["versions/currentInstance"],e=Object.values(this.$store.state.versions.data.instances).map(s=>({text:s.name,value:s.name}));return{instance:{disabled:e.length<=1,empty:!1,icon:"box",label:this.$t("versions.label.targetInstance"),options:e,placeholder:t.name,type:"select",value:t.name}}}},methods:{async onSubmit(){if(this.inProgress!==!0)try{this.inProgress=!0;let t=this.$refs.form.value.instance||this.$store.getters["versions/currentInstance"].name;await this.$store.dispatch({type:"versions/deployVersion",version:this.version.name,instance:t}),this.$store.dispatch("notification/success",":)"),this.$refs.dialog.close()}catch(t){this.$refs.dialog.error(t.message||t)}finally{this.inProgress=!1}},open(t){this.version=t,this.$refs.dialog.open()}}};var P=function(){var e=this,s=e._self._c;return s("k-dialog",{ref:"dialog",staticClass:"lbvs-version-dialog",attrs:{"submit-button":e.$t("versions.button.deploy"),theme:"positive"},on:{submit:e.onSubmit}},[e.version?s("lbvs-version",{attrs:{version:e.version}}):e._e(),s("k-form",{ref:"form",attrs:{fields:e.fields},on:{submit:e.onSubmit}})],1)},j=[],I=i(A,P,j,!1,null,null,null,null);const E=I.exports,L={data(){return{data:null,version:{}}},computed:{details(){return this.data?[{title:this.$t("versions.label.fileSize"),value:this.data.filesize}]:[]},supportsClipboard(){try{return window.navigator.clipboard.writeText,!0}catch{return!1}}},methods:{async copyToClipboard(){await window.navigator.clipboard.writeText(this.data.url),this.$store.dispatch("notification/success",":)")},download(){window.location=this.data.url,this.$store.dispatch("notification/success",":)")},async open(t){this.data=null,this.version=t,this.$refs.dialog.open();let e=await this.$store.dispatch({type:"versions/exportVersion",version:this.version.name});t===this.version&&(this.data=e)}}};var N=function(){var e=this,s=e._self._c;return s("k-dialog",{ref:"dialog",staticClass:"lbvs-version-dialog",attrs:{"cancel-button":e.$t(e.data?"close":"cancel"),"submit-button":!1}},[e.version?s("lbvs-version",{attrs:{details:e.details,version:e.version}}):e._e(),e.data?s("k-button-group",[s("k-button",{attrs:{icon:"download"},on:{click:e.download}},[e._v(" "+e._s(e.$t("versions.button.download"))+" ")]),s("k-button",{attrs:{icon:"copy",disabled:!e.supportsClipboard},on:{click:e.copyToClipboard}},[e._v(" "+e._s(e.$t("versions.button.copyLink"))+" ")])],1):s("p",[e._v(" "+e._s(e.$t("versions.message.exporting"))+" ")])],1)},z=[],M=i(L,N,z,!1,null,null,null,null);const Y=M.exports,B={props:{inline:Boolean,instance:[Object,String]},computed:{element(){return this.inline?"span":"strong"},instanceObj(){return typeof this.instance=="string"?{name:this.instance,color:"var(--color-gray-300)"}:this.instance}}};var H=function(){var e=this,s=e._self._c;return s(e.element,{tag:"component",staticClass:"lbvs-instance-name",style:{backgroundColor:e.instanceObj.color}},[e._v(" "+e._s(e.instanceObj.name)+" ")])},U=[],X=i(B,H,U,!1,null,null,null,null);const q=X.exports,W={props:{value:[Array,String]},computed:{instances(){return Array.isArray(this.value)?this.value:[this.value]}}};var G=function(){var e=this,s=e._self._c;return s("div",{staticClass:"lbvs-instance-names-cell"},e._l(e.instances,function(n){return s("lbvs-instance-name",{key:n,attrs:{inline:!0,instance:e.$store.state.versions.data.instances[n]||n}})}),1)},J=[],K=i(W,G,J,!1,null,null,null,null);const Q=K.exports,Z={computed:{canCreateVersion(){return this.$permissions["lukasbestle.versions"].create===!0&&Object.keys(this.currentChanges).length>0},currentChanges(){return this.$store.getters["versions/currentInstance"].changes}},methods:{onCreate(){let t=this.$store.getters["versions/currentInstance"].name;return this.$refs.createDialog.open(t)}}};var ee=function(){var e=this,s=e._self._c;return s("div",{staticClass:"lbvs-status"},[s("k-view",[s("k-grid",[s("k-column",{attrs:{width:"1/3"}},[s("header",{staticClass:"k-section-header"},[s("k-label",{attrs:{type:"section"}},[e._v(" "+e._s(e.$t("versions.label.instances"))+" ")])],1),s("ul",{staticClass:"lbvs-status-instances"},e._l(e.$store.state.versions.data.instances,function(n){return s("li",{key:n.name,class:{current:n.isCurrent}},[s("lbvs-instance-name",{attrs:{instance:n}}),n.isCurrent?s("span",{staticClass:"lbvs-status-current"},[e._v(" "+e._s(e.$t("versions.label.current"))+" ")]):e._e(),n.version?s("lbvs-version",{attrs:{version:{name:n.version,label:n.versionLabel}}}):e._e()],1)}),0)]),s("k-column",{staticClass:"lbvs-status-changes",attrs:{width:"2/3"}},[s("header",{staticClass:"k-section-header"},[s("k-label",{attrs:{type:"section"}},[e._v(" "+e._s(e.$t("versions.label.changes"))+" ")]),s("k-button",{attrs:{icon:"add",size:"xs",disabled:e.canCreateVersion===!1},on:{click:e.onCreate}},[e._v(" "+e._s(e.$t("versions.button.create"))+" ")])],1),s("lbvs-changes",{attrs:{changes:e.currentChanges}})],1)],1)],1),s("lbvs-create-dialog",{ref:"createDialog"})],1)},se=[],te=i(Z,ee,se,!1,null,null,null,null);const ne=te.exports,re={props:{details:{type:Array,default(){return[]}},instances:Boolean,version:Object},computed:{mergedDetails(){return[{title:this.$t("versions.label.versionName"),value:this.version.name},...this.details].filter(e=>e.value)}}};var ae=function(){var e=this,s=e._self._c;return s("div",{staticClass:"lbvs-version"},[s("strong",[e._v(e._s(e.version.label))]),s("dl",{staticClass:"lbvs-version-details"},[e._l(e.mergedDetails,function(n){return[s("dt",{key:n.title,staticClass:"sr-only"},[e._v(e._s(n.title)+":")]),s("dd",{key:n.title,attrs:{title:n.title}},[e._v(" "+e._s(n.value)+" ")])]})],2)])},ie=[],oe=i(re,ae,ie,!1,null,null,null,null);const le=oe.exports,ce={props:{value:Object}};var ue=function(){var e=this,s=e._self._c;return s("div",{staticClass:"lbvs-version-label-cell"},[s("lbvs-version",{attrs:{version:e.value}})],1)},ve=[],de=i(ce,ue,ve,!1,null,null,null,null);const _e=de.exports,fe={computed:{columns(){return{title:{label:this.$t("versions.label.label"),type:"lbvs-version-label",mobile:!0,width:"35%"},instances:{label:this.$t("versions.label.instances"),type:"lbvs-instance-names",mobile:!0,width:"25%"},creation:{label:this.$t("versions.label.creation"),type:"text",width:"25%"},originInstance:{label:this.$t("versions.label.originInstance"),type:"lbvs-instance-names",width:"15%"}}},items(){return Object.values(this.$store.state.versions.data.versions).map(t=>(t.creation=this.$t("versions.label.creationData",{created:t.created?this.$library.dayjs.unix(t.created).format("YYYY-MM-DD HH:mm"):"?",creator:t.creatorName||t.creatorEmail||"?"}),t.title={label:t.label,name:t.name},t.options=this.options(t),t))}},methods:{onOption(t,e){return this.$refs[t+"Dialog"].open(e)},options(t){let e=this.$permissions["lukasbestle.versions"];return[{click:"export",disabled:e.export!==!0,icon:"download",text:this.$t("versions.button.export")},{click:"deploy",disabled:e.deploy!==!0,icon:"wand",text:this.$t("versions.button.deploy")},{click:"delete",disabled:e.delete!==!0||t.instances.length>0,icon:"trash",text:this.$t("versions.button.delete")}]}}};var he=function(){var e=this,s=e._self._c;return s("div",{staticClass:"lbvs-versions"},[s("header",{staticClass:"k-section-header"},[s("k-label",{attrs:{type:"section"}},[e._v(" "+e._s(e.$t("versions.label.versions"))+" ")])],1),e.items.length?s("k-items",{attrs:{columns:e.columns,items:e.items,layout:"table",sortable:!1},on:{option:e.onOption}}):s("k-empty",{attrs:{icon:"protected",layout:"table"}},[e._v(" "+e._s(e.$t("versions.label.empty"))+" ")]),s("lbvs-export-dialog",{ref:"exportDialog"}),s("lbvs-deploy-dialog",{ref:"deployDialog"}),s("lbvs-delete-dialog",{ref:"deleteDialog"})],1)},be=[],pe=i(fe,he,be,!1,null,null,null,null);const me=pe.exports,ge={data(){return{isLoading:!0}},async mounted(){this.$permissions["lukasbestle.versions"].access!==!0&&this.$go("/");try{this.isLoading=!0,await this.$store.dispatch("versions/load")}finally{this.isLoading=!1}}};var $e=function(){var e=this,s=e._self._c;return s("k-inside",[s("div",{staticClass:"lbvs-view"},[e.isLoading?s("k-loader"):[s("lbvs-status"),s("lbvs-versions")]],2)])},ye=[],Ce=i(ge,$e,ye,!1,null,null,null,null);const ke=Ce.exports,we=t=>({namespaced:!0,state:{data:{instances:{},versions:{}}},getters:{currentInstance(e){return Object.values(e.data.instances).find(s=>s.isCurrent)}},mutations:{SET_DATA(e,{instances:s,versions:n}){e.data.instances=s,e.data.versions=n}},actions:{async load({commit:e}){e("SET_DATA",await t.$api.get("versions"))},async prepareVersionCreation(e,{instance:s}){return await t.$api.post("versions/prepareCreation",{instance:s})},async createVersion({commit:e},{instance:s,label:n}){let r=await t.$api.post("versions/create",{instance:s,label:n});e("SET_DATA",r)},async deleteVersion({commit:e},{version:s}){let n=await t.$api.delete("versions/versions/"+s);e("SET_DATA",n)},async deployVersion({commit:e},{instance:s,version:n}){let r=await t.$api.post("versions/versions/"+n+"/deploy",{instance:s});e("SET_DATA",r)},async exportVersion(e,{version:s}){return await t.$api.post("versions/versions/"+s+"/export")}}});panel.plugin("lukasbestle/versions",{components:{"k-table-lbvs-instance-names-cell":Q,"k-table-lbvs-version-label-cell":_e,"lbvs-changes":p,"lbvs-create-error-dialog":C,"lbvs-create-dialog":S,"lbvs-delete-dialog":O,"lbvs-deploy-dialog":E,"lbvs-export-dialog":Y,"lbvs-instance-name":q,"lbvs-status":ne,"lbvs-version":le,"lbvs-versions":me,"lbvs-view":ke},created(t){t.$store.registerModule("versions",we(t))}})})();