From 28d60da9a2f80fa8fc3dd28ec5bdd7847a36727c Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Mon, 16 Nov 2015 12:24:24 +1300 Subject: Extend async request to include devices --- src/org/traccar/web/AsyncServlet.java | 11 ++++++++++- web/app/controller/Root.js | 13 ++++++++----- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/src/org/traccar/web/AsyncServlet.java b/src/org/traccar/web/AsyncServlet.java index 3347f765c..ddcbce2ff 100644 --- a/src/org/traccar/web/AsyncServlet.java +++ b/src/org/traccar/web/AsyncServlet.java @@ -158,7 +158,16 @@ public class AsyncServlet extends BaseServlet { JsonObjectBuilder result = Json.createObjectBuilder(); result.add("success", true); - result.add("data", JsonConverter.arrayToJson(positions.values())); + + if (Context.getConfig().getBoolean("web.oldAsyncFormat")) { + result.add("data", JsonConverter.arrayToJson(positions.values())); + } else { + JsonObjectBuilder data = Json.createObjectBuilder(); + data.add("devices", Json.createArrayBuilder().build()); // TODO: send device status + data.add("positions", JsonConverter.arrayToJson(positions.values())); + result.add("data", data.build()); + } + positions.clear(); try { diff --git a/web/app/controller/Root.js b/web/app/controller/Root.js index 79827b8a6..b260cb8a1 100644 --- a/web/app/controller/Root.js +++ b/web/app/controller/Root.js @@ -96,19 +96,22 @@ Ext.define('Traccar.controller.Root', { first: first }, callback: Traccar.app.getErrorHandler(this, function (options, success, response) { - var i, store, data, position; + var i, store, data, devices, positions, position; if (success) { store = Ext.getStore('LatestPositions'); data = Ext.decode(response.responseText).data; + devices = data.devices; + positions = data.positions; - for (i = 0; i < data.length; i++) { - position = store.findRecord('deviceId', data[i].deviceId, 0, false, false, true); + for (i = 0; i < positions.length; i++) { + position = store.findRecord('deviceId', positions[i].deviceId, 0, false, false, true); if (position) { - position.set(data[i]); + position.set(positions[i]); } else { - store.add(Ext.create('Traccar.model.Position', data[i])); + store.add(Ext.create('Traccar.model.Position', positions[i])); } } + this.asyncUpdate(false); } }) -- cgit v1.2.3