-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathindex.js
1 lines (1 loc) · 6.11 KB
/
index.js
1
!function n(a,r,u){function c(e,t){if(!r[e]){if(!a[e]){var s="function"==typeof require&&require;if(!t&&s)return s(e,!0);if(d)return d(e,!0);var o=new Error("Cannot find module '"+e+"'");throw o.code="MODULE_NOT_FOUND",o}var i=r[e]={exports:{}};a[e][0].call(i.exports,function(t){return c(a[e][1][t]||t)},i,i.exports,n,a,r,u)}return r[e].exports}for(var d="function"==typeof require&&require,t=0;t<u.length;t++)c(u[t]);return c}({1:[function(o,t,i){!function(){"use strict";Object.defineProperty(i,"__esModule",{value:!0});var t,e=o(2),s=(t=e)&&t.__esModule?t:{default:t},n=o(3);i.default={inheritAttrs:!1,components:{WebhookStatus:s.default},props:{statusInitial:Object,label:String,name:String,hook:{type:Object,required:!0},endpoint:{type:String,required:!0},siteModified:Number,hookUpdated:Number,labels:{type:Object,required:!0},debug:Boolean,monochrome:Boolean},data:function(){return{statusLive:this.statusInitial,timer:null,hookUpdatedLive:this.hookUpdated,siteModifiedLive:this.siteModified}},computed:{statusCta:function(){return this.labels[this.status]?this.labels[this.status].cta:"Run now"},ctaDisabled:function(){return["hooksEmpty","hookNotfound","hookNoUrl"].includes(this.status)},status:function(){return this.hook.showOutdated&&"new"!==this.statusLive&&this.siteModifiedLive>this.hookUpdatedLive?"outdated":this.statusLive}},methods:{triggerHook:function(){var s=this,t=this.hook.url;(0,n.request)(t,this.hook.method,function(t){var e=t.response?JSON.parse(t.response):null;s.setStatus("progress",e),s.log("hook "+s.hook.name+" started")},function(t){s.setStatus("error",t.response),s.log("could not reach webhook URL",!0)},this.hook.payload)},getStatus:function(){var s=this,t="/"+this.endpoint+"/"+this.hook.name+"/status";(0,n.request)(t,"GET",function(t){var e=JSON.parse(t.response);e&&e.status!==s.statusLive&&(s.statusLive=e.status,s.updateTime())},function(){return s.log("there was an error with checking the status :(",!0)})},getSiteModified:function(){var s=this,t="/"+this.endpoint+"/site-modified";(0,n.request)(t,"GET",function(t){var e=JSON.parse(t.response);e&&e.modified&&(s.siteModifiedLive=e.modified)},function(){return s.log("could not get the time the site was last modified :(",!0)})},setStatus:function(t,e){var s=this,o=1<arguments.length&&void 0!==e?e:null;this.statusLive=t,this.updateTime();var i="/"+this.endpoint+"/"+this.hook.name+"/"+t;(0,n.request)(i,"POST",function(t){return s.log(t.response)},function(){return s.log("there was an error with updating the status :(",!0)},o)},updateTime:function(){"success"!==this.statusLive&&(this.hookUpdatedLive=Date.now()/1e3)},log:function(t,e){var s=1<arguments.length&&void 0!==e&&e;this.debug&&(s?console.warn:console.log)(t)}},watch:{status:{immediate:!0,handler:function(t){"progress"===t?(window.clearInterval(this.timer),this.timer=setInterval(this.getStatus,1e3)):!this.hook.showOutdated||"success"!==t&&"error"!==t?window.clearInterval(this.timer):(window.clearInterval(this.timer),this.timer=setInterval(this.getSiteModified,1e3))}},beforeDestroy:function(){window.clearInterval(this.timer)}}}}(),t.exports.__esModule&&(t.exports=t.exports.default);var e="function"==typeof t.exports?t.exports.options:t.exports;e.render=function(){var t=this,e=t.$createElement,s=t._self._c||e;return s("k-field",t._b({staticClass:"pju-webhook",class:{monochrome:t.monochrome}},"k-field",t.$props,!1),[s("WebhookStatus",{attrs:{status:t.status,hookUpdated:t.hookUpdatedLive,hookName:t.hook.name,labels:t.labels}}),t._v(" "),s("k-button",{staticClass:"pju-webhook--btn",attrs:{icon:"upload",type:"submit",disabled:t.ctaDisabled},on:{click:t.triggerHook}},[t._v("\n "+t._s(t.statusCta)+"\n ")])],1)},e.staticRenderFns=[]},{2:2,3:3}],2:[function(t,e,s){!function(){"use strict";Object.defineProperty(s,"__esModule",{value:!0});var e="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t};s.default={props:{status:String,hookName:String,hookUpdated:Number,labels:Object},computed:{icon:function(){var t=void 0;switch(this.status){case"success":t="check";break;case"progress":t="loader";break;case"error":t="cancel";break;case"new":t="bolt";break;case"outdated":t="alert";break;default:t="cancel"}return t},statusName:function(){return this.labels[this.status]?this.labels[this.status].name:this.status},statusText:function(){return this.labels[this.status]?this.labels[this.status].text:""},statusClass:function(){return"status-"+this.status},iconClass:function(){return"icon-"+this.icon},updatedText:function(){var t=new Date(1e3*this.hookUpdated);return"undefined"!=typeof window&&window.Intl&&"object"===e(window.Intl)?new Intl.DateTimeFormat(void 0,{year:"numeric",month:"numeric",day:"numeric",hour:"numeric",minute:"numeric"}).format(t):""}}}}(),e.exports.__esModule&&(e.exports=e.exports.default);var o="function"==typeof e.exports?e.exports.options:e.exports;o.render=function(){var t=this,e=t.$createElement,s=t._self._c||e;return s("k-box",{staticClass:"pju-webhook--status",class:[t.statusClass,t.iconClass]},[s("span",{staticClass:"visuallyhidden"},[t._v("Status")]),t._v(" "),s("k-icon",{staticClass:"pju-webhook--status--icon",attrs:{type:t.icon}}),t._v(" "),s("div",{staticClass:"pju-webhook--status--label"},[s("p",{staticClass:"pju-webhook--status--name"},[t._v("\n "+t._s(t.statusName)+"\n ")]),t._v(" "),s("p",{staticClass:"pju-webhook--status--description"},[s("small",[t._v("\n "+t._s(t.statusText)+"\n ")])]),t._v(" "),s("p",{staticClass:"pju-webhook--status--description"},[s("small",[t._v("\n "+t._s(t.updatedText)+"\n ")])])])],1)},o.staticRenderFns=[]},{}],3:[function(t,e,s){"use strict";Object.defineProperty(s,"__esModule",{value:!0}),s.request=function(t,e,s,o,i){var n=new XMLHttpRequest;n.open(e,t,!0),n.onreadystatechange=function(){4===n.readyState&&n.status<400?s&&s(n):4===n.readyState&&o&&o(n)},i?(n.setRequestHeader("Content-Type","application/json"),n.send(JSON.stringify(i))):n.send()}},{}],4:[function(t,e,s){"use strict";var o,i=t(1),n=(o=i)&&o.__esModule?o:{default:o};panel.plugin("pju/webhook-field",{fields:{webhook:n.default}})},{1:1}]},{},[4]);