framework/extensions/package-manager/js/dist/admin.js
flarum-bot fe20e2c212 Bundled output for commit 795a500adb
Includes transpiled JS/TS, and Typescript declaration files (typings).

[skip ci]
2022-07-24 13:06:41 +00:00

2 lines
31 KiB
JavaScript
Executable File
Generated

(()=>{var a={3:function(a){a.exports=function(){"use strict";var a,t,e=1e3,n=6e4,r=36e5,s=864e5,i=/\[([^\]]+)]|Y{1,4}|M{1,4}|D{1,2}|d{1,4}|H{1,2}|h{1,2}|a|A|m{1,2}|s{1,2}|Z{1,2}|SSS/g,o=31536e6,l=2592e6,u=/^(-|\+)?P(?:([-+]?[0-9,.]*)Y)?(?:([-+]?[0-9,.]*)M)?(?:([-+]?[0-9,.]*)W)?(?:([-+]?[0-9,.]*)D)?(?:T(?:([-+]?[0-9,.]*)H)?(?:([-+]?[0-9,.]*)M)?(?:([-+]?[0-9,.]*)S)?)?$/,c={years:o,months:l,days:s,hours:r,minutes:n,seconds:e,milliseconds:1,weeks:6048e5},m=function(a){return a instanceof v},d=function(a,t,e){return new v(a,e,t.$l)},p=function(a){return t.p(a)+"s"},f=function(a){return a<0},g=function(a){return f(a)?Math.ceil(a):Math.floor(a)},h=function(a){return Math.abs(a)},k=function(a,t){return a?f(a)?{negative:!0,format:""+h(a)+t}:{negative:!1,format:""+a+t}:{negative:!1,format:""}},v=function(){function f(a,t,e){var n=this;if(this.$d={},this.$l=e,void 0===a&&(this.$ms=0,this.parseFromMilliseconds()),t)return d(a*c[p(t)],this);if("number"==typeof a)return this.$ms=a,this.parseFromMilliseconds(),this;if("object"==typeof a)return Object.keys(a).forEach((function(t){n.$d[p(t)]=a[t]})),this.calMilliseconds(),this;if("string"==typeof a){var r=a.match(u);if(r){var s=r.slice(2).map((function(a){return null!=a?Number(a):0}));return this.$d.years=s[0],this.$d.months=s[1],this.$d.weeks=s[2],this.$d.days=s[3],this.$d.hours=s[4],this.$d.minutes=s[5],this.$d.seconds=s[6],this.calMilliseconds(),this}}return this}var h=f.prototype;return h.calMilliseconds=function(){var a=this;this.$ms=Object.keys(this.$d).reduce((function(t,e){return t+(a.$d[e]||0)*c[e]}),0)},h.parseFromMilliseconds=function(){var a=this.$ms;this.$d.years=g(a/o),a%=o,this.$d.months=g(a/l),a%=l,this.$d.days=g(a/s),a%=s,this.$d.hours=g(a/r),a%=r,this.$d.minutes=g(a/n),a%=n,this.$d.seconds=g(a/e),a%=e,this.$d.milliseconds=a},h.toISOString=function(){var a=k(this.$d.years,"Y"),t=k(this.$d.months,"M"),e=+this.$d.days||0;this.$d.weeks&&(e+=7*this.$d.weeks);var n=k(e,"D"),r=k(this.$d.hours,"H"),s=k(this.$d.minutes,"M"),i=this.$d.seconds||0;this.$d.milliseconds&&(i+=this.$d.milliseconds/1e3);var o=k(i,"S"),l=a.negative||t.negative||n.negative||r.negative||s.negative||o.negative,u=r.format||s.format||o.format?"T":"",c=(l?"-":"")+"P"+a.format+t.format+n.format+u+r.format+s.format+o.format;return"P"===c||"-P"===c?"P0D":c},h.toJSON=function(){return this.toISOString()},h.format=function(a){var e=a||"YYYY-MM-DDTHH:mm:ss",n={Y:this.$d.years,YY:t.s(this.$d.years,2,"0"),YYYY:t.s(this.$d.years,4,"0"),M:this.$d.months,MM:t.s(this.$d.months,2,"0"),D:this.$d.days,DD:t.s(this.$d.days,2,"0"),H:this.$d.hours,HH:t.s(this.$d.hours,2,"0"),m:this.$d.minutes,mm:t.s(this.$d.minutes,2,"0"),s:this.$d.seconds,ss:t.s(this.$d.seconds,2,"0"),SSS:t.s(this.$d.milliseconds,3,"0")};return e.replace(i,(function(a,t){return t||String(n[a])}))},h.as=function(a){return this.$ms/c[p(a)]},h.get=function(a){var t=this.$ms,e=p(a);return"milliseconds"===e?t%=1e3:t="weeks"===e?g(t/c[e]):this.$d[e],0===t?0:t},h.add=function(a,t,e){var n;return n=t?a*c[p(t)]:m(a)?a.$ms:d(a,this).$ms,d(this.$ms+n*(e?-1:1),this)},h.subtract=function(a,t){return this.add(a,t,!0)},h.locale=function(a){var t=this.clone();return t.$l=a,t},h.clone=function(){return d(this.$ms,this)},h.humanize=function(t){return a().add(this.$ms,"ms").locale(this.$l).fromNow(!t)},h.milliseconds=function(){return this.get("milliseconds")},h.asMilliseconds=function(){return this.as("milliseconds")},h.seconds=function(){return this.get("seconds")},h.asSeconds=function(){return this.as("seconds")},h.minutes=function(){return this.get("minutes")},h.asMinutes=function(){return this.as("minutes")},h.hours=function(){return this.get("hours")},h.asHours=function(){return this.as("hours")},h.days=function(){return this.get("days")},h.asDays=function(){return this.as("days")},h.weeks=function(){return this.get("weeks")},h.asWeeks=function(){return this.as("weeks")},h.months=function(){return this.get("months")},h.asMonths=function(){return this.as("months")},h.years=function(){return this.get("years")},h.asYears=function(){return this.as("years")},f}();return function(e,n,r){a=r,t=r().$utils(),r.duration=function(a,t){var e=r.locale();return d(a,{$l:e},t)},r.isDuration=m;var s=n.prototype.add,i=n.prototype.subtract;n.prototype.add=function(a,t){return m(a)&&(a=a.asMilliseconds()),s.bind(this)(a,t)},n.prototype.subtract=function(a,t){return m(a)&&(a=a.asMilliseconds()),i.bind(this)(a,t)}}}()}},t={};function e(n){var r=t[n];if(void 0!==r)return r.exports;var s=t[n]={exports:{}};return a[n].call(s.exports,s,s.exports,e),s.exports}e.n=a=>{var t=a&&a.__esModule?()=>a.default:()=>a;return e.d(t,{a:t}),t},e.d=(a,t)=>{for(var n in t)e.o(t,n)&&!e.o(a,n)&&Object.defineProperty(a,n,{enumerable:!0,get:t[n]})},e.o=(a,t)=>Object.prototype.hasOwnProperty.call(a,t),e.r=a=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(a,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(a,"__esModule",{value:!0})};var n={};(()=>{"use strict";e.r(n);const a=flarum.core.compat["common/extend"],t=flarum.core.compat["admin/app"];var r=e.n(t);const s=flarum.core.compat["admin/components/ExtensionPage"];var i=e.n(s);const o=flarum.core.compat["common/components/Button"];var l=e.n(o);const u=flarum.core.compat["admin/components/LoadingModal"];var c=e.n(u);const d=flarum.core.compat["admin/utils/isExtensionEnabled"];var p=e.n(d);function f(a,t){return f=Object.setPrototypeOf||function(a,t){return a.__proto__=t,a},f(a,t)}function g(a,t){a.prototype=Object.create(t.prototype),a.prototype.constructor=a,f(a,t)}function h(a,t){if(null==a)return{};var e,n,r={},s=Object.keys(a);for(n=0;n<s.length;n++)e=s[n],t.indexOf(e)>=0||(r[e]=a[e]);return r}const k=flarum.core.compat["common/Component"];var v=e.n(k);const y=flarum.core.compat["common/components/LoadingIndicator"];var b=e.n(y);const x=flarum.core.compat["common/components/Tooltip"];var _=e.n(x);const N=flarum.core.compat["common/helpers/icon"];var M=e.n(N);const w=flarum.core.compat["common/utils/ItemList"];var P=e.n(w);const $=flarum.core.compat["common/utils/extractText"];var U=e.n($);const q=flarum.core.compat["common/utils/classList"];var T=e.n(q),j=["className","type"],S=function(a){function t(){return a.apply(this,arguments)||this}return g(t,a),t.prototype.view=function(a){var t=this.attrs,e=t.className,n=(t.type,h(t,j));return m("span",Object.assign({className:T()(["Label","Label--"+this.attrs.type,e])},n),a.children)},t}(v());const B=flarum.core.compat["common/components/Modal"];var L=e.n(B),O=function(a){function t(){return a.apply(this,arguments)||this}g(t,a);var e=t.prototype;return e.className=function(){return"Modal--large QuickModal"},e.title=function(){return r().translator.trans("flarum-package-manager.admin.sections.queue.operations."+this.attrs.task.operation())},e.content=function(){return m("div",{className:"Modal-body"},m("div",{className:"TaskOutputModal-data"},m("div",{className:"Form-group"},m("label",null,r().translator.trans("flarum-package-manager.admin.sections.queue.output_modal.command")),m("div",{className:"FormControl TaskOutputModal-data-command"},m("code",null,"$ composer ",this.attrs.task.command()))),m("div",{className:"Form-group"},m("label",null,r().translator.trans("flarum-package-manager.admin.sections.queue.output_modal.output")),m("div",{className:"FormControl TaskOutputModal-data-output"},m("code",null,m("pre",null,this.attrs.task.output()))))))},t}(L()),E=e(3),A=e.n(E),C=function(a){function t(){return a.apply(this,arguments)||this}return g(t,a),t.prototype.view=function(){var a=this;return m("nav",{class:"Pagination UserListPage-gridPagination"},m(l(),{disabled:!this.attrs.list.hasPrev(),title:r().translator.trans("core.admin.users.pagination.back_button"),onclick:function(){return a.attrs.list.prev()},icon:"fas fa-chevron-left",className:"Button Button--icon UserListPage-backBtn"}),m("span",{class:"UserListPage-pageNumber"},r().translator.trans("core.admin.users.pagination.page_counter",{current:this.attrs.list.pageNumber()+1,total:this.attrs.list.getTotalPages()})),m(l(),{disabled:!this.attrs.list.hasNext(),title:r().translator.trans("core.admin.users.pagination.next_button"),onclick:function(){return a.attrs.list.next()},icon:"fas fa-chevron-right",className:"Button Button--icon UserListPage-nextBtn"}))},t}(v()),D=["label","content"],F=function(a){function t(){return a.apply(this,arguments)||this}g(t,a);var e=t.prototype;return e.oninit=function(t){a.prototype.oninit.call(this,t),r().packageManagerQueue.load()},e.view=function(){return m("section",{id:"PackageManager-queueSection",className:"ExtensionPage-permissions PackageManager-queueSection"},m("div",{className:"ExtensionPage-permissions-header PackageManager-queueSection-header"},m("div",{className:"container"},m("h2",{className:"ExtensionTitle"},r().translator.trans("flarum-package-manager.admin.sections.queue.title")),m(l(),{className:"Button Button--icon",icon:"fas fa-sync-alt",onclick:function(){return r().packageManagerQueue.load()},"aria-label":r().translator.trans("flarum-package-manager.admin.sections.queue.refresh")}))),m("div",{className:"container"},this.queueTable()))},e.columns=function(){var a=this,t=new(P());return t.add("operation",{label:U()(r().translator.trans("flarum-package-manager.admin.sections.queue.columns.operation")),content:function(t){return m("div",{className:"PackageManager-queueTable-operation"},m("span",{className:"PackageManager-queueTable-operation-icon"},a.operationIcon(t.operation())),m("span",{className:"PackageManager-queueTable-operation-name"},r().translator.trans("flarum-package-manager.admin.sections.queue.operations."+t.operation())))}},80),t.add("package",{label:U()(r().translator.trans("flarum-package-manager.admin.sections.queue.columns.package")),content:function(a){var t,e=r().data.extensions[null==(t=a.package())?void 0:t.replace(/(\/flarum-|\/flarum-ext-|\/)/g,"-")];return e?m("div",{className:"PackageManager-queueTable-package"},m("div",{className:"PackageManager-queueTable-package-icon ExtensionIcon",style:e.icon},e.icon?M()(e.icon.name):""),m("div",{className:"PackageManager-queueTable-package-details"},m("span",{className:"PackageManager-queueTable-package-title"},e.extra["flarum-extension"].title),m("span",{className:"PackageManager-queueTable-package-name"},a.package()))):a.package()}},75),t.add("status",{label:U()(r().translator.trans("flarum-package-manager.admin.sections.queue.columns.status")),content:function(a){return m(S,{className:"PackageManager-queueTable-status",type:{running:"neutral",failure:"error",pending:"warning",success:"success"}[a.status()]},r().translator.trans("flarum-package-manager.admin.sections.queue.statuses."+a.status()))}},70),t.add("elapsedTime",{label:U()(r().translator.trans("flarum-package-manager.admin.sections.queue.columns.elapsed_time")),content:function(a){return a.startedAt()?m(_(),{text:dayjs(a.startedAt()).format("LL LTS")+" "+dayjs(a.finishedAt()).format("LL LTS")},m("span",null,function(a,t){dayjs.extend(A());var e=dayjs(t).diff(a);return dayjs.duration(e).humanize()}(a.startedAt(),a.finishedAt()))):r().translator.trans("flarum-package-manager.admin.sections.queue.task_just_started")}},65),t.add("memoryUsed",{label:U()(r().translator.trans("flarum-package-manager.admin.sections.queue.columns.peak_memory_used")),content:function(a){return m("span",null,a.peakMemoryUsed())}},60),t.add("details",{label:U()(r().translator.trans("flarum-package-manager.admin.sections.queue.columns.details")),content:function(a){return m(l(),{className:"Button Button--icon Table-controls-item",icon:"fas fa-file-alt","aria-label":r().translator.trans("flarum-package-manager.admin.sections.queue.columns.details"),onclick:function(){return r().modal.show(O,{task:a})}})},className:"Table-controls"},55),t},e.queueTable=function(){var a=r().packageManagerQueue.getItems();if(!a)return m(b(),null);if(a&&!a.length)return m("h3",{className:"ExtensionPage-subHeader"},r().translator.trans("flarum-package-manager.admin.sections.queue.none"));var t=this.columns();return m("[",null,m("table",{className:"Table PackageManager-queueTable"},m("thead",null,m("tr",null,t.toArray().map((function(a,t){return m("th",{key:t},a.label)})))),m("tbody",null,a.map((function(a,e){return m("tr",{key:e},t.toArray().map((function(t,e){t.label;var n=t.content,r=h(t,D);return m("td",Object.assign({key:e},r),n(a))})))})))),m(C,{list:r().packageManagerQueue}))},e.operationIcon=function(a){return M()({update_check:"fas fa-sync-alt",update_major:"fas fa-play",update_minor:"fas fa-play",update_global:"fas fa-play",extension_install:"fas fa-download",extension_remove:"fas fa-times",extension_update:"fas fa-arrow-alt-circle-up",why_not:"fas fa-exclamation-circle"}[a])},t}(v());const Y=flarum.core.compat["common/components/Alert"];var H=e.n(Y);const I=flarum.core.compat["common/utils/Stream"];var W=e.n(I);function Q(a){var t=a.response.errors[0];if(!["composer_command_failure","extension_already_installed","extension_not_installed"].includes(t.code))throw a;switch(t.code){case"composer_command_failure":t.guessed_cause?(r().alerts.show({type:"error"},r().translator.trans("flarum-package-manager.admin.exceptions.guessed_cause."+t.guessed_cause)),r().modal.close()):r().alerts.show({type:"error"},r().translator.trans("flarum-package-manager.admin.exceptions.composer_command_failure"));break;case"extension_already_installed":r().alerts.show({type:"error"},r().translator.trans("flarum-package-manager.admin.exceptions.extension_already_installed")),r().modal.close();break;case"extension_not_installed":r().alerts.show({type:"error"},r().translator.trans("flarum-package-manager.admin.exceptions.extension_not_installed")),r().modal.close()}}function G(){r().modal.close(),m.route.set(r().route("extension",{id:"flarum-package-manager"})),r().packageManagerQueue.load(),setTimeout((function(){var a;null==(a=document.getElementById("PackageManager-queueSection"))||a.scrollIntoView({block:"nearest"})}),200)}window.jumpToQueue=G;var R=function(a){function t(){for(var t,e=arguments.length,n=new Array(e),r=0;r<e;r++)n[r]=arguments[r];return(t=a.call.apply(a,[this].concat(n))||this).packageName=void 0,t.isLoading=!1,t}g(t,a);var e=t.prototype;return e.oninit=function(t){a.prototype.oninit.call(this,t),this.packageName=W()("")},e.view=function(){return m("div",{className:"Form-group PackageManager-installer"},m("label",{htmlFor:"install-extension"},r().translator.trans("flarum-package-manager.admin.extensions.install")),m("p",{className:"helpText"},r().translator.trans("flarum-package-manager.admin.extensions.install_help",{extiverse:m("a",{href:"https://extiverse.com"},"extiverse.com")})),m("div",{className:"FormControl-container"},m("input",{className:"FormControl",id:"install-extension",placeholder:"vendor/package-name",bidi:this.packageName}),m(l(),{className:"Button",icon:"fas fa-download",onclick:this.onsubmit.bind(this),loading:this.isLoading},r().translator.trans("flarum-package-manager.admin.extensions.proceed"))))},e.data=function(){return{package:this.packageName()}},e.onsubmit=function(){var a=this;this.isLoading=!0,r().modal.show(c()),r().request({method:"POST",url:r().forum.attribute("apiUrl")+"/package-manager/extensions",body:{data:this.data()},errorHandler:Q}).then((function(a){if(a.processing)G();else{var t=a.id;r().alerts.show({type:"success"},r().translator.trans("flarum-package-manager.admin.extensions.successful_install",{extension:t})),window.location.href=r().forum.attribute("adminUrl")+"#/extension/"+t,window.location.reload()}})).finally((function(){a.isLoading=!1,m.redraw()}))},t}(v());function Z(a,t){for(var e=0;e<t.length;e++){var n=t[e];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(a,n.key,n)}}const z=flarum.core.compat["common/helpers/humanTime"];var J=e.n(z),V=function(a){function t(){for(var t,e=arguments.length,n=new Array(e),r=0;r<e;r++)n[r]=arguments[r];return(t=a.call.apply(a,[this].concat(n))||this).loading=!0,t.whyNot=null,t}g(t,a);var e=t.prototype;return e.className=function(){return"Modal--large WhyNotModal"},e.title=function(){return r().translator.trans("flarum-package-manager.admin.why_not_modal.title")},e.oncreate=function(t){a.prototype.oncreate.call(this,t),this.requestWhyNot()},e.content=function(){return m("div",{className:"Modal-body"},this.loading?m(b(),null):m("pre",{className:"WhyNotModal-contents"},this.whyNot))},e.requestWhyNot=function(){var a=this;r().request({method:"POST",url:r().forum.attribute("apiUrl")+"/package-manager/why-not",body:{data:{package:this.attrs.package}},errorHandler:Q}).then((function(t){a.loading=!1,a.whyNot=t.data.reason,m.redraw()}))},t}(L()),K=function(a){function t(){return a.apply(this,arguments)||this}g(t,a);var e=t.prototype;return e.view=function(a){var t,e=this.attrs,n=e.extension,s=e.updates,i=e.onClickUpdate,o=e.whyNotWarning,u=e.isCore,c=e.isDanger,d=null!=(t=s["latest-minor"])?t:s["latest-major"]&&!u?s["latest-major"]:null;return m("div",{className:T()({"PackageManager-extension":!0,"PackageManager-extension--core":u,"PackageManager-extension--danger":c})},m("div",{className:"PackageManager-extension-icon ExtensionIcon",style:n.icon},n.icon?M()(n.icon.name):""),m("div",{className:"PackageManager-extension-info"},m("div",{className:"PackageManager-extension-name"},n.extra["flarum-extension"].title),m("div",{className:"PackageManager-extension-version"},m("span",{className:"PackageManager-extension-version-current"},this.version(n.version)),d?m(S,{className:"PackageManager-extension-version-latest",type:s["latest-minor"]?"success":"warning"},this.version(d)):null)),m("div",{className:"PackageManager-extension-controls"},i?m(_(),{text:r().translator.trans("flarum-package-manager.admin.extensions.update")},m(l(),{icon:"fas fa-arrow-alt-circle-up",className:"Button Button--icon Button--flat",onclick:i,"aria-label":r().translator.trans("flarum-package-manager.admin.extensions.update")})):null,o?m(_(),{text:r().translator.trans("flarum-package-manager.admin.extensions.check_why_it_failed_updating")},m(l(),{icon:"fas fa-exclamation-circle",className:"Button Button--icon Button--flat Button--danger",onclick:function(){return r().modal.show(V,{package:n.name})},"aria-label":r().translator.trans("flarum-package-manager.admin.extensions.check_why_it_failed_updating")})):null))},e.version=function(a){return"v"+a.replace("v","")},t}(v()),X=function(a){function t(){for(var t,e=arguments.length,n=new Array(e),r=0;r<e;r++)n[r]=arguments[r];return(t=a.call.apply(a,[this].concat(n))||this).isLoading=null,t.updateState=void 0,t}g(t,a);var e=t.prototype;return e.oninit=function(t){a.prototype.oninit.call(this,t),this.updateState=this.attrs.updateState},e.view=function(a){return m("div",{className:"Form-group Form-group--danger PackageManager-majorUpdate"},m("img",{alt:"flarum logo",src:r().forum.attribute("baseUrl")+"/assets/extensions/flarum-package-manager/flarum.svg"}),m("label",null,r().translator.trans("flarum-package-manager.admin.major_updater.title",{version:this.attrs.coreUpdate["latest-major"]})),m("p",{className:"helpText"},r().translator.trans("flarum-package-manager.admin.major_updater.description")),m("div",{className:"PackageManager-updaterControls"},m(_(),{text:r().translator.trans("flarum-package-manager.admin.major_updater.dry_run_help")},m(l(),{className:"Button",icon:"fas fa-vial",onclick:this.update.bind(this,!0)},r().translator.trans("flarum-package-manager.admin.major_updater.dry_run"))),m(l(),{className:"Button Button--danger",icon:"fas fa-play",onclick:this.update.bind(this,!1)},r().translator.trans("flarum-package-manager.admin.major_updater.update"))),this.updateState.incompatibleExtensions.length?m("div",{className:"PackageManager-majorUpdate-incompatibleExtensions PackageManager-extensions-grid"},this.updateState.incompatibleExtensions.map((function(a){return m(K,{extension:r().data.extensions[a.replace("flarum-","").replace("flarum-ext-","").replace("/","-")],updates:{},onClickUpdate:null,isDanger:!0})}))):null,"failure"===this.updateState.status?m(H(),{type:"error",className:"PackageManager-majorUpdate-failure",dismissible:!1,controls:[m(l(),{className:"Button Button--text PackageManager-majorUpdate-failure-details",icon:"fas fa-question-circle",onclick:function(){return r().modal.show(V,{package:"flarum/core"})}},r().translator.trans("flarum-package-manager.admin.major_updater.failure.why"))]},m("p",{className:"PackageManager-majorUpdate-failure-desc"},r().translator.trans("flarum-package-manager.admin.major_updater.failure.desc"))):null)},e.update=function(a){var t=this;this.isLoading="update-"+(a?"dry-run":"run"),r().modal.show(c()),r().request({method:"POST",url:r().forum.attribute("apiUrl")+"/package-manager/major-update",body:{data:{dryRun:a}},errorHandler:Q}).then((function(a){null!=a&&a.processing?G():(r().alerts.show({type:"success"},r().translator.trans("flarum-package-manager.admin.update_successful")),window.location.reload())})).catch((function(a){var e,n,s;r().modal.close(),t.updateState.status="failure",t.updateState.incompatibleExtensions=null==(e=a.response)||null==(n=e.errors)||null==(s=n.pop())?void 0:s.incompatible_extensions})).finally((function(){t.isLoading=null,m.redraw()}))},t}(v()),aa=function(a){function t(){for(var t,e=arguments.length,n=new Array(e),s=0;s<e;s++)n[s]=arguments[s];return(t=a.call.apply(a,[this].concat(n))||this).isLoading=null,t.packageUpdates={},t.lastUpdateCheck=JSON.parse(r().data.settings["flarum-package-manager.last_update_check"]),t}g(t,a);var e,n,s=t.prototype;return s.oninit=function(t){a.prototype.oninit.call(this,t)},s.view=function(){var a,t,e=this,n=this.getExtensionUpdates(),s=this.getCoreUpdate();return s&&(t={id:"flarum-core",name:"flarum/core",version:r().data.settings.version,icon:{backgroundImage:"url("+r().forum.attribute("baseUrl")+"/assets/extensions/flarum-package-manager/flarum.svg"},extra:{"flarum-extension":{title:r().translator.trans("flarum-package-manager.admin.updater.flarum")}}}),[m("div",{className:"Form-group"},m("label",null,r().translator.trans("flarum-package-manager.admin.updater.updater_title")),m("p",{className:"helpText"},r().translator.trans("flarum-package-manager.admin.updater.updater_help")),(null==(a=this.lastUpdateCheck)?void 0:a.checkedAt)&&m("p",{className:"PackageManager-lastUpdatedAt"},m("span",{className:"PackageManager-lastUpdatedAt-label"},r().translator.trans("flarum-package-manager.admin.updater.last_update_checked_at")),m("span",{className:"PackageManager-lastUpdatedAt-value"},J()(this.lastUpdateCheck.checkedAt))),m("div",{className:"PackageManager-updaterControls"},m(l(),{className:"Button",icon:"fas fa-sync-alt",onclick:this.checkForUpdates.bind(this),loading:"check"===this.isLoading,disabled:null!==this.isLoading&&"check"!==this.isLoading},r().translator.trans("flarum-package-manager.admin.updater.check_for_updates")),m(l(),{className:"Button",icon:"fas fa-play",onclick:this.updateGlobally.bind(this),loading:"global-update"===this.isLoading,disabled:null!==this.isLoading&&"global-update"!==this.isLoading},r().translator.trans("flarum-package-manager.admin.updater.run_global_update"))),null!==this.isLoading?m("div",{className:"PackageManager-extensions"},m(b(),null)):n.length||t?m("div",{className:"PackageManager-extensions"},m("div",{className:"PackageManager-extensions-grid"},t?m(K,{extension:t,updates:s,isCore:!0,onClickUpdate:this.updateCoreMinor.bind(this),whyNotWarning:this.lastUpdateRun.limitedPackages().includes("flarum/core")}):null,n.map((function(a){return m(K,{extension:a,updates:e.packageUpdates[a.id],onClickUpdate:e.updateExtension.bind(e,a),whyNotWarning:e.lastUpdateRun.limitedPackages().includes(a.name)})})))):null),s&&s["latest-major"]?m(X,{coreUpdate:s,updateState:this.lastUpdateRun.major}):null]},s.getExtensionUpdates=function(){var a,t,e,n=this;return null==(a=this.lastUpdateCheck)||null==(t=a.updates)||null==(e=t.installed)||e.filter((function(a){var t=a.name.replace("/","-").replace(/(flarum-ext-)|(flarum-)/,""),e=r().data.extensions[t],s=["semver-safe-update","update-possible"].includes(a["latest-status"]);return e&&s&&(n.packageUpdates[e.id]=a),e&&s})),Object.values(r().data.extensions).filter((function(a){return n.packageUpdates[a.id]}))},s.getCoreUpdate=function(){var a,t,e;return null==(a=this.lastUpdateCheck)||null==(t=a.updates)||null==(e=t.installed)?void 0:e.filter((function(a){return"flarum/core"===a.name})).pop()},s.checkForUpdates=function(){var a=this;this.isLoading="check",r().request({method:"POST",url:r().forum.attribute("apiUrl")+"/package-manager/check-for-updates",errorHandler:Q}).then((function(t){t.processing?G():a.lastUpdateCheck=t})).finally((function(){a.isLoading=null,m.redraw()}))},s.updateCoreMinor=function(){var a=this;confirm(U()(r().translator.trans("flarum-package-manager.admin.minor_update_confirmation.content")))&&(r().modal.show(c()),this.isLoading="minor-update",r().request({method:"POST",url:r().forum.attribute("apiUrl")+"/package-manager/minor-update",errorHandler:Q}).then((function(a){null!=a&&a.processing?G():(r().alerts.show({type:"success"},r().translator.trans("flarum-package-manager.admin.update_successful")),window.location.reload())})).finally((function(){a.isLoading=null,m.redraw()})))},s.updateExtension=function(a){var t=this;r().modal.show(c()),this.isLoading="extension-update",r().request({method:"PATCH",url:r().forum.attribute("apiUrl")+"/package-manager/extensions/"+a.id,errorHandler:Q}).then((function(t){null!=t&&t.processing?G():(r().alerts.show({type:"success"},r().translator.trans("flarum-package-manager.admin.extensions.successful_update",{extension:a.extra["flarum-extension"].title})),window.location.reload())})).finally((function(){t.isLoading=null,m.redraw()}))},s.updateGlobally=function(){var a=this;r().modal.show(c()),this.isLoading="global-update",r().request({method:"POST",url:r().forum.attribute("apiUrl")+"/package-manager/global-update",errorHandler:Q}).then((function(a){null!=a&&a.processing?G():(r().alerts.show({type:"success"},r().translator.trans("flarum-package-manager.admin.updater.global_update_successful")),window.location.reload())})).finally((function(){a.isLoading=null,m.redraw()}))},e=t,(n=[{key:"lastUpdateRun",get:function(){var a=JSON.parse(r().data.settings["flarum-package-manager.last_update_run"]);return a.limitedPackages=function(){return[].concat(a.major.limitedPackages,a.minor.limitedPackages,a.global.limitedPackages)},a}}])&&Z(e.prototype,n),Object.defineProperty(e,"prototype",{writable:!1}),t}(v()),ta=function(a){function t(){return a.apply(this,arguments)||this}return g(t,a),t.prototype.view=function(){return m("div",{className:"ExtensionPage-permissions PackageManager-controlSection"},m("div",{className:"ExtensionPage-permissions-header"},m("div",{className:"container"},m("h2",{className:"ExtensionTitle"},r().translator.trans("flarum-package-manager.admin.sections.control.title")))),m("div",{className:"container"},r().data["flarum-package-manager.writable_dirs"]?m("[",null,m(R,null),m(aa,null)):m("div",{className:"Form-group"},m(H(),{type:"warning",dismissible:!1},r().translator.trans("flarum-package-manager.admin.file_permissions")))))},t}(v()),ea=function(a){function t(){return a.apply(this,arguments)||this}return g(t,a),t.prototype.sections=function(t){var e=a.prototype.sections.call(this,t);return r().data.settings["flarum-package-manager.queue_jobs"]&&e.add("queue",m(F,null),5),e.add("control",m(ta,null),8),e.setPriority("content",10),e.setPriority("permissions",0),e},t}(i());const na=flarum.core.compat["common/Model"];var ra=e.n(na);function sa(){return sa=Object.assign||function(a){for(var t=1;t<arguments.length;t++){var e=arguments[t];for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(a[n]=e[n])}return a},sa.apply(this,arguments)}var ia=["B","kB","MB","GB","TB","PB","EB","ZB","YB"],oa=["B","kiB","MiB","GiB","TiB","PiB","EiB","ZiB","YiB"],la=["b","kbit","Mbit","Gbit","Tbit","Pbit","Ebit","Zbit","Ybit"],ua=["b","kibit","Mibit","Gibit","Tibit","Pibit","Eibit","Zibit","Yibit"],ca=function(a,t,e){var n=a;return"string"==typeof t||Array.isArray(t)?n=a.toLocaleString(t,e):!0!==t&&void 0===e||(n=a.toLocaleString(void 0,e)),n},ma=function(a){function t(){return a.apply(this,arguments)||this}g(t,a);var e=t.prototype;return e.status=function(){return ra().attribute("status").call(this)},e.operation=function(){return ra().attribute("operation").call(this)},e.command=function(){return ra().attribute("command").call(this)},e.package=function(){return ra().attribute("package").call(this)},e.output=function(){return ra().attribute("output").call(this)},e.createdAt=function(){return ra().attribute("createdAt",ra().transformDate).call(this)},e.startedAt=function(){return ra().attribute("startedAt",ra().transformDate).call(this)},e.finishedAt=function(){return ra().attribute("finishedAt",ra().transformDate).call(this)},e.peakMemoryUsed=function(){return function(a,t){if(!Number.isFinite(a))throw new TypeError("Expected a finite number, got "+typeof a+": "+a);var e=(t=sa({bits:!1,binary:!1},t)).bits?t.binary?ua:la:t.binary?oa:ia;if(t.signed&&0===a)return" 0 "+e[0];var n,r=a<0,s=r?"-":t.signed?"+":"";if(r&&(a=-a),void 0!==t.minimumFractionDigits&&(n={minimumFractionDigits:t.minimumFractionDigits}),void 0!==t.maximumFractionDigits&&(n=sa({maximumFractionDigits:t.maximumFractionDigits},n)),a<1)return s+ca(a,t.locale,n)+" "+e[0];var i=Math.min(Math.floor(t.binary?Math.log(a)/Math.log(1024):Math.log10(a)/3),e.length-1);return a/=Math.pow(t.binary?1024:1e3,i),n||(a=a.toPrecision(3)),s+ca(Number(a),t.locale,n)+" "+e[i]}(1024*ra().attribute("peakMemoryUsed").call(this))},t}(ra()),da=function(){function a(){this.tasks=null,this.limit=5,this.offset=0,this.total=0}var t=a.prototype;return t.load=function(a){var t,e=this;return this.tasks=null,a=sa({page:sa({limit:this.limit,offset:this.offset},null==(t=a)?void 0:t.page)},a),r().store.find("package-manager-tasks",a||{}).then((function(a){var t;return e.tasks=a,e.total=null==(t=a.payload.meta)?void 0:t.total,m.redraw(),a}))},t.getItems=function(){return this.tasks},t.getTotalPages=function(){return Math.ceil(this.total/this.limit)},t.pageNumber=function(){return Math.ceil(this.offset/this.limit)},t.hasPrev=function(){return 0!==this.pageNumber()},t.hasNext=function(){return this.offset+this.limit<this.total},t.prev=function(){this.hasPrev()&&(this.offset-=this.limit,this.load())},t.next=function(){this.hasNext()&&(this.offset+=this.limit,this.load())},a}();r().initializers.add("flarum-package-manager",(function(t){t.store.models["package-manager-tasks"]=ma,t.packageManagerQueue=new da,t.extensionData.for("flarum-package-manager").registerSetting({setting:"flarum-package-manager.queue_jobs",label:t.translator.trans("flarum-package-manager.admin.settings.queue_jobs"),help:m.trust(U()(t.translator.trans("flarum-package-manager.admin.settings.queue_jobs_help",{basic_impl_link:"https://discuss.flarum.org/d/28151-database-queue-the-simplest-queue-even-for-shared-hosting",adv_impl_link:"https://discuss.flarum.org/d/21873-redis-sessions-cache-queues",php_version:"<strong>"+t.data.phpVersion+"</strong>",folder_perms_link:"https://docs.flarum.org/install#folder-ownership"}))),default:!1,type:"boolean",disabled:t.data["flarum-package-manager.using_sync_queue"]}).registerPage(ea),(0,a.extend)(i().prototype,"topItems",(function(a){var e=this;"flarum-package-manager"===this.extension.id||p()(this.extension.id)||a.add("remove",m(l(),{className:"Button Button--danger",icon:"fas fa-times",onclick:function(){t.modal.show(c()),t.request({url:t.forum.attribute("apiUrl")+"/package-manager/extensions/"+e.extension.id,method:"DELETE"}).then((function(a){null!=a&&a.processing?G():(t.alerts.show({type:"success"},t.translator.trans("flarum-package-manager.admin.extensions.successful_remove")),window.location=t.forum.attribute("adminUrl"))})).finally((function(){t.modal.close()}))}},"Remove"))}))}))})(),module.exports=n})();
//# sourceMappingURL=admin.js.map