Skip to content

Commit

Permalink
For #591 #318 - added possibility to hide 'protocol' and 'odometer' f…
Browse files Browse the repository at this point in the history
…rom popup
  • Loading branch information
vitalidze committed May 7, 2016
1 parent 32843e3 commit 0eee56c
Show file tree
Hide file tree
Showing 9 changed files with 70 additions and 8 deletions.
4 changes: 4 additions & 0 deletions src/main/java/org/traccar/web/client/i18n/Messages.java
Original file line number Diff line number Diff line change
Expand Up @@ -544,4 +544,8 @@ String defaultNotificationTemplate(@Select DeviceEventType type,
String arrowColorOffline();

String showName();

String showProtocol();

String showOdometer();
}
6 changes: 6 additions & 0 deletions src/main/java/org/traccar/web/client/view/DeviceDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,12 @@ public interface DeviceHandler {
@UiField
NumberField<Double> speedLimit;

@UiField
CheckBox showProtocol;

@UiField
CheckBox showOdometer;

@UiField
ScrollPanel panelPhoto;

Expand Down
14 changes: 14 additions & 0 deletions src/main/java/org/traccar/web/client/view/DeviceDialog.ui.xml
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,20 @@
</form:widget>
</form:FieldLabel>
</container:child>
<container:child layoutData="{verticalLayoutData}">
<form:FieldLabel text="{i18n.showProtocol}" labelWidth="180">
<form:widget>
<form:CheckBox ui:field="showProtocol" />
</form:widget>
</form:FieldLabel>
</container:child>
<container:child layoutData="{verticalLayoutData}">
<form:FieldLabel text="{i18n.showOdometer}" labelWidth="180">
<form:widget>
<form:CheckBox ui:field="showOdometer" />
</form:widget>
</form:FieldLabel>
</container:child>
<container:child layoutData="{verticalLayoutDataWithButtons}">
<form:FieldLabel text="{i18n.photo}" labelWidth="180">
<form:widget>
Expand Down
11 changes: 8 additions & 3 deletions src/main/java/org/traccar/web/client/view/PositionInfoPopup.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,16 @@ public void show(int x, int y, final Position position) {
(position.getAltitude() == null ? "" : ("<td style=\"font-size: 10pt; border-bottom: 1px solid #000000; padding: 3px 10px 3px 10px;\" valign=\"bottom\"" + (position.getSpeed() == null ? " colspan=\"2\" align=\"right\"" : "") + ">" + position.getAltitude() + " " + i18n.meter() + "</td>")) +
"</tr>";

if (position.getDevice().getOdometer() > 0) {
Device device = deviceStore.findModelWithKey(Long.toString(position.getDevice().getId()));

if (position.getDevice().getOdometer() > 0 && device.isShowOdometer()) {
body += "<tr><td style=\"padding: 3px 0px 3px 0px;\">" + i18n.odometer() + "</td><td>" + ApplicationContext.getInstance().getFormatterUtil().getDistanceFormat().format(position.getDevice().getOdometer()) + "</td></tr>";
}
if (position.getProtocol() != null) {
if (position.getProtocol() != null && device.isShowProtocol()) {
body += "<tr><td style=\"padding: 3px 0px 3px 0px;\">" + i18n.protocol() + "</td><td>" + position.getProtocol() + "</td></tr>";
}
String other = position.getOther();
if (other != null) {
Device device = deviceStore.findModelWithKey(Long.toString(position.getDevice().getId()));
Map<String, Sensor> sensors = new HashMap<>(device.getSensors().size());
for (Sensor sensor : device.getSensors()) {
sensors.put(sensor.getParameterName(), sensor);
Expand Down Expand Up @@ -106,6 +107,10 @@ public void show(int x, int y, final Position position) {
}
}

if (!device.isShowProtocol()) {
sensorData.remove("protocol");
}

// write values
for (Map.Entry<String, Object> entry : sensorData.entrySet()) {
String parameterName = entry.getKey();
Expand Down
12 changes: 7 additions & 5 deletions src/main/java/org/traccar/web/server/model/DBMigrations.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public void migrate(EntityManager em) throws Exception {
new SetDefaultDeviceIconType(),
new SetDefaultDeviceIconModeAndRotation(),
new SetDefaultArrowIconSettings(),
new SetDefaultDeviceShowName(),
new SetDefaultDeviceShowNameProtocolAndOdometer(),
new SetDefaultHashImplementation(),
new SetGlobalHashSalt(),
new SetDefaultUserSettings(),
Expand Down Expand Up @@ -439,12 +439,14 @@ public void migrate(EntityManager em) throws Exception {
}
}

static class SetDefaultDeviceShowName implements Migration {
static class SetDefaultDeviceShowNameProtocolAndOdometer implements Migration {
@Override
public void migrate(EntityManager em) throws Exception {
em.createQuery("UPDATE " + Device.class.getName() + " D SET D.showName=:true WHERE D.showName IS NULL")
.setParameter("true", true)
.executeUpdate();
for (String prop : new String[] { "showName", "showProtocol", "showOdometer" }) {
em.createQuery("UPDATE " + Device.class.getName() + " D SET D." + prop + "=:true WHERE D." + prop + " IS NULL")
.setParameter("true", true)
.executeUpdate();
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -527,6 +527,8 @@ public Device updateDevice(Device device) throws TraccarException {
tmp_device.setIconArrowStoppedColor(device.getIconArrowStoppedColor());
tmp_device.setIconArrowOfflineColor(device.getIconArrowOfflineColor());
tmp_device.setShowName(device.isShowName());
tmp_device.setShowProtocol(device.isShowProtocol());
tmp_device.setShowOdometer(device.isShowOdometer());

double prevOdometer = tmp_device.getOdometer();
tmp_device.setOdometer(device.getOdometer());
Expand Down
25 changes: 25 additions & 0 deletions src/main/java/org/traccar/web/shared/model/Device.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ public Device() {
iconArrowStoppedColor = DEFAULT_STOPPED_ARROW_COLOR;
iconArrowOfflineColor = DEFAULT_OFFLINE_ARROW_COLOR;
showName = true;
showProtocol = true;
showOdometer = true;
}

public Device(Device device) {
Expand Down Expand Up @@ -89,6 +91,8 @@ public Device(Device device) {
iconArrowStoppedColor = device.iconArrowStoppedColor;
iconArrowOfflineColor = device.iconArrowOfflineColor;
showName = device.showName;
showProtocol = device.showProtocol;
showOdometer = device.showOdometer;
}

@Id
Expand Down Expand Up @@ -449,6 +453,27 @@ public void setShowName(boolean showName) {
this.showName = showName;
}

@Column(nullable = true)
private boolean showProtocol;
@Column(nullable = true)
private boolean showOdometer;

public boolean isShowProtocol() {
return showProtocol;
}

public void setShowProtocol(boolean showProtocol) {
this.showProtocol = showProtocol;
}

public boolean isShowOdometer() {
return showOdometer;
}

public void setShowOdometer(boolean showOdometer) {
this.showOdometer = showOdometer;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ phoneNumber = Phone number
plateNumber = Plate number
vehicleBrandModelColor = Vehicle brand / model / color
photo = Photo
showProtocol = Show protocol
showOdometer = Show odometer
# device markers
icon = Icon
defaultIcon = Default
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ phoneNumber = Номер телефона
plateNumber = Номерной знак
vehicleBrandModelColor = Марка / модель / цвет
photo = Фотография
showProtocol = Показывать протокол
showOdometer = Показывать счетчик пробега
# device markers dialog
icon = Иконка
defaultIcon = По умолчанию
Expand Down

0 comments on commit 0eee56c

Please sign in to comment.