forked from distantnative/retour-for-kirby
/
index.js
1 lines (1 loc) · 17.3 KB
/
index.js
1
(function(){"use strict";const jt="";function i(e,t,r,s,a,c,u,Ot){var n=typeof e=="function"?e.options:e;t&&(n.render=t,n.staticRenderFns=r,n._compiled=!0),s&&(n.functional=!0),c&&(n._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__),a&&a.call(this,o),o&&o._registeredComponents&&o._registeredComponents.add(u)},n._ssrRegister=l):a&&(l=Ot?function(){a.call(this,(n.functional?this.parent:this).$root.$options.shadowRoot)}:a),l)if(n.functional){n._injectStyles=l;var Rt=n.render;n.render=function(Yt,h){return l.call(h),Rt(Yt,h)}}else{var f=n.beforeCreate;n.beforeCreate=f?[].concat(f,l):[l]}return{exports:e,options:n}}const d={props:{data:[Object,Array],stats:[Boolean,Array],tab:String,tabs:Array,timespan:Object}},m={mixins:[d]};var v=function(){var t=this,r=t._self._c;return r("k-inside",{staticClass:"k-retour-view"},[r("k-header",{scopedSlots:t._u([{key:"buttons",fn:function(){return[t.stats?r("k-retour-timespan",{attrs:{timespan:t.timespan}}):t._t("buttons")]},proxy:!0}])},[t._v(" "+t._s(t.$t("view.retour"))+" ")]),t.stats?[r("k-retour-stats",{attrs:{data:t.stats,timespan:t.timespan}}),r("k-retour-tabs",{attrs:{tab:t.tab,tabs:t.tabs}},[t._t("buttons")],2)]:t._e(),t._t("default")],2)},$=[],y=i(m,v,$,!1,null,null,null,null);const b=y.exports,Dt="",k={mixins:[d],data(){return{searching:!1,q:null,sortDirection:"asc",pagination:{page:1,limit:20}}},computed:{buttons(){return[]},columns(){return{}},empty(){return{}},filteredItems(){let e=this.data;return this.q&&(e=e.filter(t=>JSON.stringify(t).toLowerCase().includes(this.q.toLowerCase()))),e},index(){return(this.pagination.page-1)*this.pagination.limit+1},paginatedItems(){return this.filteredItems.sortBy(`${this.sortBy} ${this.sortDirection}`).slice(this.index-1,this.pagination.limit*this.pagination.page)}},methods:{id(e){return encodeURIComponent(e.replace(/\//g,""))},onCell(){},onHeader({columnIndex:e}){this.sortBy===e?this.sortDirection=this.sortDirection==="asc"?"desc":"asc":this.sortDirection="asc",this.sortBy=e,this.pagination.page=1},options(){return[]},async toggleSearch(e=!1){if(e&&this.q){this.q=null;return}this.q=null,this.searching=!this.searching,this.searching&&(await this.$nextTick(),this.$refs.search.focus())}}};var g=function(){var t=this,r=t._self._c;return r("k-retour-view",t._b({staticClass:"k-retour-collection-view",scopedSlots:t._u([{key:"buttons",fn:function(){return[t.stats?t._e():r("k-button",{attrs:{link:"https://paypal.me/distantnative",theme:"positive",icon:"heart",size:"sm",variant:"filled"}},[t._v(" "+t._s(t.$t("retour.system.support"))+" ")]),t.searching?r("k-search-input",{ref:"search",staticClass:"k-models-section-search k-input",attrs:{autofocus:!0,placeholder:t.$t("filter")+" …",value:t.q},on:{input:function(s){t.q=s,t.pagination.page=1}},nativeOn:{keydown:function(s){return!s.type.indexOf("key")&&t._k(s.keyCode,"esc",27,s.key,["Esc","Escape"])?null:t.toggleSearch(!0)}}}):t._e(),r("k-button",{attrs:{icon:"filter",title:t.$t("filter"),size:"sm",variant:"filled"},on:{click:t.toggleSearch}}),t._l(t.buttons,function(s,a){return r("k-button",t._b({key:a,attrs:{size:"sm",variant:"filled"}},"k-button",s,!1))})]},proxy:!0}])},"k-retour-view",t.$props,!1),[t.filteredItems.length===0?r("k-empty",t._b({attrs:{layout:"table"}},"k-empty",t.empty,!1)):r("k-table",{attrs:{columns:t.columns,index:t.index,rows:t.paginatedItems},on:{cell:t.onCell,header:t.onHeader},scopedSlots:t._u([{key:"header",fn:function({columnIndex:s,label:a}){return[r("span",[t._v(" "+t._s(a)+" "),s===t.sortBy?r("k-icon",{attrs:{type:t.sortDirection==="asc"?"angle-up":"angle-down"}}):t._e()],1)]}},{key:"options",fn:function({row:s}){return[r("k-options-dropdown",{attrs:{options:t.options(s)}})]}}])}),r("footer",{staticClass:"k-bar k-collection-footer"},[r("k-pagination",t._b({attrs:{details:!0,total:t.filteredItems.length},on:{paginate:function(s){t.pagination.page=s.page}}},"k-pagination",t.pagination,!1))],1)],1)},C=[],w=i(k,g,C,!1,null,null,null,null);const _=w.exports;var x=i({extends:_,data(){return{sortBy:"from"}},computed:{buttons(){return[{icon:"add",text:this.$t("add"),click:()=>this.$drawer("retour/redirects/create")}]},columns(){return{from:{label:this.$t("retour.redirects.from"),type:"path",width:"7/20"},to:{label:this.$t("retour.redirects.to"),type:"link",width:"7/20"},status:{label:this.$t("retour.redirects.status"),type:"status",width:"1/10"},priority:{label:this.$t("retour.redirects.priority.abbr"),type:"priority",width:"1/10"},hits:{label:this.$t("retour.hits"),width:"1/10",type:"count"}}},empty(){return{icon:"shuffle",text:this.$t("retour.redirects.empty")}}},methods:{onCell({row:e,columnIndex:t}){this.$drawer(`retour/redirects/${this.id(e.from)}/edit`,{query:{column:t}})},options(e){return[{text:this.$t("edit"),icon:"edit",click:()=>this.$drawer(`retour/redirects/${this.id(e.from)}/edit`)},{text:this.$t("remove"),icon:"trash",click:()=>this.$dialog(`retour/redirects/${this.id(e.from)}/delete`)}]}}},null,null,!1,null,null,null,null);const M=x.exports;var L=i({extends:_,data(){return{sortBy:"hits",sortDirection:"desc"}},computed:{buttons(){return[{icon:"trash",text:this.$t("retour.failures.clear"),click:()=>this.$dialog("retour/failures/flush")}]},columns(){return{path:{label:this.$t("retour.failures.path"),type:"path",width:"1/3"},referrer:{label:this.$t("retour.failures.referrer"),type:"path",width:"1/3"},last:{label:this.$t("retour.last"),type:"date",display:"D MMM YYYY, HH:mm:ss",width:"2/8"},hits:{label:this.$t("retour.hits"),type:"count",width:"1/16",align:"right"}}},empty(){return{icon:"cloud-off",text:this.$t("retour.failures.empty")}}},methods:{options(e){return[{text:this.$t("retour.failures.resolve"),icon:"add",click:()=>this.$drawer(`retour/failures/${this.id(e.path)}/resolve`)},{text:this.$t("remove"),icon:"trash",click:()=>this.$dialog(`retour/failures/${this.id(e.path)}/delete`)}]}}},null,null,!1,null,null,null,null);const F=L.exports,Vt="",S={mixins:[d],computed:{reports(){return[{label:this.$t("retour.system.redirects"),value:String(this.data.redirects),icon:"shuffle"},{label:this.$t("retour.system.failures"),value:String(this.data.failures),icon:"cloud-off"},{label:this.$t("retour.system.deleteAfter"),value:this.$t("retour.system.deleteAfter.months",{count:this.data.deleteAfter}),icon:"trash"}]}}};var O=function(){var t=this,r=t._self._c;return r("k-retour-view",t._b({staticClass:"k-retour-system-view",scopedSlots:t._u([{key:"buttons",fn:function(){return[r("k-button",{attrs:{link:"https://paypal.me/distantnative",icon:"heart",size:"sm",target:"_blank",theme:"positive",variant:"filled"}},[t._v(" "+t._s(t.$t("retour.system.support"))+" ")])]},proxy:!0}])},"k-retour-view",t.$props,!1),[r("k-stats",{attrs:{reports:t.reports,size:"huge"}}),r("k-text",{staticClass:"k-help",attrs:{html:t.$t("retour.system.docs",{docs:"https://github.com/distantnative/retour-for-kirby"})}})],1)},R=[],Y=i(S,O,R,!1,null,null,null,null);const j=Y.exports,Zt="",D={props:{data:Array},computed:{gradient(){let e="",t=0;const r=this.total/180;for(let s=0;s<this.data.length;s++)e+=`${this.data[s].color} ${t}deg,`,t+=this.data[s].data/r,e+=`${this.data[s].color} ${t}deg,`;return e+="transparent 180deg",e},icons(){return["shuffle","check-double","cloud-off"]},total(){return this.data.reduce((e,t)=>e+=t.data,0)}}};var A=function(){var t=this,r=t._self._c;return r("figure",{staticClass:"chart-pie"},[r("div",{staticClass:"graph",style:"--gradient: "+t.gradient}),r("figcaption",[t._l(t.data,function(s,a){return[r("k-icon",{key:s.label+"-icon",style:"--color:"+s.color,attrs:{type:t.icons[a]}}),r("div",{key:s.label+"-no"},[t._v(" "+t._s(new Intl.NumberFormat().format(s.data))+" ")]),r("div",{key:s.label+"-label"},[t._v(" "+t._s(s.label)+" ")])]})],2)])},P=[],z=i(D,A,P,!1,null,null,null,null);const q=z.exports,Ht="",B={props:{data:Array,timespan:Object},computed:{axisY(){const e=this.max/5;return[1,2,3,4,5].map(t=>{let r=t*e;return r>=1e3&&(r=Math.floor(r/100)/10+"k"),r})},format(){return{day:"HH",week:"ddd",month:"D",year:"MMM",months:"MMM YY"}[this.timespan.unit]??"D MMM"},subunit(){return{day:"hour",year:"month"}[this.timespan.unit]??"day"},max(){let e=Math.max(...this.data.map(t=>t.areas.reduce((r,s)=>r+=s.data,0)));if(e>0){const t=e.toString().length,r=Math.pow(10,t)/4;return Math.ceil(e*1.1/r)*r}return 5}},methods:{bounds(e,t){const r=e.areas.slice(0,t).reduce((s,a)=>s+=a.data,0);return{path:r+e.areas[t].data,mask:r}},clip(e,t){let r=this.bounds(this.data[e],t),s={path:0,mask:0};return this.data[e+1]&&(s=this.bounds(this.data[e+1],t)),`--p0: ${r.path/this.max}; --p1: ${s.path/this.max}; --m0: ${r.mask/this.max}; --m1: ${s.mask/this.max};`},color(e,t){const r=this.data[e+1];if(r){const s=this.$library.dayjs(r.label),a=this.$library.dayjs();if(s.isAfter(a,this.subunit))return"transparent"}return t.color},isCurrent(e){const t=this.$library.dayjs();return this.$library.dayjs(e.label).isSame(t,this.subunit)},label(e){return this.$library.dayjs(e.label).format(this.format)},zoom(e){const t=this.$library.dayjs(e.label);this.$reload({query:{from:t.startOf(this.subunit).format("YYYY-MM-DD"),to:t.endOf(this.subunit).format("YYYY-MM-DD")}})}}};var T=function(){var t=this,r=t._self._c;return r("table",{staticClass:"chart-areas"},[r("thead",[r("tr",t._l(t.axisY,function(s){return r("th",{key:s},[t._v(" "+t._s(s)+" ")])}),0)]),r("tbody",t._l(t.data,function(s,a){return r("tr",{key:a,on:{dblclick:function(c){return t.zoom(s)}}},t._l(s.areas,function(c,u){return r("td",{key:a+"_"+u,style:`--color: ${t.color(a,c)}; ${t.clip(a,u)}`})}),0)}),0),r("tfoot",{attrs:{"data-less":t.data.length>31}},t._l(t.data,function(s){return r("tr",{key:s.label,attrs:{"data-current":t.isCurrent(s)},on:{dblclick:function(a){return t.zoom(s)}}},[r("td",[t._v(t._s(t.label(s)))])])}),0)])},V=[],Z=i(B,T,V,!1,null,null,null,null);const H=Z.exports,It="",I={components:{Pie:q,Timeline:H},props:{data:Array,timespan:Object},computed:{areas(){return this.data.map(e=>({label:e.date,areas:[{data:e.redirected,color:"var(--color-blue-600)"},{data:e.resolved,color:"var(--color-gray-300)"},{data:e.failed,color:"var(--color-red-600)"}]}))},pie(){return[{data:this.data.reduce((e,t)=>e+=t.redirected,0),color:"var(--color-blue-600)",label:this.$t("retour.stats.redirected")},{data:this.data.reduce((e,t)=>e+=t.resolved,0),color:"var(--color-gray-300)",label:this.$t("retour.stats.resolved")},{data:this.data.reduce((e,t)=>e+=t.failed,0),color:"var(--color-red-600)",label:this.$t("retour.stats.failed")}]}}};var N=function(){var t=this,r=t._self._c;return r("section",{staticClass:"k-retour-stats"},[r("pie",{attrs:{data:t.pie}}),r("timeline",{attrs:{data:t.areas,timespan:t.timespan}})],1)},U=[],E=i(I,N,U,!1,null,null,null,null);const W=E.exports,Nt="",X={props:{tab:String,tabs:Array}};var J=function(){var t=this,r=t._self._c;return r("div",{staticClass:"k-retour-tabs",attrs:{"data-end":t.tabs.length<2}},[r("k-tabs",{attrs:{tab:t.tab,tabs:t.tabs}}),r("k-button-group",[t._t("default")],2)],1)},G=[],K=i(X,J,G,!1,null,null,null,null);const Q=K.exports,tt={props:{timespan:Object},computed:{dropdown(){return[...this.units.map(e=>{if(!(e==="all"&&!this.timespan.hasAll))return{text:this.$t("retour.stats.mode."+e),icon:this.icon(e),current:this.isCurrentUnit(e),click:()=>this.set(e)}}),"-",{text:this.$t("retour.timespan.today.label"),icon:"merge",click:()=>this.set("today")},{text:this.$t("retour.timespan.set.label"),icon:"calendar",click:()=>this.$dialog("retour/timespan")}].filter(Boolean)},units(){return["all","year","month","day"]}},methods:{icon(e){return this.isCurrentUnit(e)===!0?this.timespan.isCurrent?"circle-focus":"circle-nested":"circle"},isCurrentUnit(e){return e===this.timespan.unit||e==="all"&&this.timespan.isAll},navigate(e){const t=this.timespan.unit,r=this.$library.dayjs(this.timespan.from),s=this.$library.dayjs(this.timespan.to);this.update({from:r[e](1,t).startOf(t),to:s[e](1,t).endOf(t)})},set(e){if(e==="all")return this.update({from:this.$library.dayjs(this.timespan.first),to:this.$library.dayjs(this.timespan.last)});let t=this.$library.dayjs(this.timespan.from);(e===this.timespan.unit||e==="today")&&(e=this.timespan.unit,t=this.$library.dayjs()),this.update({from:t.startOf(e),to:t.endOf(e)})},update({from:e,to:t}){this.$reload({query:{from:e.format("YYYY-MM-DD"),to:t.format("YYYY-MM-DD")}})}}};var et=function(){var t=this,r=t._self._c;return r("k-button-group",{staticClass:"k-retour-timespan",attrs:{layout:"collapsed"}},[r("k-button",{attrs:{dropdown:!0,text:t.timespan.label,icon:"calendar",size:"sm",variant:"filled"},on:{click:function(s){return t.$refs.units.toggle()}}}),r("k-dropdown-content",{ref:"units",attrs:{options:t.dropdown,"align-x":"end"}}),r("k-button",{attrs:{icon:"angle-left",size:"sm",variant:"filled",disabled:!t.timespan.hasPrev||t.timespan.isAll},on:{click:function(s){return t.navigate("subtract")}}}),r("k-button",{attrs:{disabled:!t.timespan.hasNext||t.timespan.isAll,icon:"angle-right",size:"sm",variant:"filled"},on:{click:function(s){return t.navigate("add")}}})],1)},rt=[],st=i(tt,et,rt,!1,null,null,null,null);const at=st.exports,Ut="",it={props:{row:Object},computed:{title(){return this.$t("retour.hits.last")+": "+(this.row.last??"-")}}};var nt=function(){var t=this,r=t._self._c;return r("div",{staticClass:"k-count-preview-field",attrs:{title:t.title}},[t.row.hits>0?[t._v(" "+t._s(t.row.hits)+" "),r("k-icon",{attrs:{title:t.title,type:"clock"}})]:r("p",[t._v("–")])],2)},ot=[],lt=i(it,nt,ot,!1,null,null,null,null);const ct=lt.exports,ut={props:{column:{type:Object,default:()=>({})},field:Object,value:[String,Object]},computed:{isExternal(){return this.value&&this.value.startsWith("http")},link(){return this.isExternal?this.value:window.panel.$urls.site+"/"+this.value}}};var dt=function(){var t=this,r=t._self._c;return r("p",{staticClass:"k-text k-url-field-preview k-path-field-preview"},[r("k-link",{attrs:{to:t.link,title:`${t.column.label}: ${t.value}`,target:"_blank"},nativeOn:{click:function(s){s.stopPropagation()}}},[r("span",[t._v(t._s(t.value))])])],1)},_t=[],pt=i(ut,dt,_t,!1,null,null,null,null);const ft=pt.exports,Et="",ht={props:{value:Boolean,column:Object}};var mt=function(){var t=this,r=t._self._c;return r("div",{staticClass:"k-priority-field-preview"},[t.value?r("k-icon",{attrs:{type:"bolt",title:t.column.label}}):r("p",[t._v("–")])],1)},vt=[],$t=i(ht,mt,vt,!1,null,null,null,null);const yt=$t.exports,p={computed:{color(){return this.value?parseInt(this.value)>=400?"var(--color-red-500)":parseInt(this.value)>=300?"var(--color-green-500)":"var(--color-blue-500)":"var(--color-gray-400)"}}},Wt="",bt={mixins:[p],props:{value:Number,row:Object,column:Object}};var kt=function(){var t=this,r=t._self._c;return r("div",{staticClass:"k-text k-status-field-preview",attrs:{title:`${t.column.label}: ${t.value}`}},[r("k-icon",{style:"color: "+t.color,attrs:{type:"circle-filled"}}),r("code",[t._v(t._s(t.value))])],1)},gt=[],Ct=i(bt,kt,gt,!1,null,null,null,null);const wt=Ct.exports,xt={extends:"k-select-field",mixins:[p],methods:{onInput(e){this.value=e}}};var Mt=function(){var t=this,r=t._self._c;return r("k-field",t._b({staticClass:"k-select-field",attrs:{input:t._uid}},"k-field",t.$props,!1),[r("k-input",t._g(t._b({ref:"input",attrs:{id:t._uid,type:"select",theme:"field"},on:{input:t.onInput},scopedSlots:t._u([{key:"before",fn:function(){return[r("k-icon",{attrs:{type:"circle-filled",color:t.color}})]},proxy:!0}])},"k-input",t.$props,!1),t.$listeners))],1)},Lt=[],Ft=i(xt,Mt,Lt,!1,null,null,null,null);const St=Ft.exports;panel.plugin("distantnative/retour",{components:{"k-count-field-preview":ct,"k-path-field-preview":ft,"k-priority-field-preview":yt,"k-status-field-preview":wt,"k-retour-stats":W,"k-retour-tabs":Q,"k-retour-timespan":at,"k-retour-view":b,"k-retour-redirects-view":M,"k-retour-failures-view":F,"k-retour-system-view":j},fields:{"retour-status":St},icons:{"circle-focus":'<path d="M12 20C16.4183 20 20 16.4183 20 12C20 7.58172 16.4183 4 12 4C7.58172 4 4 7.58172 4 12C4 16.4183 7.58172 20 12 20ZM12 22C6.47715 22 2 17.5228 2 12C2 6.47715 6.47715 2 12 2C17.5228 2 22 6.47715 22 12C22 17.5228 17.5228 22 12 22ZM12 14C10.8954 14 10 13.1046 10 12C10 10.8954 10.8954 10 12 10C13.1046 10 14 10.8954 14 12C14 13.1046 13.1046 14 12 14Z"></path>',"check-double":'<path d="M11.602 13.7599L13.014 15.1719L21.4795 6.7063L22.8938 8.12051L13.014 18.0003L6.65 11.6363L8.06421 10.2221L10.189 12.3469L11.6025 13.7594L11.602 13.7599ZM11.6037 10.9322L16.5563 5.97949L17.9666 7.38977L13.014 12.3424L11.6037 10.9322ZM8.77698 16.5873L7.36396 18.0003L1 11.6363L2.41421 10.2221L3.82723 11.6352L3.82604 11.6363L8.77698 16.5873Z"></path>',"cloud-off":'<path d="M3.51472 2.10051L22.6066 21.1924L21.1924 22.6066L19.1782 20.5924C18.503 20.8556 17.7684 21 17 21H7C3.68629 21 1 18.3137 1 15C1 12.3846 2.67346 10.16 5.00804 9.33857C5.0027 9.22639 5 9.11351 5 9C5 8.22228 5.12683 7.47418 5.36094 6.77527L2.10051 3.51472L3.51472 2.10051ZM7 9C7 9.08147 7.00193 9.16263 7.00578 9.24344L7.07662 10.7309L5.67183 11.2252C4.0844 11.7837 3 13.2889 3 15C3 17.2091 4.79086 19 7 19H17C17.1858 19 17.3687 18.9873 17.5478 18.9628L7.03043 8.44519C7.01032 8.62736 7 8.81247 7 9ZM12 2C15.866 2 19 5.13401 19 9C19 9.11351 18.9973 9.22639 18.992 9.33857C21.3265 10.16 23 12.3846 23 15C23 16.0883 22.7103 17.1089 22.2037 17.9889L20.7111 16.4955C20.8974 16.0335 21 15.5287 21 15C21 12.79 19.21 11 17 11C16.4711 11 15.9661 11.1027 15.5039 11.2892L14.0111 9.7964C14.8912 9.28978 15.9118 9 17 9C17 6.23858 14.7614 4 12 4C10.9295 4 9.93766 4.33639 9.12428 4.90922L7.69418 3.48056C8.88169 2.55284 10.3763 2 12 2Z"></path>'}})})();