From 4e1383124b274731da6cfd54becdc35ce4645f57 Mon Sep 17 00:00:00 2001 From: Vitaly Litvak Date: Tue, 1 Dec 2015 09:42:16 +0300 Subject: [PATCH] For #364 - added notification message placeholders for more fields of position entity --- .../org/traccar/web/client/i18n/Messages.java | 8 +++- .../view/NotificationSettingsDialog.java | 40 ++++++++++++++++--- .../view/NotificationSettingsDialog.ui.xml | 4 +- .../server/model/NotificationServiceImpl.java | 33 +++++++++++---- .../web/shared/model/MessagePlaceholder.java | 12 +++++- .../web/client/i18n/Messages.properties | 6 +++ .../web/client/i18n/Messages_ru.properties | 6 +++ 7 files changed, 91 insertions(+), 18 deletions(-) diff --git a/src/main/java/org/traccar/web/client/i18n/Messages.java b/src/main/java/org/traccar/web/client/i18n/Messages.java index 3c5521c0..4dcb4209 100644 --- a/src/main/java/org/traccar/web/client/i18n/Messages.java +++ b/src/main/java/org/traccar/web/client/i18n/Messages.java @@ -299,7 +299,13 @@ String defaultNotificationTemplate(@Select DeviceEventType type, @Optional String geoFenceName, @Optional String eventTime, @Optional String positionTime, - @Optional String maintenanceName); + @Optional String maintenanceName, + @Optional String positionAddress, + @Optional String positionLat, + @Optional String positionLon, + @Optional String positionAlt, + @Optional String positionSpeed, + @Optional String positionCourse); String noMarkers(); diff --git a/src/main/java/org/traccar/web/client/view/NotificationSettingsDialog.java b/src/main/java/org/traccar/web/client/view/NotificationSettingsDialog.java index 94433575..774f057e 100644 --- a/src/main/java/org/traccar/web/client/view/NotificationSettingsDialog.java +++ b/src/main/java/org/traccar/web/client/view/NotificationSettingsDialog.java @@ -32,10 +32,7 @@ import com.sencha.gxt.widget.core.client.form.*; import com.sencha.gxt.widget.core.client.form.validator.MaxNumberValidator; import com.sencha.gxt.widget.core.client.form.validator.MinNumberValidator; -import com.sencha.gxt.widget.core.client.grid.ColumnConfig; -import com.sencha.gxt.widget.core.client.grid.ColumnModel; -import com.sencha.gxt.widget.core.client.grid.Grid; -import com.sencha.gxt.widget.core.client.grid.GridView; +import com.sencha.gxt.widget.core.client.grid.*; import org.traccar.web.client.i18n.Messages; import org.traccar.web.client.model.EnumKeyProvider; import org.traccar.web.client.model.NotificationSettingsProperties; @@ -159,12 +156,32 @@ public String getValue(MessagePlaceholder ph) { return i18n.placeholderDescription(ph); } })); + ColumnConfig colGroup = new ColumnConfig<>(new ToStringValueProvider() { + @Override + public String getValue(MessagePlaceholder ph) { + switch (ph) { + case positionCourse: + case positionTime: + case positionAddress: + case positionAlt: + case positionLat: + case positionLon: + case positionSpeed: + return i18n.eventPosition(); + default: + return ""; + } + } + }); placeholderColumns.get(placeholderColumns.size() - 1).setHeader(i18n.description()); ListStore placeholderListStore = new ListStore<>(new EnumKeyProvider()); placeholderListStore.addAll(Arrays.asList(MessagePlaceholder.values())); - GridView placeholderGridView = new GridView<>(); + GroupingView placeholderGridView = new GroupingView<>(); placeholderGridView.setStripeRows(true); placeholderGridView.setAutoFill(true); + placeholderGridView.setEnableNoGroups(false); + placeholderGridView.setEnableGroupingMenu(false); + placeholderGridView.groupBy(colGroup); placeholderGrid = new Grid<>(placeholderListStore, new ColumnModel<>(placeholderColumns), placeholderGridView); uiBinder.createAndBindUi(this); @@ -214,7 +231,18 @@ public void onEventTypeChanged(SelectionEvent event) { if (messageTemplate == null) { messageTemplate = new NotificationTemplate(); messageTemplate.setType(event.getSelectedItem()); - messageTemplate.setBody(i18n.defaultNotificationTemplate(event.getSelectedItem(), "${deviceName}", "${geoFenceName}", "${eventTime}", "${positionTime}", "${maintenanceName}")); + messageTemplate.setBody(i18n.defaultNotificationTemplate(event.getSelectedItem(), + "${deviceName}", + "${geoFenceName}", + "${eventTime}", + "${positionTime}", + "${maintenanceName}", + "${positionAddress}", + "${positionLat}", + "${positionLon}", + "${positionAlt}", + "${positionSpeed}", + "${positionCourse}")); settings.getTransferTemplates().put(event.getSelectedItem(), messageTemplate); } messageSubject.setText(messageTemplate.getSubject()); diff --git a/src/main/java/org/traccar/web/client/view/NotificationSettingsDialog.ui.xml b/src/main/java/org/traccar/web/client/view/NotificationSettingsDialog.ui.xml index 5604c221..ce61814e 100644 --- a/src/main/java/org/traccar/web/client/view/NotificationSettingsDialog.ui.xml +++ b/src/main/java/org/traccar/web/client/view/NotificationSettingsDialog.ui.xml @@ -37,7 +37,7 @@ } - + @@ -143,7 +143,7 @@ - + diff --git a/src/main/java/org/traccar/web/server/model/NotificationServiceImpl.java b/src/main/java/org/traccar/web/server/model/NotificationServiceImpl.java index ad7cf1fc..2cb202b5 100644 --- a/src/main/java/org/traccar/web/server/model/NotificationServiceImpl.java +++ b/src/main/java/org/traccar/web/server/model/NotificationServiceImpl.java @@ -15,6 +15,8 @@ */ package org.traccar.web.server.model; +import static org.traccar.web.shared.model.MessagePlaceholder.*; + import com.fasterxml.jackson.core.JsonEncoding; import com.fasterxml.jackson.core.JsonFactory; import com.fasterxml.jackson.core.JsonGenerator; @@ -153,7 +155,7 @@ public void doWork() throws Exception { } Engine engine = getTemplateEngine(getTimeZone(user)); - Map model = getTemplateModel(deviceEvent); + Map model = getTemplateModel(user, deviceEvent); String subject = engine.transform(template.getSubject(), model); String body = engine.transform(template.getBody(), model); @@ -454,9 +456,15 @@ public String checkTemplate(NotificationTemplate template) { c.set(Calendar.HOUR, c.get(Calendar.HOUR) - 1); c.set(Calendar.MINUTE, c.get(Calendar.MINUTE) - 15); testPosition.setTime(c.getTime()); + testPosition.setAddress("New York, Times Square"); + testPosition.setLatitude(40.758899); + testPosition.setLongitude(-73.987325); + testPosition.setAltitude(100d); + testPosition.setSpeed(UserSettings.SpeedUnit.kilometersPerHour.toKnots(5d)); + testPosition.setCourse(30d); Engine engine = getTemplateEngine(getTimeZone(sessionUser.get())); - Map model = getTemplateModel(new DeviceEvent(new Date(), testDevice, testPosition, testGeoFence, testMaintenance)); + Map model = getTemplateModel(sessionUser.get(), new DeviceEvent(new Date(), testDevice, testPosition, testGeoFence, testMaintenance)); String transformedSubject = engine.transform(template.getSubject(), model); String transformedBody = engine.transform(template.getBody(), model); @@ -469,13 +477,22 @@ public String checkTemplate(NotificationTemplate template) { ""; } - private static Map getTemplateModel(DeviceEvent event) { + private static Map getTemplateModel(User user, DeviceEvent event) { Map model = new HashMap<>(); - model.put(MessagePlaceholder.deviceName.name(), event.getDevice() == null ? "N/A" : event.getDevice().getName()); - model.put(MessagePlaceholder.geoFenceName.name(), event.getGeoFence() == null ? "N/A" : event.getGeoFence().getName()); - model.put(MessagePlaceholder.eventTime.name(), event.getTime()); - model.put(MessagePlaceholder.positionTime.name(), event.getPosition() == null ? null : event.getPosition().getTime()); - model.put(MessagePlaceholder.maintenanceName.name(), event.getMaintenance() == null ? "N/A" : event.getMaintenance().getName()); + model.put(deviceName.name(), event.getDevice() == null ? "N/A" : event.getDevice().getName()); + model.put(geoFenceName.name(), event.getGeoFence() == null ? "N/A" : event.getGeoFence().getName()); + model.put(eventTime.name(), event.getTime()); + if (event.getPosition() != null) { + Position p = event.getPosition(); + model.put(positionTime.name(), p.getTime()); + model.put(positionAddress.name(), p.getAddress()); + model.put(positionLat.name(), p.getLatitude()); + model.put(positionLon.name(), p.getLongitude()); + model.put(positionAlt.name(), p.getAltitude()); + model.put(positionSpeed.name(), p.getSpeed() == null ? null : (p.getSpeed() * user.getUserSettings().getSpeedUnit().getFactor())); + model.put(positionCourse.name(), p.getCourse()); + } + model.put(maintenanceName.name(), event.getMaintenance() == null ? "N/A" : event.getMaintenance().getName()); return model; } diff --git a/src/main/java/org/traccar/web/shared/model/MessagePlaceholder.java b/src/main/java/org/traccar/web/shared/model/MessagePlaceholder.java index 28efeaec..42ff2b9d 100644 --- a/src/main/java/org/traccar/web/shared/model/MessagePlaceholder.java +++ b/src/main/java/org/traccar/web/shared/model/MessagePlaceholder.java @@ -16,5 +16,15 @@ package org.traccar.web.shared.model; public enum MessagePlaceholder { - deviceName, geoFenceName, eventTime, positionTime, maintenanceName; + deviceName, + geoFenceName, + eventTime, + positionTime, + positionAddress, + positionLat, + positionLon, + positionAlt, + positionSpeed, + positionCourse, + maintenanceName; } diff --git a/src/main/resources/org/traccar/web/client/i18n/Messages.properties b/src/main/resources/org/traccar/web/client/i18n/Messages.properties index 3597c197..8d92da0f 100644 --- a/src/main/resources/org/traccar/web/client/i18n/Messages.properties +++ b/src/main/resources/org/traccar/web/client/i18n/Messages.properties @@ -190,6 +190,12 @@ placeholderDescription[deviceName] = Name of device placeholderDescription[geoFenceName] = Name of geo-fence placeholderDescription[eventTime] = Date and time when event was recorded placeholderDescription[positionTime] = Date and time of associated position +placeholderDescription[positionAddress] = Address of associated position +placeholderDescription[positionLat] = Latitude of associated position +placeholderDescription[positionLon] = Longitude of associated position +placeholderDescription[positionAlt] = Altitude of associated position +placeholderDescription[positionSpeed] = Speed of associated position +placeholderDescription[positionCourse] = Course of associated position placeholderDescription[maintenanceName] = Name of maintenance service defaultNotificationTemplate = Unknown message defaultNotificationTemplate[OFFLINE] = Device ''{1}'' went offline at {3} diff --git a/src/main/resources/org/traccar/web/client/i18n/Messages_ru.properties b/src/main/resources/org/traccar/web/client/i18n/Messages_ru.properties index 4e7abebf..caf86cb7 100644 --- a/src/main/resources/org/traccar/web/client/i18n/Messages_ru.properties +++ b/src/main/resources/org/traccar/web/client/i18n/Messages_ru.properties @@ -189,6 +189,12 @@ placeholderDescription[deviceName] = Имя устройств placeholderDescription[geoFenceName] = Имя геозоны placeholderDescription[eventTime] = Дата и время события placeholderDescription[positionTime] = Дата и время последней позиции +placeholderDescription[positionAddress] = Адрес последней позиции +placeholderDescription[positionLat] = Широта последней позиции +placeholderDescription[positionLon] = Долгота последней позиции +placeholderDescription[positionAlt] = Высота последней позиции +placeholderDescription[positionSpeed] = Скорость последней позиции +placeholderDescription[positionCourse] = Курс последней позиции placeholderDescription[maintenanceName] = Имя техобслуживания defaultNotificationTemplate = Неизвестное сообщение defaultNotificationTemplate[OFFLINE] = Потеряна связь с устройством ''{1}'' в {3}