Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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()) {
Expand All @@ -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<LogEntry> 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}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -591,6 +592,11 @@ public OlogQuery fromString(String s) {

}


public List<LogEntry> 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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public class Messages
CloseRequestHeader,
CloseRequestButtonContinue,
CloseRequestButtonDiscard,
CreateLogEntryFromSelection,
DownloadSelected,
DownloadingAttachments,
EditLogEntry,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@
public enum EditMode {

NEW_LOG_ENTRY,
UPDATE_LOG_ENTRY
UPDATE_LOG_ENTRY,
NEW_LOG_ENTRY_FROM_SELECTION
}
Original file line number Diff line number Diff line change
Expand Up @@ -388,9 +388,11 @@
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());

Check warning on line 395 in app/logbook/olog/ui/src/main/java/org/phoebus/logbook/olog/ui/write/LogEntryEditorController.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

This block of commented-out lines of code should be removed.

See more on https://sonarcloud.io/project/issues?id=ControlSystemStudio_phoebus&issues=AZ7vlV9UIn8fCMBI_HO-&open=AZ7vlV9UIn8fCMBI_HO-&pullRequest=3841
descriptionProperty.addListener((observable, oldValue, newValue) -> isDirty = true);

Image tagIcon = ImageCache.getImage(LogEntryEditorController.class, "/icons/add_tag.png");
Expand Down Expand Up @@ -745,17 +747,20 @@
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;

Expand Down
Original file line number Diff line number Diff line change
@@ -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 {

Check warning on line 7 in app/logbook/olog/ui/src/main/java/org/phoebus/logbook/olog/ui/write/LogEntryUtils.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Add a private constructor to hide the implicit public one.

See more on https://sonarcloud.io/project/issues?id=ControlSystemStudio_phoebus&issues=AZ7azf5wbMcWAlw33vma&open=AZ7azf5wbMcWAlw33vma&pullRequest=3841

public static LogEntry createLogEntryFromList(String baseURL, List<LogEntry> 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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
<top>
<ToolBar fx:id="toolBar">
<items>
<Button fx:id="newLogEntryButton" mnemonicParsing="false" onAction="#newLogEntry" text="%NewLogEntry"/>
<Button fx:id="newLogEntryButton" mnemonicParsing="false" onAction="#createNewLogEntry" text="%NewLogEntry"/>
<Button fx:id="replyButton" mnemonicParsing="false" onAction="#reply" text="%Reply" disable="true"/>
<ToggleButton fx:id="showHideLogEntryGroupButton" contentDisplay="RIGHT" mnemonicParsing="false"
text="%ShowHideLogEntryGroup" disable="true" onAction="#showHideLogEntryGroup"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ CloseRequestHeader=Log entry not saved. Do you wish to close?
CloseRequestButtonContinue=Continue Editing
CloseRequestButtonDiscard=Close
CreateLogbookEntry=Create Log Book Entry
#milena
CreateLogEntryFromSelection=Create Log Entry From Selection
CopyMarkdown=Copy Markdown
CopyURL=Copy URL
CSSWindow=CSS Window
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package org.phoebus.logbook.olog.ui.write;

import org.junit.jupiter.api.Test;
import org.phoebus.logbook.*;
import org.phoebus.olog.es.api.model.OlogLog;
import java.util.List;

import static org.junit.jupiter.api.Assertions.*;

public class LogEntryUtilsTest {

@Test
public void testCreateLogEntryFromList(){

OlogLog ologEntry01 = new OlogLog();
ologEntry01.setTitle("Title01");
ologEntry01.setId(1L);

OlogLog ologEntry02 = new OlogLog();
ologEntry02.setTitle("Title02");
ologEntry02.setId(2L);


OlogLog ologEntry03 = new OlogLog();
ologEntry03.setTitle("Title03");
ologEntry03.setId(3L);

LogEntry testListLog = LogEntryUtils.createLogEntryFromList("someURL", List.of(ologEntry01, ologEntry02, ologEntry03));

assertEquals("\n- [Title01](someURL/1)\n- [Title02](someURL/2)\n- [Title03](someURL/3)", testListLog.getSource());
}
}

Loading