Skip to content

Commit

Permalink
Allow the copy of all the cells in histories
Browse files Browse the repository at this point in the history
  • Loading branch information
car031 committed Oct 21, 2024
1 parent 2060362 commit 5c40468
Show file tree
Hide file tree
Showing 10 changed files with 208 additions and 47 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ public UserHistoryDS(long userId) {
}

public UserHistoryDS(long userId, String event, Integer max) {
this(null, userId, event, null, max);
}

public UserHistoryDS(Long tenantId, Long userId, String event, String commentPrefix, Integer max) {
setRecordXPath("/list/history");
DataSourceTextField user = new DataSourceTextField("user");

Expand All @@ -49,9 +53,15 @@ public UserHistoryDS(long userId, String event, Integer max) {
setFields(user, date, evnt, ip, device, geolocation, comment, reason, sid, key, folderId);
setClientOnly(true);

String url = "data/userhistory.xml?id=" + userId + "&locale=" + I18N.getLocale();
String url = "data/userhistory.xml?&locale=" + I18N.getLocale();
if (tenantId != null)
url += "&tenantId=" + tenantId;
if (userId != null)
url += "&id=" + userId;
if (event != null)
url += "&event=" + event;
if (commentPrefix != null)
url += "&comment=" + commentPrefix;
url += "&max=" + (max != null ? max : getDefaultMaxHistories());
setDataURL(url);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package com.logicaldoc.gui.common.client.widgets.grid;

import com.logicaldoc.gui.common.client.util.LD;
import com.smartgwt.client.widgets.grid.ListGrid;
import com.smartgwt.client.widgets.grid.ListGridField;
import com.smartgwt.client.widgets.grid.events.CellClickEvent;
import com.smartgwt.client.widgets.grid.events.CellClickHandler;

/**
* A click handler useful to give users the option to look and copy into the clipboard the content of a grid cell
*
* @author Marco Meschieri - LogicalDOC
* @since 9.0.1
*/
public class CopyCellClickHandler implements CellClickHandler {
@Override
public void onCellClick(CellClickEvent click) {
ListGrid grid=(ListGrid)click.getSource();
ListGridField field = grid.getField(click.getColNum());
String title = field.getTitle();
String value = grid.getDefaultFormattedFieldValue(click.getRecord(), field);

// In case the value contains HTML formatting, fallback to the original content
if (value != null && (value.contains("<div") || value.contains("<p") || value.contains("<img")
|| value.contains("<b>")))
value = click.getRecord().getAttribute(grid.getFieldName(click.getColNum()));

LD.askForValue(title, title, value, v -> {
// Nothing to do
});
click.cancel();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import com.logicaldoc.gui.common.client.i18n.I18N;
import com.logicaldoc.gui.common.client.util.GridUtil;
import com.logicaldoc.gui.common.client.util.ItemFactory;
import com.logicaldoc.gui.common.client.util.LD;
import com.logicaldoc.gui.common.client.widgets.grid.CopyCellClickHandler;
import com.logicaldoc.gui.common.client.widgets.grid.DateListGridField;
import com.logicaldoc.gui.common.client.widgets.grid.DateListGridField.DateCellFormatter;
import com.logicaldoc.gui.common.client.widgets.grid.FileNameListGridField;
Expand Down Expand Up @@ -67,6 +67,7 @@ protected void onDraw() {
list.setCanFreezeFields(true);
list.setAutoFetchData(true);
list.setDataSource(getDataSource(null));
list.addCellClickHandler(new CopyCellClickHandler());

if (Menu.enabled(Menu.SESSIONS)) {
if (versionFields)
Expand All @@ -81,16 +82,6 @@ protected void onDraw() {
list.setFields(user, event, date, comment, fileName, path);
}

list.addCellClickHandler(click -> {
ListGridField field = list.getField(click.getColNum());
String title = field.getTitle();
String value = list.getDefaultFormattedFieldValue(click.getRecord(), field);
LD.askForValue(title, title, value, v -> {
// Nothing to do
});
click.cancel();
});

ToolStrip buttons = new ToolStrip();
buttons.setWidth100();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import com.logicaldoc.gui.common.client.util.LD;
import com.logicaldoc.gui.common.client.widgets.FolderSelector;
import com.logicaldoc.gui.common.client.widgets.InfoPanel;
import com.logicaldoc.gui.common.client.widgets.grid.CopyCellClickHandler;
import com.logicaldoc.gui.common.client.widgets.grid.DateListGridField;
import com.logicaldoc.gui.common.client.widgets.grid.DateListGridField.DateCellFormatter;
import com.logicaldoc.gui.common.client.widgets.grid.FileNameListGridField;
Expand Down Expand Up @@ -276,19 +277,11 @@ public void onDraw() {
histories.setFilterOnKeypress(true);
histories.setAutoFetchData(true);
histories.sort("date", SortDirection.DESCENDING);
histories.addCellClickHandler(new CopyCellClickHandler());
histories.addCellContextClickHandler(evn -> {
showContextMenu();
evn.cancel();
});
histories.addCellClickHandler(click -> {
ListGridField field = histories.getField(click.getColNum());
String title = field.getTitle();
String value = histories.getDefaultFormattedFieldValue(click.getRecord(), field);
LD.askForValue(title, title, value, v -> {
// Nothing to do
});
click.cancel();
});

results.addMember(histories);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import com.logicaldoc.gui.common.client.i18n.I18N;
import com.logicaldoc.gui.common.client.util.GridUtil;
import com.logicaldoc.gui.common.client.util.ItemFactory;
import com.logicaldoc.gui.common.client.util.LD;
import com.logicaldoc.gui.common.client.widgets.grid.CopyCellClickHandler;
import com.logicaldoc.gui.common.client.widgets.grid.DateListGridField;
import com.logicaldoc.gui.common.client.widgets.grid.DateListGridField.DateCellFormatter;
import com.logicaldoc.gui.common.client.widgets.grid.RefreshableListGrid;
Expand Down Expand Up @@ -44,15 +44,7 @@ public void onDraw() {
list.setAutoFetchData(true);
list.setDataSource(new UserHistoryDS(userId));
list.setFields(event, date, ip, geolocation, device, sid, comment);
list.addCellClickHandler(click -> {
ListGridField field = list.getField(click.getColNum());
String title = field.getTitle();
String value = list.getDefaultFormattedFieldValue(click.getRecord(), field);
LD.askForValue(title, title, value, v -> {
// Nothing to do
});
click.cancel();
});
list.addCellClickHandler(new CopyCellClickHandler());

ToolStrip buttons = new ToolStrip();
buttons.setWidth100();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
* @author Marco Meschieri - LogicalDOC
* @since 8.5.5
*/
public class SearchIndexHistoryPanel extends VLayout {
public class IndexingHistoryPanel extends VLayout {

private static final String EVENTS = "event.indexed,event.indexed.error";

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
package com.logicaldoc.gui.frontend.client.settings.searchindex;

import com.logicaldoc.gui.common.client.Session;
import com.logicaldoc.gui.common.client.data.UserHistoryDS;
import com.logicaldoc.gui.common.client.i18n.I18N;
import com.logicaldoc.gui.common.client.util.GridUtil;
import com.logicaldoc.gui.common.client.util.ItemFactory;
import com.logicaldoc.gui.common.client.widgets.grid.ColoredListGridField;
import com.logicaldoc.gui.common.client.widgets.grid.CopyCellClickHandler;
import com.logicaldoc.gui.common.client.widgets.grid.DateListGridField;
import com.logicaldoc.gui.common.client.widgets.grid.DateListGridField.DateCellFormatter;
import com.logicaldoc.gui.common.client.widgets.grid.RefreshableListGrid;
import com.logicaldoc.gui.common.client.widgets.grid.UserListGridField;
import com.smartgwt.client.types.Alignment;
import com.smartgwt.client.widgets.form.fields.SpinnerItem;
import com.smartgwt.client.widgets.grid.ListGridField;
import com.smartgwt.client.widgets.layout.Layout;
import com.smartgwt.client.widgets.layout.VLayout;
import com.smartgwt.client.widgets.toolbar.ToolStrip;
import com.smartgwt.client.widgets.toolbar.ToolStripButton;

/**
* Shows search history
*
* @author Marco Meschieri - LogicalDOC
* @since 9.0.1
*/
public class SearchHistoryPanel extends VLayout {

private static final String USERID = "userId";

private SpinnerItem maxItem;

@Override
protected void onDraw() {
setWidth100();
setHeight100();
initGUI();
}

private void initGUI() {
ColoredListGridField id = new ColoredListGridField("id");
id.setHidden(true);

ListGridField date = new DateListGridField("date", "date", DateCellFormatter.FORMAT_LONG);

ColoredListGridField comment = new ColoredListGridField("comment", I18N.message("search"));
comment.setWidth("*");
comment.setCellFormatter((value, rcd, rowNum, colNum) -> {
if (value == null)
return null;
String val = value.toString().replace("FulltextSearch[", "").replace(",expression=", ",<b>expression=")
.replace(",userId=", "</b>,userId=").replace(",fields=", ",<b>fields=")
.replace(",page=", "</b>,page=");
if (val.endsWith("]"))
val = val.substring(0, val.length() - 1);
return val;
});

ListGridField userId = new ListGridField(USERID, I18N.message("userid"), 100);
userId.setCanFilter(true);
userId.setHidden(true);

ListGridField userField = new UserListGridField("user", USERID, "user");
userField.setCanFilter(true);
userField.setAlign(Alignment.CENTER);

final RefreshableListGrid list = new RefreshableListGrid();
list.setEmptyMessage(I18N.message("notitemstoshow"));
list.setCanFreezeFields(true);
list.setAutoFetchData(true);
list.setDataSource(new UserHistoryDS(Session.get().getTenantId(), null, "event.user.search", "Fulltext",
Session.get().getConfigAsInt("gui.maxhistories")));
list.setFields(id, date, userId, userField, comment);
list.addCellClickHandler(new CopyCellClickHandler());

ToolStrip buttons = new ToolStrip();
buttons.setWidth100();

maxItem = ItemFactory.newSpinnerItem("max", "display", Session.get().getConfigAsInt("gui.maxhistories"), 1,
(Integer) null);
maxItem.setWidth(70);
maxItem.setStep(20);
maxItem.setSaveOnEnter(true);
maxItem.setImplicitSave(true);
maxItem.setHint(I18N.message("elements"));
maxItem.addChangedHandler(evnt -> refresh(list));

ToolStripButton refresh = new ToolStripButton(I18N.message("refresh"));
refresh.addClickHandler(evnt -> refresh(list));

buttons.addButton(refresh);
buttons.addFormItem(maxItem);
buttons.addSeparator();

ToolStripButton export = new ToolStripButton(I18N.message("export"));
buttons.addButton(export);
export.addClickHandler(evnt -> GridUtil.exportCSV(list, true));

ToolStripButton print = new ToolStripButton(I18N.message("print"));
buttons.addButton(print);
print.addClickHandler(evnt -> GridUtil.print(list));

buttons.addSeparator();

Layout container = new VLayout();
container.setMembersMargin(3);
container.addMember(buttons);
container.addMember(list);
addMember(container);
}

private void refresh(RefreshableListGrid list) {
list.refresh(new UserHistoryDS(Session.get().getTenantId(), null, "event.user.search", "Fulltext",
Integer.parseInt(maxItem.getValueAsString())));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -117,12 +117,12 @@ public void onSuccess(GUISearchEngine searchEngine) {
tabs.addTab(fillFiltersTab());
tabs.addTab(fillLanguagesTab());
tabs.addTab(fillParsersTab());
tabs.addTab(fillHistoryTab());

if (Session.get().isDefaultTenant()) {
tabs.addTab(fillIndexingQueueTab(100));
tabs.addTab(fillEntiesTab());
}
tabs.addTab(fillIndexingHistoryTab());
tabs.addTab(fillSearchHistoryTab());
}
});
}
Expand All @@ -141,10 +141,16 @@ private Tab fillIndexingQueueTab(final int maxValue) {
return indexingQueueTab;
}

private Tab fillHistoryTab() {
Tab historyTab = new Tab(I18N.message("indexinghistory"));
historyTab.setPane(new SearchIndexHistoryPanel());
return historyTab;
private Tab fillIndexingHistoryTab() {
Tab indexingHistoryTab = new Tab(I18N.message("indexinghistory"));
indexingHistoryTab.setPane(new IndexingHistoryPanel());
return indexingHistoryTab;
}

private Tab fillSearchHistoryTab() {
Tab searchHistoryTab = new Tab(I18N.message("searchhistory"));
searchHistoryTab.setPane(new SearchHistoryPanel());
return searchHistoryTab;
}

private Tab fillParsersTab() {
Expand Down Expand Up @@ -499,7 +505,7 @@ public void onSuccess(Long count) {
timeoutRetain.setHint(I18N.message("ontimeoutretaintexthint"));
timeoutRetain.setValue(this.searchEngine.isParsingTimeoutRetain() ? "yes" : "no");
timeoutRetain.setRequired(true);

// The optional max text that will be put in the index
SpinnerItem maxText = ItemFactory.newSpinnerItem("maxtext", this.searchEngine.getMaxText());
maxText.setHint(I18N.message("maxtextinindex"));
Expand Down
3 changes: 2 additions & 1 deletion logicaldoc-i18n/src/main/resources/i18n/messages.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2622,4 +2622,5 @@ eventhasbeencanceled = The event has been canceled
askalertcancelation = Do you want to notify attendees about this cancelation ?
canceledevent = Canceled event
result = Result
indexinghistory = Indexing History
indexinghistory = Indexing History
searchhistory = Search History
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,15 @@ protected void service(HttpServletRequest request, HttpServletResponse response,
MenuDAO mDao = (MenuDAO) Context.get().getBean(MenuDAO.class);
boolean showSid = mDao.isReadEnable(Menu.SESSIONS, session.getUserId());

long userId = Long.parseLong(request.getParameter("id"));
Long userId = StringUtils.isNotEmpty(request.getParameter("id")) ? Long.parseLong(request.getParameter("id"))
: null;
Long tenantId = StringUtils.isNotEmpty(request.getParameter("tenantId"))
? Long.parseLong(request.getParameter("tenantId"))
: null;
String comment = request.getParameter("comment");
String event = request.getParameter("event");

List<Object> records = executeQuery(max, userId, event);
List<Object> records = executeQuery(max, tenantId, userId, event, comment);

PrintWriter writer = response.getWriter();
writer.write("<list>");
Expand All @@ -54,7 +59,7 @@ protected void service(HttpServletRequest request, HttpServletResponse response,
*/
for (Object gridRecord : records)
printHistory(writer, (Object[]) gridRecord, locale, showSid, df);

writer.write("</list>");
}

Expand All @@ -78,20 +83,33 @@ private void printHistory(PrintWriter writer, Object[] columns, Locale locale, b
if (columns[10] != null)
writer.print("<geolocation><![CDATA[" + columns[10] + "]]></geolocation>");
if (columns[11] != null)
writer.print("<geolocation><![CDATA[" + columns[11] + "]]></geolocation>");
writer.print("<geolocation><![CDATA[" + columns[11] + "]]></geolocation>");
writer.print("</history>");
}

private List<Object> executeQuery(Integer max, long userId, String event) throws PersistenceException {
private List<Object> executeQuery(Integer max, Long tenantId, Long userId, String event, String comment)
throws PersistenceException {
Map<String, Object> params = new HashMap<>();
params.put("userId", userId);

StringBuilder query = new StringBuilder(
"select A.id, A.username, A.event, A.date, A.comment, A.reason, A.sessionId, A.userId, A.ip, A.device, A.geolocation, A.keyLabel from UserHistory A where A.deleted = 0 and A.userId = :userId ");
"select A.id, A.username, A.event, A.date, A.comment, A.reason, A.sessionId, A.userId, A.ip, A.device, A.geolocation, A.keyLabel from UserHistory A where A.deleted = 0 ");
if (StringUtils.isNotEmpty(event)) {
query.append(" and A.event = :event ");
params.put("event", event);
}
if (tenantId != null) {
query.append(" and A.tenantId = :tenantId ");
params.put("tenantId", tenantId);
}
if (userId != null) {
query.append(" and A.userId = :userId ");
params.put("userId", userId);
}
if (StringUtils.isNotEmpty(comment)) {
query.append(" and A.comment like :comment ");
params.put("comment", comment + "%");
}

query.append(" order by A.date desc ");

UserHistoryDAO dao = (UserHistoryDAO) Context.get().getBean(UserHistoryDAO.class);
Expand Down

0 comments on commit 5c40468

Please sign in to comment.