aboutsummaryrefslogtreecommitdiff
path: root/web/app
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2017-06-07 08:21:06 -0700
committerGitHub <noreply@github.com>2017-06-07 08:21:06 -0700
commita330ae09293c62aae381cb2c7f36cfa76b86e813 (patch)
tree26478c08fc6f7136ec8355d13af2a1bbf97207dc /web/app
parentb6f2faab0d35d54189fefd7567b6310023c3ad7b (diff)
parente04a02921ea015d4f4fe69c1c3f1813a07be9cf4 (diff)
downloadtrackermap-web-a330ae09293c62aae381cb2c7f36cfa76b86e813.tar.gz
trackermap-web-a330ae09293c62aae381cb2c7f36cfa76b86e813.tar.bz2
trackermap-web-a330ae09293c62aae381cb2c7f36cfa76b86e813.zip
Merge pull request #501 from Abyss777/position_attributes_reports
Known position attributes for reports and charts
Diffstat (limited to 'web/app')
-rw-r--r--web/app/AttributeFormatter.js73
-rw-r--r--web/app/controller/Root.js24
-rw-r--r--web/app/model/Position.js32
-rw-r--r--web/app/model/ReportSummary.js9
-rw-r--r--web/app/model/ReportTrip.js9
-rw-r--r--web/app/store/DistanceUnits.js4
-rw-r--r--web/app/store/PositionAttributes.js2
-rw-r--r--web/app/store/ReportChartTypes.js12
-rw-r--r--web/app/store/SpeedUnits.js4
-rw-r--r--web/app/view/ReportController.js14
-rw-r--r--web/app/view/StateController.js9
-rw-r--r--web/app/view/dialog/ReportConfig.js2
-rw-r--r--web/app/view/edit/Attributes.js4
13 files changed, 122 insertions, 76 deletions
diff --git a/web/app/AttributeFormatter.js b/web/app/AttributeFormatter.js
index 302a8941..3f7c1276 100644
--- a/web/app/AttributeFormatter.js
+++ b/web/app/AttributeFormatter.js
@@ -18,6 +18,14 @@
Ext.define('Traccar.AttributeFormatter', {
singleton: true,
+ numberFormatterFactory: function (precision, suffix) {
+ return function (value) {
+ if (value !== undefined) {
+ return Number(value.toFixed(precision)) + ' ' + suffix;
+ }
+ };
+ },
+
coordinateFormatter: function (key, value) {
return Ext.getStore('CoordinateFormats').formatValue(key, value, Traccar.app.getPreference('coordinateFormat'));
},
@@ -26,6 +34,10 @@ Ext.define('Traccar.AttributeFormatter', {
return Ext.getStore('SpeedUnits').formatValue(value, Traccar.app.getPreference('speedUnit'));
},
+ speedConverter: function (value) {
+ return Ext.getStore('SpeedUnits').convertValue(value, Traccar.app.getPreference('speedUnit'));
+ },
+
courseFormatter: function (value) {
var courseValues = ['N', 'NE', 'E', 'SE', 'S', 'SW', 'W', 'NW'];
return courseValues[Math.floor(value / 45)];
@@ -35,24 +47,8 @@ Ext.define('Traccar.AttributeFormatter', {
return Ext.getStore('DistanceUnits').formatValue(value, Traccar.app.getPreference('distanceUnit'));
},
- voltageFormatter: function (value) {
- return Number(value.toFixed(Traccar.Style.numberPrecision)) + ' ' + Strings.sharedVoltAbbreviation;
- },
-
- percentageFormatter: function (value) {
- return Number(value.toFixed(Traccar.Style.numberPrecision)) + ' &#37;';
- },
-
- temperatureFormatter: function (value) {
- return Number(value.toFixed(Traccar.Style.numberPrecision)) + ' &deg;C';
- },
-
- volumeFormatter: function (value) {
- return Number(value.toFixed(Traccar.Style.numberPrecision)) + ' ' + Strings.sharedLiterAbbreviation;
- },
-
- consumptionFormatter: function (value) {
- return Number(value.toFixed(Traccar.Style.numberPrecision)) + ' ' + Strings.sharedLiterPerHourAbbreviation;
+ distanceConverter: function (value) {
+ return Ext.getStore('DistanceUnits').convertValue(value, Traccar.app.getPreference('distanceUnit'));
},
hoursFormatter: function (value) {
@@ -131,6 +127,18 @@ Ext.define('Traccar.AttributeFormatter', {
}
},
+ getConverter: function (key) {
+ if (key === 'speed') {
+ return this.speedConverter;
+ } else if (key === 'distance' || key === 'accuracy') {
+ return this.distanceConverter;
+ } else {
+ return function (value) {
+ return value;
+ };
+ }
+ },
+
getAttributeFormatter: function (key) {
var dataType = Ext.getStore('PositionAttributes').getAttributeDataType(key);
if (!dataType) {
@@ -141,18 +149,37 @@ Ext.define('Traccar.AttributeFormatter', {
} else if (dataType === 'speed') {
return this.speedFormatter;
} else if (dataType === 'voltage') {
- return this.voltageFormatter;
+ return this.numberFormatterFactory(Traccar.Style.numberPrecision, Strings.sharedVoltAbbreviation);
} else if (dataType === 'percentage') {
- return this.percentageFormatter;
+ return this.numberFormatterFactory(Traccar.Style.numberPrecision, '&#37;');
} else if (dataType === 'temperature') {
- return this.temperatureFormatter;
+ return this.numberFormatterFactory(Traccar.Style.numberPrecision, '&deg;C');
} else if (dataType === 'volume') {
- return this.volumeFormatter;
+ return this.numberFormatterFactory(Traccar.Style.numberPrecision, Strings.sharedLiterAbbreviation);
} else if (dataType === 'consumption') {
- return this.consumptionFormatter;
+ return this.numberFormatterFactory(Traccar.Style.numberPrecision, Strings.sharedLiterPerHourAbbreviation);
} else {
return this.defaultFormatter;
}
}
+ },
+
+ getAttributeConverter: function (key) {
+ var dataType = Ext.getStore('PositionAttributes').getAttributeDataType(key);
+ if (!dataType) {
+ return function (value) {
+ return value;
+ };
+ } else {
+ if (dataType === 'distance') {
+ return this.distanceConverter;
+ } else if (dataType === 'speed') {
+ return this.speedConverter;
+ } else {
+ return function (value) {
+ return value;
+ };
+ }
+ }
}
});
diff --git a/web/app/controller/Root.js b/web/app/controller/Root.js
index 8d604b62..5d22a74a 100644
--- a/web/app/controller/Root.js
+++ b/web/app/controller/Root.js
@@ -26,7 +26,31 @@ Ext.define('Traccar.controller.Root', {
],
init: function () {
+ var i, data, attribute, chartTypesStore = Ext.getStore('ReportChartTypes');
Ext.state.Manager.setProvider(new Ext.state.CookieProvider());
+ data = Ext.getStore('PositionAttributes').getData().items;
+ for (i = 0; i < data.length; i++) {
+ attribute = data[i];
+ Traccar.model.Position.addFields([{
+ name: 'attribute.' + attribute.get('key'),
+ attributeKey: attribute.get('key'),
+ calculate: this.calculateAttribute,
+ persist: false
+ }]);
+ if (attribute.get('valueType') === 'number') {
+ chartTypesStore.add({
+ key: 'attribute.' + attribute.get('key'),
+ name: attribute.get('name')
+ });
+ }
+ }
+ },
+
+ calculateAttribute: function (data) {
+ var value = data.attributes[this.attributeKey];
+ if (value !== undefined) {
+ return Traccar.AttributeFormatter.getAttributeConverter(this.attributeKey)(value);
+ }
},
onLaunch: function () {
diff --git a/web/app/model/Position.js b/web/app/model/Position.js
index 4b1a429f..6db54653 100644
--- a/web/app/model/Position.js
+++ b/web/app/model/Position.js
@@ -45,7 +45,8 @@ Ext.define('Traccar.model.Position', {
type: 'boolean'
}, {
name: 'accuracy',
- type: 'float'
+ type: 'float',
+ convert: Traccar.AttributeFormatter.getConverter('accuracy')
}, {
name: 'latitude',
type: 'float'
@@ -57,7 +58,8 @@ Ext.define('Traccar.model.Position', {
type: 'float'
}, {
name: 'speed',
- type: 'float'
+ type: 'float',
+ convert: Traccar.AttributeFormatter.getConverter('speed')
}, {
name: 'course',
type: 'float'
@@ -66,31 +68,5 @@ Ext.define('Traccar.model.Position', {
type: 'string'
}, {
name: 'attributes'
- }, {
- name: 'speedConverted',
- type: 'float',
- calculate: function (data) {
- return Ext.getStore('SpeedUnits').convertValue(
- data.speed, Traccar.app.getPreference('speedUnit'));
- }
- }, {
- name: 'distanceConverted',
- type: 'float',
- calculate: function (data) {
- return Ext.getStore('DistanceUnits').convertValue(
- data.attributes.distance, Traccar.app.getPreference('distanceUnit'));
- }
- }, {
- name: 'rpm',
- type: 'float',
- calculate: function (data) {
- return data.attributes.rpm;
- }
- }, {
- name: 'fuel',
- type: 'float',
- calculate: function (data) {
- return data.attributes.fuel;
- }
}]
});
diff --git a/web/app/model/ReportSummary.js b/web/app/model/ReportSummary.js
index d236ecd0..5cfbdcd7 100644
--- a/web/app/model/ReportSummary.js
+++ b/web/app/model/ReportSummary.js
@@ -28,13 +28,16 @@ Ext.define('Traccar.model.ReportSummary', {
type: 'string'
}, {
name: 'maxSpeed',
- type: 'float'
+ type: 'float',
+ convert: Traccar.AttributeFormatter.getConverter('speed')
}, {
name: 'averageSpeed',
- type: 'float'
+ type: 'float',
+ convert: Traccar.AttributeFormatter.getConverter('speed')
}, {
name: 'distance',
- type: 'float'
+ type: 'float',
+ convert: Traccar.AttributeFormatter.getConverter('distance')
}, {
name: 'engineHours',
type: 'int'
diff --git a/web/app/model/ReportTrip.js b/web/app/model/ReportTrip.js
index 51f98078..d243a8ae 100644
--- a/web/app/model/ReportTrip.js
+++ b/web/app/model/ReportTrip.js
@@ -28,13 +28,16 @@ Ext.define('Traccar.model.ReportTrip', {
type: 'string'
}, {
name: 'maxSpeed',
- type: 'float'
+ type: 'float',
+ convert: Traccar.AttributeFormatter.getConverter('speed')
}, {
name: 'averageSpeed',
- type: 'float'
+ type: 'float',
+ convert: Traccar.AttributeFormatter.getConverter('speed')
}, {
name: 'distance',
- type: 'float'
+ type: 'float',
+ convert: Traccar.AttributeFormatter.getConverter('distance')
}, {
name: 'duration',
type: 'int'
diff --git a/web/app/store/DistanceUnits.js b/web/app/store/DistanceUnits.js
index 514a051e..e64ce234 100644
--- a/web/app/store/DistanceUnits.js
+++ b/web/app/store/DistanceUnits.js
@@ -42,12 +42,12 @@ Ext.define('Traccar.store.DistanceUnits', {
return back ? value / model.get('factor') : value * model.get('factor');
},
- formatValue: function (value, unit) {
+ formatValue: function (value, unit, convert) {
var model;
if (!unit) {
unit = 'km';
}
model = this.findRecord('key', unit);
- return this.convertValue(value, unit).toFixed(2) + ' ' + model.get('name');
+ return (convert ? this.convertValue(value, unit) : value).toFixed(2) + ' ' + model.get('name');
}
});
diff --git a/web/app/store/PositionAttributes.js b/web/app/store/PositionAttributes.js
index 985c558e..72154297 100644
--- a/web/app/store/PositionAttributes.js
+++ b/web/app/store/PositionAttributes.js
@@ -62,7 +62,7 @@ Ext.define('Traccar.store.PositionAttributes', {
valueType: 'string'
}, {
key: 'alarm',
- name: Strings.alarm,
+ name: Strings.positionAlarm,
valueType: 'string'
}, {
key: 'status',
diff --git a/web/app/store/ReportChartTypes.js b/web/app/store/ReportChartTypes.js
index 889db50d..8ca074f3 100644
--- a/web/app/store/ReportChartTypes.js
+++ b/web/app/store/ReportChartTypes.js
@@ -21,16 +21,10 @@ Ext.define('Traccar.store.ReportChartTypes', {
fields: ['key', 'name'],
data: [{
- key: 'speedConverted',
+ key: 'speed',
name: Strings.positionSpeed
}, {
- key: 'distanceConverted',
- name: Strings.positionDistance
- }, {
- key: 'rpm',
- name: Strings.positionRpm
- }, {
- key: 'fuel',
- name: Strings.positionFuel
+ key: 'accuracy',
+ name: Strings.positionAccuracy
}]
});
diff --git a/web/app/store/SpeedUnits.js b/web/app/store/SpeedUnits.js
index ce976952..a36be928 100644
--- a/web/app/store/SpeedUnits.js
+++ b/web/app/store/SpeedUnits.js
@@ -42,12 +42,12 @@ Ext.define('Traccar.store.SpeedUnits', {
return back ? value / model.get('factor') : value * model.get('factor');
},
- formatValue: function (value, unit) {
+ formatValue: function (value, unit, convert) {
var model;
if (!unit) {
unit = 'kn';
}
model = this.findRecord('key', unit);
- return this.convertValue(value, unit).toFixed(1) + ' ' + model.get('name');
+ return (convert ? this.convertValue(value, unit) : value).toFixed(1) + ' ' + model.get('name');
}
});
diff --git a/web/app/view/ReportController.js b/web/app/view/ReportController.js
index d83d9986..3daa2957 100644
--- a/web/app/view/ReportController.js
+++ b/web/app/view/ReportController.js
@@ -64,6 +64,20 @@ Ext.define('Traccar.view.ReportController', {
return this.getView().getComponent('chart');
},
+ init: function () {
+ var i, data, attribute;
+ data = Ext.getStore('PositionAttributes').getData().items;
+ for (i = 0; i < data.length; i++) {
+ attribute = data[i];
+ this.routeColumns.push({
+ text: attribute.get('name'),
+ dataIndex: 'attribute.' + attribute.get('key'),
+ renderer: Traccar.AttributeFormatter.getAttributeFormatter(attribute.get('key')),
+ hidden: true
+ });
+ }
+ },
+
onConfigureClick: function () {
var dialog = Ext.create('Traccar.view.dialog.ReportConfig');
dialog.lookupReference('eventTypeField').setHidden(this.lookupReference('reportTypeField').getValue() !== 'events');
diff --git a/web/app/view/StateController.js b/web/app/view/StateController.js
index 0723dc13..4c99a8be 100644
--- a/web/app/view/StateController.js
+++ b/web/app/view/StateController.js
@@ -101,7 +101,7 @@ Ext.define('Traccar.view.StateController', {
},
updatePosition: function () {
- var attributes, store, key, aliasIndex, name;
+ var attributes, store, key, aliasIndex, name, value;
store = Ext.getStore('Attributes');
store.removeAll();
@@ -126,11 +126,16 @@ Ext.define('Traccar.view.StateController', {
} else {
name = Ext.getStore('PositionAttributes').getAttributeName(key, true);
}
+ if (this.position.get('attribute.' + key) !== undefined) {
+ value = Traccar.AttributeFormatter.getAttributeFormatter(key)(this.position.get('attribute.' + key));
+ } else {
+ value = Traccar.AttributeFormatter.defaultFormatter(attributes[key]);
+ }
store.add(Ext.create('Traccar.model.Attribute', {
priority: 1024,
name: name,
attribute: key,
- value: Traccar.AttributeFormatter.getAttributeFormatter(key)(attributes[key])
+ value: value
}));
}
}
diff --git a/web/app/view/dialog/ReportConfig.js b/web/app/view/dialog/ReportConfig.js
index b8493cbb..836b6050 100644
--- a/web/app/view/dialog/ReportConfig.js
+++ b/web/app/view/dialog/ReportConfig.js
@@ -61,7 +61,7 @@ Ext.define('Traccar.view.dialog.ReportConfig', {
reference: 'chartTypeField',
store: 'ReportChartTypes',
hidden: true,
- value: 'speedConverted',
+ value: 'speed',
valueField: 'key',
displayField: 'name',
queryMode: 'local'
diff --git a/web/app/view/edit/Attributes.js b/web/app/view/edit/Attributes.js
index b080e569..66d8bb12 100644
--- a/web/app/view/edit/Attributes.js
+++ b/web/app/view/edit/Attributes.js
@@ -58,9 +58,9 @@ Ext.define('Traccar.view.edit.Attributes', {
attribute = Ext.getStore(this.attributesStore).getById(record.get('name'));
}
if (attribute && attribute.get('dataType') === 'speed') {
- return Ext.getStore('SpeedUnits').formatValue(value, Traccar.app.getPreference('speedUnit', 'kn'));
+ return Ext.getStore('SpeedUnits').formatValue(value, Traccar.app.getPreference('speedUnit', 'kn'), true);
} else if (attribute && attribute.get('dataType') === 'distance') {
- return Ext.getStore('DistanceUnits').formatValue(value, Traccar.app.getPreference('distanceUnit', 'km'));
+ return Ext.getStore('DistanceUnits').formatValue(value, Traccar.app.getPreference('distanceUnit', 'km'), true);
} else {
return value;
}