aboutsummaryrefslogtreecommitdiff
path: root/web
diff options
context:
space:
mode:
authorAbyss777 <abyss@fox5.ru>2017-06-06 11:43:09 +0500
committerAbyss777 <abyss@fox5.ru>2017-06-06 11:43:09 +0500
commitf538963be5fcee2280b22050c8a51475c3a984f8 (patch)
tree6a08cb27c330480b60bb8fd160570e308802de0c /web
parentb6f2faab0d35d54189fefd7567b6310023c3ad7b (diff)
downloadtrackermap-web-f538963be5fcee2280b22050c8a51475c3a984f8.tar.gz
trackermap-web-f538963be5fcee2280b22050c8a51475c3a984f8.tar.bz2
trackermap-web-f538963be5fcee2280b22050c8a51475c3a984f8.zip
- Reworked fields and attributes formatting
- Convert position and reports fields in the model - Add hidden columns to Route report - Add Number attributes to possible chart types
Diffstat (limited to 'web')
-rw-r--r--web/app/AttributeFormatter.js70
-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.js9
-rw-r--r--web/app/store/PositionAttributes.js2
-rw-r--r--web/app/store/ReportChartTypes.js12
-rw-r--r--web/app/store/SpeedUnits.js9
-rw-r--r--web/app/view/ReportController.js18
-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
-rw-r--r--web/l10n/en.json2
14 files changed, 162 insertions, 49 deletions
diff --git a/web/app/AttributeFormatter.js b/web/app/AttributeFormatter.js
index 302a8941..9d66794d 100644
--- a/web/app/AttributeFormatter.js
+++ b/web/app/AttributeFormatter.js
@@ -26,6 +26,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,26 +39,51 @@ Ext.define('Traccar.AttributeFormatter', {
return Ext.getStore('DistanceUnits').formatValue(value, Traccar.app.getPreference('distanceUnit'));
},
+ distanceConverter: function (value) {
+ return Ext.getStore('DistanceUnits').convertValue(value, Traccar.app.getPreference('distanceUnit'));
+ },
+
voltageFormatter: function (value) {
return Number(value.toFixed(Traccar.Style.numberPrecision)) + ' ' + Strings.sharedVoltAbbreviation;
},
+ voltageConverter: function (value) {
+ return Number(value);
+ },
+
percentageFormatter: function (value) {
return Number(value.toFixed(Traccar.Style.numberPrecision)) + ' &#37;';
},
+ percentageConverter: function (value) {
+ return Number(value);
+ },
+
temperatureFormatter: function (value) {
return Number(value.toFixed(Traccar.Style.numberPrecision)) + ' &deg;C';
},
+ temperatureConverter: function (value) {
+ return Number(value);
+ },
+
+
volumeFormatter: function (value) {
return Number(value.toFixed(Traccar.Style.numberPrecision)) + ' ' + Strings.sharedLiterAbbreviation;
},
+ volumeConverter: function (value) {
+ return Number(value);
+ },
+
consumptionFormatter: function (value) {
return Number(value.toFixed(Traccar.Style.numberPrecision)) + ' ' + Strings.sharedLiterPerHourAbbreviation;
},
+ consumptionConverter: function (value) {
+ return Number(value);
+ },
+
hoursFormatter: function (value) {
var hours = Math.round(value / 3600000);
return (hours + ' ' + Strings.sharedHourAbbreviation);
@@ -131,6 +160,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) {
@@ -154,5 +195,34 @@ Ext.define('Traccar.AttributeFormatter', {
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 if (dataType === 'voltage') {
+ return this.voltageConverter;
+ } else if (dataType === 'percentage') {
+ return this.percentageConverter;
+ } else if (dataType === 'temperature') {
+ return this.temperatureConverter;
+ } else if (dataType === 'volume') {
+ return this.volumeConverter;
+ } else if (dataType === 'consumption') {
+ return this.consumptionConverter;
+ } 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..189f79bd 100644
--- a/web/app/store/DistanceUnits.js
+++ b/web/app/store/DistanceUnits.js
@@ -48,6 +48,15 @@ Ext.define('Traccar.store.DistanceUnits', {
unit = 'km';
}
model = this.findRecord('key', unit);
+ return value.toFixed(2) + ' ' + model.get('name');
+ },
+
+ convertAndFormat: function (value, unit) {
+ var model;
+ if (!unit) {
+ unit = 'km';
+ }
+ model = this.findRecord('key', unit);
return this.convertValue(value, unit).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..fc2e573e 100644
--- a/web/app/store/SpeedUnits.js
+++ b/web/app/store/SpeedUnits.js
@@ -48,6 +48,15 @@ Ext.define('Traccar.store.SpeedUnits', {
unit = 'kn';
}
model = this.findRecord('key', unit);
+ return value.toFixed(1) + ' ' + model.get('name');
+ },
+
+ convertAndFormat: function (value, unit) {
+ var model;
+ if (!unit) {
+ unit = 'kn';
+ }
+ model = this.findRecord('key', unit);
return this.convertValue(value, unit).toFixed(1) + ' ' + model.get('name');
}
});
diff --git a/web/app/view/ReportController.js b/web/app/view/ReportController.js
index d83d9986..8631b7ca 100644
--- a/web/app/view/ReportController.js
+++ b/web/app/view/ReportController.js
@@ -64,6 +64,10 @@ Ext.define('Traccar.view.ReportController', {
return this.getView().getComponent('chart');
},
+ init: function () {
+ this.addAttributeColumns();
+ },
+
onConfigureClick: function () {
var dialog = Ext.create('Traccar.view.dialog.ReportConfig');
dialog.lookupReference('eventTypeField').setHidden(this.lookupReference('reportTypeField').getValue() !== 'events');
@@ -383,6 +387,20 @@ Ext.define('Traccar.view.ReportController', {
this.updateButtons();
},
+ addAttributeColumns: 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
+ });
+ }
+ },
+
routeColumns: [{
text: Strings.reportDeviceName,
dataIndex: 'deviceId',
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..0d16e1e8 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').convertAndFormat(value, Traccar.app.getPreference('speedUnit', 'kn'));
} else if (attribute && attribute.get('dataType') === 'distance') {
- return Ext.getStore('DistanceUnits').formatValue(value, Traccar.app.getPreference('distanceUnit', 'km'));
+ return Ext.getStore('DistanceUnits').convertAndFormat(value, Traccar.app.getPreference('distanceUnit', 'km'));
} else {
return value;
}
diff --git a/web/l10n/en.json b/web/l10n/en.json
index 22a9cfd7..30f66ba9 100644
--- a/web/l10n/en.json
+++ b/web/l10n/en.json
@@ -164,6 +164,7 @@
"positionRssi": "RSSI",
"positionGps": "GPS",
"positionEvent": "Event",
+ "positionAlarm": "Alarm",
"positionStatus": "Status",
"positionOdometer": "Odometer",
"positionServiceOdometer": "Service Odometer",
@@ -186,6 +187,7 @@
"positionThrottle": "Throttle",
"positionMotion": "Motion",
"positionArmed": "Armed",
+ "positionAcceleration": "Acceleration",
"positionDeviceTemp": "Device Temperature",
"positionOperator": "Operator",
"positionCommand": "Acceleration",