419 lines
11 KiB
Java
419 lines
11 KiB
Java
package org.gcube.portlets.widgets.ckancontentmoderator.client.ui;
|
|
|
|
import java.util.ArrayList;
|
|
import java.util.List;
|
|
|
|
import org.gcube.datacatalogue.utillibrary.shared.ItemStatus;
|
|
import org.gcube.portlets.widgets.ckancontentmoderator.client.CkanContentModeratorWidgetController;
|
|
import org.gcube.portlets.widgets.ckancontentmoderator.client.events.CheckBoxSelectIemsEvent;
|
|
import org.gcube.portlets.widgets.ckancontentmoderator.client.ui.table.ItemsTable.DISPLAY_FIELD;
|
|
import org.gcube.portlets.widgets.ckancontentmoderator.client.ui.util.UtilFunct;
|
|
import org.gcube.portlets.widgets.ckancontentmoderator.shared.CatalogueDataset;
|
|
|
|
import com.github.gwtbootstrap.client.ui.AlertBlock;
|
|
import com.github.gwtbootstrap.client.ui.Button;
|
|
import com.github.gwtbootstrap.client.ui.CheckBox;
|
|
import com.github.gwtbootstrap.client.ui.Dropdown;
|
|
import com.github.gwtbootstrap.client.ui.Heading;
|
|
import com.github.gwtbootstrap.client.ui.NavLink;
|
|
import com.github.gwtbootstrap.client.ui.base.AlertBase;
|
|
import com.github.gwtbootstrap.client.ui.event.ClosedEvent;
|
|
import com.github.gwtbootstrap.client.ui.event.ClosedHandler;
|
|
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.event.logical.shared.ValueChangeEvent;
|
|
import com.google.gwt.event.logical.shared.ValueChangeHandler;
|
|
import com.google.gwt.event.shared.HandlerManager;
|
|
import com.google.gwt.uibinder.client.UiBinder;
|
|
import com.google.gwt.uibinder.client.UiField;
|
|
import com.google.gwt.user.client.rpc.AsyncCallback;
|
|
import com.google.gwt.user.client.ui.Composite;
|
|
import com.google.gwt.user.client.ui.HTMLPanel;
|
|
import com.google.gwt.user.client.ui.ScrollPanel;
|
|
import com.google.gwt.user.client.ui.Widget;
|
|
|
|
|
|
/**
|
|
* The Class HomeView.
|
|
*
|
|
* @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it
|
|
*
|
|
* Jun 22, 2021
|
|
*/
|
|
public class HomeView extends Composite {
|
|
|
|
private static HomeViewUiBinder uiBinder = GWT.create(HomeViewUiBinder.class);
|
|
private ContentModeratorSystemBaseView cmsPanel = new ContentModeratorSystemBaseView();
|
|
private ContentModeratorPaginatedView paginatedView;
|
|
|
|
@UiField
|
|
HTMLPanel panelContainer;
|
|
|
|
@UiField
|
|
CheckBox cbSelectAll;
|
|
|
|
@UiField
|
|
Dropdown dropdownSetStatus;
|
|
|
|
@UiField
|
|
Heading pageHeader;
|
|
|
|
@UiField
|
|
HTMLPanel confirmPanel;
|
|
|
|
@UiField
|
|
Button permanentlyDelete;
|
|
|
|
private ScrollPanel confirmPanelContainer = new ScrollPanel();
|
|
|
|
private List<NavLink> setStatusOptions = new ArrayList<NavLink>();
|
|
|
|
private ItemStatus displayingItemStatus;
|
|
|
|
private HandlerManager eventBus;
|
|
|
|
/**
|
|
* The Interface HomeViewUiBinder.
|
|
*
|
|
* @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it
|
|
*
|
|
* Jun 22, 2021
|
|
*/
|
|
interface HomeViewUiBinder extends UiBinder<Widget, HomeView> {
|
|
}
|
|
|
|
/**
|
|
* Instantiates a new home view.
|
|
*
|
|
* @param eventBus the event bus
|
|
* @param status the status
|
|
* @param displayFields the display fields
|
|
* @param sortByField the sort by field
|
|
*/
|
|
public HomeView(HandlerManager eventBus, ItemStatus status, DISPLAY_FIELD[] displayFields,
|
|
DISPLAY_FIELD sortByField) {
|
|
initWidget(uiBinder.createAndBindUi(this));
|
|
setDisplayingWithStatus(status);
|
|
this.eventBus = eventBus;
|
|
paginatedView = new ContentModeratorPaginatedView(eventBus, status, displayFields, sortByField);
|
|
cmsPanel.addToCenter(paginatedView.getCellPanel());
|
|
cmsPanel.addToBottom(paginatedView.getPagerPanel());
|
|
panelContainer.add(cmsPanel.getPanel());
|
|
setVisibleUpdateStatusAction(false);
|
|
setVisiblePermanentlyDelete(false);
|
|
|
|
// Filling the Dropdown with status options
|
|
for (ItemStatus iStatus : ItemStatus.values()) {
|
|
NavLink nl = new NavLink(iStatus.getLabel());
|
|
dropdownSetStatus.add(nl);
|
|
setStatusOptions.add(nl);
|
|
|
|
}
|
|
|
|
setStatusOptions();
|
|
bindEvents();
|
|
confirmPanel.add(confirmPanelContainer);
|
|
|
|
}
|
|
|
|
/**
|
|
* Sets the status options according to item status selected
|
|
*/
|
|
private void setStatusOptions() {
|
|
|
|
// Fired when user clicks on CMS action
|
|
for (final NavLink navLink : setStatusOptions) {
|
|
navLink.setVisible(true);
|
|
// Hiding the status selected/displayed from navigation link
|
|
if (navLink.getText().trim().equals(displayingItemStatus.getLabel())) {
|
|
navLink.setVisible(false);
|
|
}
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Sets the displaying with status.
|
|
*
|
|
* @param status the new displaying with status
|
|
*/
|
|
private void setDisplayingWithStatus(ItemStatus status) {
|
|
this.displayingItemStatus = status;
|
|
this.pageHeader.setSubtext(status.getLabel());
|
|
}
|
|
|
|
/**
|
|
* Bind events.
|
|
*/
|
|
public void bindEvents() {
|
|
|
|
cbSelectAll.addValueChangeHandler(new ValueChangeHandler<Boolean>() {
|
|
|
|
@Override
|
|
public void onValueChange(ValueChangeEvent<Boolean> event) {
|
|
GWT.log("Is checked: " + cbSelectAll.getValue());
|
|
eventBus.fireEvent(new CheckBoxSelectIemsEvent<CatalogueDataset>(cbSelectAll.getValue()));
|
|
|
|
}
|
|
});
|
|
|
|
// Fired when user clicks on CMS action
|
|
for (final NavLink navLink : setStatusOptions) {
|
|
navLink.addClickHandler(new ClickHandler() {
|
|
|
|
@Override
|
|
public void onClick(ClickEvent event) {
|
|
if (paginatedView.getSelectItems().size() > 0) {
|
|
showDoActionView(navLink);
|
|
}
|
|
|
|
}
|
|
});
|
|
}
|
|
|
|
permanentlyDelete.addClickHandler(new ClickHandler() {
|
|
|
|
@Override
|
|
public void onClick(ClickEvent event) {
|
|
if (paginatedView.getSelectItems().size() > 0) {
|
|
showDoActionViewDeletePermanently();
|
|
|
|
}
|
|
|
|
}
|
|
});
|
|
}
|
|
|
|
/**
|
|
* Gets the panel.
|
|
*
|
|
* @return the panel
|
|
*/
|
|
public Composite getPanel() {
|
|
return this;
|
|
}
|
|
|
|
/**
|
|
* Sets the visible update status action.
|
|
*
|
|
* @param bool the new visible update status action
|
|
*/
|
|
public void setVisibleUpdateStatusAction(boolean bool) {
|
|
dropdownSetStatus.setVisible(bool);
|
|
}
|
|
|
|
/**
|
|
* Sets the visible permanently delete.
|
|
*
|
|
* @param bool the new visible permanently delete
|
|
*/
|
|
public void setVisiblePermanentlyDelete(boolean bool) {
|
|
permanentlyDelete.setVisible(bool);
|
|
}
|
|
|
|
/**
|
|
* Mark items as checked.
|
|
*
|
|
* @param select the select
|
|
* @param limitToPage the limit to page
|
|
*/
|
|
public void markItemsAsChecked(boolean select, boolean limitToPage) {
|
|
paginatedView.selectItems(select, limitToPage);
|
|
}
|
|
|
|
/**
|
|
* Sets the checked checkbox select all.
|
|
*
|
|
* @param bool the new checked checkbox select all
|
|
*/
|
|
public void setCheckedCheckboxSelectAll(boolean bool) {
|
|
cbSelectAll.setValue(bool);
|
|
}
|
|
|
|
/**
|
|
* Show do action view.
|
|
*
|
|
* @param navLink the nav link
|
|
*/
|
|
private void showDoActionView(NavLink navLink) {
|
|
confirmPanelContainer.clear();
|
|
GWT.log("showConfirm clicked link: " + navLink.getText());
|
|
ItemStatus fromStatus = displayingItemStatus;
|
|
ItemStatus toStatus = UtilFunct.toStatusFromStatusLabel(navLink.getText().trim());
|
|
GWT.log("Do action on from: " + fromStatus + " to: " + toStatus);
|
|
if (toStatus == null) {
|
|
return;
|
|
}
|
|
|
|
DoActionCMSView doActionCMS = new DoActionCMSView();
|
|
doActionCMS.updateStatus(fromStatus, toStatus, paginatedView.getSelectItems());
|
|
|
|
final AlertBlock newAlertBlock = doActionCMS.getAlertBlockDoAction();
|
|
newAlertBlock.addClosedHandler(new ClosedHandler<AlertBase>() {
|
|
|
|
@Override
|
|
public void onClosed(ClosedEvent<AlertBase> event) {
|
|
confirmPanelContainer.clear();
|
|
}
|
|
});
|
|
|
|
Button buttActionConfirmYes = doActionCMS.getButtonActionConfirmYES();
|
|
buttActionConfirmYes.addClickHandler(new ClickHandler() {
|
|
|
|
@Override
|
|
public void onClick(ClickEvent event) {
|
|
confirmPanelContainer.clear();
|
|
|
|
}
|
|
});
|
|
|
|
Button buttonActionConfirmNo = doActionCMS.getButtonActionConfirmNO();
|
|
buttonActionConfirmNo.addClickHandler(new ClickHandler() {
|
|
|
|
@Override
|
|
public void onClick(ClickEvent event) {
|
|
confirmPanelContainer.clear();
|
|
|
|
}
|
|
});
|
|
|
|
confirmPanelContainer.add(doActionCMS);
|
|
}
|
|
|
|
/**
|
|
* Show do action delete permanently.
|
|
*/
|
|
private void showDoActionViewDeletePermanently() {
|
|
confirmPanelContainer.clear();
|
|
GWT.log("showDoActionDeletePermanently...");
|
|
|
|
DoActionCMSView doActionCMS = new DoActionCMSView();
|
|
doActionCMS.permanentlyDelete(paginatedView.getSelectItems());
|
|
|
|
final AlertBlock newAlertBlock = doActionCMS.getAlertBlockDoAction();
|
|
newAlertBlock.addClosedHandler(new ClosedHandler<AlertBase>() {
|
|
|
|
@Override
|
|
public void onClosed(ClosedEvent<AlertBase> event) {
|
|
confirmPanelContainer.clear();
|
|
}
|
|
});
|
|
|
|
Button buttActionConfirmYes = doActionCMS.getButtonActionConfirmYES();
|
|
buttActionConfirmYes.addClickHandler(new ClickHandler() {
|
|
|
|
@Override
|
|
public void onClick(ClickEvent event) {
|
|
confirmPanelContainer.clear();
|
|
|
|
}
|
|
});
|
|
|
|
Button buttonActionConfirmNo = doActionCMS.getButtonActionConfirmNO();
|
|
buttonActionConfirmNo.addClickHandler(new ClickHandler() {
|
|
|
|
@Override
|
|
public void onClick(ClickEvent event) {
|
|
confirmPanelContainer.clear();
|
|
|
|
}
|
|
});
|
|
|
|
confirmPanelContainer.add(doActionCMS);
|
|
}
|
|
|
|
/**
|
|
* Load form server the items with status.
|
|
*
|
|
* @param itemStatus the item status
|
|
*/
|
|
public void loadItemsWithStatus(ItemStatus itemStatus) {
|
|
GWT.log("loadItemsWithStatus started");
|
|
setDisplayingWithStatus(itemStatus);
|
|
setCheckedCheckboxSelectAll(false);
|
|
setVisibleUpdateStatusAction(false);
|
|
setVisiblePermanentlyDelete(false);
|
|
setStatusOptions();
|
|
confirmPanelContainer.clear();
|
|
if (itemStatus.equals(ItemStatus.REJECTED))
|
|
setVisiblePermanentlyDelete(true);
|
|
|
|
paginatedView.loadItemsForStatus(itemStatus);
|
|
|
|
GWT.log("loadItemsWithStatus end");
|
|
}
|
|
|
|
/**
|
|
* Perform CMS action.
|
|
*
|
|
* @param doActionCMSView the do action CMS view
|
|
*/
|
|
public void performCMSAction(DoActionCMSView doActionCMSView) {
|
|
|
|
ItemStatus toStatus = doActionCMSView.getToStatus();
|
|
List<String> listDatasetNames = UtilFunct.toListDatasetNames(doActionCMSView.getListSelectItems());
|
|
switch (toStatus) {
|
|
case PENDING:
|
|
|
|
CkanContentModeratorWidgetController.contentModeratorService.setStatus(toStatus, listDatasetNames,
|
|
new AsyncCallback<Void>() {
|
|
|
|
@Override
|
|
public void onSuccess(Void result) {
|
|
// TODO Auto-generated method stub
|
|
|
|
}
|
|
|
|
@Override
|
|
public void onFailure(Throwable caught) {
|
|
// TODO Auto-generated method stub
|
|
|
|
}
|
|
});
|
|
|
|
break;
|
|
|
|
case APPROVED:
|
|
|
|
CkanContentModeratorWidgetController.contentModeratorService.approveItem(listDatasetNames,
|
|
new AsyncCallback<Void>() {
|
|
|
|
@Override
|
|
public void onSuccess(Void result) {
|
|
// TODO Auto-generated method stub
|
|
|
|
}
|
|
|
|
@Override
|
|
public void onFailure(Throwable caught) {
|
|
// TODO Auto-generated method stub
|
|
|
|
}
|
|
});
|
|
|
|
case REJECTED:
|
|
|
|
CkanContentModeratorWidgetController.contentModeratorService.rejectItem(listDatasetNames,
|
|
doActionCMSView.isPermanentlyDelete(), doActionCMSView.getTxtReasonMsg(),
|
|
new AsyncCallback<Void>() {
|
|
|
|
@Override
|
|
public void onFailure(Throwable caught) {
|
|
// TODO Auto-generated method stub
|
|
|
|
}
|
|
|
|
@Override
|
|
public void onSuccess(Void result) {
|
|
// TODO Auto-generated method stub
|
|
|
|
}
|
|
});
|
|
|
|
default:
|
|
break;
|
|
}
|
|
}
|
|
|
|
}
|