Display state info from reports

This commit is contained in:
Anton Tananaev
2015-11-08 13:31:04 +13:00
parent d2f8ca9cb1
commit ea38e23c5c

View File

@@ -28,8 +28,11 @@ Ext.define('Traccar.view.StateController', {
},
store: {
'#LatestPositions': {
add: 'update',
update: 'update'
add: 'updateLatest',
update: 'updateLatest'
},
'#Positions': {
clear: 'clearReport'
}
}
}
@@ -50,6 +53,18 @@ Ext.define('Traccar.view.StateController', {
return result;
}()),
updateLatest: function (store, data) {
var i;
if (!Ext.isArray(data)) {
data = [data];
}
for (i = 0; i < data.length; i++) {
if (this.deviceId === data[i].get('deviceId')) {
this.updatePosition(data[i]);
}
}
},
formatValue: function (value) {
if (typeof (id) === 'number') {
return Number(value.toFixed(2));
@@ -90,29 +105,22 @@ Ext.define('Traccar.view.StateController', {
},
selectDevice: function (device) {
var found;
var position;
this.deviceId = device.get('id');
found = Ext.getStore('LatestPositions').findRecord('deviceId', this.deviceId, 0, false, false, true);
if (found) {
this.updatePosition(found);
position = Ext.getStore('LatestPositions').findRecord('deviceId', this.deviceId, 0, false, false, true);
if (position) {
this.updatePosition(position);
} else {
Ext.getStore('Attributes').removeAll();
}
},
selectReport: function (position) {
console.log(position);
this.deviceId = null;
this.updatePosition(position);
},
update: function (store, data) {
var i;
if (!Ext.isArray(data)) {
data = [data];
}
for (i = 0; i < data.length; i++) {
if (this.deviceId === data[i].get('deviceId')) {
this.updatePosition(data[0]);
}
}
clearReport: function (store) {
Ext.getStore('Attributes').removeAll();
}
});