diff --git a/app/controllers/element.js b/app/controllers/element.js index 6e5062cd6..aae6baa04 100644 --- a/app/controllers/element.js +++ b/app/controllers/element.js @@ -312,6 +312,78 @@ myAppController.controller('ElementBaseController', function ($scope, $q, $inter }); +/** + * The controller that handles a device chart. + * @class ElementChartController + */ +myAppController.controller('ElementChartController', function ($scope, $sce, dataFactory, $interval) { + $scope.widgetChart = { + find: {}, + alert: {message: false, status: 'is-hidden', icon: false}, + hasURL : false, + intchartUrl : '', + url : {}, + time : 0, + chartOptions: { + // Chart.js options can go here. + //responsive: true + } + }; + + /** + * Reload chart url + */ + $scope.reloadUrl = function () { + dataFactory.getApi('devices', '/' + $scope.dataHolder.devices.find.id, true).then(function (response) { + var device = response.data.data; + + if($scope.widgetChart.time < device.metrics.intchartTime){ + $scope.widgetChart.find = device; + $scope.widgetChart.intchartUrl = device.metrics.intchartUrl + '&' + new Date().getTime(); + $scope.widgetChart.time = device.metrics.intchartTime; + + $scope.widgetChart.url = $sce.trustAsResourceUrl($scope.widgetChart.intchartUrl); + } + }); + }; + + /** + * Load device + */ + $scope.loadDeviceUrl = function () { + $scope.widgetChart.alert = {message: $scope._t('loading'), status: 'alert-warning', icon: 'fa-spinner fa-spin'}; + + dataFactory.getApi('devices', '/' + $scope.dataHolder.devices.find.id, true).then(function (response) { + var device = response.data.data; + if (!device) { + $scope.widgetChart.alert = {message: $scope._t('error_load_data'), status: 'alert-danger', icon: 'fa-exclamation-triangle'}; + return; + } + $scope.widgetChart.find = device; + + if (!device.metrics.intchartUrl){ + $scope.widgetChart.alert = {message: $scope._t('error_load_data'), status: 'alert-danger', icon: 'fa-exclamation-triangle'}; + return; + } + + $scope.widgetChart.hasURL = true; + $scope.widgetChart.intchartUrl = device.metrics.intchartUrl; + $scope.widgetChart.time = device.metrics.intchartTime; + $scope.widgetChart.url = $sce.trustAsResourceUrl($scope.widgetChart.intchartUrl); + + $scope.refreshInterval = $interval($scope.reloadUrl, $scope.cfg.interval); + + $scope.widgetChart.alert = {message: false}; + + }, function (error) { + $scope.widgetChart.alert = {message: $scope._t('error_load_data'), status: 'alert-danger', icon: 'fa-exclamation-triangle'}; + }); + }; + $scope.loadDeviceUrl(); + +}); + + /** * The controller that handles a device history. * @class ElementHistoryController @@ -1203,4 +1275,4 @@ myAppController.controller('ElementIconController', function ($scope, $timeout, console.log(output); } ; -}); \ No newline at end of file +}); diff --git a/dist/app/js/build.js b/dist/app/js/build.js index c4e26e7dd..a8603ee74 100644 --- a/dist/app/js/build.js +++ b/dist/app/js/build.js @@ -11470,7 +11470,7 @@ angular.module('myAppTemplates', []).run(['$templateCache', function($templateCa $templateCache.put('app/views/elements/list.html', - "
img -1\"> img
{{dataHolder.devices.rooms[v.location].title|cutText:true:25}} 

{{v.metrics.title|cutText:true:25}}


" + "
img -1\"> img
{{dataHolder.devices.rooms[v.location].title|cutText:true:25}} 

{{v.metrics.title|cutText:true:25}}


" ); @@ -11527,6 +11527,12 @@ angular.module('myAppTemplates', []).run(['$templateCache', function($templateCa $templateCache.put('app/views/elements/widgets/doorlock.html', "
 
" ); + + + // inserted intchart + $templateCache.put('app/views/elements/widgets/intchartModal.html', + "

{{widgetChart.find.metrics.title}}

" + ); $templateCache.put('app/views/elements/widgets/historyModal.html', @@ -16047,6 +16053,77 @@ myAppController.controller('ElementBaseController', function ($scope, $q, $inter }); +/** + * The controller that handles a device chart. + * @class ElementChartController + */ +myAppController.controller('ElementChartController', function ($scope, $sce, dataFactory, $interval) { + $scope.widgetChart = { + find: {}, + alert: {message: false, status: 'is-hidden', icon: false}, + hasURL : false, + intchartUrl : '', + url : {}, + time : 0, + chartOptions: { + // Chart.js options can go here. + //responsive: true + } + }; + + /** + * Reload chart url + */ + $scope.reloadUrl = function () { + dataFactory.getApi('devices', '/' + $scope.dataHolder.devices.find.id, true).then(function (response) { + var device = response.data.data; + + if($scope.widgetChart.time < device.metrics.intchartTime){ + $scope.widgetChart.find = device; + $scope.widgetChart.intchartUrl = device.metrics.intchartUrl + '&' + new Date().getTime(); + $scope.widgetChart.time = device.metrics.intchartTime; + + $scope.widgetChart.url = $sce.trustAsResourceUrl($scope.widgetChart.intchartUrl); + } + }); + }; + + /** + * Load device + */ + $scope.loadDeviceUrl = function () { + $scope.widgetChart.alert = {message: $scope._t('loading'), status: 'alert-warning', icon: 'fa-spinner fa-spin'}; + + dataFactory.getApi('devices', '/' + $scope.dataHolder.devices.find.id, true).then(function (response) { + var device = response.data.data; + if (!device) { + $scope.widgetChart.alert = {message: $scope._t('error_load_data'), status: 'alert-danger', icon: 'fa-exclamation-triangle'}; + return; + } + $scope.widgetChart.find = device; + + if (!device.metrics.intchartUrl){ + $scope.widgetChart.alert = {message: $scope._t('error_load_data'), status: 'alert-danger', icon: 'fa-exclamation-triangle'}; + return; + } + + $scope.widgetChart.hasURL = true; + $scope.widgetChart.intchartUrl = device.metrics.intchartUrl; + $scope.widgetChart.time = device.metrics.intchartTime; + $scope.widgetChart.url = $sce.trustAsResourceUrl($scope.widgetChart.intchartUrl); + + $scope.refreshInterval = $interval($scope.reloadUrl, $scope.cfg.interval); + + $scope.widgetChart.alert = {message: false}; + + }, function (error) { + $scope.widgetChart.alert = {message: $scope._t('error_load_data'), status: 'alert-danger', icon: 'fa-exclamation-triangle'}; + }); + }; + $scope.loadDeviceUrl(); + +}); + /** * The controller that handles a device history. * @class ElementHistoryController diff --git a/dist/app/views/elements/list.html b/dist/app/views/elements/list.html index 4c06ba6a5..52faa94ae 100644 --- a/dist/app/views/elements/list.html +++ b/dist/app/views/elements/list.html @@ -13,6 +13,7 @@
+
@@ -74,6 +75,7 @@

{{v.metrics.title|cutText:true:25}}

+
@@ -86,4 +88,4 @@

{{v.metrics.title|cutText:true:25}}

- \ No newline at end of file + diff --git a/dist/app/views/elements/widgets/intchartModal.html b/dist/app/views/elements/widgets/intchartModal.html new file mode 100644 index 000000000..1caeb7fc8 --- /dev/null +++ b/dist/app/views/elements/widgets/intchartModal.html @@ -0,0 +1,16 @@ + +
+
+
+ +

{{widgetChart.find.metrics.title}}

+
+
+ +
+
+
+
+
+ +