Skip to content

Commit

Permalink
Merge pull request #2200 from ControlSystemStudio/CSSTUDIO-1645
Browse files Browse the repository at this point in the history
Indicate attachments in Olog grouped view
  • Loading branch information
shroffk authored Apr 7, 2022
2 parents 1b88a02 + 3eaeaae commit 272047a
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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<LogEntry, Void> logSelectionHandler;

Expand All @@ -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());
Expand Down Expand Up @@ -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("<div class='separator' onClick='window.javaConnector.toLowerCase(" + logEntry.getId() + ")'>");
stringBuilder.append("<div class='separator' onClick='window.javaConnector.toLowerCase(").append(logEntry.getId()).append(")'>");
stringBuilder.append(SECONDS_FORMAT.format(logEntry.getCreatedDate())).append(", ");
stringBuilder.append(logEntry.getOwner()).append(", ");
stringBuilder.append(logEntry.getTitle());
stringBuilder.append("<div style='float: right;'>").append(logEntry.getId()).append("</div>");
stringBuilder.append("<div class='entry-id'>").append(logEntry.getId()).append("</div>");
if(logEntry.getAttachments().size() > 0){
stringBuilder.append("<div class='attachment-icon'>&nbsp;</div>");
}
stringBuilder.append("</div>");
return stringBuilder.toString();
}

private void getLogEntries(LogEntry logEntry) {

String id =
Optional<Property> 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<String, String> mMap = new HashMap<>();
Expand All @@ -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> logEntry = logEntries.stream().filter(l -> Long.toString(l.getId()).equals(value)).findFirst();
if(logEntry.isEmpty()){
return;
}
logSelectionHandler.apply(logEntry.get());
}
}
}
16 changes: 16 additions & 0 deletions app/logbook/olog/ui/src/main/resources/detail_log_webview.css
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

0 comments on commit 272047a

Please sign in to comment.