-
-
Notifications
You must be signed in to change notification settings - Fork 6
/
index.js
1 lines (1 loc) · 8.15 KB
/
index.js
1
(function(){"use strict";function l(e,t,s,n,r,u,d,A){var i=typeof e=="function"?e.options:e;t&&(i.render=t,i.staticRenderFns=s,i._compiled=!0),n&&(i.functional=!0),u&&(i._scopeId="data-v-"+u);var o;if(d?(o=function(a){a=a||this.$vnode&&this.$vnode.ssrContext||this.parent&&this.parent.$vnode&&this.parent.$vnode.ssrContext,!a&&typeof __VUE_SSR_CONTEXT__<"u"&&(a=__VUE_SSR_CONTEXT__),r&&r.call(this,a),a&&a._registeredComponents&&a._registeredComponents.add(d)},i._ssrRegister=o):r&&(o=A?function(){r.call(this,(i.functional?this.parent:this).$root.$options.shadowRoot)}:r),o)if(i.functional){i._injectStyles=o;var L=i.render;i.render=function(V,p){return o.call(p),L(V,p)}}else{var g=i.beforeCreate;i.beforeCreate=g?[].concat(g,o):[o]}return{exports:e,options:i}}const c=["site.changeTitle","page.changeTitle","page.changeStatus","model.update"];function h(){return{total:0,added:0,untracked:0,modified:0,renamed:0,deleted:0}}const m={data:()=>({headline:null,stats:h()}),computed:{finalHeadline(){let e=this.headline;return this.stats.total&&(e+=` (${this.stats.total} changes)`),e},link(){return window.panel.$url("git").toString()},positiveStatus(){let e=[];return this.stats.added&&e.push(`${this.stats.added} added`),this.stats.untracked&&e.push(`${this.stats.untracked} untracked`),e.length?e.join(", "):null},noticeStatus(){let e=[];return this.stats.modified&&e.push(`${this.stats.modified} modified`),this.stats.renamed&&e.push(`${this.stats.renamed} renamed`),e.length?e.join(", "):null},negativeStatus(){return this.stats.deleted?`${this.stats.deleted} deleted`:null},list(){let e=[];return this.positiveStatus&&e.push({text:this.positiveStatus,image:{icon:"copy",back:"var(--color-positive)",color:"var(--color-gray-800)"}}),this.noticeStatus&&e.push({text:this.noticeStatus,image:{icon:"edit",back:"var(--color-notice)",color:"var(--color-gray-800)"}}),this.negativeStatus&&e.push({text:this.negativeStatus,image:{icon:"trash",back:"var(--color-negative)",color:"var(--color-gray-800)"}}),e.map(t=>({...t,key:t.image.icon}))}},created(){this.load().then(e=>{this.headline=e.headline,this.status()}),c.forEach(e=>this.$events.$on(e,this.status))},destroyed(){c.forEach(e=>this.$events.$off(e,this.status))},methods:{status(){this.$api.get("git/status").then(e=>{this.stats=h(),e.length&&this.updateStats(e)})},updateStats(e){this.stats.total=e.length,e.forEach(t=>{switch(t.staged||t.unstaged){case"A":this.stats.added++;break;case"?":this.stats.untracked++;break;case"M":this.stats.modified++;break;case"R":this.stats.renamed++;break;case"D":this.stats.deleted++}})}}};var f=function(){var t=this,s=t._self._c;return s("section",{staticClass:"k-section area-git-changes-list"},[s("header",{staticClass:"k-section-header"},[s("k-headline",[t._v(t._s(t.finalHeadline))]),t.list.length?s("k-button-group",[s("k-button",{attrs:{icon:"share",link:t.link}},[t._v("Open")])],1):t._e()],1),t.list.length?s("k-items",{attrs:{items:t.list}}):[s("k-empty",{attrs:{icon:"check"}},[t._v("No changes")])]],2)},_=[],v=l(m,f,_,!1,null,null,null,null);const k=v.exports,$={props:{title:{type:String},data:{type:Array}},data(){return{perPage:15,pageIdx:0}},computed:{pages(){return this.data.reduce((e,t,s)=>{let n=Math.floor(s/this.perPage);return(e[n]||(e[n]=[])).push(t),e},[])},page(){return this.pages[this.pageIdx]||(this.pageIdx=0),this.pages[this.pageIdx]},entries(){return this.page?this.page.map(e=>{let t={back:"black",icon:"question",color:"var(--color-gray-800)"};switch(e.mode){case"?":case"A":t.back="var(--color-positive)",t.icon="copy";break;case"M":t.back="var(--color-notice)",t.icon="edit";break;case"R":t.back="var(--color-notice)",t.icon="refresh";break;case"D":t.back="var(--color-negative)",t.icon="trash"}return{text:e.file,image:t}}):null}},methods:{changePage(e){this.pageIdx=e.page-1}}};var b=function(){var t=this,s=t._self._c;return s("section",{staticClass:"area-git-changes-list"},[s("header",{staticClass:"k-section-header"},[s("k-headline",[t._v(t._s(t.title))]),t._t("action")],2),t.entries?s("k-items",{attrs:{items:t.entries}}):[s("k-empty",{attrs:{icon:"check"}},[t._v("No changes")])],s("k-pagination",{attrs:{align:"center",details:!0,page:t.pageIdx+1,total:t.data.length,limit:t.perPage},on:{paginate:t.changePage}})],2)},P=[],C=l($,b,P,!1,null,null,null,null);const S=C.exports,M="",D={props:{data:Object},data(){return{page:1,limit:15}},computed:{listItems(){var e;return(e=this.data)==null?void 0:e.commits.map(t=>({key:t.hash,text:t.subject,info:t.hash,image:{back:t.new?"green":"black",icon:t.new?"upload":"circle-filled",color:t.new?"gray-800":"gray-500"}}))}},created(){this.$emit("paginate",{page:this.page,limit:this.limit})}};var w=function(){var t=this,s=t._self._c;return s("section",[s("header",{staticClass:"k-section-header"},[s("k-headline",[t._v("Commits")]),t._t("action")],2),t.listItems?s("k-items",{attrs:{items:t.listItems}}):[s("k-empty",{attrs:{icon:"circle-filled"}},[t._v("No commits")])],t.data?s("k-pagination",t._g({attrs:{align:"center",details:!0,page:t.page,total:t.data.total,limit:t.limit}},t.$listeners)):t._e()],2)},x=[],y=l(D,w,x,!1,null,"8f04b04a",null,null);const R=y.exports,I={components:{ChangesList:S,CommitsList:R},data(){return{staged:[],unstaged:[],commitData:{message:null},logData:null,logPgn:null,isPulling:!1,isPushing:!1}},computed:{canPull(){return!this.isPushing&&!this.isPulling},canPush(){var e;return!this.isPushing&&!this.isPulling&&((e=this.logData)==null?void 0:e.new)}},created(){this.$api.get("git/status").then(e=>{this.updateStatus(e)}).catch(e=>{this.$store.dispatch("notification/error",e)})},methods:{updateStatus(e){this.staged=[],this.unstaged=[],e.forEach(t=>{t.unstaged&&this.unstaged.push({file:t.file,mode:t.unstaged}),t.staged&&t.staged!=="?"&&this.staged.push({file:t.file,mode:t.staged})})},add(){this.$api.post("git/add").then(()=>this.$api.get("git/status")).then(e=>{this.updateStatus(e)})},commit(){this.$api.post("git/commit",this.commitData).then(()=>(this.$refs.commitDialog.close(),this.$api.get("git/status"))).then(e=>{this.commitData.message=null,this.updateStatus(e)}).catch(e=>{this.$refs.commitDialog.error(e.message)}).then(()=>{this.listCommits()})},paginateLog(e){this.logPgn={page:e.page,limit:e.limit},this.listCommits()},listCommits(){return this.$api.get("git/log",this.logPgn).then(e=>{this.logData=e})},push(){this.isPushing=!0,this.$api.post("git/push").then(()=>this.listCommits()).catch(e=>{this.$store.dispatch("notification/error",e)}).then(()=>{this.isPushing=!1})},pull(){this.isPulling=!0,this.$api.get("git/pull").then(()=>this.listCommits()).catch(e=>{this.$store.dispatch("notification/error",e)}).then(()=>{this.isPulling=!1})}}};var E=function(){var t=this,s=t._self._c;return s("k-inside",[s("k-view",[s("k-header",[t._v("Version Control")]),s("k-grid",{attrs:{gutter:"medium"}},[s("k-column",{attrs:{width:"1/3"}},[s("changes-list",{attrs:{title:"Unstaged",data:this.unstaged}},[this.unstaged.length?s("k-button-group",{attrs:{slot:"action"},slot:"action"},[s("k-button",{attrs:{icon:"add"},on:{click:t.add}},[t._v("Add")])],1):t._e()],1)],1),s("k-column",{attrs:{width:"1/3"}},[s("changes-list",{attrs:{title:"Staged",data:this.staged}},[this.staged.length?s("k-button-group",{attrs:{slot:"action"},slot:"action"},[s("k-button",{attrs:{icon:"circle-filled"},on:{click:function(n){return t.$refs.commitDialog.open()}}},[t._v(" Commit ")])],1):t._e()],1),s("k-dialog",{ref:"commitDialog",attrs:{theme:"positive"},on:{submit:function(n){return t.$refs.commitForm.submit()}}},[s("k-form",{ref:"commitForm",attrs:{fields:{message:{type:"text",label:"Message",required:!0}}},on:{submit:t.commit},model:{value:t.commitData,callback:function(n){t.commitData=n},expression:"commitData"}})],1)],1),s("k-column",{attrs:{width:"1/3"}},[s("commits-list",{attrs:{data:t.logData},on:{paginate:t.paginateLog}},[s("k-button-group",{attrs:{slot:"action"},slot:"action"},[s("k-button",{attrs:{icon:"download",disabled:!t.canPull},on:{click:t.pull}},[t._v(" "+t._s(t.isPulling?"Pulling\u2026":"Pull")+" ")]),s("k-button",{attrs:{icon:"upload",theme:"positive",disabled:!t.canPush},on:{click:t.push}},[t._v(" "+t._s(t.isPushing?"Pushing\u2026":"Push")+" ")])],1)],1)],1)],1)],1)],1)},T=[],F=l(I,E,T,!1,null,null,null,null);const N=F.exports;panel.plugin("oblik/git",{sections:{git:k},components:{"k-git-view":N}})})();