Improved display of results on multiple fields #26372
This commit is contained in:
parent
c16bcdbc76
commit
9ca7b52b60
|
@ -4,6 +4,10 @@
|
||||||
All notable changes to this project will be documented in this file.
|
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).
|
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
|
## [v3.2.1] - 2023-06-16
|
||||||
|
|
||||||
- Fixed issue in the Search facility [#25265]
|
- Fixed issue in the Search facility [#25265]
|
||||||
|
|
2
pom.xml
2
pom.xml
|
@ -14,7 +14,7 @@
|
||||||
<groupId>org.gcube.portlets.user</groupId>
|
<groupId>org.gcube.portlets.user</groupId>
|
||||||
<artifactId>geoportal-data-entry-app</artifactId>
|
<artifactId>geoportal-data-entry-app</artifactId>
|
||||||
<packaging>war</packaging>
|
<packaging>war</packaging>
|
||||||
<version>3.2.1</version>
|
<version>3.2.2-SNAPSHOT</version>
|
||||||
<name>GeoPortal Data Entry App</name>
|
<name>GeoPortal Data Entry App</name>
|
||||||
<description>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</description>
|
<description>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</description>
|
||||||
<scm>
|
<scm>
|
||||||
|
|
|
@ -188,6 +188,16 @@ public class GeonaRecordsPaginatedView {
|
||||||
}
|
}
|
||||||
// initFirstRangeChanged = false;
|
// initFirstRangeChanged = false;
|
||||||
|
|
||||||
|
//printData((List<DocumentDV>) result.getData());
|
||||||
|
}
|
||||||
|
|
||||||
|
private void printData(List<DocumentDV> data) {
|
||||||
|
GWT.log("printData");
|
||||||
|
int i = 0;
|
||||||
|
for (DocumentDV documentDV : data) {
|
||||||
|
GWT.log(++i + ") json: " + documentDV.getDocumentAsJSON());
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -27,6 +27,7 @@ import com.google.gwt.core.shared.GWT;
|
||||||
import com.google.gwt.dom.client.Style.Unit;
|
import com.google.gwt.dom.client.Style.Unit;
|
||||||
import com.google.gwt.event.shared.HandlerManager;
|
import com.google.gwt.event.shared.HandlerManager;
|
||||||
import com.google.gwt.i18n.client.DateTimeFormat;
|
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.SafeHtml;
|
||||||
import com.google.gwt.safehtml.shared.SafeHtmlBuilder;
|
import com.google.gwt.safehtml.shared.SafeHtmlBuilder;
|
||||||
import com.google.gwt.safehtml.shared.SafeHtmlUtils;
|
import com.google.gwt.safehtml.shared.SafeHtmlUtils;
|
||||||
|
@ -102,6 +103,127 @@ public class ItemsTable<T extends DocumentDV> extends AbstractItemsCellTable<T>
|
||||||
super.addItems(items);
|
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 = "<br>";
|
||||||
|
String newLineTxt = "\n";
|
||||||
|
String bullet = "• "; // it is the dot. As <li> rendered in the <ul> tag
|
||||||
|
|
||||||
|
String newBullet = newLine + bullet;
|
||||||
|
|
||||||
|
List<String> 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<Object> arrayValues = (ArrayList<Object>) value;
|
||||||
|
String toReturn = "<ul>";
|
||||||
|
for (Object arrayValue : arrayValues) {
|
||||||
|
toReturn += "<li>" + arrayValue + "</li>";
|
||||||
|
}
|
||||||
|
toReturn += "</ul>";
|
||||||
|
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("<span title=\"{0}\">")
|
||||||
|
SafeHtml startToolTip(String toolTipText);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* End tool tip.
|
||||||
|
*
|
||||||
|
* @return the safe html
|
||||||
|
*/
|
||||||
|
@Template("</span>")
|
||||||
|
SafeHtml endToolTip();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Inits the table.
|
* Inits the table.
|
||||||
*
|
*
|
||||||
|
@ -130,27 +252,10 @@ public class ItemsTable<T extends DocumentDV> extends AbstractItemsCellTable<T>
|
||||||
String displayName = itemField.getDisplayName();
|
String displayName = itemField.getDisplayName();
|
||||||
|
|
||||||
TextColumn<T> col = new TextColumn<T>() {
|
TextColumn<T> col = new TextColumn<T>() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getValue(T object) {
|
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 "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -158,39 +263,12 @@ public class ItemsTable<T extends DocumentDV> extends AbstractItemsCellTable<T>
|
||||||
public void render(com.google.gwt.cell.client.Cell.Context context, T object, SafeHtmlBuilder sb) {
|
public void render(com.google.gwt.cell.client.Cell.Context context, T object, SafeHtmlBuilder sb) {
|
||||||
if (object == null)
|
if (object == null)
|
||||||
return;
|
return;
|
||||||
|
Templates TEMPLATES = GWT.create(Templates.class);
|
||||||
|
|
||||||
DocumentDV documentDV = (DocumentDV) object;
|
CellRender cellRender = toCellRender(itemField, object);
|
||||||
String objectToRender = "";
|
sb.append(TEMPLATES.startToolTip(cellRender.getTooltip()));
|
||||||
try {
|
sb.appendHtmlConstant(cellRender.getValue());
|
||||||
// removing the '_theDocument.' prefix for searching in the Document Map
|
sb.append(TEMPLATES.endToolTip());
|
||||||
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<Object> arrayValues = (ArrayList<Object>) value;
|
|
||||||
String toReturn = "<ul>";
|
|
||||||
for (Object arrayValue : arrayValues) {
|
|
||||||
toReturn += "<li>" + arrayValue + "</li>";
|
|
||||||
}
|
|
||||||
toReturn += "</ul>";
|
|
||||||
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("</span>");
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue