Skip to content

armgit / core

Public Imported from GitHub
0

100% open-source IoT Platform - Integrate your devices, add intelligence, build custom apps

Show latest attribute value update in manager asset view if live updates have been enabled before datapoint chart is expanded

Christian Bauer219a907ffc19
diff --git a/client/src/main/java/org/openremote/app/client/assets/asset/AssetViewActivity.java b/client/src/main/java/org/openremote/app/client/assets/asset/AssetViewActivity.java
index a9657766f..63f052412 100644
--- a/client/src/main/java/org/openremote/app/client/assets/asset/AssetViewActivity.java
+++ b/client/src/main/java/org/openremote/app/client/assets/asset/AssetViewActivity.java
@@ -20,6 +20,7 @@
package org.openremote.app.client.assets.asset;
import com.google.gwt.http.client.URL;
+import com.google.gwt.i18n.client.DateTimeFormat;
import com.google.inject.Provider;
import org.openremote.app.client.Environment;
import org.openremote.app.client.app.dialog.JsonEditor;
@@ -57,10 +58,7 @@ import org.openremote.model.simulator.SimulatorState;
import org.openremote.model.value.Values;
import javax.inject.Inject;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.List;
-import java.util.Optional;
+import java.util.*;
import static org.openremote.model.util.TextUtil.isNullOrEmpty;
@@ -230,7 +228,7 @@ public class AssetViewActivity
if (assetAttributeRef.map(ref -> ref.equals(attributeEvent.getAttributeRef())).orElse(false)) {
assetAttribute.setValue(attributeEvent.getValue().orElse(null), attributeEvent.getTimestamp());
- attributeView.onAttributeChanged(System.currentTimeMillis());
+ attributeView.onAttributeChanged(attributeEvent.getTimestamp());
break;
}
}
@@ -393,13 +391,22 @@ public class AssetViewActivity
/*###########################################################################################*/
protected DatapointBrowser createDatapointBrowser(AssetAttribute attribute, AttributeViewImpl view) {
- return new DatapointBrowser(environment, this.view.getStyle(), view, attribute, 675, 200) {
- @SuppressWarnings("ConstantConditions")
+ return new DatapointBrowser(environment,
+ this.view.getStyle(),
+ view,
+ attribute,
+ 675,
+ 200,
+ DatapointInterval.HOUR,
+ attribute.getValueTimestamp().orElse(System.currentTimeMillis())
+ ) {
@Override
protected void queryDatapoints(DatapointInterval interval,
long timestamp,
Consumer<NumberDatapoint[]> consumer) {
- queryDataPoints(attribute.getName().get(), interval, timestamp, consumer);
+ attribute.getName().ifPresent(attributeName ->
+ queryDataPoints(attributeName, interval, timestamp, consumer)
+ );
}
};
}
diff --git a/client/src/main/java/org/openremote/app/client/datapoint/DatapointBrowser.java b/client/src/main/java/org/openremote/app/client/datapoint/DatapointBrowser.java
index 17ed98232..7a873f8b9 100644
--- a/client/src/main/java/org/openremote/app/client/datapoint/DatapointBrowser.java
+++ b/client/src/main/java/org/openremote/app/client/datapoint/DatapointBrowser.java
@@ -25,13 +25,13 @@ import com.google.gwt.text.shared.AbstractRenderer;
import com.google.gwt.user.client.ui.FlowPanel;
import com.google.gwt.user.client.ui.Label;
import elemental.client.Browser;
-import org.openremote.app.client.interop.chartjs.Chart;
-import org.openremote.app.client.interop.chartjs.ChartUtil;
-import org.openremote.app.client.widget.*;
import org.openremote.app.client.Environment;
import org.openremote.app.client.assets.attributes.AbstractAttributeViewExtension;
import org.openremote.app.client.assets.attributes.AttributeView;
import org.openremote.app.client.assets.attributes.AttributeViewImpl;
+import org.openremote.app.client.interop.chartjs.Chart;
+import org.openremote.app.client.interop.chartjs.ChartUtil;
+import org.openremote.app.client.widget.*;
import org.openremote.model.Constants;
import org.openremote.model.asset.AssetAttribute;
import org.openremote.model.attribute.AttributeValidationResult;
@@ -59,10 +59,6 @@ public abstract class DatapointBrowser extends AbstractAttributeViewExtension {
FormOutputText timeOutput;
FormButton nextButton;
- public DatapointBrowser(Environment environment, AttributeView.Style style, AttributeViewImpl parentView, AssetAttribute attribute, int width, int height) {
- this(environment, style, parentView, attribute, width, height, DatapointInterval.HOUR, System.currentTimeMillis());
- }
-
public DatapointBrowser(Environment environment, AttributeView.Style style, AttributeViewImpl parentView, AssetAttribute attribute, int width, int height, DatapointInterval interval, long timestamp) {
super(environment, style, parentView, attribute, environment.getMessages().historicalData());
this.environment = environment;
@@ -102,6 +98,9 @@ public abstract class DatapointBrowser extends AbstractAttributeViewExtension {
}
public void refresh(long timestamp) {
+ // Keep timestamp so when chart is != null at some point, it has the latest refresh timestamp
+ this.timestamp = timestamp;
+
if (chart == null) {
return;
}
@@ -109,13 +108,14 @@ public abstract class DatapointBrowser extends AbstractAttributeViewExtension {
}
public void refresh(long timestamp, DatapointInterval interval) {
+ // Keep timestamp so when chart is != null at some point, it has the latest refresh timestamp
+ this.timestamp = timestamp;
+ this.interval = interval;
+
if (chart == null) {
return;
}
- this.timestamp = timestamp;
- this.interval = interval;
-
timeOutput.setText(
DateTimeFormat.getFormat(Constants.DEFAULT_DATETIME_FORMAT).format(new Date(timestamp))
);