From 11fd5525f32ed3f1dec2708b529de521679c756e Mon Sep 17 00:00:00 2001 From: Robert Lu Date: Sun, 17 Sep 2023 13:10:00 -0400 Subject: [PATCH] add start,stop btn --- .../luci-static/resources/view/v2ray/main.js | 98 +++++++++---------- 1 file changed, 49 insertions(+), 49 deletions(-) diff --git a/htdocs/luci-static/resources/view/v2ray/main.js b/htdocs/luci-static/resources/view/v2ray/main.js index b941348..42be14d 100644 --- a/htdocs/luci-static/resources/view/v2ray/main.js +++ b/htdocs/luci-static/resources/view/v2ray/main.js @@ -17,38 +17,13 @@ // "require view"; "require view/v2ray/include/custom as custom"; -var CBILocalTime = form.DummyValue.extend({ - renderWidget: function(section_id, option_id, cfgvalue) { - return E([], [ - E('span', { 'class': 'control-group' }, [ - E('button', { - 'class': 'cbi-button cbi-button-apply', - 'click': ui.createHandlerFn(this, function() { - return callSetLocaltime(Math.floor(Date.now() / 1000)); - }), - 'disabled': (this.readonly != null) ? this.readonly : this.map.readonly - }, _('Sync with browser')), - ' ', - this.ntpd_support ? E('button', { - 'class': 'cbi-button cbi-button-apply', - 'click': ui.createHandlerFn(this, function() { - return callInitAction('sysntpd', 'restart'); - }), - 'disabled': (this.readonly != null) ? this.readonly : this.map.readonly - }, _('Sync with NTP-Server')) : '' - ]) - ]); - }, -}); - -// @ts-ignore -return L.view.extend({ - handleServiceReload: function (ev) { +var StartControlGroup = form.DummyValue.extend({ + handleServiceReload: function () { return fs .exec("/etc/init.d/luci_v2ray", ["reload"]) .then( L.bind( - function (btn, res) { + function (res) { if (res.code !== 0) { ui.addNotification(null, [ E( @@ -60,20 +35,19 @@ return L.view.extend({ L.raise("Error", "Reload failed"); } }, - this, - ev.target + this ) ) .catch(function (e) { ui.addNotification(null, E("p", e.message)); }); }, - handleServiceStop: function (ev) { + handleServiceStop: function () { return fs .exec("/etc/init.d/luci_v2ray", ["stop"]) .then( L.bind( - function (btn, res) { + function (res) { if (res.code !== 0) { ui.addNotification(null, [ E( @@ -85,20 +59,19 @@ return L.view.extend({ L.raise("Error", "Stop failed"); } }, - this, - ev.target + this ) ) .catch(function (e) { ui.addNotification(null, E("p", e.message)); }); }, - handleServiceStart: function (ev) { + handleServiceStart: function () { return fs .exec("/etc/init.d/luci_v2ray", ["start"]) .then( L.bind( - function (btn, res) { + function (res) { if (res.code !== 0) { ui.addNotification(null, [ E( @@ -110,14 +83,46 @@ return L.view.extend({ L.raise("Error", "Start failed"); } }, - this, - ev.target + this ) ) .catch(function (e) { ui.addNotification(null, E("p", e.message)); }); }, + renderWidget: function (section_id, option_id, cfgvalue) { + return E([], [ + E('span', { 'class': 'control-group' }, [ + E('button', { + 'class': 'cbi-button cbi-button-apply', + 'click': ui.createHandlerFn(this, function () { + return this.handleServiceReload(); + }), + 'disabled': (this.readonly != null) ? this.readonly : this.map.readonly + }, _('Reload')), + ' ', + E('button', { + 'class': 'cbi-button cbi-button-apply', + 'click': ui.createHandlerFn(this, function () { + return this.handleServiceStop(); + }), + 'disabled': (this.readonly != null) ? this.readonly : this.map.readonly + }, _('Stop')), + ' ', + E('button', { + 'class': 'cbi-button cbi-button-apply', + 'click': ui.createHandlerFn(this, function () { + return this.handleServiceStart(); + }), + 'disabled': (this.readonly != null) ? this.readonly : this.map.readonly + }, _('Start')) + ]) + ]); + }, +}); + +// @ts-ignore +return L.view.extend({ load: function() { return Promise.all([ v2ray.getSections("inbound"), v2ray.getSections("outbound") ]); }, @@ -137,20 +142,15 @@ return L.view.extend({ s.addremove = false; s.anonymous = true; - var o; + let o; var a = void 0 === e ? [] : e, r = a[0], t = void 0 === r ? [] : r, n = a[1], i = void 0 === n ? [] : n; - o = s.option( - form.Button, - "_reload", - _("Reload Service"), - _("This will restart service when config file changes.") - ); - o.inputstyle = "action reload"; - o.inputtitle = _("Reload"); - o.onclick = L.bind(this.handleServiceReload, this); + s.option(custom.RunningStatus, "_status"); + + o = s.option(form.Flag, "enabled", _("Enabled")); + o.rmempty = false; - o = s.option(CBILocalTime, '_systime', _('Local Time')); + o = s.option(StartControlGroup, '_reload', _("Reload Service")); (o = s.option(form.Value, "v2ray_file", _("V2Ray file"), _("Set the V2Ray executable file path."))).datatype = "file", o.placeholder = "/usr/bin/v2ray", o.rmempty = !1, (o = s.option(form.Value, "asset_location", _("V2Ray asset location"), _("Directory where geoip.dat and geosite.dat files are, default: same directory as V2Ray file."))).datatype = "directory",