From bfe1e1b86a3e97c624a9f959e952acb9b29ab31c Mon Sep 17 00:00:00 2001 From: Vitaly Litvak Date: Mon, 7 Dec 2015 18:57:07 +0300 Subject: [PATCH] Dropped 'fictive' 'follow' and 'recordTrace' properties from the 'Device' entity --- .../client/controller/DeviceController.java | 29 ------------ .../web/client/model/DeviceProperties.java | 4 -- .../traccar/web/client/view/DeviceView.java | 46 +++++++++++++++++-- .../org/traccar/web/shared/model/Device.java | 22 --------- 4 files changed, 42 insertions(+), 59 deletions(-) diff --git a/src/main/java/org/traccar/web/client/controller/DeviceController.java b/src/main/java/org/traccar/web/client/controller/DeviceController.java index 6e46171b..4351c88f 100644 --- a/src/main/java/org/traccar/web/client/controller/DeviceController.java +++ b/src/main/java/org/traccar/web/client/controller/DeviceController.java @@ -81,35 +81,6 @@ public DeviceController(MapController mapController, this.deviceGeoFences = deviceGeoFences; this.groupStore = groupStore; - this.deviceStore.addStoreRecordChangeHandler(new StoreRecordChangeEvent.StoreRecordChangeHandler() { - @Override - public void onRecordChange(StoreRecordChangeEvent event) { - if (event.getProperty().getPath().equals("follow")) { - boolean follow = (Boolean) event.getRecord().getValue(event.getProperty()); - Device device = event.getRecord().getModel(); - if (follow) { - ApplicationContext.getInstance().follow(device); - for (int i = 0; i < deviceStore.size(); i++) { - Device next = deviceStore.get(i); - if (next.getId() != device.getId()) { - ApplicationContext.getInstance().stopFollowing(next); - deviceStore.getRecord(next).revert(event.getProperty()); - } - } - } else { - ApplicationContext.getInstance().stopFollowing(device); - } - } else if (event.getProperty().getPath().equals("recordTrace")) { - boolean recordTrace = (Boolean) event.getRecord().getValue(event.getProperty()); - Device device = event.getRecord().getModel(); - if (recordTrace) { - ApplicationContext.getInstance().recordTrace(device); - } else { - ApplicationContext.getInstance().stopRecordingTrace(device); - } - } - } - }); deviceView = new DeviceView(this, geoFenceHandler, commandHandler, deviceStore, geoFenceStore, groupStore); } diff --git a/src/main/java/org/traccar/web/client/model/DeviceProperties.java b/src/main/java/org/traccar/web/client/model/DeviceProperties.java index 4c02a898..433534a8 100644 --- a/src/main/java/org/traccar/web/client/model/DeviceProperties.java +++ b/src/main/java/org/traccar/web/client/model/DeviceProperties.java @@ -46,10 +46,6 @@ public interface DeviceProperties extends PropertyAccess { @Path("name") LabelProvider label(); - ValueProvider follow(); - - ValueProvider recordTrace(); - ValueProvider odometer(); ValueProvider autoUpdateOdometer(); diff --git a/src/main/java/org/traccar/web/client/view/DeviceView.java b/src/main/java/org/traccar/web/client/view/DeviceView.java index e53e6115..a3d20a64 100644 --- a/src/main/java/org/traccar/web/client/view/DeviceView.java +++ b/src/main/java/org/traccar/web/client/view/DeviceView.java @@ -33,6 +33,7 @@ import com.google.gwt.user.client.ui.AbstractImagePrototype; import com.sencha.gxt.cell.core.client.form.CheckBoxCell; import com.sencha.gxt.core.client.ToStringValueProvider; +import com.sencha.gxt.core.client.ValueProvider; import com.sencha.gxt.core.client.XTemplates; import com.sencha.gxt.data.shared.SortInfo; import com.sencha.gxt.data.shared.Store; @@ -359,16 +360,53 @@ public void onBrowserEvent(Context context, Element parent, String value, Native Resources resources = GWT.create(Resources.class); HeaderIconTemplate headerTemplate = GWT.create(HeaderIconTemplate.class); - ColumnConfig colFollow = new ColumnConfig<>(deviceProperties.follow(), 50, - headerTemplate.render(AbstractImagePrototype.create(resources.follow()).getSafeHtml())); + ColumnConfig colFollow = new ColumnConfig<>(new ValueProvider() { + + @Override + public Boolean getValue(Device device) { + return ApplicationContext.getInstance().isFollowing(device); + } + + @Override + public void setValue(Device device, Boolean value) { + if (value) { + ApplicationContext.getInstance().follow(device); + } else { + ApplicationContext.getInstance().stopFollowing(device); + } + } + + @Override + public String getPath() { + return "follow"; + } + }, 50, headerTemplate.render(AbstractImagePrototype.create(resources.follow()).getSafeHtml())); colFollow.setCell(new CheckBoxCell()); colFollow.setFixed(true); colFollow.setResizable(false); colFollow.setToolTip(new SafeHtmlBuilder().appendEscaped(i18n.follow()).toSafeHtml()); columnConfigList.add(colFollow); - ColumnConfig colRecordTrace = new ColumnConfig<>(deviceProperties.recordTrace(), 50, - headerTemplate.render(AbstractImagePrototype.create(resources.footprints()).getSafeHtml())); + ColumnConfig colRecordTrace = new ColumnConfig<>(new ValueProvider() { + @Override + public Boolean getValue(Device device) { + return ApplicationContext.getInstance().isRecordingTrace(device); + } + + @Override + public void setValue(Device device, Boolean value) { + if (value) { + ApplicationContext.getInstance().recordTrace(device); + } else { + ApplicationContext.getInstance().stopRecordingTrace(device); + } + } + + @Override + public String getPath() { + return "recordTrace"; + } + }, 50, headerTemplate.render(AbstractImagePrototype.create(resources.footprints()).getSafeHtml())); colRecordTrace.setCell(new CheckBoxCell()); colRecordTrace.setFixed(true); colRecordTrace.setResizable(false); diff --git a/src/main/java/org/traccar/web/shared/model/Device.java b/src/main/java/org/traccar/web/shared/model/Device.java index 11f05930..2cee491e 100644 --- a/src/main/java/org/traccar/web/shared/model/Device.java +++ b/src/main/java/org/traccar/web/shared/model/Device.java @@ -124,28 +124,6 @@ public void setDescription(String description) { this.description = description; } - @JsonIgnore - private transient boolean follow; - - public boolean isFollow() { - return follow; - } - - public void setFollow(boolean follow) { - this.follow = follow; - } - - @JsonIgnore - private transient boolean recordTrace; - - public boolean isRecordTrace() { - return recordTrace; - } - - public void setRecordTrace(boolean recordTrace) { - this.recordTrace = recordTrace; - } - /** * Consider device offline after 'timeout' seconds spent from last position */