Managed files already published

This commit is contained in:
Francesco Mangiacrapa 2020-01-28 12:00:22 +01:00
parent 3450eda4f2
commit 1f720a786b
5 changed files with 121 additions and 78 deletions

View File

@ -1,5 +1,6 @@
package org.gcube.portlets.widgets.ckan2zenodopublisher.client;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@ -24,13 +25,16 @@ import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.google.gwt.user.client.ui.Widget;
/**
* The Class CkanToZendoPublisherWidget.
*
* @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it)
*
* Dec 9, 2019
* Jan 28, 2020
*/
public class CkanToZendoPublisherWidget {
@ -41,16 +45,24 @@ public class CkanToZendoPublisherWidget {
private BasicTabPanel basicTabPanel;
private ModalFooter modalFooter;
public static Map<String, String> mapOfFieldsDescriptions = new HashMap<String, String>();
private final Modal modal = new Modal(true);
/**
* Instantiates a new ckan to zendo publisher widget.
*/
public CkanToZendoPublisherWidget() {
ckanToZenodoService = CkanToZenodoPublisherServiceAsync.Util.getInstance();
}
/**
* Publish on zenodo.
*
* @param item the item
*/
public void publishOnZenodo(final CatalogueItem item) {
final Modal modal = new Modal(true);
modal.setTitle("Upload to Zenodo...");
modal.addStyleName("ckan2zenodo-modal-style");
modal.setCloseVisible(true);
@ -71,20 +83,10 @@ public class CkanToZendoPublisherWidget {
loader.setVisible(false);
modal.remove(loader);
Alert erroLabel = new Alert();
erroLabel.setClose(false);
//erroLabel.setClose(false);
erroLabel.setType(AlertType.ERROR);
erroLabel.setText(caught.getLocalizedMessage());
modal.add(erroLabel);
Button close = new Button("Close");
close.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
modal.hide();
}
});
modal.add(close);
//Window.alert(caught.getMessage());
showResults(Arrays.asList(erroLabel.asWidget()));
}
@Override
@ -143,21 +145,11 @@ public class CkanToZendoPublisherWidget {
buttonPublish.setEnabled(true);
basicTabPanel.getElement().getStyle().setOpacity(1.0);
modalFooter.remove(loaderPublishing);
//modal.clear();
Alert erroLabel = new Alert();
erroLabel.setClose(false);
//erroLabel.setClose(false);
erroLabel.setType(AlertType.ERROR);
erroLabel.setText(caught.getLocalizedMessage());
modalFooter.add(erroLabel);
Button close = new Button("Close");
close.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
modal.hide();
}
});
modal.add(close);
showResults(Arrays.asList(erroLabel.asWidget()));
}
@Override
@ -175,26 +167,14 @@ public class CkanToZendoPublisherWidget {
infoLabel.setClose(false);
infoLabel.setType(AlertType.INFO);
infoLabel.setText(msg);
modalFooter.add(infoLabel);
showResults(Arrays.asList(infoLabel.asWidget()));
}
});
}else {
basicTabPanel.managePager(PAGER.BACK); //TO SHOW THE FIELD MISSING
// Alert infoLabel = new Alert(true);
// infoLabel.setAnimation(true);
// infoLabel.set
// infoLabel.setType(AlertType.WARNING);
// infoLabel.setText("Please, check your inputs, a required field is missing...");
// modalFooter.add(infoLabel);
basicTabPanel.managePager(PAGER.BACK); //TO SHOW THE FIELD/s MISSING
}
// else {
// Alert infoLabel = new Alert();
// infoLabel.setClose(false);
// infoLabel.setType(AlertType.WARNING);
// infoLabel.setText("Please, check your inputs, a required field is missing...");
// modalFooter.add(infoLabel);
// }
}
});
@ -203,4 +183,20 @@ public class CkanToZendoPublisherWidget {
modal.show();
}
/**
* Show results.
*
* @param listWidget the list widget
*/
private void showResults(List<Widget> listWidget) {
VerticalPanel vp = new VerticalPanel();
for (Widget widget : listWidget) {
widget.getElement().getStyle().setMarginBottom(5.0, com.google.gwt.dom.client.Style.Unit.PX);
vp.add(widget);
}
modal.insert(vp, 1);
vp.getElement().focus();
}
}

View File

@ -3,69 +3,109 @@ package org.gcube.portlets.widgets.ckan2zenodopublisher.client.ui.publishfile;
import java.util.ArrayList;
import java.util.List;
import org.gcube.portlets.widgets.ckan2zenodopublisher.shared.wrapped.ZenodoFile;
import com.github.gwtbootstrap.client.ui.Fieldset;
import com.google.gwt.core.client.GWT;
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.HorizontalPanel;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.Widget;
/**
* The Class PublishFilesFormView.
*
* @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it)
*
* Dec 17, 2019
* Jan 28, 2020
*/
public class PublishFilesFormView extends Composite {
private static PublishFilesFormViewUiBinder uiBinder = GWT.create(PublishFilesFormViewUiBinder.class);
@UiField
Fieldset field_form_files;
@UiField
Fieldset field_form_files_already_published;
// @UiField
// Pager pager;
@UiField
HorizontalPanel panelOfFilesPublished;
private List<PublishFileView> lstPFV = new ArrayList<PublishFileView>();
private List<ZenodoFile> alreadyPublished = new ArrayList<ZenodoFile>();
/**
* The Interface PublishFilesFormViewUiBinder.
*
* @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it)
*
* Dec 17, 2019
* Dec 17, 2019
*/
interface PublishFilesFormViewUiBinder extends UiBinder<Widget, PublishFilesFormView> {
}
/**
* Instantiates a new publish files form view.
* @param tabIndex
*
* @param tabIndex the tab index
*/
public PublishFilesFormView(int tabIndex) {
initWidget(uiBinder.createAndBindUi(this));
}
/**
* Adds the file.
*
* @param fileVP the file VP
*/
public void addFile(PublishFileView fileVP) {
lstPFV.add(fileVP);
field_form_files.add(fileVP);
}
/**
* Gets the list of publishing file view.
*
* @return the list of publishing file view
*/
public List<PublishFileView> getListOfPublishingFileView(){
public List<PublishFileView> getListOfPublishingFileView() {
return lstPFV;
}
/**
* Adds the file.
*
* @param file the file
* @return the publish file view if is a file to publish
*/
public PublishFileView addFile(ZenodoFile file) {
PublishFileView pv = null;
if (file.getIsAlreadyPublished()) {
Label alert = new Label();
alert.setText(file.getFilename());
panelOfFilesPublished.add(alert);
field_form_files_already_published.setVisible(true);
alreadyPublished.add(file);
}else {
pv = new PublishFileView(file);
pv.getField_file_name().setValue(file.getFilename());
pv.getSwitchButton().setValue(true);
lstPFV.add(pv);
field_form_files.add(pv);
}
return pv;
}
/**
* Gets the already published.
*
* @return the already published
*/
public List<ZenodoFile> getAlreadyPublished() {
return alreadyPublished;
}
public Fieldset getField_form_files_already_published() {
return field_form_files_already_published;
}
}

View File

@ -10,16 +10,31 @@
.noBorder {
border: 0px;
}
.maring-top-high {
margin-top: 30px;
}
.margin-left-files-published {
margin-left: 20px;
}
</ui:style>
<g:HTMLPanel>
<b:Form type="HORIZONTAL">
<b:Fieldset styleName="{style.noBorder}"
ui:field="field_form_files_already_published" visible="false">
<b:Legend addStyleNames="legend-style">
File/s already published on Zenodo
<g:HorizontalPanel
ui:field="panelOfFilesPublished"
addStyleNames="{style.margin-left-files-published}"></g:HorizontalPanel>
</b:Legend>
</b:Fieldset>
<b:Fieldset styleName="{style.noBorder}"
ui:field="field_form_files">
<b:Legend addStyleNames="legend-style"> Select the file/s to upload...
<b:Legend addStyleNames="legend-style"> Select the file/s to upload
</b:Legend>
</b:Fieldset>
</b:Form>
<!-- <b:Pager left="Back" right="Next" aligned="true" -->
<!-- ui:field="pager" /> -->
</g:HTMLPanel>
</ui:UiBinder>

View File

@ -8,6 +8,7 @@ import org.gcube.portlets.widgets.ckan2zenodopublisher.client.ui.publishfile.Pub
import org.gcube.portlets.widgets.ckan2zenodopublisher.shared.wrapped.ZenodoFile;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.HTML;
public class PublishFileViewManager {
@ -25,23 +26,15 @@ public class PublishFileViewManager {
if (listFiles != null) {
for (ZenodoFile file : listFiles) {
PublishFileView pfv = addFileForPublishing(file);
publishFileFormView.addFile(pfv);
publishFileFormView.addFile(file);
}
if(publishFileFormView.getAlreadyPublished().size()>0) {
publishFileFormView.getField_form_files_already_published().add(new HTML("<hr>"));
}
}
}
private PublishFileView addFileForPublishing(ZenodoFile file) {
PublishFileView pv = new PublishFileView(file);
pv.getField_file_name().setValue(file.getFilename());
pv.getSwitchButton().setValue(true);
if(file.getIsAlreadyPublished()) {
pv.hideSwitchButton(true, "File already published on Zenodo");
}
return pv;
}
public Composite getView(){
return publishFileFormView;
}

View File

@ -18,7 +18,6 @@ import org.gcube.data.publishing.ckan2zenodo.model.faults.TransformationExceptio
import org.gcube.data.publishing.ckan2zenodo.model.faults.ZenodoException;
import org.gcube.data.publishing.ckan2zenodo.model.zenodo.DepositionMetadata;
import org.gcube.data.publishing.ckan2zenodo.model.zenodo.ZenodoDeposition;
import org.gcube.portlets.widgets.ckan2zenodopublisher.client.CkanToZendoPublisherWidgetConstant;
import org.gcube.portlets.widgets.ckan2zenodopublisher.client.CkanToZenodoPublisherService;
import org.gcube.portlets.widgets.ckan2zenodopublisher.server.configuration.ZenodoFieldsDescriptionsReader;
import org.gcube.portlets.widgets.ckan2zenodopublisher.server.converter.ItemToZenodoConverter;