Improved Publication Report. Moved to -SNAPSHOT
parent
67a8a88f48
commit
6734edf04e
@ -0,0 +1,172 @@
|
||||
package org.gcube.portlets.user.geoportaldataentry.client.ui.report;
|
||||
|
||||
import com.github.gwtbootstrap.client.ui.Paragraph;
|
||||
import com.google.gwt.core.client.GWT;
|
||||
import com.google.gwt.json.client.JSONArray;
|
||||
import com.google.gwt.json.client.JSONObject;
|
||||
import com.google.gwt.json.client.JSONParser;
|
||||
import com.google.gwt.json.client.JSONValue;
|
||||
import com.google.gwt.uibinder.client.UiBinder;
|
||||
import com.google.gwt.uibinder.client.UiField;
|
||||
import com.google.gwt.user.client.ui.Composite;
|
||||
import com.google.gwt.user.client.ui.HTML;
|
||||
import com.google.gwt.user.client.ui.VerticalPanel;
|
||||
import com.google.gwt.user.client.ui.Widget;
|
||||
|
||||
|
||||
/**
|
||||
* The Class ReportTemplateToHTML.
|
||||
*
|
||||
* @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it)
|
||||
*
|
||||
* Jan 25, 2021
|
||||
*/
|
||||
public class ReportTemplateToHTML extends Composite {
|
||||
|
||||
private static ReportTemplateToHTMLUiBinder uiBinder = GWT.create(ReportTemplateToHTMLUiBinder.class);
|
||||
|
||||
/**
|
||||
* The Interface ReportTemplateToHTMLUiBinder.
|
||||
*
|
||||
* @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it)
|
||||
*
|
||||
* Jan 25, 2021
|
||||
*/
|
||||
interface ReportTemplateToHTMLUiBinder extends UiBinder<Widget, ReportTemplateToHTML> {
|
||||
}
|
||||
|
||||
@UiField
|
||||
VerticalPanel vpContainer;
|
||||
|
||||
@UiField
|
||||
VerticalPanel htmlContainer;
|
||||
|
||||
@UiField
|
||||
Paragraph reportJSON;
|
||||
|
||||
boolean toJSONERROR = false;
|
||||
|
||||
/**
|
||||
* Instantiates a new report template to HTML.
|
||||
*
|
||||
* @param report the report
|
||||
*/
|
||||
public ReportTemplateToHTML(String report) {
|
||||
initWidget(uiBinder.createAndBindUi(this));
|
||||
vpContainer.setVisible(false);
|
||||
if (report != null) {
|
||||
GWT.log("report is: " + report);
|
||||
vpContainer.setVisible(true);
|
||||
|
||||
try {
|
||||
JSONValue jsonObj = JSONParser.parse(report);
|
||||
JSONObject json = (JSONObject) jsonObj;
|
||||
JSONValue valueChildren = json.get("children");
|
||||
JSONArray jsonChildren = (JSONArray) valueChildren;
|
||||
/*JSONObject jsonChildrenObject = (JSONObject) jsonChildren.get(0);
|
||||
|
||||
if (jsonChildrenObject.containsKey("objectName")) {
|
||||
JSONValue validationReportON = jsonChildrenObject.get("objectName");
|
||||
String titleValue = HTMLUtil.getHTMLElement(HTML_TAG.div, 14, "000", "bold", validationReportON.toString());
|
||||
htmlContainer.add(new HTML(titleValue));
|
||||
}
|
||||
|
||||
String toTableHTML = jsonToHTML(jsonChildrenObject.get("children").toString());
|
||||
GWT.log("toJSONERROR is: " + toJSONERROR);
|
||||
GWT.log("toTableHTML is: " + toTableHTML);
|
||||
|
||||
Set<String> keySet = jsonChildrenObject.keySet();*/
|
||||
|
||||
String toTableHTML = null;
|
||||
for (int i=0; i<jsonChildren.size(); i++) {
|
||||
JSONObject jsO = (JSONObject) jsonChildren.get(i);
|
||||
|
||||
if (jsO.containsKey("children")) {
|
||||
/*if (jsO.containsKey("objectName")) {
|
||||
JSONValue validationReportON = jsO.get("objectName");
|
||||
String titleValue = HTMLUtil.getHTMLElement(HTML_TAG.div, 14, "000", "bold", validationReportON.toString());
|
||||
htmlContainer.add(new HTML(titleValue));
|
||||
}*/
|
||||
toTableHTML = jsonToHTML(jsO.get("children").toString());
|
||||
}else {
|
||||
toTableHTML = jsonToHTML(jsO.toString());
|
||||
}
|
||||
|
||||
htmlContainer.add(new HTML(toTableHTML));
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
GWT.log("error: " + e.getMessage());
|
||||
}
|
||||
reportJSON.setText(report);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Json to HTML.
|
||||
*
|
||||
* @param jsonTxt the json txt
|
||||
* @return the string
|
||||
*/
|
||||
public static native String jsonToHTML(String jsonTxt)/*-{
|
||||
try {
|
||||
var jsonObj = JSON.parse(jsonTxt);
|
||||
|
||||
if (jsonObj.length == undefined)
|
||||
jsonObj = [ jsonObj ]
|
||||
//console.log(jsonObj.length)
|
||||
|
||||
// EXTRACT VALUE FOR HTML HEADER.
|
||||
var col = [];
|
||||
for (var i = 0; i < jsonObj.length; i++) {
|
||||
for ( var key in jsonObj[i]) {
|
||||
//console.log('key json' +key)
|
||||
if (col.indexOf(key) === -1) {
|
||||
col.push(key);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// CREATE DYNAMIC TABLE.
|
||||
var table = document.createElement("table");
|
||||
try {
|
||||
table.classList.add("my-html-table");
|
||||
|
||||
} catch (e) {
|
||||
console.log('invalid css add', e);
|
||||
}
|
||||
|
||||
// ADD JSON DATA TO THE TABLE AS ROWS.
|
||||
for (var i = 0; i < col.length; i++) {
|
||||
tr = table.insertRow(-1);
|
||||
var firstCell = tr.insertCell(-1);
|
||||
//firstCell.style.cssText="font-weight: bold; text-align: center; vertical-align: middle;";
|
||||
firstCell.innerHTML = col[i];
|
||||
for (var j = 0; j < jsonObj.length; j++) {
|
||||
var tabCell = tr.insertCell(-1);
|
||||
var theValue = jsonObj[j][col[i]];
|
||||
//console.log("the value: "+theValue);
|
||||
if(Object.prototype.toString.call(theValue) === '[object Array]'){
|
||||
var formattedValueArray = "";
|
||||
for(var k = 0; k < theValue.length; k++) {
|
||||
var theValueArray = theValue[k];
|
||||
//console.log(theValueArray);
|
||||
formattedValueArray += theValueArray+"<br>";
|
||||
}
|
||||
tabCell.innerHTML = formattedValueArray;
|
||||
}
|
||||
else{
|
||||
tabCell.innerHTML = theValue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return table.outerHTML;
|
||||
} catch (e) {
|
||||
console.log('invalid json', e);
|
||||
return jsonTxt;
|
||||
}
|
||||
|
||||
}-*/;
|
||||
}
|
@ -0,0 +1,25 @@
|
||||
<!DOCTYPE ui:UiBinder SYSTEM "http://dl.google.com/gwt/DTD/xhtml.ent">
|
||||
<ui:UiBinder xmlns:ui="urn:ui:com.google.gwt.uibinder"
|
||||
xmlns:g="urn:import:com.google.gwt.user.client.ui"
|
||||
xmlns:b="urn:import:com.github.gwtbootstrap.client.ui">
|
||||
<ui:style>
|
||||
.important {
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
.margin-top-10 {
|
||||
margin-top: 10px;
|
||||
}
|
||||
</ui:style>
|
||||
<g:HTMLPanel>
|
||||
<g:VerticalPanel ui:field="vpContainer"
|
||||
addStyleNames="{style.margin-top-10}">
|
||||
<b:Label>Publication Report: </b:Label>
|
||||
<g:VerticalPanel ui:field="htmlContainer" addStyleNames="{style.margin-top-10}"></g:VerticalPanel>
|
||||
<b:AccordionGroup heading="Show Report as JSON">
|
||||
<b:Paragraph ui:field="reportJSON"></b:Paragraph>
|
||||
</b:AccordionGroup>
|
||||
|
||||
</g:VerticalPanel>
|
||||
</g:HTMLPanel>
|
||||
</ui:UiBinder>
|
@ -0,0 +1,81 @@
|
||||
package org.gcube.portlets.user.geoportaldataentry.client.ui.utils;
|
||||
|
||||
/**
|
||||
* The Class HTMLUtil.
|
||||
*
|
||||
* @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it)
|
||||
*
|
||||
* Jan 26, 2021
|
||||
*/
|
||||
public class HTMLUtil {
|
||||
|
||||
/**
|
||||
* The Enum HTML_TAG.
|
||||
*
|
||||
* @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it)
|
||||
*
|
||||
* Jan 26, 2021
|
||||
*/
|
||||
public static enum HTML_TAG {
|
||||
p, div, span
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the HTML element.
|
||||
*
|
||||
* @param tag the tag
|
||||
* @param textSize the text size
|
||||
* @param rgb the rgb
|
||||
* @param fontWeight the font weight
|
||||
* @param text the text
|
||||
* @return the HTML element
|
||||
*/
|
||||
public static String getHTMLElement(HTML_TAG tag, Integer textSize, String rgb, String fontWeight, String text) {
|
||||
StringBuilder htmlEl = new StringBuilder();
|
||||
|
||||
if (textSize != null || rgb != null || fontWeight != null) {
|
||||
String style = "";
|
||||
if (textSize != null) {
|
||||
style += "font-size:" + textSize + ";";
|
||||
}
|
||||
if (rgb != null) {
|
||||
style += "color:#" + rgb + ";";
|
||||
}
|
||||
if (fontWeight != null) {
|
||||
style += "font-weight:" + fontWeight + ";";
|
||||
}
|
||||
htmlEl.append("<" + tag.name() + " style='" + style + "'>");
|
||||
} else {
|
||||
htmlEl.append(tagOPEN(tag));
|
||||
}
|
||||
|
||||
if (text != null) {
|
||||
htmlEl.append(text);
|
||||
}
|
||||
|
||||
htmlEl.append(tagCLosed(tag));
|
||||
|
||||
return htmlEl.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Tag OPEN.
|
||||
*
|
||||
* @param tag the tag
|
||||
* @return the string
|
||||
*/
|
||||
public static String tagOPEN(HTML_TAG tag) {
|
||||
return "<" + tag.name() + ">";
|
||||
}
|
||||
|
||||
/**
|
||||
* Tag C losed.
|
||||
*
|
||||
* @param tag the tag
|
||||
* @return the string
|
||||
*/
|
||||
public static String tagCLosed(HTML_TAG tag) {
|
||||
return "</" + tag.name() + ">";
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue