From cb24b654da4f7d76c2cec3a9d992d6ba8b71036f Mon Sep 17 00:00:00 2001 From: trashbo4t Date: Mon, 29 Jul 2019 13:48:52 -0400 Subject: [PATCH] Status | Added defaulting "Auto Refresh" option for status module (#61) * auto refreshing option for status * destroying refresh --- Status/js/module.js | 121 ++++++++++++++++++++++++++++++++++++-------- Status/module.html | 43 ++++++++++++---- Status/module.info | 2 +- 3 files changed, 135 insertions(+), 31 deletions(-) diff --git a/Status/js/module.js b/Status/js/module.js index 1ff6b83..94e0249 100644 --- a/Status/js/module.js +++ b/Status/js/module.js @@ -2,6 +2,10 @@ registerController('Status_Controller', ['$api', '$scope', '$rootScope', '$inter $scope.title = "Loading..."; $scope.version = "Loading..."; + $scope.autoRefresh = true; + $rootScope.autoRefresh = true; + $rootScope.version = "Loading..."; + $scope.refreshInfo = (function() { $api.request({ module: 'Status', @@ -14,9 +18,13 @@ registerController('Status_Controller', ['$api', '$scope', '$rootScope', '$inter $scope.refreshInfo(); + $scope.toggleAutoRefresh = function() { + $rootScope.autoRefresh = $scope.autoRefresh; + }; + }]); -registerController('Status_SystemController', ['$api', '$scope', '$rootScope', '$filter', function($api, $scope, $rootScope, $filter) { +registerController('Status_SystemController', ['$api', '$scope', '$rootScope', '$interval', '$filter', function($api, $scope, $rootScope, $interval, $filter) { $scope.info = { machine: "Loading...", currentTime: "Loading...", @@ -34,10 +42,19 @@ registerController('Status_SystemController', ['$api', '$scope', '$rootScope', ' }; $scope.getInfo(); + $scope.statusRefreshInterval = $interval(function() { + if ($rootScope.autoRefresh) + { + $scope.getInfo(); + } + }, 1000); + $scope.$on('$destroy', function() { + $interval.cancel($scope.statusRefreshInterval); + }); }]); -registerController('Status_CPUController', ['$api', '$scope', '$rootScope', '$filter', '$sce', function($api, $scope, $rootScope, $filter, $sce) { +registerController('Status_CPUController', ['$api', '$scope', '$rootScope', '$interval', '$filter', '$sce', function($api, $scope, $rootScope, $interval, $filter, $sce) { $scope.info = { cpuModel: "Loading...", bogoMIPS: "Loading...", @@ -55,7 +72,7 @@ registerController('Status_CPUController', ['$api', '$scope', '$rootScope', '$fi }); }; - $scope.getSrc = (function() { + $scope.getSrc = (function() { $scope.src = $sce.trustAsResourceUrl('/modules/Status/svg/graph_cpu.svg'); }); @@ -64,11 +81,21 @@ registerController('Status_CPUController', ['$api', '$scope', '$rootScope', '$fi }); $scope.setSrc(); + $scope.getInfo(); + $scope.statusRefreshInterval = $interval(function() { + if ($rootScope.autoRefresh) + { + $scope.getInfo(); + } + }, 2000); + $scope.$on('$destroy', function() { + $interval.cancel($scope.statusRefreshInterval); + }); }]); -registerController('Status_DHCPController', ['$api', '$scope', '$rootScope', '$filter', function($api, $scope, $rootScope, $filter) { +registerController('Status_DHCPController', ['$api', '$scope', '$rootScope', '$interval', '$filter', function($api, $scope, $rootScope, $interval, $filter) { $scope.info = { clientsList: [] }; @@ -76,11 +103,9 @@ registerController('Status_DHCPController', ['$api', '$scope', '$rootScope', '$f $scope.title = "Loading..."; $scope.output = "Loading..."; - $scope.loading = false; + $scope.loading = true; $scope.getInfo = function() { - $scope.loading = true; - $api.request({ module: 'Status', action: 'getDHCP' @@ -119,10 +144,20 @@ registerController('Status_DHCPController', ['$api', '$scope', '$rootScope', '$f }; $scope.getInfo(); + $scope.statusRefreshInterval = $interval(function() { + if ($rootScope.autoRefresh) + { + $scope.getInfo(); + } + }, 5000); + + $scope.$on('$destroy', function() { + $interval.cancel($scope.statusRefreshInterval); + }); }]); -registerController('Status_MemoryController', ['$api', '$scope', '$rootScope', '$filter', function($api, $scope, $rootScope, $filter) { +registerController('Status_MemoryController', ['$api', '$scope', '$rootScope', '$interval', '$filter', function($api, $scope, $rootScope, $interval, $filter) { $scope.info = { memoryTotal: "Loading...", memoryFree: "Loading...", @@ -141,20 +176,28 @@ registerController('Status_MemoryController', ['$api', '$scope', '$rootScope', ' }; $scope.getInfo(); + $scope.statusRefreshInterval = $interval(function() { + if ($rootScope.autoRefresh) + { + $scope.getInfo(); + } + }, 2000); + + $scope.$on('$destroy', function() { + $interval.cancel($scope.statusRefreshInterval); + }); }]); -registerController('Status_WiFiController', ['$api', '$scope', '$rootScope', '$filter', function($api, $scope, $rootScope, $filter) { +registerController('Status_WiFiController', ['$api', '$scope', '$rootScope', '$interval', '$filter', function($api, $scope, $rootScope, $interval, $filter) { $scope.info = { wifiClientsList: [] }; $scope.title = "Loading..."; $scope.output = "Loading..."; - $scope.loading = false; + $scope.loading = true; $scope.getInfo = function() { - $scope.loading = true; - $api.request({ module: 'Status', action: 'getWiFi' @@ -193,10 +236,20 @@ registerController('Status_WiFiController', ['$api', '$scope', '$rootScope', '$f }; $scope.getInfo(); + $scope.statusRefreshInterval = $interval(function() { + if ($rootScope.autoRefresh) + { + $scope.getInfo(); + } + }, 5000); + + $scope.$on('$destroy', function() { + $interval.cancel($scope.statusRefreshInterval); + }); }]); -registerController('Status_SwapController', ['$api', '$scope', '$rootScope', '$filter', function($api, $scope, $rootScope, $filter) { +registerController('Status_SwapController', ['$api', '$scope', '$rootScope', '$interval', '$filter', function($api, $scope, $rootScope, $interval, $filter) { $scope.info = { swapAvailable: false, swapTotal: "Loading...", @@ -216,19 +269,27 @@ registerController('Status_SwapController', ['$api', '$scope', '$rootScope', '$f }; $scope.getInfo(); + $scope.statusRefreshInterval = $interval(function() { + if ($rootScope.autoRefresh) + { + $scope.getInfo(); + } + }, 2000); + + $scope.$on('$destroy', function() { + $interval.cancel($scope.statusRefreshInterval); + }); }]); -registerController('Status_StorageController', ['$api', '$scope', '$rootScope', '$filter', function($api, $scope, $rootScope, $filter) { +registerController('Status_StorageController', ['$api', '$scope', '$rootScope', '$interval', '$filter', function($api, $scope, $rootScope, $interval, $filter) { $scope.info = { storagesList: [] }; - $scope.loading = false; + $scope.loading = true; $scope.getInfo = function() { - $scope.loading = true; - $api.request({ module: 'Status', action: 'getStorage' @@ -239,10 +300,20 @@ registerController('Status_StorageController', ['$api', '$scope', '$rootScope', }; $scope.getInfo(); + $scope.statusRefreshInterval = $interval(function() { + if ($rootScope.autoRefresh) + { + $scope.getInfo(); + } + }, 10000); + + $scope.$on('$destroy', function() { + $interval.cancel($scope.statusRefreshInterval); + }); }]); -registerController('Status_InterfaceController', ['$api', '$scope', '$rootScope', '$filter', '$sce', function($api, $scope, $rootScope, $filter, $sce) { +registerController('Status_InterfaceController', ['$api', '$scope', '$rootScope', '$interval', '$filter', '$sce', function($api, $scope, $rootScope, $interval, $filter, $sce) { $scope.info = { wanIpAddress: "Loading...", wanGateway: "Loading...", @@ -253,7 +324,7 @@ registerController('Status_InterfaceController', ['$api', '$scope', '$rootScope' $scope.title = "Loading..."; $scope.output = "Loading..."; - $scope.loading = false; + $scope.loading = true; $scope.getMACInfo = function(param) { $scope.title = "Loading..."; @@ -284,8 +355,6 @@ registerController('Status_InterfaceController', ['$api', '$scope', '$rootScope' }; $scope.getInfo = function() { - $scope.loading = true; - $api.request({ module: 'Status', action: 'getInterfaces' @@ -306,5 +375,15 @@ registerController('Status_InterfaceController', ['$api', '$scope', '$rootScope' $scope.setSrc(); $scope.getInfo(); + $scope.statusRefreshInterval = $interval(function() { + if ($rootScope.autoRefresh) + { + $scope.getInfo(); + } + }, 10000); + + $scope.$on('$destroy', function() { + $interval.cancel($scope.statusRefreshInterval); + }); }]); diff --git a/Status/module.html b/Status/module.html index 8fbca6c..dc18501 100644 --- a/Status/module.html +++ b/Status/module.html @@ -1,11 +1,36 @@ -

{{title}}

{{version}}
+
+
+

{{title}}

+ {{version}} +
+
+ + + + + + + + + +
+ Auto Refresh + + +
+
+

System

- +
@@ -42,7 +67,7 @@

CPU

- +
@@ -106,7 +131,7 @@

Memory

- +
@@ -148,7 +173,7 @@

Swap

- +
@@ -200,7 +225,7 @@

WiFi Clients {{info.wifiClientsList.length}}

- +
@@ -246,7 +271,7 @@

DHCP Clients {{info.clientsList.length}}

- +
@@ -295,7 +320,7 @@

Storage

- +
@@ -325,7 +350,7 @@

Interfaces

- +
diff --git a/Status/module.info b/Status/module.info index 870f531..f2ea1db 100644 --- a/Status/module.info +++ b/Status/module.info @@ -6,5 +6,5 @@ "tetra" ], "title": "Status", - "version": "1.3" + "version": "1.4" }