Skip to content

Commit

Permalink
context menu with multiple folders selection
Browse files Browse the repository at this point in the history
  • Loading branch information
car031 committed Aug 20, 2024
1 parent e09af03 commit 237c992
Show file tree
Hide file tree
Showing 18 changed files with 849 additions and 806 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -122,10 +122,20 @@ public void store(Folder folder) throws PersistenceException {
public void store(Folder folder, FolderHistory transaction) throws PersistenceException {
if (!checkStoringAspect())
return;

if (folder.getId() != 0L && getCurrentSession().contains(folder))
getCurrentSession().merge(folder);

if (folder.getType() == Folder.TYPE_WORKSPACE) {
Folder defaultWs = findDefaultWorkspace(folder.getTenantId());
if (defaultWs != null && defaultWs.equals(folder) && !folder.getName().equals(Folder.DEFAULTWORKSPACENAME))
throw new PersistenceException("You cannot rename the default workspace");

Folder root = findRoot(folder.getTenantId());
if (root != null && folder.getParentId() != root.getId())
throw new PersistenceException("You cannot move a workspace");
}

if (!folder.getName().equals(SLASH)) {
// To avoid java script and xml injection
folder.setName(HTMLSanitizer.sanitizeSimpleText(folder.getName()));
Expand Down Expand Up @@ -157,7 +167,7 @@ public void store(Folder folder, FolderHistory transaction) throws PersistenceEx
folder.getAttributes().values().removeIf(Attribute::isSection);

AccessControlUtil.removeForbiddenPermissionsForGuests(folder);

if (folder.getTemplate() == null) {
folder.setOcrTemplateId(null);
folder.setBarcodeTemplateId(null);
Expand All @@ -167,7 +177,7 @@ public void store(Folder folder, FolderHistory transaction) throws PersistenceEx
Map<String, Object> dictionary = new HashMap<>();
for (FolderListener listener : listenerManager.getListeners())
listener.beforeStore(folder, transaction, dictionary);

saveOrUpdate(folder);
if (StringUtils.isEmpty(folder.getPath())) {
folder.setPath(computePath(folder.getId()));
Expand Down Expand Up @@ -1159,7 +1169,7 @@ private void checkIfCanDelete(long folderId) throws PersistenceException {
if (folderId == rootId)
throw new PersistenceException("You cannot delete folder " + folder.getName() + " - " + folderId);

if (folder.getName().equals("Default") && folder.getParentId() == rootId)
if (folder.getName().equals(Folder.DEFAULTWORKSPACENAME) && folder.getParentId() == rootId)
throw new PersistenceException("You cannot delete folder " + folder.getName() + " - " + folderId);
}

Expand Down Expand Up @@ -2213,7 +2223,7 @@ public void applyStoreToTree(long id, FolderHistory transaction) throws Persiste
@Override
public void applyOCRToTree(long id, FolderHistory transaction) throws PersistenceException {
Folder parent = getExistingFolder(id);

transaction.setEvent(FolderEvent.CHANGED.toString());
transaction.setTenantId(parent.getTenantId());
transaction.setNotifyEvent(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ public FoldersDS(String id, boolean nopagination, Long max) {

DataSourceTextField folderId = new DataSourceTextField("folderId", I18N.message("id"));
folderId.setHidden(true);

DataSourceTextField parentId = new DataSourceTextField("parentId", I18N.message("parentid"));
parentId.setHidden(true);

DataSourceTextField foldRef = new DataSourceTextField("foldRef");
foldRef.setHidden(true);
Expand All @@ -59,7 +62,7 @@ public FoldersDS(String id, boolean nopagination, Long max) {
parent.setForeignKey(dsId + ".id");
parent.setRootValue("/");

setFields(recordId, name, folderId, foldRef, parent, type, size, color);
setFields(recordId, name, folderId, parentId, foldRef, parent, type, size, color);

setDataURL(
"data/folders.xml" + (nopagination ? "?nopagination=true" : "") + (max != null ? "&max=" + max : ""));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,10 @@ public WebsocketMessage deserializeMessage(String data) {
}

private void onEvent(WebsocketMessage event) {
// Skip events related to other tenants
if (event.getTenantId() != Session.get().getInfo().getTenant().getId())
return;

if (!moniteredEvents.contains(event.getEvent()))
return;

Expand Down Expand Up @@ -149,19 +153,18 @@ private void handleEvent(WebsocketMessage event) {
} else if ("event.reading.requested".equals(event.getEvent())) {
String recipient = event.getComment().substring(event.getComment().indexOf(':') + 1).trim();
if (Session.get().getUser().getUsername().equals(recipient)) {
ReadingRequestService.Instance.get()
.getUnconfimedReadings(new AsyncCallback<>() {

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

@Override
public void onSuccess(List<GUIReadingRequest> readings) {
ReadingRequestController.get().addUnconfirmedReadings(readings);
}
});
ReadingRequestService.Instance.get().getUnconfimedReadings(new AsyncCallback<>() {

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

@Override
public void onSuccess(List<GUIReadingRequest> readings) {
ReadingRequestController.get().addUnconfirmedReadings(readings);
}
});
}
} else if (isCommandEvent(event)) {
processCommand(event);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ public class WebsocketMessage implements Serializable {
private String payload;

private String target;

private long tenantId;

public WebsocketMessage(String sid, String event) {
super();
Expand Down Expand Up @@ -175,4 +177,12 @@ public String getCommand() {
public void setCommand(String command) {
this.command = command;
}

public long getTenantId() {
return tenantId;
}

public void setTenantId(long tenantId) {
this.tenantId = tenantId;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,9 @@ protected void fillContextMenu(GUIFolder folder, final List<GUIDocument> selecti
workflow.addClickHandler(click -> new StartWorkflowDialog(getSelectionIds(selection)).show());

automation = new MenuItem(I18N.message("executeautomation"));
automation.addClickHandler(click -> new AutomationDialog(folder.getId(), getSelectionIds(selection)).show());
automation.addClickHandler(
click -> new AutomationDialog(Arrays.asList(new Long[] { folder.getId() }), getSelectionIds(selection))
.show());

preview = preparePreview();

Expand Down Expand Up @@ -1192,8 +1194,8 @@ public void onSuccess(GUIAutomationRoutine routine) {
* A routine with parameters is referenced, so
* open the input popup
*/
FillRoutineParams dialog = new FillRoutineParams(action.getName(), routine, folderId,
selectedDocIds);
FillRoutineParams dialog = new FillRoutineParams(action.getName(), routine,
Arrays.asList(new Long[] { folderId }), selectedDocIds);
dialog.show();
} else {
/*
Expand Down Expand Up @@ -1254,18 +1256,19 @@ private void onDownload(final GUIFolder folder, final List<GUIDocument> selectio
}

private void executeRoutine(long folderId, List<Long> docIds, GUIAutomationRoutine routine) {
AutomationService.Instance.get().execute(routine, docIds, folderId, new AsyncCallback<>() {
AutomationService.Instance.get().execute(routine, docIds, Arrays.asList(new Long[] { folderId }),
new AsyncCallback<>() {

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

@Override
public void onSuccess(Void arg0) {
// Nothing to do
}
});
@Override
public void onSuccess(Void arg0) {
// Nothing to do
}
});
}

private void onRename(long docId, String newFilename) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,7 @@
public class FillRoutineParams extends Window {
private ExtendedPropertiesPanel propertiesPanel;

private GUIAutomationRoutine routine;

private long folderId;

private List<Long> docIds;

public FillRoutineParams(String title, GUIAutomationRoutine routine, long folderId, List<Long> docIds) {
this.routine = routine;
this.folderId = folderId;
this.docIds = docIds;

public FillRoutineParams(String title, GUIAutomationRoutine routine, List<Long> folderIds, List<Long> docIds) {
setHeaderControls(HeaderControls.HEADER_LABEL, HeaderControls.CLOSE_BUTTON);
setTitle(title);
setWidth(500);
Expand All @@ -47,7 +37,7 @@ public FillRoutineParams(String title, GUIAutomationRoutine routine, long folder
IButton execute = new IButton();
execute.setTitle(I18N.message("execute"));
execute.setAutoFit(true);
execute.addClickHandler(event -> onExecute());
execute.addClickHandler(event -> onExecute(routine, docIds, folderIds));

HLayout buttonsBar = new HLayout();
buttonsBar.setWidth100();
Expand All @@ -64,11 +54,11 @@ public FillRoutineParams(String title, GUIAutomationRoutine routine, long folder
addItem(layout);
}

public void onExecute() {
public void onExecute(GUIAutomationRoutine routine, List<Long> folderIds, List<Long> docIds) {
if (!propertiesPanel.validate())
return;

AutomationService.Instance.get().execute(routine, docIds, folderId, new AsyncCallback<>() {
AutomationService.Instance.get().execute(routine, docIds, folderIds, new AsyncCallback<>() {

@Override
public void onFailure(Throwable caught) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public class AutomationDialog extends Window {

private TabSet tabSet = new TabSet();

public AutomationDialog(Long folderId, List<Long> docIds) {
public AutomationDialog(List<Long> folderIds, List<Long> docIds) {
HeaderControl closeIcon = new HeaderControl(HeaderControl.CLOSE, (ClickEvent event) -> destroy());

setHeaderControls(HeaderControls.HEADER_LABEL, closeIcon);
Expand All @@ -59,7 +59,7 @@ public AutomationDialog(Long folderId, List<Long> docIds) {

ToolStripButton execute = new ToolStripButton();
execute.setTitle(I18N.message("execute"));
execute.addClickHandler(event -> onExecute(folderId, docIds));
execute.addClickHandler(event -> onExecute(folderIds, docIds));

ToolStripButton close = new ToolStripButton();
close.setTitle(I18N.message("close"));
Expand Down Expand Up @@ -136,7 +136,7 @@ private Tab prepareParametersTab() {
return new Tab(I18N.message("parameters"));
}

private void onExecute(Long folderId, List<Long> docIds) {
private void onExecute(List<Long> folderIds, List<Long> docIds) {
if (routine.getId() == 0L && !scriptForm.validate())
return;

Expand All @@ -149,7 +149,7 @@ private void onExecute(Long folderId, List<Long> docIds) {
LD.contactingServer();
AutomationDialog.this.destroy();
GuiLog.info(I18N.message("automationlaunched"));
AutomationService.Instance.get().execute(routine, docIds, folderId, new AsyncCallback<>() {
AutomationService.Instance.get().execute(routine, docIds, folderIds, new AsyncCallback<>() {

@Override
public void onFailure(Throwable caught) {
Expand Down
Loading

0 comments on commit 237c992

Please sign in to comment.