|
| 1 | +/** |
| 2 | + * The contents of this file are subject to the license and copyright |
| 3 | + * detailed in the LICENSE file at the root of the source |
| 4 | + * tree and available online at |
| 5 | + * |
| 6 | + * https://github.com/keeps/roda |
| 7 | + */ |
| 8 | +package org.roda.wui.client.common.lists; |
| 9 | + |
| 10 | +import java.util.Arrays; |
| 11 | +import java.util.Date; |
| 12 | +import java.util.HashMap; |
| 13 | +import java.util.List; |
| 14 | +import java.util.Map; |
| 15 | + |
| 16 | +import org.roda.core.data.common.RodaConstants; |
| 17 | +import org.roda.core.data.v2.index.collapse.Collapse; |
| 18 | +import org.roda.core.data.v2.index.sort.Sorter; |
| 19 | +import org.roda.core.data.v2.log.LogEntry; |
| 20 | +import org.roda.wui.client.common.lists.utils.AsyncTableCell; |
| 21 | +import org.roda.wui.client.common.lists.utils.AsyncTableCellOptions; |
| 22 | +import org.roda.wui.client.common.utils.HtmlSnippetUtils; |
| 23 | +import org.roda.wui.common.client.tools.Humanize; |
| 24 | +import org.roda.wui.common.client.tools.StringUtils; |
| 25 | + |
| 26 | +import com.google.gwt.cell.client.DateCell; |
| 27 | +import com.google.gwt.cell.client.SafeHtmlCell; |
| 28 | +import com.google.gwt.core.client.GWT; |
| 29 | +import com.google.gwt.i18n.client.DateTimeFormat; |
| 30 | +import com.google.gwt.safehtml.shared.SafeHtml; |
| 31 | +import com.google.gwt.safehtml.shared.SafeHtmlUtils; |
| 32 | +import com.google.gwt.user.cellview.client.CellTable; |
| 33 | +import com.google.gwt.user.cellview.client.Column; |
| 34 | +import com.google.gwt.user.cellview.client.ColumnSortList; |
| 35 | +import com.google.gwt.user.cellview.client.ColumnSortList.ColumnSortInfo; |
| 36 | +import com.google.gwt.user.cellview.client.TextColumn; |
| 37 | + |
| 38 | +import config.i18n.client.ClientMessages; |
| 39 | + |
| 40 | +public class InternalLogEntryList extends AsyncTableCell<LogEntry> { |
| 41 | + |
| 42 | + private static final ClientMessages messages = GWT.create(ClientMessages.class); |
| 43 | + |
| 44 | + private Column<LogEntry, Date> dateColumn; |
| 45 | + private Column<LogEntry, SafeHtml> actionComponentColumn; |
| 46 | + private TextColumn<LogEntry> actionMethodColumn; |
| 47 | + private TextColumn<LogEntry> usernameColumn; |
| 48 | + private TextColumn<LogEntry> durationColumn; |
| 49 | + private Column<LogEntry, SafeHtml> stateColumn; |
| 50 | + |
| 51 | + private static final List<String> fieldsToReturn = Arrays.asList(RodaConstants.INDEX_UUID, RodaConstants.LOG_ID, |
| 52 | + RodaConstants.LOG_DATETIME, RodaConstants.LOG_ACTION_COMPONENT, RodaConstants.LOG_ACTION_METHOD, |
| 53 | + RodaConstants.LOG_USERNAME, RodaConstants.LOG_DURATION, RodaConstants.LOG_STATE, |
| 54 | + RodaConstants.LOG_REQUEST_HEADER_UUID); |
| 55 | + |
| 56 | + public InternalLogEntryList() { |
| 57 | + super(); |
| 58 | + } |
| 59 | + |
| 60 | + @Override |
| 61 | + protected void adjustOptions(AsyncTableCellOptions<LogEntry> options) { |
| 62 | + options.withFieldsToReturn(fieldsToReturn); |
| 63 | + } |
| 64 | + |
| 65 | + @Override |
| 66 | + protected void configureDisplay(CellTable<LogEntry> display) { |
| 67 | + dateColumn = new Column<LogEntry, Date>( |
| 68 | + new DateCell(DateTimeFormat.getFormat(RodaConstants.DEFAULT_DATETIME_FORMAT))) { |
| 69 | + @Override |
| 70 | + public Date getValue(LogEntry logEntry) { |
| 71 | + return logEntry != null ? logEntry.getDatetime() : null; |
| 72 | + } |
| 73 | + }; |
| 74 | + |
| 75 | + actionComponentColumn = new Column<LogEntry, SafeHtml>(new SafeHtmlCell()) { |
| 76 | + @Override |
| 77 | + public SafeHtml getValue(LogEntry logEntry) { |
| 78 | + return SafeHtmlUtils |
| 79 | + .fromSafeConstant(translate(RodaConstants.LOG_ACTION_COMPONENT, logEntry.getActionComponent())); |
| 80 | + } |
| 81 | + }; |
| 82 | + |
| 83 | + actionMethodColumn = new TextColumn<LogEntry>() { |
| 84 | + @Override |
| 85 | + public String getValue(LogEntry logEntry) { |
| 86 | + if (logEntry == null) { |
| 87 | + return null; |
| 88 | + } |
| 89 | + |
| 90 | + return StringUtils.getPrettifiedActionMethod(logEntry.getActionMethod()); |
| 91 | + } |
| 92 | + }; |
| 93 | + |
| 94 | + usernameColumn = new TextColumn<LogEntry>() { |
| 95 | + @Override |
| 96 | + public String getValue(LogEntry logEntry) { |
| 97 | + return logEntry != null ? logEntry.getUsername() : null; |
| 98 | + } |
| 99 | + }; |
| 100 | + |
| 101 | + durationColumn = new TextColumn<LogEntry>() { |
| 102 | + @Override |
| 103 | + public String getValue(LogEntry logEntry) { |
| 104 | + return logEntry != null ? Humanize.durationMillisToShortDHMS(logEntry.getDuration()) : null; |
| 105 | + } |
| 106 | + }; |
| 107 | + |
| 108 | + stateColumn = new Column<LogEntry, SafeHtml>(new SafeHtmlCell()) { |
| 109 | + @Override |
| 110 | + public SafeHtml getValue(LogEntry logEntry) { |
| 111 | + return HtmlSnippetUtils.getLogEntryStateHtml(logEntry.getState()); |
| 112 | + } |
| 113 | + }; |
| 114 | + |
| 115 | + dateColumn.setSortable(true); |
| 116 | + actionComponentColumn.setSortable(true); |
| 117 | + actionMethodColumn.setSortable(true); |
| 118 | + usernameColumn.setSortable(true); |
| 119 | + durationColumn.setSortable(true); |
| 120 | + stateColumn.setSortable(true); |
| 121 | + |
| 122 | + addColumn(dateColumn, messages.logEntryDate(), true, false, 14); |
| 123 | + addColumn(actionComponentColumn, messages.logEntryComponent(), true, false); |
| 124 | + addColumn(actionMethodColumn, messages.logEntryMethod(), true, false); |
| 125 | + addColumn(usernameColumn, messages.logEntryUser(), true, false); |
| 126 | + addColumn(durationColumn, messages.logEntryDuration(), true, true, 5); |
| 127 | + addColumn(stateColumn, messages.logEntryState(), true, false); |
| 128 | + |
| 129 | + // default sorting |
| 130 | + display.getColumnSortList().push(new ColumnSortInfo(dateColumn, false)); |
| 131 | + addStyleName("my-collections-table"); |
| 132 | + } |
| 133 | + |
| 134 | + @Override |
| 135 | + protected Sorter getSorter(ColumnSortList columnSortList) { |
| 136 | + Map<Column<LogEntry, ?>, List<String>> columnSortingKeyMap = new HashMap<>(); |
| 137 | + columnSortingKeyMap.put(dateColumn, Arrays.asList(RodaConstants.LOG_DATETIME)); |
| 138 | + columnSortingKeyMap.put(actionComponentColumn, Arrays.asList(RodaConstants.LOG_ACTION_COMPONENT)); |
| 139 | + columnSortingKeyMap.put(actionMethodColumn, Arrays.asList(RodaConstants.LOG_ACTION_METHOD)); |
| 140 | + columnSortingKeyMap.put(usernameColumn, Arrays.asList(RodaConstants.LOG_USERNAME)); |
| 141 | + columnSortingKeyMap.put(durationColumn, Arrays.asList(RodaConstants.LOG_DURATION)); |
| 142 | + columnSortingKeyMap.put(stateColumn, Arrays.asList(RodaConstants.LOG_STATE)); |
| 143 | + return createSorter(columnSortList, columnSortingKeyMap); |
| 144 | + } |
| 145 | + |
| 146 | + @Override |
| 147 | + public Collapse getCollapse() { |
| 148 | + return null; |
| 149 | + } |
| 150 | +} |
0 commit comments