aboutsummaryrefslogtreecommitdiff
path: root/web/app/view/ReportController.js
diff options
context:
space:
mode:
Diffstat (limited to 'web/app/view/ReportController.js')
-rw-r--r--web/app/view/ReportController.js96
1 files changed, 86 insertions, 10 deletions
diff --git a/web/app/view/ReportController.js b/web/app/view/ReportController.js
index 775394d0..1f3f3a2a 100644
--- a/web/app/view/ReportController.js
+++ b/web/app/view/ReportController.js
@@ -32,11 +32,18 @@ Ext.define('Traccar.view.ReportController', {
listen: {
controller: {
'*': {
- selectdevice: 'selectDevice'
+ selectdevice: 'selectDevice',
+ showsingleevent: 'showSingleEvent'
},
'map': {
selectreport: 'selectReport'
}
+ },
+ store: {
+ '#ReportEvents': {
+ add: 'loadEvents',
+ load: 'loadEvents'
+ }
}
}
},
@@ -112,8 +119,8 @@ Ext.define('Traccar.view.ReportController', {
deviceId: this.deviceId,
groupId: this.groupId,
type: this.eventType,
- from: from.toISOString(),
- to: to.toISOString()
+ from: Ext.Date.format(from, 'c'),
+ to: Ext.Date.format(to, 'c')
});
}
}
@@ -126,7 +133,7 @@ Ext.define('Traccar.view.ReportController', {
clearReport: function (reportType) {
this.getView().getStore().removeAll();
- if (reportType === 'trips') {
+ if (reportType === 'trips' || reportType === 'events') {
Ext.getStore('ReportRoute').removeAll();
}
},
@@ -139,6 +146,9 @@ Ext.define('Traccar.view.ReportController', {
if (report instanceof Traccar.model.ReportTrip) {
this.selectTrip(report);
}
+ if (report instanceof Traccar.model.Event) {
+ this.selectEvent(report);
+ }
}
},
@@ -149,10 +159,16 @@ Ext.define('Traccar.view.ReportController', {
},
selectReport: function (object, center) {
- var reportType = this.lookupReference('reportTypeField').getValue();
- if (object instanceof Traccar.model.Position && reportType === 'route') {
- this.getView().getSelectionModel().select([object], false, true);
- this.getView().getView().focusRow(object);
+ var positionEvent, reportType = this.lookupReference('reportTypeField').getValue();
+ if (object instanceof Traccar.model.Position) {
+ if (reportType === 'route') {
+ this.getView().getSelectionModel().select([object], false, true);
+ this.getView().getView().focusRow(object);
+ } else if (reportType === 'events') {
+ positionEvent = this.getView().getStore().findRecord('positionId', object.get('id'), 0, false, true, true);
+ this.getView().getSelectionModel().select([positionEvent], false, true);
+ this.getView().getView().focusRow(positionEvent);
+ }
}
},
@@ -170,6 +186,67 @@ Ext.define('Traccar.view.ReportController', {
});
},
+ selectEvent: function (event) {
+ var position;
+ if (event.get('positionId')) {
+ position = Ext.getStore('ReportRoute').getById(event.get('positionId'));
+ if (position) {
+ this.fireEvent('selectreport', position, true);
+ }
+ }
+ },
+
+ loadEvents: function (store, data) {
+ var i, eventObject, positionIds = [];
+ Ext.getStore('ReportRoute').removeAll();
+ for (i = 0; i < data.length; i++) {
+ eventObject = data[i];
+ if (eventObject.get('positionId')) {
+ positionIds.push(eventObject.get('positionId'));
+ }
+ }
+ if (positionIds.length > 0) {
+ Ext.getStore('Positions').load({
+ 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,
@@ -272,8 +349,7 @@ Ext.define('Traccar.view.ReportController', {
text: Strings.sharedType,
dataIndex: 'type',
renderer: function (value) {
- var typeKey = 'event' + value.charAt(0).toUpperCase() + value.slice(1);
- return Strings[typeKey];
+ return Traccar.app.getEventString(value);
}
}, {
text: Strings.sharedGeofence,