Skip to content

Commit

Permalink
1262 Add notes on past versions of a document
Browse files Browse the repository at this point in the history
  • Loading branch information
car031 committed Jun 21, 2024
1 parent 46a20ec commit 75ce635
Show file tree
Hide file tree
Showing 11 changed files with 157 additions and 70 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2739,7 +2739,7 @@ public static RichTextItem newRichTextItemForNote(String name, String title, Str
item.setShowTitle(false);
item.setRequired(true);
item.setWidth("*");
item.setHeight("*");
item.setHeight(300);

addNoteValidator(item);
return item;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.logicaldoc.gui.common.client.widgets;

/**
* Listener invoked when the note has been changed/saved
*
* @author Marco Meschieri - LogicalDOC
* @since 8.9.3
*/
public interface NoteChangeListener {
public void onChanged();
}
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ protected void captureNotesPosition() {
*/
protected void onSave() {
captureNotesPosition();
DocumentService.Instance.get().saveNotes(document.getId(), notes, types, new AsyncCallback<>() {
DocumentService.Instance.get().saveNotes(document.getId(), fileVersion, notes, types, new AsyncCallback<>() {
@Override
public void onFailure(Throwable caught) {
GuiLog.serverError(caught);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
import com.logicaldoc.gui.common.client.i18n.I18N;
import com.logicaldoc.gui.common.client.util.AwesomeFactory;
import com.logicaldoc.gui.common.client.util.LD;
import com.logicaldoc.gui.common.client.widgets.NoteChangeListener;
import com.smartgwt.client.widgets.drawing.DrawItem;
import com.smartgwt.client.widgets.events.ClickEvent;
import com.smartgwt.client.widgets.menu.Menu;
import com.smartgwt.client.widgets.menu.MenuItem;
import com.smartgwt.client.widgets.menu.events.MenuItemClickEvent;
import com.smartgwt.client.widgets.toolbar.ToolStrip;
import com.smartgwt.client.widgets.toolbar.ToolStripButton;
import com.smartgwt.client.widgets.toolbar.ToolStripMenuButton;
Expand All @@ -34,23 +34,23 @@ public class AnnotationsWindow extends AbstractAnnotationsWindow {

private static final String COMMENT_FLIPPED = "comment-flipped";

private NotesPanel notesPanel;

private boolean editEnabled = true;

private NoteChangeListener saveHandler;

/**
* Constructor
*
* @param doc the document to be displayed
* @param fileVer file version specification, null to use the current
* version
* @param notesPanel the notes panel associated to this window, optional
* @param saveHandler the handler to invoke on save
* @param editEnabled if the user can edit the annotations
*/
public AnnotationsWindow(GUIDocument doc, String fileVer, NotesPanel notesPanel, boolean editEnabled) {
public AnnotationsWindow(GUIDocument doc, String fileVer, NoteChangeListener saveHandler, boolean editEnabled) {
super(doc, fileVer != null ? fileVer : doc.getFileVersion(), null);

this.notesPanel = notesPanel;
this.saveHandler = saveHandler;
this.editEnabled = editEnabled;
}

Expand Down Expand Up @@ -125,13 +125,13 @@ private ToolStripMenuButton getShapeMenuButton() {
menu.setShadowDepth(3);

MenuItem arrow = new MenuItem(AwesomeFactory.getIconHtml("arrow-alt-right"));
arrow.addClickHandler((MenuItemClickEvent event) -> addNewNote("thickarrow"));
arrow.addClickHandler(click -> addNewNote("thickarrow"));

MenuItem comment = new MenuItem(AwesomeFactory.getIconHtml(COMMENT_ALT));
comment.addClickHandler((MenuItemClickEvent event) -> addNewNote(COMMENT));
comment.addClickHandler(click -> addNewNote(COMMENT));

MenuItem commentFlipped = new MenuItem(AwesomeFactory.getIconHtml(COMMENT_ALT, "fa-rotate-180", null));
commentFlipped.addClickHandler((MenuItemClickEvent event) -> addNewNote(COMMENT_FLIPPED));
commentFlipped.addClickHandler(click -> addNewNote(COMMENT_FLIPPED));

menu.setData(comment, commentFlipped, arrow);

Expand All @@ -144,10 +144,10 @@ private ToolStripMenuButton getPolygonMenuButton() {
menu.setShadowDepth(3);

MenuItem square = new MenuItem(AwesomeFactory.getIconHtml(SQUARE2));
square.addClickHandler((MenuItemClickEvent event) -> addNewNote(SQUARE2));
square.addClickHandler(click -> addNewNote(SQUARE2));

MenuItem circle = new MenuItem(AwesomeFactory.getIconHtml(CIRCLE));
circle.addClickHandler((MenuItemClickEvent event) -> addNewNote(CIRCLE));
circle.addClickHandler(click -> addNewNote(CIRCLE));

menu.setItems(square, circle);

Expand All @@ -160,10 +160,10 @@ private ToolStripMenuButton getLineMenuButton() {
menu.setShadowDepth(3);

MenuItem line = new MenuItem(AwesomeFactory.getIconHtml("horizontal-rule"));
line.addClickHandler((MenuItemClickEvent event) -> addNewNote("line"));
line.addClickHandler(click -> addNewNote("line"));

MenuItem arrow = new MenuItem(AwesomeFactory.getIconHtml("long-arrow-right"));
arrow.addClickHandler((MenuItemClickEvent event) -> addNewNote("arrow"));
arrow.addClickHandler(click -> addNewNote("arrow"));

menu.setItems(line, arrow);

Expand All @@ -172,8 +172,8 @@ private ToolStripMenuButton getLineMenuButton() {

@Override
protected void onNotesSaved() {
if (notesPanel != null)
notesPanel.refresh();
if (saveHandler != null)
saveHandler.onChanged();
destroy();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
import com.logicaldoc.gui.common.client.i18n.I18N;
import com.logicaldoc.gui.common.client.log.GuiLog;
import com.logicaldoc.gui.common.client.util.ItemFactory;
import com.logicaldoc.gui.common.client.widgets.NoteChangeListener;
import com.logicaldoc.gui.frontend.client.services.DocumentService;
import com.smartgwt.client.types.HeaderControls;
import com.smartgwt.client.widgets.HeaderControl;
import com.smartgwt.client.widgets.Window;
import com.smartgwt.client.widgets.form.DynamicForm;
import com.smartgwt.client.widgets.form.fields.RichTextItem;
import com.smartgwt.client.widgets.form.fields.events.ChangedHandler;
import com.smartgwt.client.widgets.toolbar.ToolStrip;
import com.smartgwt.client.widgets.toolbar.ToolStripButton;

Expand All @@ -34,10 +34,10 @@ public class NoteUpdateDialog extends Window {

private DynamicForm noteForm;

private ChangedHandler saveHandler;
private NoteChangeListener saveHandler;

public NoteUpdateDialog(final long docId, final long noteId, String fileVersion, String noteMessage,
final ChangedHandler saveHandler) {
final NoteChangeListener saveHandler) {
super();
this.saveHandler = saveHandler;
this.noteId = noteId;
Expand Down Expand Up @@ -73,10 +73,12 @@ private void initGUI(String noteMessage) {
close.addClickHandler(event -> destroy());

toolStrip = new ToolStrip();
toolStrip.setWidth100();
toolStrip.addButton(save);
toolStrip.addSeparator();
toolStrip.addButton(close);
toolStrip.addFill();
toolStrip.setWidth100();
toolStrip.setMinWidth(590);

message = ItemFactory.newRichTextItemForNote("message", "message", noteMessage);
message.setBrowserSpellCheck(false);
Expand All @@ -94,26 +96,26 @@ private void onSave() {
if (!noteForm.validate())
return;

DocumentService.Instance.get().updateNote(docId, noteId, fileVersion, message.getValue().toString(), new AsyncCallback<>() {

@Override
public void onFailure(Throwable caught) {
GuiLog.serverError(caught);
destroy();
}

@Override
public void onSuccess(Void result) {
if (saveHandler != null)
saveHandler.onChanged(null);
destroy();
}
});
DocumentService.Instance.get().updateNote(docId, noteId, fileVersion, message.getValue().toString(),
new AsyncCallback<>() {

@Override
public void onFailure(Throwable caught) {
GuiLog.serverError(caught);
destroy();
}

@Override
public void onSuccess(Void result) {
if (saveHandler != null)
saveHandler.onChanged();
destroy();
}
});
}

private void resetDimensions() {
setWidth(580);
setHeight(300);
setAutoSize(true);
centerInPage();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,12 @@ public void refresh() {

ToolStripButton addNote = new ToolStripButton(I18N.message("addnote"));
addNote.addClickHandler(
click -> new NoteUpdateDialog(document.getId(), 0L, null, null, save -> refresh()).show());
click -> new NoteUpdateDialog(document.getId(), 0L, null, null, () -> refresh()).show());

ToolStripButton annotations = new ToolStripButton(I18N.message("annotations"));
annotations.addClickHandler(
click -> new com.logicaldoc.gui.frontend.client.document.note.AnnotationsWindow(document, null,
NotesPanel.this, true).show());
() -> refresh(), true).show());

ToolStripButton export = new ToolStripButton(I18N.message("export"));
export.addClickHandler(click -> GridUtil.exportCSV(notesGrid, true));
Expand Down Expand Up @@ -132,12 +132,9 @@ public void refresh() {
MenuItem edit = new MenuItem();
edit.setTitle(I18N.message("edit"));
edit.setEnabled(false);
edit.addClickHandler(clickEvent -> {
NoteUpdateDialog note = new NoteUpdateDialog(document.getId(),
notesGrid.getSelectedRecord().getAttributeAsLong("id"), null,
notesGrid.getSelectedRecord().getAttribute(MESSAGE), save -> refresh());
note.show();
});
edit.addClickHandler(clickEvent -> new NoteUpdateDialog(document.getId(),
notesGrid.getSelectedRecord().getAttributeAsLong("id"), null,
notesGrid.getSelectedRecord().getAttribute(MESSAGE), () -> refresh()).show());

MenuItem prnt = new MenuItem();
prnt.setTitle(I18N.message("print"));
Expand Down
Loading

0 comments on commit 75ce635

Please sign in to comment.