From a320ea286b27a2cc47cec2f27d669e343701d1e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antonio=20Irland=C3=A9s=20Garc=C3=ADa?= Date: Thu, 6 Jun 2019 15:16:42 +0200 Subject: [PATCH 01/74] Fixing some errors with charts and dates --- src/js/Collection/BaseCollection.js | 10 +++++++++ src/js/Collection/DeviceCollection.js | 17 +++++--------- src/js/Utils.js | 22 +++++++++++++++++++ src/js/View/DateView.js | 5 +---- src/js/View/widgets/Charts/ComparisonChart.js | 5 +++++ .../View/widgets/WidgetMultiVariableChart.js | 4 ++-- src/js/template/chart/base_chart_legend.html | 5 ++++- 7 files changed, 49 insertions(+), 19 deletions(-) diff --git a/src/js/Collection/BaseCollection.js b/src/js/Collection/BaseCollection.js index 21c7e551..bb636fce 100644 --- a/src/js/Collection/BaseCollection.js +++ b/src/js/Collection/BaseCollection.js @@ -32,6 +32,16 @@ App.Collection.Base = Backbone.Collection.extend({ } this.options = options; + + // To change the attribute "data" (string), + // inside the payload, to JSON object + this.on('sync', _.bind(function (response) { + if (response.options && + response.options.data && + typeof response.options.data === 'string') { + this.options.data = JSON.parse(response.options.data); + } + }, this)); } }); diff --git a/src/js/Collection/DeviceCollection.js b/src/js/Collection/DeviceCollection.js index c2c643e7..1318b930 100644 --- a/src/js/Collection/DeviceCollection.js +++ b/src/js/Collection/DeviceCollection.js @@ -159,7 +159,6 @@ App.Collection.DeviceTimeSerie = Backbone.Collection.extend({ } }); -// App.Collection.DeviceTimeSerieChart = App.Collection.DeviceTimeSerie.extend({ App.Collection.DeviceTimeSerieChart = Backbone.Collection.extend({ initialize: function (models, options) { @@ -180,9 +179,12 @@ App.Collection.DeviceTimeSerieChart = Backbone.Collection.extend({ var stepOption = options.data && options.data.time ? options.data.time.step || this.options.step : this.options.step; + var currentAggOptions = options.data && Array.isArray(options.data.agg) + ? options.data.agg + : this.options.agg; options.data = JSON.stringify({ - agg: _.map(this.options.agg, function (val) { return val }), + agg: _.map(currentAggOptions, function (val) { return val }), vars: this.options.vars, time: { start: App.ctx.getDateRange().start, @@ -250,12 +252,8 @@ App.Collection.DeviceRaw = App.Collection.Post.extend({ }, fetch: function (options) { - if (typeof options === 'undefined') { - var options = {} - } - // Default options - options = _.defaults(options, { + options = _.defaults(options || {}, { data: {} }); @@ -263,11 +261,6 @@ App.Collection.DeviceRaw = App.Collection.Post.extend({ options.data = JSON.parse(options.data) } - // Options "format" - if (typeof options.data.format === 'undefined' && this.options.format) { - options.data.format = this.options.format; - } - // Options "time" if (typeof options.data.time === 'undefined') { options.data.time = App.ctx.getDateRange(); diff --git a/src/js/Utils.js b/src/js/Utils.js index 83aeaaac..b26c8cbe 100644 --- a/src/js/Utils.js +++ b/src/js/Utils.js @@ -448,3 +448,25 @@ App.Utils.setArrayToINSQL = function (data) { return currentData; } +/** + * Transform a date like that --> "2019-05-08T23:00:07.000Z" + * in some like that --> "2019-05-08 23:00:07" + * + * @param {String} date - string date + * @return {String} - string parse date + */ +App.Utils.removeUTCFromDate = function (date) { + + var splitDate = date.split('T'); + + if (Array.isArray(splitDate) && splitDate[1]) { + var day = splitDate[0]; + var time = splitDate[1]; + var splitTime = time.split('.'); + + return day + ' ' + splitTime[0] || time; + } + + return date; +} + diff --git a/src/js/View/DateView.js b/src/js/View/DateView.js index 8cacb043..3e2ac9a1 100644 --- a/src/js/View/DateView.js +++ b/src/js/View/DateView.js @@ -219,8 +219,6 @@ App.View.Date = Backbone.View.extend({ ? lastDateMinusRange : moment(this.options.minDate); - // var lastDate = moment(this.$('.date.finish').datepicker('getDate')).startOf('day'); - // var firstDate = lastDate.clone().subtract(this.options.maxRange); inst.settings.minDate = firstDate.toDate(); inst.settings.maxDate = lastDate.toDate(); } else if (input.classList.contains('finish')) { @@ -234,8 +232,6 @@ App.View.Date = Backbone.View.extend({ ? firstDateAddRange : moment(this.options.maxDate); - // var firstDate = moment(this.$('.date.start').datepicker('getDate')).startOf('day'); - // var lastDate = firstDate.clone().add(this.options.maxRange); inst.settings.minDate = firstDate.toDate(); inst.settings.maxDate = lastDate.toDate(); } else { @@ -292,6 +288,7 @@ App.View.Date = Backbone.View.extend({ }); this._addCompact(); + this._setValuesInDatePickers(); }, /** diff --git a/src/js/View/widgets/Charts/ComparisonChart.js b/src/js/View/widgets/Charts/ComparisonChart.js index a2f3ef0a..a00b8c30 100644 --- a/src/js/View/widgets/Charts/ComparisonChart.js +++ b/src/js/View/widgets/Charts/ComparisonChart.js @@ -163,6 +163,11 @@ App.View.Widgets.Charts.Comparison = App.View.Widgets.Charts.Base.extend({ if(_this.options.get('legendNameFunc') && _this.options.get('legendNameFunc')(elem.key)) elem.key = __(_this.options.get('legendNameFunc')(elem.key)); + // Fix the changes in models and collections (BaseModel & BaseCollections) + if (collection && collection.options && typeof collection.options.data === 'string') { + collection.options.data = JSON.parse(collection.options.data); + } + // Add date to key elem.key += ' ' + App.formatDate(collection.options.data.time.start) + ' - ' + App.formatDate(collection.options.data.time.finish); diff --git a/src/js/View/widgets/WidgetMultiVariableChart.js b/src/js/View/widgets/WidgetMultiVariableChart.js index 027b64e7..ade1f656 100644 --- a/src/js/View/widgets/WidgetMultiVariableChart.js +++ b/src/js/View/widgets/WidgetMultiVariableChart.js @@ -91,8 +91,8 @@ App.View.Widgets.MultiVariableChart = Backbone.View.extend({ if (!this.collection.options.data) { this.collection.options.data = { time: {} } } - this.collection.options.data.time.start = this._ctx.get('start'); - this.collection.options.data.time.finish = this._ctx.get('finish'); + this.collection.options.data.time.start = this._ctx.getDateRange().start; + this.collection.options.data.time.finish = this._ctx.getDateRange().finish; App.Utils.checkBeforeFetching(this); diff --git a/src/js/template/chart/base_chart_legend.html b/src/js/template/chart/base_chart_legend.html index 6ab3863c..aa7c8c38 100644 --- a/src/js/template/chart/base_chart_legend.html +++ b/src/js/template/chart/base_chart_legend.html @@ -34,8 +34,11 @@ var aggInfo = false; if(aggregationInfo && aggregationInfo.length) { aggInfo = aggregationInfo[index][mKey]; - }else if(aggregationInfo && aggregationInfo[mKey]) { + } else if(aggregationInfo && aggregationInfo[mKey]) { aggInfo = aggregationInfo[mKey]; + } else if(aggregationInfo && aggregationInfo[dato.realKey]) { + aggInfo = aggregationInfo[dato.realKey]; + mKey = dato.realKey; } if(aggInfo){ %> From 3514b9ef96e7d8dab868acc7dad1e17b600a7ea5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antonio=20Irland=C3=A9s=20Garc=C3=ADa?= Date: Thu, 6 Jun 2019 15:20:29 +0200 Subject: [PATCH 02/74] Removind unnecesary code --- src/js/View/DateView.js | 1 - 1 file changed, 1 deletion(-) diff --git a/src/js/View/DateView.js b/src/js/View/DateView.js index 3e2ac9a1..97ecd6de 100644 --- a/src/js/View/DateView.js +++ b/src/js/View/DateView.js @@ -288,7 +288,6 @@ App.View.Date = Backbone.View.extend({ }); this._addCompact(); - this._setValuesInDatePickers(); }, /** From 0838ad207aefa7b950665ac9d122be2c002f1f20 Mon Sep 17 00:00:00 2001 From: fjguipen Date: Fri, 7 Jun 2019 10:02:54 +0200 Subject: [PATCH 03/74] added may --- src/js/View/DashboardView.deprecated.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/js/View/DashboardView.deprecated.js b/src/js/View/DashboardView.deprecated.js index 1845640f..b65d6833 100644 --- a/src/js/View/DashboardView.deprecated.js +++ b/src/js/View/DashboardView.deprecated.js @@ -342,7 +342,7 @@ App.View.Dashboard = Backbone.View.extend({ 'className': 'lvigauge', 'var_id': 'waste.ilv.indicator', // 'timeinstant':timeinstant - 'date': scope === 'guadalajara' ? new Date(2019, 3, 1) : new Date(2018, 7, 1), + 'date': scope === 'guadalajara' ? new Date(2019, 4, 1) : new Date(2018, 7, 1), 'url': '/' + scope + '/waste/indicators', 'extra_info': { 'unit': '%', From 7a8443c40724ffb1a397a872c22a880caf72eeee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antonio=20Irland=C3=A9s=20Garc=C3=ADa?= Date: Mon, 10 Jun 2019 14:20:54 +0200 Subject: [PATCH 04/74] Changing dates in some function parse from collections --- src/js/Collection/DeviceCollection.js | 7 +- .../DevicesGroupTimeserieCollection.js | 113 +++++++++--------- src/js/Collection/Variables.js | 2 +- 3 files changed, 61 insertions(+), 61 deletions(-) diff --git a/src/js/Collection/DeviceCollection.js b/src/js/Collection/DeviceCollection.js index 1318b930..26ea9774 100644 --- a/src/js/Collection/DeviceCollection.js +++ b/src/js/Collection/DeviceCollection.js @@ -208,11 +208,6 @@ App.Collection.DeviceTimeSerieChart = Backbone.Collection.extend({ _.each(response, function (r) { _.each(Object.keys(r.data), function (k) { - // Prepare the date ("time" parameter) - var currentTime = r.time.split('T'); - var currentTimeDay = currentTime[0]; - var currentTimeHour = currentTime[1].replace('.000Z', ''); - if (!aux[k]) { aux[k] = []; } @@ -220,7 +215,7 @@ App.Collection.DeviceTimeSerieChart = Backbone.Collection.extend({ r.data[k] = 0; } aux[k].push({ - x: moment(currentTimeDay + ' ' + currentTimeHour).toDate(), + x: moment(App.Utils.removeUTCFromDate(r.time)).toDate(), y: k === 'seconds' ? r.data[k] / 60 : r.data[k] diff --git a/src/js/Collection/DevicesGroupTimeserieCollection.js b/src/js/Collection/DevicesGroupTimeserieCollection.js index 15425d7c..e18e397a 100644 --- a/src/js/Collection/DevicesGroupTimeserieCollection.js +++ b/src/js/Collection/DevicesGroupTimeserieCollection.js @@ -1,71 +1,76 @@ -// Copyright 2017 Telefónica Digital España S.L. -// -// This file is part of UrboCore WWW. -// -// UrboCore WWW is free software: you can redistribute it and/or -// modify it under the terms of the GNU Affero General Public License as -// published by the Free Software Foundation, either version 3 of the -// License, or (at your option) any later version. -// -// UrboCore WWW is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -// General Public License for more details. -// -// You should have received a copy of the GNU Affero General Public License -// along with UrboCore WWW. If not, see http://www.gnu.org/licenses/. -// -// For those usages not covered by this license please contact with +// Copyright 2017 Telefónica Digital España S.L. +// +// This file is part of UrboCore WWW. +// +// UrboCore WWW is free software: you can redistribute it and/or +// modify it under the terms of the GNU Affero General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// UrboCore WWW is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero +// General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with UrboCore WWW. If not, see http://www.gnu.org/licenses/. +// +// For those usages not covered by this license please contact with // iot_support at tid dot es 'use strict'; App.Collection.DevicesGroupTimeserie = Backbone.Collection.extend({ - initialize: function(models,options) { - this.options = options; - }, + initialize: function (models, options) { + this.options = options; + }, - url: function(){ - return App.config.api_url + '/' + this.options.scope +'/variables/' + this.options.variable + '/devices_group_timeserie' - }, + url: function () { + return App.config.api_url + '/' + this.options.scope + '/variables/' + this.options.variable + '/devices_group_timeserie' + }, - parse: function(response) { + parse: function (response) { - var aux = {}; + var aux = {}; - _.each(response, function(r) { - _.each(Object.keys(r.data), function(k) { - if(!aux[k]) - aux[k] = []; - if(r.data[k] != null) - aux[k].push({'x':new Date(r.time), 'y':k == 'seconds' ? r.data[k]/60:r.data[k]}); - }); - }); + _.each(response, function (r) { + _.each(Object.keys(r.data), function (k) { + if (!aux[k]) + aux[k] = []; + if (r.data[k] != null) + aux[k].push({ + x: moment(App.Utils.removeUTCFromDate(r.time)).toDate(), + y: k == 'seconds' + ? r.data[k] / 60 + : r.data[k] + }); + }); + }); - response = _.map(aux, function(values, key){ - return {'key':key, 'values':values, 'disabled':false} - }); + response = _.map(aux, function (values, key) { + return { 'key': key, 'values': values, 'disabled': false } + }); - return response; - }, + return response; + }, - fetch: function(options) { + fetch: function (options) { - options = options || {}; + options = options || {}; - var date = App.ctx.getDateRange(); - options['data'] = { - 'start': date.start, - 'finish': date.finish, - 'id_variable':this.options.variable, - 'step':this.options.step, - 'agg':this.options.agg, - 'groupagg':true - }; + var date = App.ctx.getDateRange(); + options['data'] = { + 'start': date.start, + 'finish': date.finish, + 'id_variable': this.options.variable, + 'step': this.options.step, + 'agg': this.options.agg, + 'groupagg': true + }; - if(App.ctx.get('bbox')) - options['data']['bbox'] = App.ctx.get('bbox'); + if (App.ctx.get('bbox')) + options['data']['bbox'] = App.ctx.get('bbox'); - return Backbone.Collection.prototype.fetch.call(this, options); - } + return Backbone.Collection.prototype.fetch.call(this, options); + } }); diff --git a/src/js/Collection/Variables.js b/src/js/Collection/Variables.js index ea139b33..fb226d19 100644 --- a/src/js/Collection/Variables.js +++ b/src/js/Collection/Variables.js @@ -124,7 +124,7 @@ App.Collection.Variables.TimeserieGrouped = App.Collection.Post.extend({ aux[d.agg] = []; } aux[d.agg].push({ - x: new Date(r.time), + x: moment(App.Utils.removeUTCFromDate(r.time)).toDate(), y: d.value }); }); From a770b40e2f4da4622329f76440ea1c303a48b5d1 Mon Sep 17 00:00:00 2001 From: fjguipen Date: Mon, 10 Jun 2019 14:44:54 +0200 Subject: [PATCH 05/74] changed filter name to AJUSTES --- src/js/View/Map/LayerTreeView.js | 38 ++++++++++++++++---------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/src/js/View/Map/LayerTreeView.js b/src/js/View/Map/LayerTreeView.js index 3825a20f..06e7b76d 100644 --- a/src/js/View/Map/LayerTreeView.js +++ b/src/js/View/Map/LayerTreeView.js @@ -1,21 +1,21 @@ -// Copyright 2017 Telefónica Digital España S.L. -// -// This file is part of UrboCore WWW. -// -// UrboCore WWW is free software: you can redistribute it and/or -// modify it under the terms of the GNU Affero General Public License as -// published by the Free Software Foundation, either version 3 of the -// License, or (at your option) any later version. -// -// UrboCore WWW is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -// General Public License for more details. -// -// You should have received a copy of the GNU Affero General Public License -// along with UrboCore WWW. If not, see http://www.gnu.org/licenses/. -// -// For those usages not covered by this license please contact with +// Copyright 2017 Telefónica Digital España S.L. +// +// This file is part of UrboCore WWW. +// +// UrboCore WWW is free software: you can redistribute it and/or +// modify it under the terms of the GNU Affero General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// UrboCore WWW is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero +// General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with UrboCore WWW. If not, see http://www.gnu.org/licenses/. +// +// For those usages not covered by this license please contact with // iot_support at tid dot es App.View.Map.LayerTree.View = Backbone.View.extend({ @@ -25,7 +25,7 @@ App.View.Map.LayerTree.View = Backbone.View.extend({ initialize: function(options) { this.options= _.defaults(options,{ - title: __('Filtros'), + title: __('Ajustes'), compact: false }); if(this.options.collection.first().get('legendData')){ From 9c4ac40fde2c30954ab9f82a80b7cc1541e1b84f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antonio=20Irland=C3=A9s=20Garc=C3=ADa?= Date: Mon, 10 Jun 2019 15:33:15 +0200 Subject: [PATCH 06/74] Fixing error in WidgetMultivariableChart after select an aggregation --- src/js/View/widgets/WidgetMultiVariableChart.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/js/View/widgets/WidgetMultiVariableChart.js b/src/js/View/widgets/WidgetMultiVariableChart.js index ade1f656..edb1c972 100644 --- a/src/js/View/widgets/WidgetMultiVariableChart.js +++ b/src/js/View/widgets/WidgetMultiVariableChart.js @@ -336,7 +336,7 @@ App.View.Widgets.MultiVariableChart = Backbone.View.extend({ // TODO - DELETE AFTER AQUASIG PILOT JULY 2019 // Remove 'SUM' from variables (metadata) - if (c.realKey.indexOf('aq_cons.sensor') > -1) { + if (c.realKey.indexOf('aq_cons.sensor') > -1 && c.aggs.indexOf('SUM') > -1) { c.aggs.splice(c.aggs.indexOf('SUM'), 1); } // END TODO From 771342860df277e5583eba87da8656fa15537f67 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Iv=C3=A1n=20Moreno?= Date: Tue, 11 Jun 2019 14:21:30 +0200 Subject: [PATCH 07/74] fix error. plot layer disappear on zooming --- src/js/View/Map/Layer/MapboxGLLayer.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/js/View/Map/Layer/MapboxGLLayer.js b/src/js/View/Map/Layer/MapboxGLLayer.js index bd5a663c..37fe5843 100644 --- a/src/js/View/Map/Layer/MapboxGLLayer.js +++ b/src/js/View/Map/Layer/MapboxGLLayer.js @@ -146,7 +146,7 @@ App.View.Map.Layer.MapboxGLLayer = Backbone.View.extend({ }, _success: function(change) { - this.dataSource = (change.changed.type)? change.changed : {type: "FeatureCollection", features: []}, + this.dataSource = (change.changed.type)? change.changed : {type: "FeatureCollection", features: change.changed.features || []}, this._map.getSource(this._idSource).setData(this.dataSource); this._map._sources.find(function(src) { return src.id === this._idSource; From 9a09f7555f19aad0f1a3c217f1f8438ac451cd2a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Iv=C3=A1n=20Moreno?= Date: Tue, 11 Jun 2019 17:24:00 +0200 Subject: [PATCH 08/74] support open vertical in new tab --- src/js/App.js | 6 ++++++ src/js/template/categories_list_template.html | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/js/App.js b/src/js/App.js index 0e19a3b0..a03b02c2 100644 --- a/src/js/App.js +++ b/src/js/App.js @@ -613,6 +613,12 @@ $(function() { $('body').on('click', 'a', function (e){ var attr = $(this).attr('jslink'); var href = $(this).attr('href'); + var blank = $(this).attr('target') === '_blank'; + + if (blank) { + $(this).attr('href', `/${App.lang}${href}`); + return; + } //Prevent update url history when clicking a link to the current page if (href && href.slice(1) === Backbone.history.getFragment()) { diff --git a/src/js/template/categories_list_template.html b/src/js/template/categories_list_template.html index 7ed711b8..56b902d3 100644 --- a/src/js/template/categories_list_template.html +++ b/src/js/template/categories_list_template.html @@ -15,7 +15,7 @@

<%_.each(categories, function(s){%> <% var link = '/' + scope + '/' + s.id + '/dashboard'; %> - +
<%= __(s.name) %> From 774e1f64460cde45baf08a57e325f036e54c4dd5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Iv=C3=A1n=20Moreno?= Date: Tue, 11 Jun 2019 17:30:43 +0200 Subject: [PATCH 09/74] fix linter --- src/js/App.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/js/App.js b/src/js/App.js index a03b02c2..f991018a 100644 --- a/src/js/App.js +++ b/src/js/App.js @@ -616,7 +616,7 @@ $(function() { var blank = $(this).attr('target') === '_blank'; if (blank) { - $(this).attr('href', `/${App.lang}${href}`); + $(this).attr('href', '/' + App.lang + href); return; } From 39cd79bebe0aa5d1340449527f5f4459d43b4ac9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Iv=C3=A1n=20Moreno?= Date: Tue, 11 Jun 2019 17:54:29 +0200 Subject: [PATCH 10/74] fix: minor error when click twice --- src/js/App.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/js/App.js b/src/js/App.js index f991018a..87405574 100644 --- a/src/js/App.js +++ b/src/js/App.js @@ -616,7 +616,8 @@ $(function() { var blank = $(this).attr('target') === '_blank'; if (blank) { - $(this).attr('href', '/' + App.lang + href); + if (!href.includes('/' + App.lang + '/')) + $(this).attr('href', '/' + App.lang + href); return; } From d2005a40ce5e267df60f651bccae6731c5f37b5c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Iv=C3=A1n=20Moreno?= Date: Tue, 11 Jun 2019 19:50:58 +0200 Subject: [PATCH 11/74] added debounce to widget refresh --- src/js/View/widgets/WidgetBase.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/js/View/widgets/WidgetBase.js b/src/js/View/widgets/WidgetBase.js index 5d1eaf6c..900f7494 100644 --- a/src/js/View/widgets/WidgetBase.js +++ b/src/js/View/widgets/WidgetBase.js @@ -60,7 +60,7 @@ App.View.Widgets.Base = Backbone.View.extend({ if (!this.model.get('embed')) { if (this.model.get('timeMode') == 'historic') { - this.listenTo(this.ctx, 'change:start change:finish', this.refresh); + _.debounce(this.listenTo(this.ctx, 'change:start change:finish', this.refresh), 2000); } this.listenTo(this.ctx, 'change:bbox', this.refresh); } From d505a880ebc5c814148eecdca400cf95e2ce1bf2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Iv=C3=A1n=20Moreno?= Date: Wed, 12 Jun 2019 15:59:46 +0200 Subject: [PATCH 12/74] open in a new window --- src/js/View/widgets/WidgetAlertsVariable.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/js/View/widgets/WidgetAlertsVariable.js b/src/js/View/widgets/WidgetAlertsVariable.js index a2d14944..2b80bcdf 100644 --- a/src/js/View/widgets/WidgetAlertsVariable.js +++ b/src/js/View/widgets/WidgetAlertsVariable.js @@ -42,7 +42,7 @@ App.View.Widgets.AlertsVariable = Backbone.View.extend({ buttonclick: function(e) { if(this.options.buttonlink) { - window.location.href = this.options.buttonlink; + window.open(this.options.buttonlink, '_blank'); } }, From 54e8d7f32134c336edab915ea2a87efeae4b65d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Iv=C3=A1n=20Moreno?= Date: Wed, 12 Jun 2019 16:57:12 +0200 Subject: [PATCH 13/74] fix widget alerts --- src/css/widgets/widget.less | 1 + 1 file changed, 1 insertion(+) diff --git a/src/css/widgets/widget.less b/src/css/widgets/widget.less index eb06a175..a51eb097 100644 --- a/src/css/widgets/widget.less +++ b/src/css/widgets/widget.less @@ -799,6 +799,7 @@ margin-bottom: 0 !important; cursor: default; padding: 20px; + padding-bottom: 40px; button { margin-top: 16px; display: block; From 95580a10b759c989b7659d1ab8b83a45e4e52d44 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Iv=C3=A1n=20Moreno?= Date: Wed, 12 Jun 2019 17:51:34 +0200 Subject: [PATCH 14/74] fix debounce --- src/js/View/widgets/WidgetBase.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/js/View/widgets/WidgetBase.js b/src/js/View/widgets/WidgetBase.js index 900f7494..116c9ffa 100644 --- a/src/js/View/widgets/WidgetBase.js +++ b/src/js/View/widgets/WidgetBase.js @@ -60,7 +60,7 @@ App.View.Widgets.Base = Backbone.View.extend({ if (!this.model.get('embed')) { if (this.model.get('timeMode') == 'historic') { - _.debounce(this.listenTo(this.ctx, 'change:start change:finish', this.refresh), 2000); + this.listenTo(this.ctx, 'change:start change:finish', _.debounce(this.refresh, 600)); } this.listenTo(this.ctx, 'change:bbox', this.refresh); } From 323f2a8ddb76ad3739b01546b262d6dfc8fae57d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antonio=20Irland=C3=A9s=20Garc=C3=ADa?= Date: Thu, 13 Jun 2019 15:12:16 +0200 Subject: [PATCH 15/74] Fixing chart multivariable --- .../View/widgets/WidgetMultiVariableChart.js | 143 ++++++++++-------- 1 file changed, 82 insertions(+), 61 deletions(-) diff --git a/src/js/View/widgets/WidgetMultiVariableChart.js b/src/js/View/widgets/WidgetMultiVariableChart.js index edb1c972..8cd587ef 100644 --- a/src/js/View/widgets/WidgetMultiVariableChart.js +++ b/src/js/View/widgets/WidgetMultiVariableChart.js @@ -26,9 +26,6 @@ App.View.Widgets.MultiVariableChart = Backbone.View.extend({ _popup_template: _.template($('#chart-base_charttooltip').html()), _list_variable_template: _.template($('#widgets-widget_multiVariable_list_variables').html()), - // Size label in X axis - _sizeXLabel: 68, - /* TODO: Create documentation Params: @@ -415,7 +412,7 @@ App.View.Widgets.MultiVariableChart = Backbone.View.extend({ var dataChart = this.data.toJSON(); var startDate = dataChart[0].values[0].x; var finishDate = dataChart[0].values[dataChart[0].values.length - 1].x; - var fnRemoveXAxis = _.debounce(this._removeLabelInXAxis.bind(this), 350); + var fnhideMaxMinXAxis = _.debounce(_.bind(this.hideMaxMinXAxis, this), 350); // Draw the X axis with values (date) with 'hours' // If the difference between dates is minus to two days @@ -442,12 +439,11 @@ App.View.Widgets.MultiVariableChart = Backbone.View.extend({ this.chart .xAxis .tickValues(this.getXTickValues(dataChart)); - // remove labels in X Axis - fnRemoveXAxis(); + // Remove max and min + fnhideMaxMinXAxis(); }.bind(this)); - - // remove labels in X Axis - fnRemoveXAxis(); + // Remove max and min + fnhideMaxMinXAxis(); } }, @@ -538,29 +534,79 @@ App.View.Widgets.MultiVariableChart = Backbone.View.extend({ */ getXTickValues: function (data) { if (data.length && data[0].values.length) { + // date start + var dateStart = data[0].values[0].x; + // date finish + var dateFinish = data[0].values[data[0].values.length-1].x; + // date current (is used to the loop) + var dateCurrent = moment(dateStart); + // dates for X axis + var datesXAxis = [dateStart]; + // current step + var currentStep = this.collection.options && this.collection.options.step + ? this.collection.options.step + : '1d'; + // Defaults values to the step + var Stepvalue = 1; + var StepRange = 'days'; + + // Which is the difference to add to dateCurrent? + switch(currentStep) { + case '1d': + Stepvalue = 1; + StepRange = 'days' + break; + case '4h': + Stepvalue = 4; + StepRange = 'hours' + break; + case '2h': + Stepvalue = 2; + StepRange = 'hours' + break; + case '1h': + Stepvalue = 1; + StepRange = 'hours' + break; + case '15m': + Stepvalue = 15; + StepRange = 'minutes' + break; + } + + // We fill (with dates) the period + while(dateCurrent.isBefore(dateFinish)) { + dateCurrent = dateCurrent.add(Stepvalue, StepRange); + datesXAxis.push(dateCurrent.toDate()); + } + // chart DOM - var chart = d3.select(this.$('.chart')[0]); + var chartRect = d3 + .select(this.$('.chart .nvd3 .nv-focus .nv-background rect')[0]); // chart width DOM - var chartWidth = $(chart[0]).width(); + var chartRectWidth = Number + .parseInt(chartRect[0][0].getAttribute('width'), 10); // size label pixels put into the X axis - var labelWidth = this._sizeXLabel; + var labelWidth = StepRange === 'days' + ? 70 //dates (59.34) + : labelWidth = StepRange === 'hours' && moment(dateFinish).diff(dateStart, 'days') > 1 + ? 78 // dates + hours (67.17) + : 40 // hours (29.77) // max tick to draw in X Axis - var maxXTick = Number.parseInt(chartWidth / labelWidth, 10); + var maxXTick = (chartRectWidth-labelWidth) / labelWidth; + // Difference between the data to draw - var diff = data[0].values.length / maxXTick; + var diff = datesXAxis.length / maxXTick; return diff < 1 - ? _.map(data[0].values, function (item) { - return item.x; + ? _.map(datesXAxis, function (item) { + return item; }) - : _.reduce(data[0].values, function (sumItems, item, index, originItems) { + : _.reduce(datesXAxis, function (sumItems, item, index, originItems) { var currentIndex = Math.round(index * diff); - if (sumItems.length <= maxXTick) { - if (index === 0 || (index + 1) === originItems.length) { - // Initial and finish range - sumItems.push(originItems[index].x); - } else if (originItems[currentIndex]) { - sumItems.push(originItems[currentIndex].x); + if (sumItems.length < maxXTick) { + if (originItems[currentIndex]) { + sumItems.push(originItems[currentIndex]); } } return sumItems; @@ -570,45 +616,20 @@ App.View.Widgets.MultiVariableChart = Backbone.View.extend({ } }, - // Remove label in X Axis - _removeLabelInXAxis: function () { - // Get all X axis points and remove (hide) any label - // that is over other label - var labels = this.$('.chart .nv-lineChart .nv-focus .nv-x .nv-axis > g:first-child g.tick') - .sort(function (a, b) { - // Order by transform valur - var aTransform = $(a).attr('transform'); - var bTransform = $(b).attr('transform'); - - aTransform = aTransform.replace('translate(', ''); - aTransform = aTransform.replace(',0)', ''); - aTransform = Number.parseFloat(aTransform); - - bTransform = bTransform.replace('translate(', ''); - bTransform = bTransform.replace(',0)', ''); - bTransform = Number.parseFloat(bTransform); - - if (aTransform < bTransform) { - return -1; - } else { - return 1; - } - }); + /** + * Remove max and min value in X axis + */ + hideMaxMinXAxis: function () { + var dataChart = this.data.toJSON(); + var axisChart = d3.selectAll(this.$('.chart .nvd3 .nv-focus .nv-axisMaxMin-x')); - var offsetXLabel = null; - _.each(labels, function (label) { - var currentOffsetXLabel = $(label).attr('transform'); - currentOffsetXLabel = currentOffsetXLabel.replace('translate(', ''); - currentOffsetXLabel = currentOffsetXLabel.replace(',0)', ''); - currentOffsetXLabel = Number.parseFloat(currentOffsetXLabel); - if (offsetXLabel === null) { // begin loop - offsetXLabel = currentOffsetXLabel; - } else if (offsetXLabel + this._sizeXLabel > currentOffsetXLabel) { // hide label - $(label).hide(); - } else { // show label - offsetXLabel = currentOffsetXLabel; - } - }.bind(this)); + if (dataChart.length && dataChart[0].values.length === 1) { + $(axisChart[0][0]).hide(); + $(axisChart[0][1]).hide(); + } else { + $(axisChart[0][0]).show(); + $(axisChart[0][1]).show(); + } }, /** From 17472174db882cf899ae83387489438d0113b9bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antonio=20Irland=C3=A9s=20Garc=C3=ADa?= Date: Thu, 13 Jun 2019 15:45:43 +0200 Subject: [PATCH 16/74] Improving the calculate --- .../View/widgets/WidgetMultiVariableChart.js | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/src/js/View/widgets/WidgetMultiVariableChart.js b/src/js/View/widgets/WidgetMultiVariableChart.js index 8cd587ef..bada757d 100644 --- a/src/js/View/widgets/WidgetMultiVariableChart.js +++ b/src/js/View/widgets/WidgetMultiVariableChart.js @@ -594,6 +594,20 @@ App.View.Widgets.MultiVariableChart = Backbone.View.extend({ : 40 // hours (29.77) // max tick to draw in X Axis var maxXTick = (chartRectWidth-labelWidth) / labelWidth; + // get multiples total dateXAxis + var multiplesTotalXAxis = this.getMultipleNumbers(datesXAxis.length); + + // If there are more the 2 values + // then we can search for the current multiple + if (multiplesTotalXAxis.length > 2) { + var newMaxTick = maxXTick; + for (var i = 0; i < multiplesTotalXAxis.length; i++) { + if (multiplesTotalXAxis[i] <= maxXTick) { + newMaxTick = multiplesTotalXAxis[i]; + } + } + maxXTick = newMaxTick; + } // Difference between the data to draw var diff = datesXAxis.length / maxXTick; @@ -632,6 +646,22 @@ App.View.Widgets.MultiVariableChart = Backbone.View.extend({ } }, + /** + * Get the multiples number to a number + * @param {Number} number + * @return {Array} multiples numbers + */ + getMultipleNumbers: function (number) { + var multiples = []; + for( var i = 1; i < number; i++) { + if (number%i === 0) { + multiples.push(i); + } + } + + return multiples; + }, + /** * Remove any event */ From eaf16a92af6b4d1fb109f148adca809fa0896415 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antonio=20Irland=C3=A9s=20Garc=C3=ADa?= Date: Thu, 13 Jun 2019 15:59:50 +0200 Subject: [PATCH 17/74] WIP --- src/js/View/widgets/WidgetMultiVariableChart.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/js/View/widgets/WidgetMultiVariableChart.js b/src/js/View/widgets/WidgetMultiVariableChart.js index bada757d..1bc067c6 100644 --- a/src/js/View/widgets/WidgetMultiVariableChart.js +++ b/src/js/View/widgets/WidgetMultiVariableChart.js @@ -653,7 +653,7 @@ App.View.Widgets.MultiVariableChart = Backbone.View.extend({ */ getMultipleNumbers: function (number) { var multiples = []; - for( var i = 1; i < number; i++) { + for( var i = 1; i <= number; i++) { if (number%i === 0) { multiples.push(i); } From 9e4e2c0fcd7a23897fc9ca1fe30f76faf007d78e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antonio=20Irland=C3=A9s=20Garc=C3=ADa?= Date: Thu, 13 Jun 2019 16:29:29 +0200 Subject: [PATCH 18/74] Fixing a problem with X Axis in Chart --- src/js/View/widgets/WidgetMultiVariableChart.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/js/View/widgets/WidgetMultiVariableChart.js b/src/js/View/widgets/WidgetMultiVariableChart.js index 1bc067c6..22cc9d97 100644 --- a/src/js/View/widgets/WidgetMultiVariableChart.js +++ b/src/js/View/widgets/WidgetMultiVariableChart.js @@ -424,7 +424,8 @@ App.View.Widgets.MultiVariableChart = Backbone.View.extend({ // Same day if (moment(finishDate).isSame(moment(startDate), 'day')) { return d3.time.format('%H:%M')(localdate); - } else if (this._multiVariableModel.sizeDiff === 'hours') { + } else if (this._multiVariableModel.sizeDiff === 'hours' + && moment(finishDate).diff(startDate, 'days') > 1) { return d3.time.format('%d/%m - %H:%M')(localdate); } // Only date @@ -589,7 +590,8 @@ App.View.Widgets.MultiVariableChart = Backbone.View.extend({ // size label pixels put into the X axis var labelWidth = StepRange === 'days' ? 70 //dates (59.34) - : labelWidth = StepRange === 'hours' && moment(dateFinish).diff(dateStart, 'days') > 1 + : labelWidth = (StepRange === 'hours' || StepRange === 'minutes') + && moment(dateFinish).diff(dateStart, 'days') > 1 ? 78 // dates + hours (67.17) : 40 // hours (29.77) // max tick to draw in X Axis From 655862d959ec87b460ccdf1b19d5e09b3726c8b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antonio=20Irland=C3=A9s=20Garc=C3=ADa?= Date: Fri, 14 Jun 2019 08:08:55 +0200 Subject: [PATCH 19/74] Fixing last found fix in widgetMultiVariabelChart --- src/js/View/widgets/WidgetMultiVariableChart.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/js/View/widgets/WidgetMultiVariableChart.js b/src/js/View/widgets/WidgetMultiVariableChart.js index 22cc9d97..1ad06c44 100644 --- a/src/js/View/widgets/WidgetMultiVariableChart.js +++ b/src/js/View/widgets/WidgetMultiVariableChart.js @@ -425,7 +425,7 @@ App.View.Widgets.MultiVariableChart = Backbone.View.extend({ if (moment(finishDate).isSame(moment(startDate), 'day')) { return d3.time.format('%H:%M')(localdate); } else if (this._multiVariableModel.sizeDiff === 'hours' - && moment(finishDate).diff(startDate, 'days') > 1) { + && moment(finishDate).diff(startDate, 'days') >= 1) { return d3.time.format('%d/%m - %H:%M')(localdate); } // Only date @@ -591,7 +591,7 @@ App.View.Widgets.MultiVariableChart = Backbone.View.extend({ var labelWidth = StepRange === 'days' ? 70 //dates (59.34) : labelWidth = (StepRange === 'hours' || StepRange === 'minutes') - && moment(dateFinish).diff(dateStart, 'days') > 1 + && moment(dateFinish).diff(dateStart, 'days') >= 1 ? 78 // dates + hours (67.17) : 40 // hours (29.77) // max tick to draw in X Axis From 141b6951168dee6631d1a1a736295262941b8404 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antonio=20Irland=C3=A9s=20Garc=C3=ADa?= Date: Fri, 14 Jun 2019 09:45:24 +0200 Subject: [PATCH 20/74] A particulary error in raw collections --- .../View/widgets/WidgetMultiVariableChart.js | 41 ++++++------------- 1 file changed, 12 insertions(+), 29 deletions(-) diff --git a/src/js/View/widgets/WidgetMultiVariableChart.js b/src/js/View/widgets/WidgetMultiVariableChart.js index 1ad06c44..f9c38749 100644 --- a/src/js/View/widgets/WidgetMultiVariableChart.js +++ b/src/js/View/widgets/WidgetMultiVariableChart.js @@ -547,37 +547,20 @@ App.View.Widgets.MultiVariableChart = Backbone.View.extend({ var currentStep = this.collection.options && this.collection.options.step ? this.collection.options.step : '1d'; + // Values to step + var matchStep = /(\d+)(\w+)/g.exec(currentStep); // Defaults values to the step - var Stepvalue = 1; - var StepRange = 'days'; - - // Which is the difference to add to dateCurrent? - switch(currentStep) { - case '1d': - Stepvalue = 1; - StepRange = 'days' - break; - case '4h': - Stepvalue = 4; - StepRange = 'hours' - break; - case '2h': - Stepvalue = 2; - StepRange = 'hours' - break; - case '1h': - Stepvalue = 1; - StepRange = 'hours' - break; - case '15m': - Stepvalue = 15; - StepRange = 'minutes' - break; - } + var stepValue = matchStep[1] || 1; + var stepRange = matchStep[2] || 'd'; + var ranges = { + d: 'days', + h: 'hours', + m: 'minutes' + }; // We fill (with dates) the period while(dateCurrent.isBefore(dateFinish)) { - dateCurrent = dateCurrent.add(Stepvalue, StepRange); + dateCurrent = dateCurrent.add(stepValue, ranges[stepRange]); datesXAxis.push(dateCurrent.toDate()); } @@ -588,9 +571,9 @@ App.View.Widgets.MultiVariableChart = Backbone.View.extend({ var chartRectWidth = Number .parseInt(chartRect[0][0].getAttribute('width'), 10); // size label pixels put into the X axis - var labelWidth = StepRange === 'days' + var labelWidth = ranges[stepRange] === 'days' ? 70 //dates (59.34) - : labelWidth = (StepRange === 'hours' || StepRange === 'minutes') + : labelWidth = (ranges[stepRange] === 'hours' || ranges[stepRange] === 'minutes') && moment(dateFinish).diff(dateStart, 'days') >= 1 ? 78 // dates + hours (67.17) : 40 // hours (29.77) From 4e0ec2e412e2df6fb8d85fc383d15fb3495daec2 Mon Sep 17 00:00:00 2001 From: fjguipen Date: Fri, 14 Jun 2019 14:30:54 +0200 Subject: [PATCH 21/74] fix table csv download --- src/js/View/widgets/CustomDeviceRawTable.js | 1 + src/js/View/widgets/WidgetTable.js | 10 ++++++++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/js/View/widgets/CustomDeviceRawTable.js b/src/js/View/widgets/CustomDeviceRawTable.js index 1ee200e5..feea4e6e 100644 --- a/src/js/View/widgets/CustomDeviceRawTable.js +++ b/src/js/View/widgets/CustomDeviceRawTable.js @@ -54,6 +54,7 @@ App.View.Widgets.CustomDeviceRawTable = App.View.Widgets.Base.extend({ scope: this.options.scope, entity: this.options.entity, device: this.options.device, + format:'csv', variables: _.pluck(this.getEntityVariables(), 'id') }); diff --git a/src/js/View/widgets/WidgetTable.js b/src/js/View/widgets/WidgetTable.js index 77ef56b5..fb3432d0 100644 --- a/src/js/View/widgets/WidgetTable.js +++ b/src/js/View/widgets/WidgetTable.js @@ -98,11 +98,17 @@ App.View.Widgets.Table = Backbone.View.extend({ _downloadCsv: function () { this._tableToCsv.options = App.Utils.toDeepJSON(this.collection.options); - this._tableToCsv.options.format = 'csv'; + //Just avoiding any breaking change + if (this._tableToCsv.options.format === 'csv'){ + //Make sure format is added inside data object for new table widgets + this._tableToCsv.options.data.format = 'csv'; + } else { + //Old table widgets + this._tableToCsv.options.format = 'csv'; + } this._tableToCsv.options.reset = false; this._tableToCsv.options.dataType = 'text' - // this._tableToCsv.fetch({'reset':false,'dataType':'text'}) this._tableToCsv.fetch(this._tableToCsv.options); }, From 8e95bf881bbf5a534b4c72dd4d2a163df0071118 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antonio=20Irland=C3=A9s=20Garc=C3=ADa?= Date: Sat, 15 Jun 2019 11:58:02 +0200 Subject: [PATCH 22/74] New feature in WidgetBase "drawTimeIcon" --- src/js/View/widgets/WidgetBase.js | 24 +++++++++++++++++++ .../widgets/widget_base_template.html | 10 -------- .../widgets/widget_date_template.html | 20 +++++++++------- .../widgets/widget_time_template.html | 7 ++++++ 4 files changed, 42 insertions(+), 19 deletions(-) create mode 100644 src/js/template/widgets/widget_time_template.html diff --git a/src/js/View/widgets/WidgetBase.js b/src/js/View/widgets/WidgetBase.js index 116c9ffa..2a051209 100644 --- a/src/js/View/widgets/WidgetBase.js +++ b/src/js/View/widgets/WidgetBase.js @@ -23,6 +23,8 @@ App.View.Widgets.Base = Backbone.View.extend({ _template: _.template($('#widgets-widget_base_template').html()), + _template_timemode_historic: _.template($('#widgets-widget_date_template').html()), + _template_timemode_now: _.template($('#widgets-widget_time_template').html()), initialize: function (options) { this.options = options; @@ -294,6 +296,9 @@ App.View.Widgets.Base = Backbone.View.extend({ render: function () { this.$el.html(this._template(this.model.toJSON())); + // Put the time icon into the widget + this.drawTimeIcon(); + this.updateFilters(); for (var i in this.subviews) { @@ -310,6 +315,25 @@ App.View.Widgets.Base = Backbone.View.extend({ return this; }, + /** + * Draw the time icon in the widget + */ + drawTimeIcon: function () { + var wrapper = this.$el.find('.botons'); + var timeMode = this.model.get('timeMode'); + + if (wrapper.length && (timeMode === 'historic' || timeMode === 'now')) { + var templateTimeIcon = timeMode === 'historic' + ? this._template_timemode_historic + : this._template_timemode_now; + + // Remove element DOM + this.$el.find('#timeIcon').remove(); + // Add template time Icon + $(wrapper[0]).prepend(templateTimeIcon); + } + }, + onClose: function () { for (var i in this.subviews) { this.subviews[i].close(); diff --git a/src/js/template/widgets/widget_base_template.html b/src/js/template/widgets/widget_base_template.html index d860e053..e414a0a6 100644 --- a/src/js/template/widgets/widget_base_template.html +++ b/src/js/template/widgets/widget_base_template.html @@ -6,16 +6,6 @@