From d3d041ccf96b3291d76ed4947a99095b42042ddd Mon Sep 17 00:00:00 2001 From: VD17593 Date: Fri, 16 Dec 2016 15:33:44 +0100 Subject: [PATCH 1/4] Module : Chart Intchart.com - addtion 1/3 The proposal is to include a functionality to the client side for the users of the new app : Chart Intchart.com. This app allows to monitor devices and log to a chart. It will add a little icon to the logged device. Once the icon clicked, the chart will open in a modal screen. To have this chart available on the smarthome 3 additions are needed. --- app/controllers/element.js | 74 +++++++++++++++++++++++++++++++++++++- 1 file changed, 73 insertions(+), 1 deletion(-) 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 +}); From 396d9511d097648c6343f888d60ee1e5ce9d7fbb Mon Sep 17 00:00:00 2001 From: VD17593 Date: Fri, 16 Dec 2016 15:40:31 +0100 Subject: [PATCH 2/4] Module Chart Intchart.com : addition 2/3 This is the second addition needed for the module --- dist/app/views/elements/list.html | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) 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 + From 74b6aba90dceb87cba56ae560e8b45536ddc4bcb Mon Sep 17 00:00:00 2001 From: VD17593 Date: Fri, 16 Dec 2016 15:45:22 +0100 Subject: [PATCH 3/4] Module : Chart Intchart.com This is the third addition for the module --- .../views/elements/widgets/intchartModal.html | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 dist/app/views/elements/widgets/intchartModal.html 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}}

+
+
+ +
+
+
+
+
+ + From 8c0a9cc9a4fba223998c04b8209fb9c9f6b20f31 Mon Sep 17 00:00:00 2001 From: VD17593 Date: Fri, 16 Dec 2016 15:52:55 +0100 Subject: [PATCH 4/4] Module : Chart Intchart.com Since I'm not familiar with the way this file is created (from the previous included additions), to be sure I included the final result in this build.js. This is the file I used to test the module, and normally everything should run as expected. --- dist/app/js/build.js | 79 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 78 insertions(+), 1 deletion(-) 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