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

[skip ci]
2023-04-16 11:48:33 +00:00

2 lines
35 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,c=2592e6,l=/^(-|\+)?P(?:([-+]?[0-9,.]*)Y)?(?:([-+]?[0-9,.]*)M)?(?:([-+]?[0-9,.]*)W)?(?:([-+]?[0-9,.]*)D)?(?:T(?:([-+]?[0-9,.]*)H)?(?:([-+]?[0-9,.]*)M)?(?:([-+]?[0-9,.]*)S)?)?$/,u={years:o,months:c,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"},g=function(a){return a<0},f=function(a){return g(a)?Math.ceil(a):Math.floor(a)},h=function(a){return Math.abs(a)},k=function(a,t){return a?g(a)?{negative:!0,format:""+h(a)+t}:{negative:!1,format:""+a+t}:{negative:!1,format:""}},v=function(){function g(a,t,e){var n=this;if(this.$d={},this.$l=e,void 0===a&&(this.$ms=0,this.parseFromMilliseconds()),t)return d(a*u[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(l);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=g.prototype;return h.calMilliseconds=function(){var a=this;this.$ms=Object.keys(this.$d).reduce((function(t,e){return t+(a.$d[e]||0)*u[e]}),0)},h.parseFromMilliseconds=function(){var a=this.$ms;this.$d.years=f(a/o),a%=o,this.$d.months=f(a/c),a%=c,this.$d.days=f(a/s),a%=s,this.$d.hours=f(a/r),a%=r,this.$d.minutes=f(a/n),a%=n,this.$d.seconds=f(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"),c=a.negative||t.negative||n.negative||r.negative||s.negative||o.negative,l=r.format||s.format||o.format?"T":"",u=(c?"-":"")+"P"+a.format+t.format+n.format+l+r.format+s.format+o.format;return"P"===u||"-P"===u?"P0D":u},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/u[p(a)]},h.get=function(a){var t=this.$ms,e=p(a);return"milliseconds"===e?t%=1e3:t="weeks"===e?f(t/u[e]):this.$d[e],0===t?0:t},h.add=function(a,t,e){var n;return n=t?a*u[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")},g}();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 c=e.n(o);const l=flarum.core.compat["admin/components/LoadingModal"];var u=e.n(l);const d=flarum.core.compat["admin/utils/isExtensionEnabled"];var p=e.n(d);const g=flarum.core.compat["common/components/Alert"];var f=e.n(g);function h(a,t){return h=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(a,t){return a.__proto__=t,a},h(a,t)}function k(a,t){a.prototype=Object.create(t.prototype),a.prototype.constructor=a,h(a,t)}function v(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 y=flarum.core.compat["common/Component"];var b=e.n(y);const x=flarum.core.compat["common/components/LoadingIndicator"];var _=e.n(x);const M=flarum.core.compat["common/components/Tooltip"];var w=e.n(M);const N=flarum.core.compat["common/helpers/icon"];var P=e.n(N);const U=flarum.core.compat["common/utils/ItemList"];var j=e.n(U);const $=flarum.core.compat["common/utils/extractText"];var q=e.n($);const T=flarum.core.compat["common/utils/classList"];var O=e.n(T),S=["className","type"],B=function(a){function t(){return a.apply(this,arguments)||this}return k(t,a),t.prototype.view=function(a){var t=this.attrs,e=t.className,n=(t.type,v(t,S));return m("span",Object.assign({className:O()(["Label","Label--"+this.attrs.type,e])},n),a.children)},t}(b());const L=flarum.core.compat["common/components/Modal"];var E=e.n(L),C=function(a){function t(){return a.apply(this,arguments)||this}k(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}(E()),A=e(3),F=e.n(A),D=function(a){function t(){return a.apply(this,arguments)||this}return k(t,a),t.prototype.view=function(){var a=this;return m("nav",{class:"Pagination UserListPage-gridPagination"},m(c(),{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(c(),{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}(b()),I=["label","content"],Y=function(a){function t(){return a.apply(this,arguments)||this}k(t,a);var e=t.prototype;return e.oninit=function(t){a.prototype.oninit.call(this,t),r().packageManager.queue.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(c(),{className:"Button Button--icon",icon:"fas fa-sync-alt",onclick:function(){return r().packageManager.queue.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(j());return t.add("operation",{label:q()(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:q()(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?P()(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:q()(r().translator.trans("flarum-package-manager.admin.sections.queue.columns.status")),content:function(a){return m(B,{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:q()(r().translator.trans("flarum-package-manager.admin.sections.queue.columns.elapsed_time")),content:function(a){return a.startedAt()?m(w(),{text:dayjs(a.startedAt()).format("LL LTS")+" "+dayjs(a.finishedAt()).format("LL LTS")},m("span",null,function(a,t){dayjs.extend(F());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:q()(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:q()(r().translator.trans("flarum-package-manager.admin.sections.queue.columns.details")),content:function(a){return m(c(),{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(C,{task:a})}})},className:"Table-controls"},55),t},e.queueTable=function(){var a=r().packageManager.queue.getItems();if(!a)return m(_(),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=v(t,I);return m("td",Object.assign({key:e},r),n(a))})))})))),m(D,{list:r().packageManager.queue}))},e.operationIcon=function(a){return P()({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}(b());const H=flarum.core.compat["common/utils/Stream"];var W=e.n(H);function R(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().packageManager.queue.load(),setTimeout((function(){var a;null==(a=document.getElementById("PackageManager-queueSection"))||a.scrollIntoView({block:"nearest"})}),200)}window.jumpToQueue=G;var 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).packageName=void 0,t}k(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(c(),{className:"Button",icon:"fas fa-download",onclick:this.onsubmit.bind(this),loading:r().packageManager.control.isLoading("extension-install"),disabled:r().packageManager.control.isLoadingOtherThan("extension-install")},r().translator.trans("flarum-package-manager.admin.extensions.proceed"))))},e.data=function(){return{package:this.packageName()}},e.onsubmit=function(){r().packageManager.control.setLoading("extension-install"),r().modal.show(u()),r().request({method:"POST",url:r().forum.attribute("apiUrl")+"/package-manager/extensions",body:{data:this.data()}}).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()}})).catch(R).finally((function(){r().packageManager.control.setLoading(null),r().modal.close(),m.redraw()}))},t}(b());const Z=flarum.core.compat["common/helpers/humanTime"];var z=e.n(Z),J=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}k(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(_(),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}}}).then((function(t){a.loading=!1,a.whyNot=t.data.reason,m.redraw()})).catch(R)},t}(E()),K=function(a){function t(){return a.apply(this,arguments)||this}k(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,l=e.isCore,u=e.isDanger,d=null!=(t=s["latest-minor"])?t:s["latest-major"]&&!l?s["latest-major"]:null;return m("div",{className:O()({"PackageManager-extension":!0,"PackageManager-extension--core":l,"PackageManager-extension--danger":u})},m("div",{className:"PackageManager-extension-icon ExtensionIcon",style:n.icon},n.icon?P()(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(s.version)),d?m(B,{className:"PackageManager-extension-version-latest",type:s["latest-minor"]?"success":"warning"},this.version(d)):null)),m("div",{className:"PackageManager-extension-controls"},i?m(w(),{text:r().translator.trans("flarum-package-manager.admin.extensions.update")},m(c(),{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(w(),{text:r().translator.trans("flarum-package-manager.admin.extensions.check_why_it_failed_updating")},m(c(),{icon:"fas fa-exclamation-circle",className:"Button Button--icon Button--flat Button--danger",onclick:function(){return r().modal.show(J,{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}(b()),Q=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).updateState=void 0,t}k(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(){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(w(),{text:r().translator.trans("flarum-package-manager.admin.major_updater.dry_run_help")},m(c(),{className:"Button",icon:"fas fa-vial",onclick:this.update.bind(this,!0),disabled:r().packageManager.control.isLoadingOtherThan("major-update-dry-run")},r().translator.trans("flarum-package-manager.admin.major_updater.dry_run"))),m(c(),{className:"Button Button--danger",icon:"fas fa-play",onclick:this.update.bind(this,!1),disabled:r().packageManager.control.isLoadingOtherThan("major-update")},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(f(),{type:"error",className:"PackageManager-majorUpdate-failure",dismissible:!1,controls:[m(c(),{className:"Button Button--text PackageManager-majorUpdate-failure-details",icon:"fas fa-question-circle",onclick:function(){return r().modal.show(J,{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;r().packageManager.control.setLoading(a?"major-update-dry-run":"major-update"),r().modal.show(u()),r().request({method:"POST",url:r().forum.attribute("apiUrl")+"/package-manager/major-update",body:{data:{dryRun:a}}}).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(R).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(){r().packageManager.control.setLoading(null),m.redraw()}))},t}(b());function X(){return X=Object.assign?Object.assign.bind():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},X.apply(this,arguments)}function aa(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)}}function ta(a,t,e){return t&&aa(a.prototype,t),e&&aa(a,e),Object.defineProperty(a,"prototype",{writable:!1}),a}function ea(a){var t=typeof a;return"function"===t||"object"===t&&!!a}var na=function(a,t){this.content=void 0,this.priority=void 0,this.content=a,this.priority=t},ra=function(){function a(){this._items={}}var t=a.prototype;return t.isEmpty=function(){return 0===Object.keys(this._items).length},t.has=function(a){return Object.keys(this._items).includes(a)},t.get=function(a){return this._items[a].content},t.getPriority=function(a){return this._items[a].priority},t.add=function(a,t,e){return void 0===e&&(e=0),this._items[a]=new na(t,e),this},t.replace=function(a,t,e){return void 0===t&&(t=null),void 0===e&&(e=null),this.has(a)?(null!==t&&(this._items[a].content=t),null!==e&&(this._items[a].priority=e),this):this},t.setContent=function(a,t){if(!this.has(a))throw new Error("[ItemList] Cannot set content of Item. Key `"+a+"` is not present.");return this.replace(a,t)},t.setPriority=function(a,t){if(!this.has(a))throw new Error("[ItemList] Cannot set priority of Item. Key `"+a+"` is not present.");return this._items[a].priority=t,this},t.remove=function(a){return delete this._items[a],this},t.merge=function(a){var t=this;return Object.keys(a._items).forEach((function(e){var n=a._items[e];n instanceof na&&(t._items[e]=n)})),this},t.toArray=function(a){var t=this;return void 0===a&&(a=!1),Object.keys(this._items).map((function(e,n){var r=t._items[e];return!a||ea(r.content)?X({},r,{content:t.createItemContentProxy(ea(r.content)?r.content:Object(r.content),e)}):X({},r)})).sort((function(a,t){return t.priority-a.priority})).map((function(a){return a.content}))},t.toObject=function(){var a=this;return Object.keys(this._items).reduce((function(t,e){var n={content:a.get(e),itemName:e,priority:a.getPriority(e)};return t[e]=n,t}),{})},t.createItemContentProxy=function(a,t){return new Proxy(a,{get:function(a,e,n){return"itemName"===e?t:Reflect.get(a,e,n)},set:function(a,e,n,r){if(null!==t&&"itemName"===e)throw new Error("`itemName` property is read-only");return Reflect.set(a,e,n,r)}})},ta(a,[{key:"items",get:function(){return new Proxy(this._items,{set:function(){return console.warn("Modifying `ItemList.items` is not allowed."),!1}})}}]),a}(),sa=function(a){function t(){return a.apply(this,arguments)||this}k(t,a);var e=t.prototype;return e.view=function(){var a=r().packageManager.control.coreUpdate;return[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")),this.lastUpdateCheckView(),m("div",{className:"PackageManager-updaterControls"},this.controlItems().toArray()),this.availableUpdatesView()),a&&a.package["latest-major"]?m(Q,{coreUpdate:a.package,updateState:r().packageManager.control.lastUpdateRun.major}):null]},e.lastUpdateCheckView=function(){var a;return(null==(a=r().packageManager.control.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"},z()(r().packageManager.control.lastUpdateCheck.checkedAt)))||null},e.availableUpdatesView=function(){var a=r().packageManager.control;return r().packageManager.control.isLoading()?m("div",{className:"PackageManager-extensions"},m(_(),null)):a.extensionUpdates.length||a.coreUpdate?m("div",{className:"PackageManager-extensions"},m("div",{className:"PackageManager-extensions-grid"},a.coreUpdate?m(K,{extension:a.coreUpdate.extension,updates:a.coreUpdate.package,isCore:!0,onClickUpdate:function(){return a.updateCoreMinor()},whyNotWarning:a.lastUpdateRun.limitedPackages().includes("flarum/core")}):null,a.extensionUpdates.map((function(t){return m(K,{extension:t,updates:a.packageUpdates[t.id],onClickUpdate:function(){return a.updateExtension(t)},whyNotWarning:a.lastUpdateRun.limitedPackages().includes(t.name)})})))):m("div",{className:"PackageManager-extensions"},m(f(),{type:"success",dismissible:!1},r().translator.trans("flarum-package-manager.admin.updater.up_to_date")))},e.controlItems=function(){var a=new ra;return a.add("updateCheck",m(c(),{className:"Button",icon:"fas fa-sync-alt",onclick:function(){return r().packageManager.control.checkForUpdates()},loading:r().packageManager.control.isLoading("check"),disabled:r().packageManager.control.isLoadingOtherThan("check")},r().translator.trans("flarum-package-manager.admin.updater.check_for_updates")),100),a.add("globalUpdate",m(c(),{className:"Button",icon:"fas fa-play",onclick:function(){return r().packageManager.control.updateGlobally()},loading:r().packageManager.control.isLoading("global-update"),disabled:r().packageManager.control.isLoadingOtherThan("global-update")},r().translator.trans("flarum-package-manager.admin.updater.run_global_update"))),a},t}(b()),ia=function(a){function t(){return a.apply(this,arguments)||this}k(t,a);var e=t.prototype;return e.oninit=function(t){a.prototype.oninit.call(this,t)},e.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(V,null),m(sa,null)):m("div",{className:"Form-group"},m(f(),{type:"warning",dismissible:!1},r().translator.trans("flarum-package-manager.admin.file_permissions")))))},t}(b()),oa=function(a){function t(){return a.apply(this,arguments)||this}return k(t,a),t.prototype.sections=function(t){var e=a.prototype.sections.call(this,t);return e.setPriority("content",10),e.add("control",m(ia,null),8),parseInt(r().data.settings["flarum-package-manager.queue_jobs"])&&e.add("queue",m(Y,null),5),e.setPriority("permissions",0),e},t}(i());const ca=flarum.core.compat["common/Model"];var la=e.n(ca),ua=["B","kB","MB","GB","TB","PB","EB","ZB","YB"],ma=["B","kiB","MiB","GiB","TiB","PiB","EiB","ZiB","YiB"],da=["b","kbit","Mbit","Gbit","Tbit","Pbit","Ebit","Zbit","Ybit"],pa=["b","kibit","Mibit","Gibit","Tibit","Pibit","Eibit","Zibit","Yibit"],ga=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},fa=function(a){function t(){return a.apply(this,arguments)||this}k(t,a);var e=t.prototype;return e.status=function(){return la().attribute("status").call(this)},e.operation=function(){return la().attribute("operation").call(this)},e.command=function(){return la().attribute("command").call(this)},e.package=function(){return la().attribute("package").call(this)},e.output=function(){return la().attribute("output").call(this)},e.createdAt=function(){return la().attribute("createdAt",la().transformDate).call(this)},e.startedAt=function(){return la().attribute("startedAt",la().transformDate).call(this)},e.finishedAt=function(){return la().attribute("finishedAt",la().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=X({bits:!1,binary:!1},t)).bits?t.binary?pa:da:t.binary?ma:ua;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=X({maximumFractionDigits:t.maximumFractionDigits},n)),a<1)return s+ga(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+ga(Number(a),t.locale,n)+" "+e[i]}(1024*la().attribute("peakMemoryUsed").call(this))},t}(la()),ha=function(){function a(){this.tasks=null,this.limit=20,this.offset=0,this.total=0}var t=a.prototype;return t.load=function(a){var t,e=this;return this.tasks=null,a=X({page:X({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}(),ka=function(){function a(){this.loading=null,this.packageUpdates={},this.lastUpdateCheck=void 0,this.extensionUpdates=void 0,this.coreUpdate=null,this.lastUpdateCheck=JSON.parse(r().data.settings["flarum-package-manager.last_update_check"]),this.extensionUpdates=this.formatExtensionUpdates(this.lastUpdateCheck),this.coreUpdate=this.formatCoreUpdate(this.lastUpdateCheck)}var t=a.prototype;return t.isLoading=function(a){return void 0===a&&(a=null),a&&this.loading===a||!a&&null!==this.loading},t.isLoadingOtherThan=function(a){return null!==this.loading&&this.loading!==a},t.setLoading=function(a){this.loading=a},t.checkForUpdates=function(){var a=this;this.setLoading("check"),r().request({method:"POST",url:r().forum.attribute("apiUrl")+"/package-manager/check-for-updates"}).then((function(t){t.processing?G():(a.lastUpdateCheck=t,a.extensionUpdates=a.formatExtensionUpdates(t),a.coreUpdate=a.formatCoreUpdate(t),m.redraw())})).catch(R).finally((function(){a.setLoading(null),m.redraw()}))},t.updateCoreMinor=function(){var a=this;confirm(q()(r().translator.trans("flarum-package-manager.admin.minor_update_confirmation.content")))&&(r().modal.show(u()),this.setLoading("minor-update"),r().request({method:"POST",url:r().forum.attribute("apiUrl")+"/package-manager/minor-update"}).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(R).finally((function(){a.setLoading(null),r().modal.close(),m.redraw()})))},t.updateExtension=function(a){var t=this;r().modal.show(u()),this.setLoading("extension-update"),r().request({method:"PATCH",url:r().forum.attribute("apiUrl")+"/package-manager/extensions/"+a.id}).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())})).catch(R).finally((function(){t.setLoading(null),r().modal.close(),m.redraw()}))},t.updateGlobally=function(){var a=this;r().modal.show(u()),this.setLoading("global-update"),r().request({method:"POST",url:r().forum.attribute("apiUrl")+"/package-manager/global-update"}).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())})).catch(R).finally((function(){a.setLoading(null),r().modal.close(),m.redraw()}))},t.formatExtensionUpdates=function(a){var t,e,n=this;return this.packageUpdates={},null==a||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]}))},t.formatCoreUpdate=function(a){var t,e,n=null==a||null==(t=a.updates)||null==(e=t.installed)?void 0:e.filter((function(a){return"flarum/core"===a.name})).pop();return n?{package:n,extension:{id:"flarum-core",name:"flarum/core",version:r().data.settings.version,icon:{backgroundImage:"url("+r().data.resources[0].attributes.baseUrl+"/assets/extensions/flarum-package-manager/flarum.svg"},extra:{"flarum-extension":{title:q()(r().translator.trans("flarum-package-manager.admin.updater.flarum"))}}}}:null},ta(a,[{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}}]),a}(),va=function(){this.queue=new ha,this.control=new ka};r().initializers.add("flarum-package-manager",(function(t){t.store.models["package-manager-tasks"]=fa,t.packageManager=new va,t.extensionData.for("flarum-package-manager").registerSetting((function(){return m("div",{className:"Form-group"},m(f(),{type:"warning",dismissible:!1},t.translator.trans("flarum-package-manager.admin.settings.access_warning")))})).registerSetting({setting:"flarum-package-manager.queue_jobs",label:t.translator.trans("flarum-package-manager.admin.settings.queue_jobs"),help:m.trust(q()(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(oa),(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(c(),{className:"Button Button--danger",icon:"fas fa-times",onclick:function(){t.modal.show(u()),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