diff --git a/app/logbook/olog/ui/src/main/java/org/phoebus/logbook/olog/ui/LogEntryDisplayController.java b/app/logbook/olog/ui/src/main/java/org/phoebus/logbook/olog/ui/LogEntryDisplayController.java index 5be01d52e3..b86b7cdc6c 100644 --- a/app/logbook/olog/ui/src/main/java/org/phoebus/logbook/olog/ui/LogEntryDisplayController.java +++ b/app/logbook/olog/ui/src/main/java/org/phoebus/logbook/olog/ui/LogEntryDisplayController.java @@ -38,10 +38,12 @@ import org.phoebus.logbook.LogEntry; import org.phoebus.logbook.olog.ui.write.EditMode; import org.phoebus.logbook.olog.ui.write.LogEntryEditorStage; +import org.phoebus.logbook.olog.ui.write.LogEntryUtils; import org.phoebus.olog.es.api.model.LogGroupProperty; import org.phoebus.olog.es.api.model.OlogLog; import org.phoebus.ui.javafx.ImageCache; +import java.util.List; import java.util.logging.Level; import java.util.logging.Logger; @@ -184,12 +186,6 @@ public void reply() { new LogEntryEditorStage(new OlogLog(), logEntryProperty.get(), EditMode.NEW_LOG_ENTRY).show(); } - @FXML - public void newLogEntry(){ - // Show a new editor dialog. - new LogEntryEditorStage(new OlogLog(), null, EditMode.NEW_LOG_ENTRY).show(); - } - @FXML public void goBack() { if (logEntryTableViewController.goBackAndGoForwardActions.isPresent()) { @@ -204,6 +200,22 @@ public void goForward() { } } + /** + * Creates a new Log Entry. + * If 2 or more existing Log Entries in the list are selected, + * they get linked into the description of the new Log Entry. + * */ + @FXML + public void createNewLogEntry(){ + List selectedLogEntries = logEntryTableViewController.getSelectedLogEntries(); + if (selectedLogEntries.size() > 1){ + LogEntry logEntry = LogEntryUtils.createLogEntryFromList(LogbookUIPreferences.web_client_root_URL, selectedLogEntries); + new LogEntryEditorStage(logEntry,null, EditMode.NEW_LOG_ENTRY_FROM_SELECTION).show(); + } else { + new LogEntryEditorStage(new OlogLog(), null, EditMode.NEW_LOG_ENTRY).show(); + } + } + /** * Sets/renders the {@link LogEntry} in the view unless already rendered or unedited. * @param logEntry A non-null {@link LogEntry} diff --git a/app/logbook/olog/ui/src/main/java/org/phoebus/logbook/olog/ui/LogEntryTableViewController.java b/app/logbook/olog/ui/src/main/java/org/phoebus/logbook/olog/ui/LogEntryTableViewController.java index 3e5bb795be..aafd648f5e 100644 --- a/app/logbook/olog/ui/src/main/java/org/phoebus/logbook/olog/ui/LogEntryTableViewController.java +++ b/app/logbook/olog/ui/src/main/java/org/phoebus/logbook/olog/ui/LogEntryTableViewController.java @@ -56,6 +56,7 @@ import org.phoebus.logbook.olog.ui.spi.Decoration; import org.phoebus.logbook.olog.ui.write.EditMode; import org.phoebus.logbook.olog.ui.write.LogEntryEditorStage; +import org.phoebus.logbook.olog.ui.write.LogEntryUtils; import org.phoebus.olog.es.api.model.LogGroupProperty; import org.phoebus.olog.es.api.model.OlogLog; import org.phoebus.security.store.SecureStore; @@ -591,6 +592,11 @@ public OlogQuery fromString(String s) { } + + public List getSelectedLogEntries(){ + return selectedLogEntries; + } + /** * Wrapper class for a {@link LogEntry} and a flag indicating whether details of the * log entry meta-data should be rendered in the list view. diff --git a/app/logbook/olog/ui/src/main/java/org/phoebus/logbook/olog/ui/Messages.java b/app/logbook/olog/ui/src/main/java/org/phoebus/logbook/olog/ui/Messages.java index b6a741f161..ba732b94c2 100644 --- a/app/logbook/olog/ui/src/main/java/org/phoebus/logbook/olog/ui/Messages.java +++ b/app/logbook/olog/ui/src/main/java/org/phoebus/logbook/olog/ui/Messages.java @@ -28,6 +28,7 @@ public class Messages CloseRequestHeader, CloseRequestButtonContinue, CloseRequestButtonDiscard, + CreateLogEntryFromSelection, DownloadSelected, DownloadingAttachments, EditLogEntry, diff --git a/app/logbook/olog/ui/src/main/java/org/phoebus/logbook/olog/ui/write/EditMode.java b/app/logbook/olog/ui/src/main/java/org/phoebus/logbook/olog/ui/write/EditMode.java index aac9c57b90..11bba351ee 100644 --- a/app/logbook/olog/ui/src/main/java/org/phoebus/logbook/olog/ui/write/EditMode.java +++ b/app/logbook/olog/ui/src/main/java/org/phoebus/logbook/olog/ui/write/EditMode.java @@ -7,5 +7,6 @@ public enum EditMode { NEW_LOG_ENTRY, - UPDATE_LOG_ENTRY + UPDATE_LOG_ENTRY, + NEW_LOG_ENTRY_FROM_SELECTION } diff --git a/app/logbook/olog/ui/src/main/java/org/phoebus/logbook/olog/ui/write/LogEntryEditorController.java b/app/logbook/olog/ui/src/main/java/org/phoebus/logbook/olog/ui/write/LogEntryEditorController.java index f5b0008876..d281d1d23f 100644 --- a/app/logbook/olog/ui/src/main/java/org/phoebus/logbook/olog/ui/write/LogEntryEditorController.java +++ b/app/logbook/olog/ui/src/main/java/org/phoebus/logbook/olog/ui/write/LogEntryEditorController.java @@ -388,9 +388,11 @@ public void initialize() { titleProperty.set(logEntry.getTitle()); textArea.textProperty().bindBidirectional(descriptionProperty); - // When editing an existing entry, set the description to the source of the entry. - descriptionProperty.set(editMode.equals(EditMode.UPDATE_LOG_ENTRY) ? logEntry.getSource() : - (logEntry.getDescription() != null ? logEntry.getDescription() : "")); + switch(editMode){ + case NEW_LOG_ENTRY -> descriptionProperty.set(""); + case UPDATE_LOG_ENTRY, NEW_LOG_ENTRY_FROM_SELECTION -> descriptionProperty.set(logEntry.getSource()); + } +// descriptionProperty.set(logEntry.getSource()); descriptionProperty.addListener((observable, oldValue, newValue) -> isDirty = true); Image tagIcon = ImageCache.getImage(LogEntryEditorController.class, "/icons/add_tag.png"); @@ -745,17 +747,20 @@ public void submit() { LogClient logClient = logFactory.getLogClient(new SimpleAuthenticationToken(usernameProperty.get(), passwordProperty.get())); try { - if(editMode.equals(EditMode.NEW_LOG_ENTRY)){ - if (replyTo == null) { + switch(editMode){ + case NEW_LOG_ENTRY: + if (replyTo == null) { + logEntryResult = Optional.of(logClient.set(ologLog)); + } else { + logEntryResult = Optional.of(logClient.reply(ologLog, replyTo)); + } + break; + case UPDATE_LOG_ENTRY: + logEntryResult = Optional.of(logClient.update(ologLog)); + break; + case NEW_LOG_ENTRY_FROM_SELECTION: logEntryResult = Optional.of(logClient.set(ologLog)); - } else { - logEntryResult = Optional.of(logClient.reply(ologLog, replyTo)); - } - } - else{ - logEntryResult = Optional.of(logClient.update(ologLog)); } - // Not dirty anymore... isDirty = false; diff --git a/app/logbook/olog/ui/src/main/java/org/phoebus/logbook/olog/ui/write/LogEntryUtils.java b/app/logbook/olog/ui/src/main/java/org/phoebus/logbook/olog/ui/write/LogEntryUtils.java new file mode 100644 index 0000000000..291061af66 --- /dev/null +++ b/app/logbook/olog/ui/src/main/java/org/phoebus/logbook/olog/ui/write/LogEntryUtils.java @@ -0,0 +1,20 @@ +package org.phoebus.logbook.olog.ui.write; + +import org.phoebus.logbook.LogEntry; +import org.phoebus.olog.es.api.model.OlogLog; +import java.util.List; + +public class LogEntryUtils { + + public static LogEntry createLogEntryFromList(String baseURL, List logEntries){ + OlogLog log = new OlogLog(); + StringBuilder stringBuilder = new StringBuilder(); + logEntries.forEach(l -> { + stringBuilder.append("\n"); + stringBuilder.append("- [").append(l.getTitle()).append("](").append(baseURL).append("/").append(l.getId()).append(")"); + }); + + log.setSource(stringBuilder.toString()); + return log; + } +} diff --git a/app/logbook/olog/ui/src/main/resources/org/phoebus/logbook/olog/ui/LogEntryDisplay.fxml b/app/logbook/olog/ui/src/main/resources/org/phoebus/logbook/olog/ui/LogEntryDisplay.fxml index a1ee45a978..e11f3f9cb0 100644 --- a/app/logbook/olog/ui/src/main/resources/org/phoebus/logbook/olog/ui/LogEntryDisplay.fxml +++ b/app/logbook/olog/ui/src/main/resources/org/phoebus/logbook/olog/ui/LogEntryDisplay.fxml @@ -28,7 +28,7 @@ -