aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2016-12-02 18:46:55 +1300
committerGitHub <noreply@github.com>2016-12-02 18:46:55 +1300
commitf8bf7ede29f2e063a30721e8ed415a6184646424 (patch)
tree43259e48230270edaed0a1981e8ef975508c9831
parent6d447219ceab19c368b7ca6efabca83001b64a04 (diff)
parentea09b2e85e014d438084a454fae7c0cce57d9773 (diff)
downloadtrackermap-web-f8bf7ede29f2e063a30721e8ed415a6184646424.tar.gz
trackermap-web-f8bf7ede29f2e063a30721e8ed415a6184646424.tar.bz2
trackermap-web-f8bf7ede29f2e063a30721e8ed415a6184646424.zip
Merge pull request #347 from Abyss777/handle_eventid
Handle eventId url parameter
-rw-r--r--web/app/controller/Root.js13
-rw-r--r--web/app/store/Positions.js5
-rw-r--r--web/app/view/MapMarkerController.js48
-rw-r--r--web/app/view/ReportController.js32
4 files changed, 76 insertions, 22 deletions
diff --git a/web/app/controller/Root.js b/web/app/controller/Root.js
index 5600d4e8..87c4cf5e 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.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 97e75925..5fa9f4ca 100644
--- a/web/app/view/MapMarkerController.js
+++ b/web/app/view/MapMarkerController.js
@@ -202,30 +202,26 @@ 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);
}
},
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 +229,15 @@ Ext.define('Traccar.view.MapMarkerController', {
position.get('longitude'),
position.get('latitude')
]);
+ 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);
@@ -243,6 +248,11 @@ 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());
+ }
},
clearReport: function () {
diff --git a/web/app/view/ReportController.js b/web/app/view/ReportController.js
index f8a01bc6..1f3f3a2a 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'
@@ -40,6 +41,7 @@ Ext.define('Traccar.view.ReportController', {
},
store: {
'#ReportEvents': {
+ add: 'loadEvents',
load: 'loadEvents'
}
}
@@ -208,15 +210,43 @@ Ext.define('Traccar.view.ReportController', {
params: {
id: positionIds
},
+ scope: this,
callback: function (records, operation, success) {
if (success) {
Ext.getStore('ReportRoute').add(records);
+ if (records.length === 1) {
+ this.fireEvent('selectreport', records[0], 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,