improved JSON update part

pull/4/head
Francesco Mangiacrapa 3 years ago
parent 48d19b6f10
commit 71cbc96d10

@ -48,6 +48,7 @@ import com.github.gwtbootstrap.client.ui.Modal;
import com.github.gwtbootstrap.client.ui.constants.AlertType;
import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.core.client.GWT;
import com.google.gwt.dom.client.Element;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.event.logical.shared.ResizeEvent;
@ -524,6 +525,7 @@ public class GeoPortalDataEntryApp implements EntryPoint {
modal3.setWidth(950);
modal3.setHeight("700px");
modal3.setCloseVisible(true);
((Element)modal3.getElement().getChildNodes().getItem(1)).addClassName("modal-body-custom");
EditModeRecord emr = new EditModeRecord(concessione,RECORD_TYPE.CONCESSIONE);
modal3.add(emr);
modal3.show();

@ -3,6 +3,7 @@ package org.gcube.portlets.user.geoportaldataentry.client;
import java.util.List;
import org.gcube.application.geoportalcommon.shared.GeoNaItemRef;
import org.gcube.application.geoportalcommon.shared.products.ConcessioneDV;
import org.gcube.portlets.user.geoportaldataentry.client.ConstantsGeoPortalDataEntryApp.RECORD_TYPE;
import org.gcube.portlets.user.geoportaldataentry.shared.CommitReport;
import org.gcube.portlets.user.geoportaldataentry.shared.GeoNaFormDataObject;
@ -73,5 +74,5 @@ public interface GeoportalDataEntryService extends RemoteService {
String getJSONRecord(String itemId, RECORD_TYPE recordType) throws Exception;
String updateRecord(String itemId, String jsonUpdate, RECORD_TYPE recordType) throws Exception;
ConcessioneDV updateRecord(String itemId, String jsonUpdate, RECORD_TYPE recordType) throws Exception;
}

@ -3,6 +3,7 @@ package org.gcube.portlets.user.geoportaldataentry.client;
import java.util.List;
import org.gcube.application.geoportalcommon.shared.GeoNaItemRef;
import org.gcube.application.geoportalcommon.shared.products.ConcessioneDV;
import org.gcube.portlets.user.geoportaldataentry.client.ConstantsGeoPortalDataEntryApp.RECORD_TYPE;
import org.gcube.portlets.user.geoportaldataentry.shared.CommitReport;
import org.gcube.portlets.user.geoportaldataentry.shared.GeoNaFormDataObject;
@ -58,5 +59,5 @@ public interface GeoportalDataEntryServiceAsync
void getJSONRecord(String itemId, RECORD_TYPE recordType, AsyncCallback<String> callback);
void updateRecord(String itemId, String jsonUpdate, RECORD_TYPE recordType, AsyncCallback<String> callback);
void updateRecord(String itemId, String jsonUpdate, RECORD_TYPE recordType, AsyncCallback<ConcessioneDV> callback);
}

@ -1,15 +1,22 @@
package org.gcube.portlets.user.geoportaldataentry.client.ui.edit;
import org.gcube.application.geoportalcommon.shared.products.BaseConcessioneDV;
import org.gcube.application.geoportalcommon.shared.products.ConcessioneDV;
import org.gcube.portlets.user.geoportaldataentry.client.ConstantsGeoPortalDataEntryApp.RECORD_TYPE;
import org.gcube.portlets.user.geoportaldataentry.client.GeoPortalDataEntryApp;
import org.gcube.portlets.user.geoportaldataentry.client.ui.edit.jseditor.MyJSONEditor;
import org.gcube.portlets.user.geoportaldataentry.client.ui.edit.jseditor.JSONEditorWrapper;
import org.gcube.portlets.user.geoportaldataentry.client.ui.utils.LoaderIcon;
import com.github.gwtbootstrap.client.ui.Button;
import com.github.gwtbootstrap.client.ui.Tab;
import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.user.client.Random;
import com.google.gwt.user.client.Timer;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.FlowPanel;
@ -26,14 +33,24 @@ public class EditModeRecord extends Composite {
private static EditModeRecordUiBinder uiBinder = GWT.create(EditModeRecordUiBinder.class);
@UiField
Tab tabRawUpdate;
@UiField
FlowPanel rawUpdatePanel;
@UiField
FlowPanel filesUpdatePanel;
@UiField
Button buttonJSONUpdate;
private BaseConcessioneDV selectedConcessione;
private RECORD_TYPE recordType;
private JSONEditorWrapper jsEditor;
/**
* The Interface EditModeRecordUiBinder.
*
@ -53,59 +70,95 @@ public class EditModeRecord extends Composite {
public EditModeRecord(BaseConcessioneDV selectedConcessione, RECORD_TYPE type) {
initWidget(uiBinder.createAndBindUi(this));
this.selectedConcessione = selectedConcessione;
this.recordType = type;
instanceJSONEditor();
bindEvents();
}
private void instanceJSONEditor() {
rawUpdatePanel.clear();
final FlowPanel fp = new FlowPanel();
fp.getElement().setId("jsoneditor"+Random.nextInt());
fp.getElement().setId("jsoneditor" + Random.nextInt());
fp.setHeight("400px");
rawUpdatePanel.add(fp);
GeoPortalDataEntryApp.geoportalDataEntryService.getJSONRecord(selectedConcessione.getItemId(), recordType,
new AsyncCallback<String>() {
GeoPortalDataEntryApp.geoportalDataEntryService.getJSONRecord(selectedConcessione.getItemId(), type, new AsyncCallback<String>() {
@Override
public void onSuccess(String jsonData) {
GWT.log("Instance JSON Editor with: "+jsonData);
//jsonEditor = ExternalLib.instanceJSONEditor(fp.getElement().getId(), jsonData);
//String updated = ExternalLib.getUpdatedJSON(jsonEditor);
//JSONEditor constuctor = new JSONEditor(fp.getElement(),"{}");
final MyJSONEditor jsEditor = MyJSONEditor.init(fp.getElement().getId());
jsEditor.setName(selectedConcessione.getNome());
// JSONValue jsValue = JSONParser.parse(jsonData);
// JSONObject extraJSONObject = jsValue.isObject();
jsEditor.set(jsonData);
new Timer() {
@Override
public void run() {
jsEditor.setMode("tree");
public void onSuccess(String jsonData) {
GWT.log("Instance JSON Editor with: " + jsonData);
jsEditor = JSONEditorWrapper.init(fp.getElement().getId());
jsEditor.setName(selectedConcessione.getNome());
jsEditor.set(jsonData);
new Timer() {
@Override
public void run() {
jsEditor.setMode("tree");
}
}.schedule(200);
}
}.schedule(200);
//GWT.log("Updated: "+updated.toString());
//org.gcube.portlets.user.geoportaldataentry.client.ui.utils.JSONEditor editor = JE.jsoneditor(fp.getElement(), jsonData);
//rawUpdatePanel.add(new Widget(editor));
}
@Override
public void onFailure(Throwable caught) {
// TODO Auto-generated method stub
}
});
bindEvents();
@Override
public void onFailure(Throwable caught) {
// TODO Auto-generated method stub
}
});
}
/**
* Bind events.
*/
private void bindEvents() {
// TODO Auto-generated method stub
buttonJSONUpdate.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
rawUpdatePanel.getElement().addClassName("disable-div");
buttonJSONUpdate.setEnabled(false);
final LoaderIcon loader = new LoaderIcon("Updating the project...");
tabRawUpdate.add(loader);
GeoPortalDataEntryApp.geoportalDataEntryService.updateRecord(selectedConcessione.getItemId(),
jsEditor.getText(), recordType, new AsyncCallback<ConcessioneDV>() {
@Override
public void onFailure(Throwable caught) {
buttonJSONUpdate.setEnabled(true);
try {
rawUpdatePanel.getElement().removeClassName("disable-div");
tabRawUpdate.remove(loader);
} catch (Exception e) {
// TODO: handle exception
}
}
@Override
public void onSuccess(ConcessioneDV result) {
buttonJSONUpdate.setEnabled(true);
try {
rawUpdatePanel.getElement().removeClassName("disable-div");
tabRawUpdate.remove(loader);
} catch (Exception e) {
// TODO: handle exception
}
selectedConcessione = result;
instanceJSONEditor();
Window.alert("Project '"+result.getNome()+"' updated correctly");
}
});
}
});
}
}

@ -6,16 +6,50 @@
.important {
font-weight: bold;
}
.button-save-style {
margin-top: 10px;
float: right;
}
.info-panel {
width: 100%;
word-break: break-word;
}
</ui:style>
<g:HTMLPanel>
<b:TabPanel tabPosition="left" ui:field="tabPanel">
<b:Tab icon="PENCIL" active="true" heading="Edit the code"
<b:Tab icon="PENCIL" active="true" heading="Edit the source"
ui:field="tabRawUpdate">
<b:Heading size="3">Raw Project Editor</b:Heading>
<b:Heading size="3">Source Project Editor</b:Heading>
<b:Label>You can update the Source Project by editing its JSON model
data displayed in the following Editor.</b:Label>
<g:HTML addStyleNames="{style.info-panel}">
<p style='color: #585858'>
Be careful not to change the
keys (e.g. nome, introduzione,
licenzaID and so
on..) reported in
<span style='color: black'>black.</span>
Update only their values
(e.g. "il nome
del
progetto",
"introduzione
del progetto") reported in
<span style='color: green'>green</span>
by the
Editor <br/>
<span>At the end of the changes press the "Update" button to make
them persistent on the service</span>
</p>
</g:HTML>
<g:FlowPanel ui:field="rawUpdatePanel">
</g:FlowPanel>
<b:Button icon="SAVE" type="INFO"
addStyleNames="{style.button-save-style}" ui:field="buttonJSONUpdate">UPDATE</b:Button>
</b:Tab>
<b:Tab icon="UPLOAD_ALT" heading="Update File/s"
ui:field="tabUploadFiles">

@ -2,20 +2,20 @@ package org.gcube.portlets.user.geoportaldataentry.client.ui.edit.jseditor;
import com.google.gwt.core.client.JavaScriptObject;
public class MyJSONEditor extends JavaScriptObject {
public class JSONEditorWrapper extends JavaScriptObject {
// 6131f0d902ad3d2580412d14
protected MyJSONEditor() {
protected JSONEditorWrapper() {
}
public static native MyJSONEditor init(String divID) /*-{
public static native JSONEditorWrapper init(String divID) /*-{
var container = $doc.getElementById(divID);
var options = {
modes : ['code','tree'],
search: true,
onError : function(error) {
console.log("MyJSONEditor error: " + error)
console.log("JSONEditorWrapper error: " + error)
}
};
console.log("container is: " + container);
@ -30,8 +30,9 @@ public class MyJSONEditor extends JavaScriptObject {
this.refresh();
}-*/;
public final native void get() /*-{
this.get();
public final native String getText() /*-{
console.log("this.get(): " +this.getText());
return this.getText();
}-*/;
public final native void onError() /*-{

@ -250,12 +250,21 @@ public class ConvertToServiceModel {
List<String> abstractLstIta = mapFields.get("Abstract in Italiano");
if(abstractLstIta!=null && abstractLstIta.size()>0) {
relazioneScavo.setAbstractIta(abstractLstIta.get(0));
/**
* TODO
*/
LOG.warn("TODO ABSTRACT RELAZIONE DI SCAVO IN ITA");
//relazioneScavo.setAbstractIta(abstractLstIta.get(0));
}
List<String> abstractLstEng = mapFields.get("Abstract in Inglese");
if(abstractLstEng!=null && abstractLstEng.size()>0) {
relazioneScavo.setAbstractEng(abstractLstEng.get(0));
/**
* TODO
*/
LOG.warn("TODO ABSTRACT RELAZIONE DI SCAVO IN ENG");
//relazioneScavo.setAbstractEng(abstractLstEng.get(0));
}
//TODO IN FUTURE WHEN THE MODEL WILL BE UPDATED

@ -636,7 +636,7 @@ public class GeoportalDataEntryServiceImpl extends RemoteServiceServlet implemen
* @throws Exception the exception
*/
@Override
public String updateRecord(String itemId, String jsonUpdate, RECORD_TYPE recordType) throws Exception {
public ConcessioneDV updateRecord(String itemId, String jsonUpdate, RECORD_TYPE recordType) throws Exception {
LOG.info("updateRecord called with itemId: " + itemId + ", recordType: " + recordType);
try {
@ -649,7 +649,10 @@ public class GeoportalDataEntryServiceImpl extends RemoteServiceServlet implemen
MongoServiceUtil serviceUtil = new MongoServiceUtil();
MongoConcessioni clientMongo = serviceUtil.getInstanceMongoConcessioni();
Concessione concessione = clientMongo.update(itemId, jsonUpdate);
return serviceUtil.toJSON(concessione);
LOG.debug("Got Record updated: "+concessione);
ConcessioneDV concessionDV = ConvertToDataViewModel.toMetadataConcessione(concessione, true);
LOG.info("Record with id "+concessionDV.getItemId()+"updated correclty");
return concessionDV;
}
return null;

@ -85,3 +85,11 @@ h1 {
top: 0;
background-color: #eeeeee;
}
.modal-body-custom {
max-height: 700px !important;
}
.disable-div {
pointer-events: none;
}

Loading…
Cancel
Save