From 3eaeaae2fbaff03027cf79cba29224956a07624e Mon Sep 17 00:00:00 2001 From: georgweiss Date: Fri, 1 Apr 2022 07:18:13 +0200 Subject: [PATCH] Indicate attachments in Olog grouped view --- .../ui/MergedLogEntryDisplayController.java | 42 +++++++++++-------- .../src/main/resources/detail_log_webview.css | 16 +++++++ 2 files changed, 41 insertions(+), 17 deletions(-) diff --git a/app/logbook/olog/ui/src/main/java/org/phoebus/logbook/olog/ui/MergedLogEntryDisplayController.java b/app/logbook/olog/ui/src/main/java/org/phoebus/logbook/olog/ui/MergedLogEntryDisplayController.java index b5880bf0f4..ef18994684 100644 --- a/app/logbook/olog/ui/src/main/java/org/phoebus/logbook/olog/ui/MergedLogEntryDisplayController.java +++ b/app/logbook/olog/ui/src/main/java/org/phoebus/logbook/olog/ui/MergedLogEntryDisplayController.java @@ -18,7 +18,6 @@ package org.phoebus.logbook.olog.ui; -import com.sun.jersey.core.util.MultivaluedMapImpl; import javafx.collections.FXCollections; import javafx.collections.ObservableList; import javafx.concurrent.Worker; @@ -28,14 +27,14 @@ import netscape.javascript.JSObject; import org.phoebus.logbook.LogClient; import org.phoebus.logbook.LogEntry; +import org.phoebus.logbook.Property; import org.phoebus.logbook.SearchResult; import org.phoebus.olog.es.api.model.LogGroupProperty; -import javax.ws.rs.core.MultivaluedMap; import java.util.Comparator; import java.util.HashMap; -import java.util.List; import java.util.Map; +import java.util.Optional; import java.util.function.Function; import java.util.logging.Level; import java.util.logging.Logger; @@ -66,11 +65,8 @@ public class MergedLogEntryDisplayController extends HtmlAwareController { private WebEngine webEngine; - /** for communication to the Javascript engine. */ - private JSObject javascriptConnector; - /** for communication from the Javascript engine. */ - private JavaConnector javaConnector = new JavaConnector(); + private final JavaConnector javaConnector = new JavaConnector(); private Function logSelectionHandler; @@ -82,7 +78,7 @@ public MergedLogEntryDisplayController(LogClient logClient) { @FXML public void initialize() { // Content is defined by the source (default) or description field. If both are null - // or empty, do no load any content to the WebView. + // or empty, do not load any content to the WebView. webEngine = logDescription.getEngine(); webEngine.setUserStyleSheetLocation(getClass() .getResource("/detail_log_webview.css").toExternalForm()); @@ -128,25 +124,32 @@ private void mergeAndRender() { * Creates the log entry separator item inserted as a header for each log entry * when showing the log group view. * - * @param logEntry - * @return + * @param logEntry The {@link LogEntry} for which to create a separator item + * @return HTML of separator item */ private String createSeparator(LogEntry logEntry) { StringBuilder stringBuilder = new StringBuilder(); - stringBuilder.append("
"); + stringBuilder.append("
"); stringBuilder.append(SECONDS_FORMAT.format(logEntry.getCreatedDate())).append(", "); stringBuilder.append(logEntry.getOwner()).append(", "); stringBuilder.append(logEntry.getTitle()); - stringBuilder.append("
").append(logEntry.getId()).append("
"); + stringBuilder.append("
").append(logEntry.getId()).append("
"); + if(logEntry.getAttachments().size() > 0){ + stringBuilder.append("
 
"); + } stringBuilder.append("
"); return stringBuilder.toString(); } private void getLogEntries(LogEntry logEntry) { - String id = + Optional property = logEntry.getProperties().stream() - .filter(p -> p.getName().equals(LogGroupProperty.NAME)).findFirst().get().getAttributes().get(LogGroupProperty.ATTRIBUTE_ID); + .filter(p -> p.getName().equals(LogGroupProperty.NAME)).findFirst(); + if(property.isEmpty()){ + return; + } + String id = property.get().getAttributes().get(LogGroupProperty.ATTRIBUTE_ID); logger.log(Level.INFO, "Fetching log entries for group " + id); try { Map mMap = new HashMap<>(); @@ -163,14 +166,19 @@ private void getLogEntries(LogEntry logEntry) { public class JavaConnector { /** - * called when the JS side wants a String to be converted. + * Called when the JS side wants a String to be converted, e.g. user clicks on separator item + * to see full log entry. * * @param value * the String to convert */ + @SuppressWarnings("unused") public void toLowerCase(String value) { - LogEntry logEntry = logEntries.stream().filter(l -> Long.toString(l.getId()).equals(value)).findFirst().get(); - logSelectionHandler.apply(logEntry); + Optional logEntry = logEntries.stream().filter(l -> Long.toString(l.getId()).equals(value)).findFirst(); + if(logEntry.isEmpty()){ + return; + } + logSelectionHandler.apply(logEntry.get()); } } } diff --git a/app/logbook/olog/ui/src/main/resources/detail_log_webview.css b/app/logbook/olog/ui/src/main/resources/detail_log_webview.css index a7f4c57387..ba3ccf9f8b 100644 --- a/app/logbook/olog/ui/src/main/resources/detail_log_webview.css +++ b/app/logbook/olog/ui/src/main/resources/detail_log_webview.css @@ -69,3 +69,19 @@ p{ font-size: 18px; background-color: #f7f7f7; } + +.attachment-icon{ +background: + url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAaRJREFUeNpi/P//PwMMMDIywtmbdx2azsjIlAESAomzMDOvdXOwCEFWD9aDzYDNuw4f/P/vn92te48Yvv/8zcAAVMPExMTw6cvXmo7q7FZkA5gYsABmJiag5scMly9fmlRbmGTy9dObSZzsbAxM/38boqvFbgAzE8OPXz8ZFk7vbgdyz545uqdPXlaSgY2dIxhdLQsy58jJ8/93HzwB8gvDP4jPXoAIQQGBJywsLNjsQnXBxy9foaz/DP/+/YGLr169+i8jVreiuQAGQAH7589fFFexsjATdgGqIRD6/afPEIVMRBkA0fXj5y+gBjSVjP+Jd8G9h08YbC2MGLbvO/L/+/cfqE7CZwAsIRWlx5gcPXGe4cSZywxXb9xlaCzLNPnPQEQg/v39F8Y8C9KEJHUW5j28Lvj0+csdEL1kzbb/EE0QvHXPkf+PHr9g+Pj50x0GjKBBzQta9V3Tr8pJizPIyUgB08I/sNcfPX3O8PT5K5BXtIHqrxHKTMb5tR0rBHj5VWDi7z+8Oz2prToT5BqiciMQaAExJ5I6UGK4BUtkyAAgwADpI74wMt7OZAAAAABJRU5ErkJggg==') + no-repeat + left center; + height: 20px; + width: 20px; + float: right; + position: relative; +} + +.entry-id{ + float: right; + padding-right: 10px +}