diff options
author | Anton Tananaev <anton.tananaev@gmail.com> | 2017-03-24 23:28:27 +1300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-03-24 23:28:27 +1300 |
commit | f094a26a9f66a85ee3111a4c8ca8a46276cdf968 (patch) | |
tree | 72de6c42c337d7f4efac3c003ef8abbd782a02d0 | |
parent | 8b343b37d623daf74692b62d2ffcfc6e4bce9bd6 (diff) | |
parent | 4597f97cf2020f900f36af2867d1129d9bebd54d (diff) | |
download | traccar-server-f094a26a9f66a85ee3111a4c8ca8a46276cdf968.tar.gz traccar-server-f094a26a9f66a85ee3111a4c8ca8a46276cdf968.tar.bz2 traccar-server-f094a26a9f66a85ee3111a4c8ca8a46276cdf968.zip |
Merge pull request #3050 from Abyss777/format_template
Format speed in notification templates
-rw-r--r-- | src/org/traccar/notification/NotificationFormatter.java | 2 | ||||
-rw-r--r-- | src/org/traccar/reports/ReportUtils.java | 2 | ||||
-rw-r--r-- | templates/mail/deviceOverspeed.vm | 8 | ||||
-rw-r--r-- | templates/sms/deviceOverspeed.vm | 8 |
4 files changed, 14 insertions, 6 deletions
diff --git a/src/org/traccar/notification/NotificationFormatter.java b/src/org/traccar/notification/NotificationFormatter.java index eae2681c9..0f723a5e1 100644 --- a/src/org/traccar/notification/NotificationFormatter.java +++ b/src/org/traccar/notification/NotificationFormatter.java @@ -24,6 +24,7 @@ import org.apache.velocity.Template; import org.apache.velocity.VelocityContext; import org.apache.velocity.exception.ResourceNotFoundException; import org.apache.velocity.tools.generic.DateTool; +import org.apache.velocity.tools.generic.NumberTool; import org.traccar.Context; import org.traccar.helper.Log; import org.traccar.model.Device; @@ -51,6 +52,7 @@ public final class NotificationFormatter { } velocityContext.put("webUrl", Context.getVelocityEngine().getProperty("web.url")); velocityContext.put("dateTool", new DateTool()); + velocityContext.put("numberTool", new NumberTool()); velocityContext.put("timezone", ReportUtils.getTimezone(userId)); velocityContext.put("locale", Locale.getDefault()); return velocityContext; diff --git a/src/org/traccar/reports/ReportUtils.java b/src/org/traccar/reports/ReportUtils.java index e2a743b2f..02e3764bc 100644 --- a/src/org/traccar/reports/ReportUtils.java +++ b/src/org/traccar/reports/ReportUtils.java @@ -17,6 +17,7 @@ package org.traccar.reports; import org.apache.velocity.tools.generic.DateTool; +import org.apache.velocity.tools.generic.NumberTool; import org.jxls.area.Area; import org.jxls.builder.xls.XlsCommentAreaBuilder; import org.jxls.common.CellRef; @@ -115,6 +116,7 @@ public final class ReportUtils { jxlsContext.putVar("speedUnit", getSpeedUnit(userId)); jxlsContext.putVar("webUrl", Context.getVelocityEngine().getProperty("web.url")); jxlsContext.putVar("dateTool", new DateTool()); + jxlsContext.putVar("numberTool", new NumberTool()); jxlsContext.putVar("timezone", getTimezone(userId)); jxlsContext.putVar("locale", Locale.getDefault()); jxlsContext.putVar("bracketsRegex", "[\\{\\}\"]"); diff --git a/templates/mail/deviceOverspeed.vm b/templates/mail/deviceOverspeed.vm index 3b203ddcd..0715a3d60 100644 --- a/templates/mail/deviceOverspeed.vm +++ b/templates/mail/deviceOverspeed.vm @@ -1,10 +1,12 @@ #set($subject = "$device.name: exceeds the speed") #if($speedUnits == 'kmh') -#set($speedString = $position.speed * 1.852 + ' km/h') +#set($speedValue = $position.speed * 1.852) +#set($speedString = $numberTool.format("0.0 km/h", $speedValue)) #elseif($speedUnits == 'mph') -#set($speedString = $position.speed * 1.15078 + ' mph') +#set($speedValue = $position.speed * 1.15078) +#set($speedString = $numberTool.format("0.0 mph", $speedValue)) #else -#set($speedString = "$position.speed kn") +#set($speedString = $numberTool.format("0.0 kn", $position.speed)) #end <!DOCTYPE html> <html> diff --git a/templates/sms/deviceOverspeed.vm b/templates/sms/deviceOverspeed.vm index 3c9eae628..ef0d9d955 100644 --- a/templates/sms/deviceOverspeed.vm +++ b/templates/sms/deviceOverspeed.vm @@ -1,8 +1,10 @@ #if($speedUnits == 'kmh') -#set($speedString = $position.speed * 1.852 + ' km/h') +#set($speedValue = $position.speed * 1.852) +#set($speedString = $numberTool.format("0.0 km/h", $speedValue)) #elseif($speedUnits == 'mph') -#set($speedString = $position.speed * 1.15078 + ' mph') +#set($speedValue = $position.speed * 1.15078) +#set($speedString = $numberTool.format("0.0 mph", $speedValue)) #else -#set($speedString = "$position.speed kn") +#set($speedString = $numberTool.format("0.0 kn", $position.speed)) #end $device.name exceeds the speed $speedString at $dateTool.format("YYYY-MM-dd HH:mm:ss", $event.serverTime, $locale, $timezone) |