Skip to content

Commit

Permalink
For #209 - added possibility to hide device name from map
Browse files Browse the repository at this point in the history
  • Loading branch information
vitalidze committed May 5, 2016
1 parent c5e71c1 commit 3549443
Show file tree
Hide file tree
Showing 11 changed files with 44 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ public void onSuccess(List<Position> result) {
long timeout = (long) position.getDevice().getTimeout() * 1000;
boolean isOffline = currentTime - position.getTime().getTime() > timeout;
position.setStatus(isOffline ? Position.Status.OFFLINE : Position.Status.LATEST);
position.setIcon(MarkerIcon.create(position).withName());
position.setIcon(MarkerIcon.create(position).setName(device.isShowName()));
deviceVisibilityHandler.offlineStatusChanged(device, isOffline);
// check 'idle since'
if (position.getSpeed() != null) {
Expand Down
2 changes: 2 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 @@ -542,4 +542,6 @@ String defaultNotificationTemplate(@Select DeviceEventType type,
String arrowColorStopped();

String arrowColorOffline();

String showName();
}
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,9 @@ void flush(Device device) {
@UiField
CheckBox iconRotation;

@UiField
CheckBox showName;

@UiField
Label iconArrowMovingColor;

Expand Down Expand Up @@ -339,6 +342,7 @@ public void onAnything() {
iconModeArrow.setValue(device.getIconMode() == DeviceIconMode.ARROW);

iconRotation.setValue(device.isIconRotation());
showName.setValue(device.isShowName());

// set up color buttons
DeviceProperties properties = GWT.create(DeviceProperties.class);
Expand Down Expand Up @@ -369,6 +373,7 @@ public void flush() {
device.setIconMode(DeviceIconMode.ARROW);
}
device.setIconRotation(iconRotation.getValue());
device.setShowName(showName.getValue());
for (ColorSelector colorSelector : arrowColors) {
colorSelector.flush(device);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,13 @@
</form:widget>
</form:FieldLabel>
</container:child>
<container:child layoutData="{imageLayoutData}">
<form:FieldLabel text="{i18n.showName}">
<form:widget>
<form:CheckBox ui:field="showName" />
</form:widget>
</form:FieldLabel>
</container:child>
</container:VerticalLayoutContainer>
<container:VerticalLayoutContainer>
<container:child layoutData="{toolBarRowData}">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -685,11 +685,7 @@ public void updateIcon(Device device) {
Position position = deviceData.positions == null || deviceData.positions.size() != 1 ? null : deviceData.positions.get(0);
if (position != null) {
position.setDevice(device);
boolean withName = position.getIcon() != null && position.getIcon().isName();
position.setIcon(MarkerIcon.create(position));
if (withName) {
position.getIcon().withName();
}
position.setIcon(MarkerIcon.create(position).setName(device.isShowName()));
boolean selected = selectedPosition != null && selectedPosition.getId() == position.getId();
changeMarkerIcon(position, selected);
}
Expand Down
10 changes: 10 additions & 0 deletions src/main/java/org/traccar/web/server/model/DBMigrations.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ public void migrate(EntityManager em) throws Exception {
new SetDefaultDeviceIconType(),
new SetDefaultDeviceIconModeAndRotation(),
new SetDefaultArrowIconSettings(),
new SetDefaultDeviceShowName(),
new SetDefaultHashImplementation(),
new SetGlobalHashSalt(),
new SetDefaultUserSettings(),
Expand Down Expand Up @@ -437,4 +438,13 @@ public void migrate(EntityManager em) throws Exception {
}
}
}

static class SetDefaultDeviceShowName 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();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -515,6 +515,7 @@ public Device updateDevice(Device device) throws TraccarException {
tmp_device.setIconArrowPausedColor(device.getIconArrowPausedColor());
tmp_device.setIconArrowStoppedColor(device.getIconArrowStoppedColor());
tmp_device.setIconArrowOfflineColor(device.getIconArrowOfflineColor());
tmp_device.setShowName(device.isShowName());

double prevOdometer = tmp_device.getOdometer();
tmp_device.setOdometer(device.getOdometer());
Expand Down
13 changes: 13 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 @@ -48,6 +48,7 @@ public Device() {
iconArrowPausedColor = DEFAULT_PAUSED_ARROW_COLOR;
iconArrowStoppedColor = DEFAULT_STOPPED_ARROW_COLOR;
iconArrowOfflineColor = DEFAULT_OFFLINE_ARROW_COLOR;
showName = true;
}

public Device(Device device) {
Expand Down Expand Up @@ -87,6 +88,7 @@ public Device(Device device) {
iconArrowPausedColor = device.iconArrowPausedColor;
iconArrowStoppedColor = device.iconArrowStoppedColor;
iconArrowOfflineColor = device.iconArrowOfflineColor;
showName = device.showName;
}

@Id
Expand Down Expand Up @@ -436,6 +438,17 @@ public void setIconRotation(boolean iconRotation) {
this.iconRotation = iconRotation;
}

@Column(nullable = true)
private boolean showName;

public boolean isShowName() {
return showName;
}

public void setShowName(boolean showName) {
this.showName = showName;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/traccar/web/shared/model/PositionIcon.java
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ public boolean isName() {
return name;
}

public PositionIcon withName() {
this.name = true;
public PositionIcon setName(boolean name) {
this.name = name;
return this;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ arrowColorMoving = Moving arrow color
arrowColorPaused = Stopped arrow color
arrowColorStopped = Idle arrow color
arrowColorOffline = Offline arrow color
showName = Show name
# device view
objects = Objects
devices = Devices
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ arrowColorMoving = Цвет стрелки при движении
arrowColorPaused = Цвет стрелки при остановке
arrowColorStopped = Цвет стрелки при стоянке
arrowColorOffline = Цвет стрелки не в сети
showName = Показывать имя
# device view
objects = Объекты
devices = Устройства
Expand Down

0 comments on commit 3549443

Please sign in to comment.