Skip to content

Commit

Permalink
Merge pull request #457 from GeographicaGS/dev
Browse files Browse the repository at this point in the history
Dev into Master
  • Loading branch information
rbsolis authored Jul 9, 2019
2 parents b2c599b + cd1494b commit 644df68
Show file tree
Hide file tree
Showing 38 changed files with 1,614 additions and 1,140 deletions.
38 changes: 19 additions & 19 deletions src/css/loading.less
Original file line number Diff line number Diff line change
@@ -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

.loading{
Expand Down Expand Up @@ -74,7 +74,7 @@

&.widgetL{
background-color: rgba(0, 71, 93, .8);
z-index: 999;
z-index: 3;
top: 5px;
left: 5px;
width: ~ "calc(100% - 10px)";
Expand Down
1 change: 1 addition & 0 deletions src/css/widgets/widget.less
Original file line number Diff line number Diff line change
Expand Up @@ -799,6 +799,7 @@
margin-bottom: 0 !important;
cursor: default;
padding: 20px;
padding-bottom: 40px;
button {
margin-top: 16px;
display: block;
Expand Down
7 changes: 0 additions & 7 deletions src/css/widgets/widget_multiVariable_chart.less
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,6 @@
padding-top: 0;
min-height: 280px;
transform: translateY(-10px);
&.normalized{
.nv-y{
text{
display: none;
}
}
}
&.without-data {
min-height: 306px;
}
Expand Down
9 changes: 8 additions & 1 deletion src/js/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ App.nl2br = function nl2br(str, is_xhtml) {
*/
App.formatDateTime = function(date, format){
if (typeof format === 'undefined') {
format = 'DD/MM/YYYY HH:mm';
format = 'DD/MM/YYYY - HH:mm';
}
return moment.utc(date).local().format(format);
}
Expand Down Expand Up @@ -613,6 +613,13 @@ $(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) {
if (!href.includes('/' + App.lang + '/'))
$(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()) {
Expand Down
27 changes: 20 additions & 7 deletions src/js/Collection/BaseCollection.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,23 +32,36 @@ 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));
}
});

App.Collection.Post = App.Collection.Base.extend({
fetch: function (options) {
options = _.defaults(options, {
// We transforms the options to JSON to merge with other options
if (typeof options !== 'undefined' && typeof options.data === 'string') {
options.data = JSON.parse(options.data);
}
// Default values
options = _.defaults(options || {}, {
type: 'POST',
contentType: 'application/json',
});

// Add initial model options
options = _.extend(this.options || {}, options);
options = _.extend({}, this.options || {}, options);

if (options.data) {
if (typeof options.data !== 'string') {
options.data = JSON.stringify(options.data);
}
// We transform to STRING to send in the requests
if (typeof options.data !== 'string') {
options.data = JSON.stringify(options.data);
}

return Backbone.Collection.prototype.fetch.call(this, options);
Expand Down
46 changes: 20 additions & 26 deletions src/js/Collection/DeviceCollection.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
// 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

Expand Down Expand Up @@ -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) {
Expand All @@ -180,9 +179,17 @@ App.Collection.DeviceTimeSerieChart = Backbone.Collection.extend({
var stepOption = options.data && options.data.time
? options.data.time.step || this.options.step
: this.options.step;
// Change step aggregation
var currentAggOptions = options.data && Array.isArray(options.data.agg)
? options.data.agg
: this.options.agg;
// Change noData option
var noData = options.data && options.data.noData
? options.data.noData
: this.options.data.noData || false

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,
Expand All @@ -194,7 +201,8 @@ App.Collection.DeviceTimeSerieChart = Backbone.Collection.extend({
condition: {
id_entity__eq: this.options.id
}
}
},
noData: noData
});

return Backbone.Collection.prototype.fetch.call(this, options);
Expand All @@ -206,21 +214,16 @@ 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] = [];
}
if (!r.data[k]) {
r.data[k] = 0;
}
aux[k].push({
x: moment(currentTimeDay + ' ' + currentTimeHour).toDate(),
y: k === 'seconds'
? r.data[k] / 60
x: moment.utc(r.time).toDate(),
y: k === 'seconds'
? r.data[k] / 60
: r.data[k]
});
});
Expand Down Expand Up @@ -250,24 +253,15 @@ 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: {}
});

if (typeof options.data === 'string') {
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();
Expand Down
113 changes: 59 additions & 54 deletions src/js/Collection/DevicesGroupTimeserieCollection.js
Original file line number Diff line number Diff line change
@@ -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.utc(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);
}
});
Loading

0 comments on commit 644df68

Please sign in to comment.