From a22e48e786ab5d2a4b5411df757885234dd0a77b Mon Sep 17 00:00:00 2001 From: gSpot Date: Sun, 20 Feb 2022 18:39:11 +0300 Subject: [PATCH] Minor fixes --- .../resources/view/internet-detector.js | 170 +++++++++--------- .../view/status/include/00_internet.js | 13 +- 2 files changed, 97 insertions(+), 86 deletions(-) diff --git a/luci-app-internet-detector/htdocs/luci-static/resources/view/internet-detector.js b/luci-app-internet-detector/htdocs/luci-static/resources/view/internet-detector.js index cbc1356..9302336 100644 --- a/luci-app-internet-detector/htdocs/luci-static/resources/view/internet-detector.js +++ b/luci-app-internet-detector/htdocs/luci-static/resources/view/internet-detector.js @@ -89,7 +89,7 @@ return view.extend({ initStatus : null, inetStatus : null, inetStatusLabel : E('span', { 'class': 'label' }), - inetStatusSpinner : E('span', { 'class': 'spinning', 'style': 'margin-top:1em' }, ' '), + inetStatusSpinner : E('span', { 'style': 'margin-top:1em' }, ' '), serviceStatusLabel : E('em'), initButton : null, uiPollCounter : 0, @@ -140,6 +140,90 @@ return view.extend({ }); }, + setInetStatusSpinner: function() { + this.inetStatusSpinner.className = 'spinning'; + }, + + unsetInetStatusSpinner: function() { + this.inetStatusSpinner.className = ''; + }, + + setInternetStatus: function() { + if(this.inetStatus === 'up') { + this.inetStatusLabel.style.background = '#46a546'; + this.inetStatusLabel.textContent = _('Connected'); + this.inetStatusLabel.style.color = '#ffffff'; + this.unsetInetStatusSpinner(); + } + else if(this.inetStatus === 'down') { + this.inetStatusLabel.textContent = _('Disconnected'); + this.inetStatusLabel.style.background = '#ff4953'; + this.inetStatusLabel.style.color = '#ffffff'; + this.unsetInetStatusSpinner(); + } + else { + this.inetStatusLabel.textContent = _('Undefined'); + this.inetStatusLabel.style.background = '#9b9b9b'; + this.inetStatusLabel.style.color = '#ffffff'; + + if(this.currentAppMode !== '0' && this.appStatus !== 'stoped') { + this.setInetStatusSpinner(); + }; + }; + + if(this.appStatus === 'running') { + this.serviceStatusLabel.textContent = _('Running'); + } else { + this.serviceStatusLabel.textContent = _('Stopped'); + }; + }, + + servicePoll: function() { + return Promise.all([ + fs.exec(this.execPath, [ 'status' ]), + fs.exec(this.execPath, [ 'inet-status' ]), + ]).then(stat => { + let curAppStatus = (stat[0].code === 0) ? stat[0].stdout.trim() : null; + let curInetStatus = (stat[1].code === 0) ? stat[1].stdout.trim() : null; + if(this.inetStatus === curInetStatus && this.appStatus === curAppStatus) { + return; + }; + this.appStatus = curAppStatus; + this.inetStatus = curInetStatus; + this.setInternetStatus(); + }).catch(e => { + this.appStatus = 'stoped'; + this.inetStatus = null; + }); + }, + + uiPoll: function() { + let curInetStatus = null; + this.uiPollCounter = ++this.uiPollCounter; + + if((this.uiPollState === 0 && this.uiPollCounter % this.uiCheckIntervalUp) || + (this.uiPollState === 1 && this.uiPollCounter % this.uiCheckIntervalDown)) { + return; + }; + + this.uiPollCounter = 0; + + return fs.exec(this.execPath, [ 'inet-status' ]).then(res => { + this.uiPollState = (res.code === 0 && res.stdout.trim() === 'up') ? 0 : 1; + + if(this.uiPollState === 0) { + curInetStatus = 'up'; + } else { + curInetStatus = 'down'; + }; + + if(this.inetStatus !== curInetStatus) { + this.inetStatus = (this.currentAppMode === '0') ? null : curInetStatus; + this.setInternetStatus(); + }; + }); + }, + serviceRestart: function(ev) { poll.stop(); return this.handleServiceAction('restart').then(() => { @@ -184,7 +268,7 @@ return view.extend({ }, renderWidget: function(section_id, option_index, cfgvalue) { - this.ctx.setInternetStatus(true); + this.ctx.setInternetStatus(); return E([ E('label', { 'class': 'cbi-value-title' }, @@ -192,14 +276,14 @@ return view.extend({ ), E('div', { 'class': 'cbi-value-field' }, [ this.ctx.inetStatusLabel, - (!this.ctx.inetStatus) ? this.ctx.inetStatusSpinner : '', + this.ctx.inetStatusSpinner ]), ]) }, }), CBIBlockServiceStatus: form.Value.extend({ - __name__ : 'CBI.BlockServiceStatuse', + __name__ : 'CBI.BlockServiceStatus', __init__ : function(map, section, ctx) { this.map = map; @@ -365,80 +449,6 @@ return view.extend({ }, }), - setInternetStatus: function(initial=false) { - if(this.inetStatus === 'up') { - this.inetStatusLabel.style.background = '#46a546'; - this.inetStatusLabel.textContent = _('Connected'); - this.inetStatusLabel.style.color = '#ffffff'; - } - else if(this.inetStatus === 'down') { - this.inetStatusLabel.textContent = _('Disconnected'); - this.inetStatusLabel.style.background = '#ff4953'; - this.inetStatusLabel.style.color = '#ffffff'; - } - else { - this.inetStatusLabel.textContent = _('Undefined'); - this.inetStatusLabel.style.background = '#9b9b9b'; - this.inetStatusLabel.style.color = '#ffffff'; - }; - - if(!initial && this.inetStatusSpinner) { - this.inetStatusSpinner.remove(); - }; - - if(this.appStatus === 'running') { - this.serviceStatusLabel.textContent = _('Running'); - } else { - this.serviceStatusLabel.textContent = _('Stopped'); - }; - }, - - servicePoll: function() { - return Promise.all([ - fs.exec(this.execPath, [ 'status' ]), - fs.exec(this.execPath, [ 'inet-status' ]), - ]).then(stat => { - let curAppStatus = (stat[0].code === 0) ? stat[0].stdout.trim() : null; - let curInetStatus = (stat[1].code === 0) ? stat[1].stdout.trim() : null; - if(this.inetStatus === curInetStatus && this.appStatus === curAppStatus) { - return; - }; - this.appStatus = curAppStatus; - this.inetStatus = curInetStatus; - this.setInternetStatus(); - }).catch(e => { - this.appStatus = 'stoped'; - this.inetStatus = null; - }); - }, - - uiPoll: function() { - let curInetStatus = null; - this.uiPollCounter = ++this.uiPollCounter; - - if((this.uiPollState === 0 && this.uiPollCounter % this.uiCheckIntervalUp) || - (this.uiPollState === 1 && this.uiPollCounter % this.uiCheckIntervalDown)) { - return; - }; - - this.uiPollCounter = 0; - - return fs.exec(this.execPath, [ 'inet-status' ]).then(res => { - this.uiPollState = (res.code === 0 && res.stdout.trim() === 'up') ? 0 : 1; - - if(this.uiPollState === 0) { - curInetStatus = 'up'; - } else { - curInetStatus = 'down'; - }; - - if(this.inetStatus !== curInetStatus) { - this.inetStatus = (this.currentAppMode === '0') ? null : curInetStatus; - this.setInternetStatus(); - }; - }); - }, - load: function() { return Promise.all([ fs.exec(this.execPath, [ 'status' ]), @@ -477,8 +487,8 @@ return view.extend({ /* Service widget */ - s = m.section(form.NamedSection, 'config', 'main'); - o = s.option(this.CBIBlockInetStatus, this); + s = m.section(form.NamedSection, 'config', 'main'); + o = s.option(this.CBIBlockInetStatus, this); if(this.currentAppMode === '2') { o = s.option(this.CBIBlockServiceStatus, this); diff --git a/luci-app-internet-detector/htdocs/luci-static/resources/view/status/include/00_internet.js b/luci-app-internet-detector/htdocs/luci-static/resources/view/status/include/00_internet.js index d0569f9..1c7251c 100644 --- a/luci-app-internet-detector/htdocs/luci-static/resources/view/status/include/00_internet.js +++ b/luci-app-internet-detector/htdocs/luci-static/resources/view/status/include/00_internet.js @@ -37,6 +37,7 @@ return baseclass.extend({ return; }; + window.internetDetectorCounter = 0; return L.resolveDefault(fs.exec(this.execPath, [ 'inet-status' ]), null); } else { @@ -65,14 +66,14 @@ return baseclass.extend({ let internetStatus = E('span', { 'class': 'label' }); if(window.internetDetectorState === 0) { - internetStatus.textContent = _('Connected'); - internetStatus.style.background = '#46a546'; - internetStatus.style.color = '#ffffff'; + internetStatus.textContent = _('Connected'); + internetStatus.style.background = '#46a546'; + internetStatus.style.color = '#ffffff'; } else if(window.internetDetectorState === 1) { - internetStatus.textContent = _('Disconnected'); - internetStatus.style.background = '#ff4953'; - internetStatus.style.color = '#ffffff'; + internetStatus.textContent = _('Disconnected'); + internetStatus.style.background = '#ff4953'; + internetStatus.style.color = '#ffffff'; } else { internetStatus.textContent = _('Undefined');