Add possibility to add notes to recordings

This commit is contained in:
0xboobface 2020-06-13 19:32:00 +02:00
parent 583c4ec722
commit 229fc1f432
10 changed files with 100 additions and 6 deletions

View File

@ -1,3 +1,10 @@
3.8.0
========================
* Server Settings are now editable in the web-interface
* Models can be added by name in the web-interface
* Added a bandwidth monitor
* Improved MFC SD downloads (much less blocking, I think)
3.7.3
========================
* Fixed problem, that MFC wouldn't show any models anymore

View File

@ -11,7 +11,7 @@
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-11"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
<attributes>
<attribute name="maven.pomderived" value="true"/>

View File

@ -1,8 +1,9 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=11
org.eclipse.jdt.core.compiler.codegen.methodParameters=do not generate
org.eclipse.jdt.core.compiler.codegen.targetPlatform=12
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=11
org.eclipse.jdt.core.compiler.compliance=12
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
@ -11,5 +12,5 @@ org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning
org.eclipse.jdt.core.compiler.release=enabled
org.eclipse.jdt.core.compiler.source=11
org.eclipse.jdt.core.compiler.release=disabled
org.eclipse.jdt.core.compiler.source=12

View File

@ -14,6 +14,7 @@ public class JavaFxRecording extends Recording {
private transient StringProperty statusProperty = new SimpleStringProperty();
private transient StringProperty progressProperty = new SimpleStringProperty();
private transient StringProperty notesProperty = new SimpleStringProperty();
private transient LongProperty sizeProperty = new SimpleLongProperty();
private Recording delegate;
@ -24,6 +25,10 @@ public class JavaFxRecording extends Recording {
setStatus(recording.getStatus());
setSizeInByte(recording.getSizeInByte());
setProgress(recording.getProgress());
setNote(recording.getNote());
notesProperty.addListener((obs, oldV, newV) -> {
delegate.setNote(newV);
});
}
public Recording getDelegate() {
@ -203,4 +208,19 @@ public class JavaFxRecording extends Recording {
lastValue = getSizeInByte();
return changed;
}
@Override
public String getNote() {
return delegate.getNote();
}
@Override
public void setNote(String note) {
delegate.setNote(note);
notesProperty.set(note);
}
public StringProperty getNoteProperty() {
return notesProperty;
}
}

View File

@ -17,6 +17,7 @@ import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
@ -42,6 +43,7 @@ import ctbrec.ui.FileDownload;
import ctbrec.ui.JavaFxRecording;
import ctbrec.ui.Player;
import ctbrec.ui.controls.DateTimeCellFactory;
import ctbrec.ui.controls.Dialogs;
import ctbrec.ui.controls.Toast;
import javafx.application.Platform;
import javafx.beans.property.SimpleObjectProperty;
@ -52,6 +54,7 @@ import javafx.concurrent.ScheduledService;
import javafx.concurrent.Task;
import javafx.geometry.Insets;
import javafx.scene.Cursor;
import javafx.scene.Node;
import javafx.scene.control.Alert.AlertType;
import javafx.scene.control.ButtonType;
import javafx.scene.control.ContextMenu;
@ -150,8 +153,12 @@ public class RecordingsTab extends Tab implements TabSelectionListener {
size.setPrefWidth(100);
size.setCellValueFactory(cdf -> cdf.getValue().getSizeProperty());
size.setCellFactory(param -> createSizeCell());
TableColumn<JavaFxRecording, String> notes = new TableColumn<>("Notes");
notes.setId("notes");
notes.setPrefWidth(400);
notes.setCellValueFactory(cdf -> cdf.getValue().getNoteProperty());
table.getColumns().addAll(name, date, status, progress, size);
table.getColumns().addAll(name, date, status, progress, size, notes);
table.setItems(observableRecordings);
table.addEventHandler(ContextMenuEvent.CONTEXT_MENU_REQUESTED, this::onContextMenuRequested);
table.addEventHandler(MouseEvent.MOUSE_PRESSED, this::onMousePressed);
@ -415,6 +422,10 @@ public class RecordingsTab extends Tab implements TabSelectionListener {
contextMenu.getItems().add(downloadRecording);
}
MenuItem notes = new MenuItem("Notes");
notes.setOnAction(e -> notes(first));
contextMenu.getItems().add(notes);
if (first.isPinned()) {
MenuItem unpinRecording = new MenuItem("Unpin");
unpinRecording.setOnAction(e -> unpin(recordings));
@ -440,6 +451,32 @@ public class RecordingsTab extends Tab implements TabSelectionListener {
return contextMenu;
}
private void notes(JavaFxRecording recording) {
Node source = getTabPane();
String notes = recording.getNote();
Optional<String> newNote = Dialogs.showTextInput(source.getScene(), "Recording Notes", "", notes);
if(newNote.isPresent()) {
table.setCursor(Cursor.WAIT);
Thread backgroundThread = new Thread(() -> {
List<Exception> exceptions = new ArrayList<>();
try {
recording.setNote(newNote.get());
recorder.setNote(recording.getDelegate(), newNote.get());
} catch (InvalidKeyException | NoSuchAlgorithmException | IOException e) {
exceptions.add(e);
} finally {
Platform.runLater(() -> {
table.setCursor(Cursor.DEFAULT);
if (!exceptions.isEmpty()) {
showErrorDialog("Error while saving note", "", exceptions);
}
});
}
});
backgroundThread.start();
}
}
private void pin(List<JavaFxRecording> recordings) {
table.setCursor(Cursor.WAIT);
Thread backgroundThread = new Thread(() -> {

View File

@ -36,6 +36,7 @@ public class Recording implements Serializable {
private String metaDataFile;
private boolean singleFile = false;
private boolean pinned = false;
private String note;
public enum State {
RECORDING("recording"),
@ -161,6 +162,14 @@ public class Recording implements Serializable {
this.pinned = pinned;
}
public String getNote() {
return note;
}
public void setNote(String note) {
this.note = note;
}
public Duration getLength() {
if (getDownload() != null) {
return getDownload().getLength();

View File

@ -694,4 +694,10 @@ public class NextGenLocalRecorder implements Recorder {
public void unpin(Recording recording) throws IOException, InvalidKeyException, NoSuchAlgorithmException {
recordingManager.unpin(recording);
}
@Override
public void setNote(Recording rec, String note) throws IOException {
rec.setNote(note);
recordingManager.saveRecording(rec);
}
}

View File

@ -120,4 +120,6 @@ public interface Recorder {
* @throws NoSuchAlgorithmException
*/
public void priorityChanged(Model model) throws IOException, InvalidKeyException, NoSuchAlgorithmException;
public void setNote(Recording rec, String note) throws IOException, InvalidKeyException, NoSuchAlgorithmException;
}

View File

@ -508,4 +508,9 @@ public class RemoteRecorder implements Recorder {
public void priorityChanged(Model model) throws IOException, InvalidKeyException, NoSuchAlgorithmException {
sendRequest("changePriority", model);
}
@Override
public void setNote(Recording recording, String note) throws IOException, InvalidKeyException, NoSuchAlgorithmException {
sendRequest("setNote", recording);
}
}

View File

@ -152,6 +152,13 @@ public class RecorderServlet extends AbstractCtbrecServlet {
resp.getWriter().write("]}");
break;
case "unpin":
recorder.setNote(request.recording, request.recording.getNote());
recAdapter = moshi.adapter(Recording.class);
resp.getWriter().write("{\"status\": \"success\", \"msg\": \"Note saved\", \"recordings\": [");
resp.getWriter().write(recAdapter.toJson(request.recording));
resp.getWriter().write("]}");
break;
case "setNote":
recorder.unpin(request.recording);
recAdapter = moshi.adapter(Recording.class);
resp.getWriter().write("{\"status\": \"success\", \"msg\": \"List of recordings\", \"recordings\": [");