diff --git a/CHANGELOG.md b/CHANGELOG.md index c9c742b..d84e65e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file. This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [v3.2.2-SNAPSHOT] - 2024-01-11 + +- Improved display of results on multiple fields (in the table) [#26372] + ## [v3.2.1] - 2023-06-16 - Fixed issue in the Search facility [#25265] diff --git a/pom.xml b/pom.xml index 702b870..b429949 100644 --- a/pom.xml +++ b/pom.xml @@ -14,7 +14,7 @@ org.gcube.portlets.user geoportal-data-entry-app war - 3.2.1 + 3.2.2-SNAPSHOT GeoPortal Data Entry App The GeoPortal Data Entry App is an application to build the web forms for data entries needed to create projects/documents (based on UCD) in the D4Science Geoportal service diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/ui/GeonaRecordsPaginatedView.java b/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/ui/GeonaRecordsPaginatedView.java index af1f8ab..8c69f93 100644 --- a/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/ui/GeonaRecordsPaginatedView.java +++ b/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/ui/GeonaRecordsPaginatedView.java @@ -188,6 +188,16 @@ public class GeonaRecordsPaginatedView { } // initFirstRangeChanged = false; + //printData((List) result.getData()); + } + + private void printData(List data) { + GWT.log("printData"); + int i = 0; + for (DocumentDV documentDV : data) { + GWT.log(++i + ") json: " + documentDV.getDocumentAsJSON()); + } + } /** diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/ui/table/ItemsTable.java b/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/ui/table/ItemsTable.java index 0317876..fe6dc50 100644 --- a/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/ui/table/ItemsTable.java +++ b/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/ui/table/ItemsTable.java @@ -27,6 +27,7 @@ import com.google.gwt.core.shared.GWT; import com.google.gwt.dom.client.Style.Unit; import com.google.gwt.event.shared.HandlerManager; import com.google.gwt.i18n.client.DateTimeFormat; +import com.google.gwt.safehtml.client.SafeHtmlTemplates; import com.google.gwt.safehtml.shared.SafeHtml; import com.google.gwt.safehtml.shared.SafeHtmlBuilder; import com.google.gwt.safehtml.shared.SafeHtmlUtils; @@ -102,6 +103,127 @@ public class ItemsTable extends AbstractItemsCellTable super.addItems(items); } + class CellRender { + + String tooltip; + String value; + + public CellRender() { + } + + public String getTooltip() { + return tooltip; + } + + public String getValue() { + return value; + } + + public void setTooltip(String tooltip) { + this.tooltip = tooltip; + } + + public void setValue(String value) { + this.value = value; + } + + } + + public CellRender toCellRender(ItemFieldDV itemField, DocumentDV documentDV) { + + StringBuilder tooltipBuilder = new StringBuilder(); + StringBuilder valueBuilder = new StringBuilder(); + String newLine = "
"; + String newLineTxt = "\n"; + String bullet = "• "; // it is the dot. As
  • rendered in the
      tag + + String newBullet = newLine + bullet; + + List listJsonFields = itemField.getJsonFields(); + + int numberOfFields = listJsonFields.size(); + + if (numberOfFields > 1) { + valueBuilder.append(bullet); + } + + for (String jsonKey : listJsonFields) { + + try { + String objectToRender = ""; + // removing the '_theDocument.' prefix for searching in the Document Map + String key = jsonKey.replace(ConstantsGeoPortalDataEntryApp.DEFAULT_DOCUMENT_PROJECTION_NAME + ".", ""); + Object value = documentDV.getDocumentAsMap().get(key); + // GWT.log("key: "+key+" is instance of: "+value.getClass()); + + if (value == null) + continue; + + GWT.log("value instance: " + value.getClass()); + + if (value instanceof ArrayList) { + ArrayList arrayValues = (ArrayList) value; + String toReturn = "
        "; + for (Object arrayValue : arrayValues) { + toReturn += "
      • " + arrayValue + "
      • "; + } + toReturn += "
      "; + GWT.log("Array returning: " + key + " is instance of: " + value.getClass() + " to return: " + + toReturn); + objectToRender = StringUtil.ellipsize(toReturn, MAX_TEXT_DIMENSION); + } else { + objectToRender = StringUtil.ellipsize(value.toString(), MAX_TEXT_DIMENSION); + } + + valueBuilder.append(objectToRender); + valueBuilder.append(newBullet); + + if (numberOfFields > 1) { + tooltipBuilder.append("* " + key + newLineTxt); + }else { + tooltipBuilder.append(key); + } + + + } catch (Exception e) { + GWT.log("Error e: " + e); + } + } + + CellRender cellRender = new CellRender(); + + String toRender = valueBuilder.toString(); + cellRender.setValue(toRender.substring(0, toRender.length() - newBullet.length())); + + String toTooltip = tooltipBuilder.toString(); + toTooltip = numberOfFields > 1 ? toTooltip.substring(0, toTooltip.length() - newLineTxt.length()) + : toTooltip; + cellRender.setTooltip(toTooltip); + + return cellRender; + + } + + interface Templates extends SafeHtmlTemplates { + + /** + * Start tool tip. + * + * @param toolTipText the tool tip text + * @return the safe html + */ + @Template("") + SafeHtml startToolTip(String toolTipText); + + /** + * End tool tip. + * + * @return the safe html + */ + @Template("") + SafeHtml endToolTip(); + } + /** * Inits the table. * @@ -130,27 +252,10 @@ public class ItemsTable extends AbstractItemsCellTable String displayName = itemField.getDisplayName(); TextColumn col = new TextColumn() { + @Override public String getValue(T object) { - if (object == null) - return ""; - - DocumentDV documentDV = (DocumentDV) object; - - try { - // removing the '_theDocument.' prefix for searching in the Document Map - String key = itemField.getJsonFields().get(0) - .replace(ConstantsGeoPortalDataEntryApp.DEFAULT_DOCUMENT_PROJECTION_NAME + ".", ""); - Object value = documentDV.getDocumentAsMap().get(key); - if(value==null) - return ""; - - return value.toString(); - } catch (Exception e) { - GWT.log("Error e: " + e); - } - return ""; } @@ -158,39 +263,12 @@ public class ItemsTable extends AbstractItemsCellTable public void render(com.google.gwt.cell.client.Cell.Context context, T object, SafeHtmlBuilder sb) { if (object == null) return; + Templates TEMPLATES = GWT.create(Templates.class); - DocumentDV documentDV = (DocumentDV) object; - String objectToRender = ""; - try { - // removing the '_theDocument.' prefix for searching in the Document Map - String key = itemField.getJsonFields().get(0) - .replace(ConstantsGeoPortalDataEntryApp.DEFAULT_DOCUMENT_PROJECTION_NAME + ".", ""); - Object value = documentDV.getDocumentAsMap().get(key); - // GWT.log("key: "+key+" is instance of: "+value.getClass()); - - if(value==null) - return; - - if (value instanceof ArrayList) { - ArrayList arrayValues = (ArrayList) value; - String toReturn = "
        "; - for (Object arrayValue : arrayValues) { - toReturn += "
      • " + arrayValue + "
      • "; - } - toReturn += "
      "; - GWT.log("Array returning: " + key + " is instance of: " + value.getClass() + " to return: " - + toReturn); - objectToRender = StringUtil.ellipsize(toReturn, MAX_TEXT_DIMENSION); - } else { - objectToRender = StringUtil.ellipsize(value.toString(), MAX_TEXT_DIMENSION); - } - - } catch (Exception e) { - GWT.log("Error e: " + e); - } - sb.appendHtmlConstant(objectToRender); -// super.render(context, object, sb); -// sb.appendHtmlConstant(""); + CellRender cellRender = toCellRender(itemField, object); + sb.append(TEMPLATES.startToolTip(cellRender.getTooltip())); + sb.appendHtmlConstant(cellRender.getValue()); + sb.append(TEMPLATES.endToolTip()); }; @@ -198,7 +276,7 @@ public class ItemsTable extends AbstractItemsCellTable sortedCellTable.addColumn(col, displayName, true); i++; } - + // COL RELATIONS TextColumn colRelationship = new TextColumn() { @Override @@ -231,7 +309,7 @@ public class ItemsTable extends AbstractItemsCellTable }; }; - + colRelationship.setCellStyleNames(CSS_CLASS_BACK_SYSTEM_CELL_B); sortedCellTable.addColumn(colRelationship, DEFAULT_DISPLAYING_COLUMN_NAME.RELATIONSHIPS.getTitle(), true); mapColumns.put(DEFAULT_DISPLAYING_COLUMN_NAME.RELATIONSHIPS, colRelationship); @@ -258,7 +336,7 @@ public class ItemsTable extends AbstractItemsCellTable } }; - + colCreated.setCellStyleNames(CSS_CLASS_BACK_SYSTEM_CELL_O); sortedCellTable.addColumn(colCreated, DEFAULT_DISPLAYING_COLUMN_NAME.CREATED.getTitle(), true); sortedCellTable.setColumnWidth(colCreated, 130, Unit.PX); @@ -286,7 +364,7 @@ public class ItemsTable extends AbstractItemsCellTable } }; - + colPublisher.setCellStyleNames(CSS_CLASS_BACK_SYSTEM_CELL_O); sortedCellTable.addColumn(colPublisher, DEFAULT_DISPLAYING_COLUMN_NAME.CREATED_BY.getTitle(), true); mapColumns.put(DEFAULT_DISPLAYING_COLUMN_NAME.CREATED_BY, colPublisher); @@ -363,7 +441,7 @@ public class ItemsTable extends AbstractItemsCellTable }; }; - + colOperationStatus.setCellStyleNames(CSS_CLASS_BACK_SYSTEM_CELL_Y); sortedCellTable.addColumn(colOperationStatus, DEFAULT_DISPLAYING_COLUMN_NAME.STATUS.getTitle(), true); sortedCellTable.setColumnWidth(colOperationStatus, 120, Unit.PX);