From b53b223a07dbba48321d42204ffbb07a33ac2caf Mon Sep 17 00:00:00 2001 From: Abyss777 Date: Thu, 1 Dec 2016 12:00:19 +0500 Subject: - Handle eventId url parameter - Fit map view to events positions markers --- web/app/Application.js | 10 +++++++++- web/app/view/MapMarkerController.js | 15 ++++++++++++++- web/app/view/ReportController.js | 29 +++++++++++++++++++++++++++++ 3 files changed, 52 insertions(+), 2 deletions(-) (limited to 'web') diff --git a/web/app/Application.js b/web/app/Application.js index 8619ba96..bae3896e 100644 --- a/web/app/Application.js +++ b/web/app/Application.js @@ -141,5 +141,13 @@ Ext.define('Traccar.Application', { } else { Ext.Msg.alert(Strings.errorTitle, Strings.errorConnection); } - } + }, + + removeUrlParameter: function (param) { + var params = Ext.Object.fromQueryString(window.location.search); + delete params[param]; + window.history.pushState(null, null, window.location.pathname + '?' + Ext.Object.toQueryString(params)); + }, + + hasEventId: false }); diff --git a/web/app/view/MapMarkerController.js b/web/app/view/MapMarkerController.js index 97e75925..9b699c04 100644 --- a/web/app/view/MapMarkerController.js +++ b/web/app/view/MapMarkerController.js @@ -225,7 +225,7 @@ Ext.define('Traccar.view.MapMarkerController', { }, addReportMarkers: function (store, data) { - var i, position, point, geometry, marker, style; + var i, position, point, geometry, marker, style, minx, miny, maxx, maxy; this.clearReport(); for (i = 0; i < data.length; i++) { position = data[i]; @@ -233,6 +233,10 @@ Ext.define('Traccar.view.MapMarkerController', { position.get('longitude'), position.get('latitude') ]); + minx = minx ? Math.min(point[0], minx) : point[0]; + miny = miny ? Math.min(point[1], miny) : point[1]; + maxx = maxx ? Math.max(point[0], maxx) : point[0]; + maxy = maxy ? Math.max(point[1], maxy) : point[1]; geometry = new ol.geom.Point(point); marker = new ol.Feature(geometry); marker.set('record', position); @@ -243,6 +247,15 @@ Ext.define('Traccar.view.MapMarkerController', { this.reportMarkers[position.get('id')] = marker; this.getView().getReportSource().addFeature(marker); } + if (minx !== maxx || miny !== maxy) { + this.getView().getMapView().fit([minx, miny, maxx, maxy], this.getView().getMap().getSize()); + } else if (geometry) { + this.getView().getMapView().fit(geometry, this.getView().getMap().getSize()); + } + if (Traccar.app.hasEventId) { + this.fireEvent('selectreport', data[0], false); + Traccar.app.hasEventId = false; + } }, clearReport: function () { diff --git a/web/app/view/ReportController.js b/web/app/view/ReportController.js index f8a01bc6..32a44df5 100644 --- a/web/app/view/ReportController.js +++ b/web/app/view/ReportController.js @@ -40,12 +40,32 @@ Ext.define('Traccar.view.ReportController', { }, store: { '#ReportEvents': { + add: 'loadEvents', load: 'loadEvents' } } } }, + init: function () { + var eventId = Ext.Object.fromQueryString(window.location.search).eventId; + if (eventId) { + this.lookupReference('reportTypeField').setValue('events'); + Ext.getStore('Events').load({ + params: { + id: eventId + }, + callback: function (records, operation, success) { + if (success) { + Ext.getStore('ReportEvents').add(records); + } + } + }); + Traccar.app.hasEventId = true; + Traccar.app.removeUrlParameter('eventId'); + } + }, + hideReports: function () { Traccar.app.showReports(false); }, @@ -214,6 +234,15 @@ Ext.define('Traccar.view.ReportController', { } } }); + } else if (Traccar.app.hasEventId && data.length > 0) { + this.getView().getSelectionModel().select([data[0]], false, true); + this.getView().getView().focusRow(data[0]); + if (Traccar.app.isMobile()) { + Traccar.app.showReports(true); + } else { + this.getView().expand(); + } + Traccar.app.hasEventId = false; } }, -- cgit v1.2.3 From 74072cf3ca6acf67d228287e446e3013277e7408 Mon Sep 17 00:00:00 2001 From: Abyss777 Date: Thu, 1 Dec 2016 12:12:54 +0500 Subject: Remove map view fit from loadReport --- web/app/view/MapMarkerController.js | 32 ++++++++++++++------------------ 1 file changed, 14 insertions(+), 18 deletions(-) (limited to 'web') diff --git a/web/app/view/MapMarkerController.js b/web/app/view/MapMarkerController.js index 9b699c04..71a15839 100644 --- a/web/app/view/MapMarkerController.js +++ b/web/app/view/MapMarkerController.js @@ -202,25 +202,21 @@ Ext.define('Traccar.view.MapMarkerController', { this.addReportMarkers(store, data); - if (data.length > 0) { - this.reportRoute = []; - for (i = 0; i < data.length; i++) { - position = data[i]; - point = ol.proj.fromLonLat([ - position.get('longitude'), - position.get('latitude') - ]); - if (i === 0 || data[i].get('deviceId') !== data[i - 1].get('deviceId')) { - this.reportRoute.push(new ol.Feature({ - geometry: new ol.geom.LineString([]) - })); - this.reportRoute[this.reportRoute.length - 1].setStyle(this.getRouteStyle(data[i].get('deviceId'))); - this.getView().getRouteSource().addFeature(this.reportRoute[this.reportRoute.length - 1]); - } - this.reportRoute[this.reportRoute.length - 1].getGeometry().appendCoordinate(point); + this.reportRoute = []; + for (i = 0; i < data.length; i++) { + position = data[i]; + point = ol.proj.fromLonLat([ + position.get('longitude'), + position.get('latitude') + ]); + if (i === 0 || data[i].get('deviceId') !== data[i - 1].get('deviceId')) { + this.reportRoute.push(new ol.Feature({ + geometry: new ol.geom.LineString([]) + })); + this.reportRoute[this.reportRoute.length - 1].setStyle(this.getRouteStyle(data[i].get('deviceId'))); + this.getView().getRouteSource().addFeature(this.reportRoute[this.reportRoute.length - 1]); } - - this.getView().getMapView().fit(this.reportRoute[0].getGeometry(), this.getView().getMap().getSize()); + this.reportRoute[this.reportRoute.length - 1].getGeometry().appendCoordinate(point); } }, -- cgit v1.2.3 From 42574b6700384bd8a45d3410c4f8da644dad112e Mon Sep 17 00:00:00 2001 From: Abyss777 Date: Thu, 1 Dec 2016 17:30:50 +0500 Subject: Implement in other way --- web/app/Application.js | 10 +------ web/app/controller/Root.js | 13 ++++++++- web/app/store/Positions.js | 5 +++- web/app/view/MapMarkerController.js | 11 ++++++-- web/app/view/ReportController.js | 55 ++++++++++++++++++------------------- 5 files changed, 51 insertions(+), 43 deletions(-) (limited to 'web') diff --git a/web/app/Application.js b/web/app/Application.js index bae3896e..8619ba96 100644 --- a/web/app/Application.js +++ b/web/app/Application.js @@ -141,13 +141,5 @@ Ext.define('Traccar.Application', { } else { Ext.Msg.alert(Strings.errorTitle, Strings.errorConnection); } - }, - - removeUrlParameter: function (param) { - var params = Ext.Object.fromQueryString(window.location.search); - delete params[param]; - window.history.pushState(null, null, window.location.pathname + '?' + Ext.Object.toQueryString(params)); - }, - - hasEventId: false + } }); diff --git a/web/app/controller/Root.js b/web/app/controller/Root.js index 5600d4e8..379a0d8a 100644 --- a/web/app/controller/Root.js +++ b/web/app/controller/Root.js @@ -75,7 +75,7 @@ Ext.define('Traccar.controller.Root', { }, loadApp: function () { - var attribution; + var attribution, eventId; Ext.getStore('Groups').load(); Ext.getStore('Geofences').load(); Ext.getStore('AttributeAliases').load(); @@ -94,6 +94,11 @@ Ext.define('Traccar.controller.Root', { } else { Ext.create('widget.main'); } + eventId = Ext.Object.fromQueryString(window.location.search).eventId; + if (eventId) { + this.application.fireEvent('showSingleEvent', eventId); + //this.removeUrlParameter('eventId'); + } }, beep: function () { @@ -108,6 +113,12 @@ Ext.define('Traccar.controller.Root', { return muteButton && !muteButton.pressed; }, + removeUrlParameter: function (param) { + var params = Ext.Object.fromQueryString(window.location.search); + delete params[param]; + window.history.pushState(null, null, window.location.pathname + '?' + Ext.Object.toQueryString(params)); + }, + asyncUpdate: function (first) { var protocol, pathname, socket, self = this; protocol = window.location.protocol === 'https:' ? 'wss:' : 'ws:'; diff --git a/web/app/store/Positions.js b/web/app/store/Positions.js index 8f185af1..388a3320 100644 --- a/web/app/store/Positions.js +++ b/web/app/store/Positions.js @@ -21,6 +21,9 @@ Ext.define('Traccar.store.Positions', { proxy: { type: 'rest', - url: 'api/positions' + url: 'api/positions', + headers: { + 'Accept': 'application/json' + } } }); diff --git a/web/app/view/MapMarkerController.js b/web/app/view/MapMarkerController.js index 71a15839..596cffb3 100644 --- a/web/app/view/MapMarkerController.js +++ b/web/app/view/MapMarkerController.js @@ -31,7 +31,8 @@ Ext.define('Traccar.view.MapMarkerController', { controller: { '*': { selectdevice: 'selectDevice', - selectreport: 'selectReport' + selectreport: 'selectReport', + showsingleevent: 'showSingleEvent' } }, store: { @@ -65,6 +66,10 @@ Ext.define('Traccar.view.MapMarkerController', { this.liveRouteLength = Traccar.app.getAttributePreference('web.liveRouteLength', 10); }, + showSingleEvent: function () { + this.singleEvent = true; + }, + getDeviceColor: function (device) { switch (device.get('status')) { case 'online': @@ -248,9 +253,9 @@ Ext.define('Traccar.view.MapMarkerController', { } else if (geometry) { this.getView().getMapView().fit(geometry, this.getView().getMap().getSize()); } - if (Traccar.app.hasEventId) { + if (this.singleEvent) { + this.singleEvent = false; this.fireEvent('selectreport', data[0], false); - Traccar.app.hasEventId = false; } }, diff --git a/web/app/view/ReportController.js b/web/app/view/ReportController.js index 32a44df5..e1a64e69 100644 --- a/web/app/view/ReportController.js +++ b/web/app/view/ReportController.js @@ -32,7 +32,8 @@ Ext.define('Traccar.view.ReportController', { listen: { controller: { '*': { - selectdevice: 'selectDevice' + selectdevice: 'selectDevice', + showsingleevent: 'showSingleEvent' }, 'map': { selectreport: 'selectReport' @@ -47,25 +48,6 @@ Ext.define('Traccar.view.ReportController', { } }, - init: function () { - var eventId = Ext.Object.fromQueryString(window.location.search).eventId; - if (eventId) { - this.lookupReference('reportTypeField').setValue('events'); - Ext.getStore('Events').load({ - params: { - id: eventId - }, - callback: function (records, operation, success) { - if (success) { - Ext.getStore('ReportEvents').add(records); - } - } - }); - Traccar.app.hasEventId = true; - Traccar.app.removeUrlParameter('eventId'); - } - }, - hideReports: function () { Traccar.app.showReports(false); }, @@ -234,18 +216,33 @@ Ext.define('Traccar.view.ReportController', { } } }); - } else if (Traccar.app.hasEventId && data.length > 0) { - this.getView().getSelectionModel().select([data[0]], false, true); - this.getView().getView().focusRow(data[0]); - if (Traccar.app.isMobile()) { - Traccar.app.showReports(true); - } else { - this.getView().expand(); - } - Traccar.app.hasEventId = false; } }, + showSingleEvent: function (eventId) { + this.lookupReference('reportTypeField').setValue('events'); + Ext.getStore('Events').load({ + id: eventId, + scope: this, + callback: function (records, operation, success) { + if (success) { + Ext.getStore('ReportEvents').add(records); + if (records.length > 0) { + if (!records[0].get('positionId')) { + if (Traccar.app.isMobile()) { + Traccar.app.showReports(true); + } else { + this.getView().expand(); + } + } + this.getView().getSelectionModel().select([records[0]], false, true); + this.getView().getView().focusRow(records[0]); + } + } + } + }); + }, + downloadFile: function (requestUrl, requestParams) { Ext.Ajax.request({ url: requestUrl, -- cgit v1.2.3 From 5433c47155452951b8c75587725bf6c92f8ff11d Mon Sep 17 00:00:00 2001 From: Abyss777 Date: Thu, 1 Dec 2016 17:45:19 +0500 Subject: Handle 'showsingleevent' only in one place --- web/app/view/MapMarkerController.js | 11 +---------- web/app/view/ReportController.js | 6 ++++++ 2 files changed, 7 insertions(+), 10 deletions(-) (limited to 'web') diff --git a/web/app/view/MapMarkerController.js b/web/app/view/MapMarkerController.js index 596cffb3..a526d912 100644 --- a/web/app/view/MapMarkerController.js +++ b/web/app/view/MapMarkerController.js @@ -31,8 +31,7 @@ Ext.define('Traccar.view.MapMarkerController', { controller: { '*': { selectdevice: 'selectDevice', - selectreport: 'selectReport', - showsingleevent: 'showSingleEvent' + selectreport: 'selectReport' } }, store: { @@ -66,10 +65,6 @@ Ext.define('Traccar.view.MapMarkerController', { this.liveRouteLength = Traccar.app.getAttributePreference('web.liveRouteLength', 10); }, - showSingleEvent: function () { - this.singleEvent = true; - }, - getDeviceColor: function (device) { switch (device.get('status')) { case 'online': @@ -253,10 +248,6 @@ Ext.define('Traccar.view.MapMarkerController', { } else if (geometry) { this.getView().getMapView().fit(geometry, this.getView().getMap().getSize()); } - if (this.singleEvent) { - this.singleEvent = false; - this.fireEvent('selectreport', data[0], false); - } }, clearReport: function () { diff --git a/web/app/view/ReportController.js b/web/app/view/ReportController.js index e1a64e69..97407e23 100644 --- a/web/app/view/ReportController.js +++ b/web/app/view/ReportController.js @@ -210,9 +210,14 @@ Ext.define('Traccar.view.ReportController', { params: { id: positionIds }, + scope: this, callback: function (records, operation, success) { if (success) { Ext.getStore('ReportRoute').add(records); + if (this.singleEvent) { + this.singleEvent = false; + this.fireEvent('selectreport', records[0], false); + } } } }); @@ -220,6 +225,7 @@ Ext.define('Traccar.view.ReportController', { }, showSingleEvent: function (eventId) { + this.singleEvent = true; this.lookupReference('reportTypeField').setValue('events'); Ext.getStore('Events').load({ id: eventId, -- cgit v1.2.3 From b64e51da50e4b3f56b1022cdd82e2ce57188a1b9 Mon Sep 17 00:00:00 2001 From: Abyss777 Date: Thu, 1 Dec 2016 17:49:16 +0500 Subject: Add check --- web/app/view/ReportController.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'web') diff --git a/web/app/view/ReportController.js b/web/app/view/ReportController.js index 97407e23..2ad2bdda 100644 --- a/web/app/view/ReportController.js +++ b/web/app/view/ReportController.js @@ -214,7 +214,7 @@ Ext.define('Traccar.view.ReportController', { callback: function (records, operation, success) { if (success) { Ext.getStore('ReportRoute').add(records); - if (this.singleEvent) { + if (this.singleEvent && records.length > 0) { this.singleEvent = false; this.fireEvent('selectreport', records[0], false); } -- cgit v1.2.3 From 1aae9dee5ecd797c3c2d2a6e985f605d783620ee Mon Sep 17 00:00:00 2001 From: Abyss777 Date: Thu, 1 Dec 2016 18:05:10 +0500 Subject: Improve firing event --- web/app/controller/Root.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'web') diff --git a/web/app/controller/Root.js b/web/app/controller/Root.js index 379a0d8a..1e83a45f 100644 --- a/web/app/controller/Root.js +++ b/web/app/controller/Root.js @@ -96,7 +96,7 @@ Ext.define('Traccar.controller.Root', { } eventId = Ext.Object.fromQueryString(window.location.search).eventId; if (eventId) { - this.application.fireEvent('showSingleEvent', eventId); + this.fireEvent('showsingleevent', eventId); //this.removeUrlParameter('eventId'); } }, -- cgit v1.2.3 From ea09b2e85e014d438084a454fae7c0cce57d9773 Mon Sep 17 00:00:00 2001 From: Abyss777 Date: Fri, 2 Dec 2016 09:29:08 +0700 Subject: - Remove single event - Redo ol.extent calculation with less compares - Uncomment url manipulation --- web/app/controller/Root.js | 2 +- web/app/view/MapMarkerController.js | 13 +++++++++---- web/app/view/ReportController.js | 4 +--- 3 files changed, 11 insertions(+), 8 deletions(-) (limited to 'web') diff --git a/web/app/controller/Root.js b/web/app/controller/Root.js index 1e83a45f..87c4cf5e 100644 --- a/web/app/controller/Root.js +++ b/web/app/controller/Root.js @@ -97,7 +97,7 @@ Ext.define('Traccar.controller.Root', { eventId = Ext.Object.fromQueryString(window.location.search).eventId; if (eventId) { this.fireEvent('showsingleevent', eventId); - //this.removeUrlParameter('eventId'); + this.removeUrlParameter('eventId'); } }, diff --git a/web/app/view/MapMarkerController.js b/web/app/view/MapMarkerController.js index a526d912..5fa9f4ca 100644 --- a/web/app/view/MapMarkerController.js +++ b/web/app/view/MapMarkerController.js @@ -229,10 +229,15 @@ Ext.define('Traccar.view.MapMarkerController', { position.get('longitude'), position.get('latitude') ]); - minx = minx ? Math.min(point[0], minx) : point[0]; - miny = miny ? Math.min(point[1], miny) : point[1]; - maxx = maxx ? Math.max(point[0], maxx) : point[0]; - maxy = maxy ? Math.max(point[1], maxy) : point[1]; + if (i === 0) { + minx = maxx = point[0]; + miny = maxy = point[1]; + } else { + minx = Math.min(point[0], minx); + miny = Math.min(point[1], miny); + maxx = Math.max(point[0], maxx); + maxy = Math.max(point[1], maxy); + } geometry = new ol.geom.Point(point); marker = new ol.Feature(geometry); marker.set('record', position); diff --git a/web/app/view/ReportController.js b/web/app/view/ReportController.js index 2ad2bdda..1f3f3a2a 100644 --- a/web/app/view/ReportController.js +++ b/web/app/view/ReportController.js @@ -214,8 +214,7 @@ Ext.define('Traccar.view.ReportController', { callback: function (records, operation, success) { if (success) { Ext.getStore('ReportRoute').add(records); - if (this.singleEvent && records.length > 0) { - this.singleEvent = false; + if (records.length === 1) { this.fireEvent('selectreport', records[0], false); } } @@ -225,7 +224,6 @@ Ext.define('Traccar.view.ReportController', { }, showSingleEvent: function (eventId) { - this.singleEvent = true; this.lookupReference('reportTypeField').setValue('events'); Ext.getStore('Events').load({ id: eventId, -- cgit v1.2.3