2021-05-06 17:48:18 +02:00
|
|
|
package org.gcube.portlets.widgets.ckancontentmoderator.client;
|
|
|
|
|
2021-06-01 13:24:09 +02:00
|
|
|
import java.util.List;
|
|
|
|
|
2021-06-14 17:39:44 +02:00
|
|
|
import org.gcube.datacatalogue.utillibrary.shared.ItemStatus;
|
2021-06-15 16:52:27 +02:00
|
|
|
import org.gcube.portlets.widgets.ckancontentmoderator.client.ui.ContentModeratorSystemPanel;
|
2021-06-15 12:38:59 +02:00
|
|
|
import org.gcube.portlets.widgets.ckancontentmoderator.client.ui.table.ItemsTable;
|
|
|
|
import org.gcube.portlets.widgets.ckancontentmoderator.client.ui.table.ItemsTable.DISPLAY_FIELD;
|
2021-06-14 11:27:53 +02:00
|
|
|
import org.gcube.portlets.widgets.ckancontentmoderator.shared.CatalogueDataset;
|
2021-06-01 13:24:09 +02:00
|
|
|
|
2021-05-06 17:48:18 +02:00
|
|
|
import com.google.gwt.core.client.GWT;
|
2021-06-15 16:52:27 +02:00
|
|
|
import com.google.gwt.user.client.Command;
|
2021-06-01 18:36:18 +02:00
|
|
|
import com.google.gwt.user.client.rpc.AsyncCallback;
|
2021-06-15 16:52:27 +02:00
|
|
|
import com.google.gwt.user.client.ui.ScrollPanel;
|
|
|
|
import com.google.gwt.view.client.ListDataProvider;
|
2021-06-01 13:24:09 +02:00
|
|
|
|
2021-05-06 17:48:18 +02:00
|
|
|
/**
|
2021-06-15 16:52:27 +02:00
|
|
|
* The Class CkanContentModeratorWidget.
|
|
|
|
*
|
|
|
|
* @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it
|
|
|
|
*
|
|
|
|
* Jun 15, 2021
|
2021-05-06 17:48:18 +02:00
|
|
|
*/
|
2021-06-15 12:38:59 +02:00
|
|
|
public class CkanContentModeratorWidget {
|
|
|
|
|
2021-06-15 16:52:27 +02:00
|
|
|
public final CkanContentModeratorServiceAsync contentModeratorService = GWT
|
|
|
|
.create(CkanContentModeratorService.class);
|
|
|
|
|
|
|
|
private ItemsTable<CatalogueDataset> itemsTable;
|
|
|
|
private ContentModeratorSystemPanel cmsPanel = new ContentModeratorSystemPanel();
|
|
|
|
private Boolean isContentModeratorEnabled = null;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Instantiates a new ckan content moderator widget.
|
|
|
|
*
|
|
|
|
* @param displayFields the display fields
|
|
|
|
* @param sortByField the sort by field
|
|
|
|
*/
|
|
|
|
public CkanContentModeratorWidget(DISPLAY_FIELD[] displayFields, DISPLAY_FIELD sortByField) {
|
2021-06-15 12:38:59 +02:00
|
|
|
itemsTable = new ItemsTable<CatalogueDataset>(null, displayFields, sortByField);
|
2021-06-15 16:52:27 +02:00
|
|
|
itemsTable.initTable(null, null, new ListDataProvider<CatalogueDataset>());
|
|
|
|
cmsPanel.add(itemsTable.getCellTable());
|
2021-06-15 12:38:59 +02:00
|
|
|
}
|
2021-06-15 16:52:27 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Load items for status.
|
|
|
|
*
|
|
|
|
* @param status the status
|
|
|
|
* @throws Exception the exception
|
|
|
|
*/
|
|
|
|
public void loadItemsForStatus(ItemStatus status) throws Exception {
|
|
|
|
|
|
|
|
if (isContentModeratorEnabled == null)
|
|
|
|
throw new Exception("Please, first check if the content moderator is enabled in this context");
|
|
|
|
|
|
|
|
if (!isContentModeratorEnabled)
|
|
|
|
throw new Exception("Content Moderator is not enabled in this context");
|
|
|
|
|
|
|
|
contentModeratorService.getListItemsForStatus(status, ContentModeratorWidgetConstants.ITEMS_PER_PAGE,
|
|
|
|
ContentModeratorWidgetConstants.ITEM_START_INDEX, new AsyncCallback<List<CatalogueDataset>>() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onSuccess(List<CatalogueDataset> result) {
|
|
|
|
itemsTable.updateItems(result, true);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onFailure(Throwable caught) {
|
|
|
|
// TODO Auto-generated method stub
|
|
|
|
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Checks if is content moderator enabled.
|
|
|
|
*
|
|
|
|
* @param onCompletation the on completation
|
|
|
|
*/
|
|
|
|
public void isContentModeratorEnabled(final Command onCompletation) {
|
|
|
|
|
|
|
|
contentModeratorService.isContentModeratorEnabled(new AsyncCallback<Boolean>() {
|
|
|
|
|
2021-06-01 18:36:18 +02:00
|
|
|
@Override
|
2021-06-15 16:52:27 +02:00
|
|
|
public void onFailure(Throwable caught) {
|
|
|
|
onCompletation.execute();
|
|
|
|
|
2021-06-01 18:36:18 +02:00
|
|
|
}
|
2021-06-15 16:52:27 +02:00
|
|
|
|
2021-06-01 18:36:18 +02:00
|
|
|
@Override
|
2021-06-15 16:52:27 +02:00
|
|
|
public void onSuccess(Boolean result) {
|
|
|
|
isContentModeratorEnabled = result;
|
|
|
|
onCompletation.execute();
|
|
|
|
|
2021-06-01 18:36:18 +02:00
|
|
|
}
|
2021-06-15 12:38:59 +02:00
|
|
|
});
|
2021-06-15 16:52:27 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
public ItemsTable<CatalogueDataset> getItemsTable() {
|
|
|
|
return itemsTable;
|
|
|
|
}
|
|
|
|
|
|
|
|
public ScrollPanel getPanel(){
|
|
|
|
return cmsPanel;
|
2021-05-26 17:58:12 +02:00
|
|
|
}
|
2021-05-06 17:48:18 +02:00
|
|
|
}
|