Search in sources :

Example 1 with ProblemCollectionDetails

use of com.playshogi.website.gwt.shared.models.ProblemCollectionDetails in project playshogi by Tellmarch.

the class MyCollectionsActivity method onSaveDraftCollection.

@EventHandler
public void onSaveDraftCollection(final SaveDraftCollectionEvent event) {
    GWT.log("MyCollectionsActivity: Handling SaveDraftCollectionEvent: " + event);
    if (event.getId() != null) {
        Window.alert("Your collection is uploading - it may take a few minutes to import all kifus to the " + "database. " + "You can keep using the website during that time.");
    }
    switch(event.getType()) {
        case KIFUS:
            kifuService.saveDraftCollectionKifus(sessionInformation.getSessionId(), event.getId(), new AsyncCallback<Void>() {

                @Override
                public void onFailure(final Throwable throwable) {
                    GWT.log("MyCollectionsActivity: error saving draft kifus");
                    Window.alert("Failed to upload the kifus.");
                }

                @Override
                public void onSuccess(final Void s) {
                    GWT.log("MyCollectionsActivity: saved draft kifus");
                    refresh();
                }
            });
            break;
        case GAMES:
            if (event.getId() == null) {
                GameCollectionDetails gcDetails = new GameCollectionDetails(event.getTitle(), event.getDescription(), event.getVisibility());
                kifuService.createGameCollection(sessionInformation.getSessionId(), gcDetails, new AsyncCallback<Void>() {

                    @Override
                    public void onFailure(final Throwable throwable) {
                        GWT.log("MyCollectionsActivity: error creating new game collection");
                        Window.alert("Failed to create the game collection.");
                    }

                    @Override
                    public void onSuccess(final Void unused) {
                        GWT.log("MyCollectionsActivity: created new game collection");
                        refresh();
                    }
                });
            } else if (event.getCollectionId() != null) {
                kifuService.addDraftToGameCollection(sessionInformation.getSessionId(), event.getId(), event.getCollectionId(), new AsyncCallback<Void>() {

                    @Override
                    public void onFailure(final Throwable throwable) {
                        GWT.log("MyCollectionsActivity: error adding draft game collection");
                        Window.alert("Failed to upload the game collection.");
                    }

                    @Override
                    public void onSuccess(final Void unused) {
                        GWT.log("MyCollectionsActivity: added draft game collection");
                        refresh();
                    }
                });
            } else {
                GameCollectionDetails gcDetails = new GameCollectionDetails(event.getTitle(), event.getDescription(), event.getVisibility());
                kifuService.saveGameCollection(sessionInformation.getSessionId(), event.getId(), gcDetails, new AsyncCallback<String>() {

                    @Override
                    public void onFailure(final Throwable throwable) {
                        GWT.log("MyCollectionsActivity: error saving draft game collection");
                        Window.alert("Failed to upload the game collection.");
                    }

                    @Override
                    public void onSuccess(final String s) {
                        GWT.log("MyCollectionsActivity: saved draft game collection");
                        refresh();
                    }
                });
            }
            break;
        case PROBLEMS:
            if (event.getId() == null) {
                ProblemCollectionDetails pcDetails = new ProblemCollectionDetails(event.getTitle(), event.getDescription(), event.getVisibility(), event.getDifficulty(), event.getTags());
                problemsService.createProblemCollection(sessionInformation.getSessionId(), pcDetails, new AsyncCallback<String>() {

                    @Override
                    public void onFailure(final Throwable throwable) {
                        GWT.log("MyCollectionsActivity: error creating new problem collection");
                        Window.alert("Failed to create the problem collection.");
                    }

                    @Override
                    public void onSuccess(final String s) {
                        GWT.log("MyCollectionsActivity: created problem collection");
                        refresh();
                    }
                });
            } else if (event.getCollectionId() != null) {
                problemsService.addDraftToProblemCollection(sessionInformation.getSessionId(), event.getId(), event.getCollectionId(), new AsyncCallback<Void>() {

                    @Override
                    public void onFailure(final Throwable throwable) {
                        GWT.log("MyCollectionsActivity: error adding draft problem collection");
                        Window.alert("Failed to upload the problem collection.");
                    }

                    @Override
                    public void onSuccess(final Void unused) {
                        GWT.log("MyCollectionsActivity: added draft problem collection");
                        refresh();
                    }
                });
            } else {
                ProblemCollectionDetails pcDetails = new ProblemCollectionDetails(event.getTitle(), event.getDescription(), event.getVisibility(), event.getDifficulty(), event.getTags());
                problemsService.saveProblemsCollection(sessionInformation.getSessionId(), event.getId(), pcDetails, new AsyncCallback<String>() {

                    @Override
                    public void onFailure(final Throwable throwable) {
                        GWT.log("MyCollectionsActivity: error saving draft problem collection");
                        Window.alert("Failed to upload the problem collection.");
                    }

                    @Override
                    public void onSuccess(final String s) {
                        GWT.log("MyCollectionsActivity: saved draft problem collection");
                        refresh();
                    }
                });
            }
            break;
    }
}
Also used : GameCollectionDetails(com.playshogi.website.gwt.shared.models.GameCollectionDetails) ProblemCollectionDetails(com.playshogi.website.gwt.shared.models.ProblemCollectionDetails) AsyncCallback(com.google.gwt.user.client.rpc.AsyncCallback) EventHandler(com.google.web.bindery.event.shared.binder.EventHandler)

Example 2 with ProblemCollectionDetails

use of com.playshogi.website.gwt.shared.models.ProblemCollectionDetails in project playshogi by Tellmarch.

the class ProblemCollectionPropertiesForm method updateDetails.

private ProblemCollectionDetails updateDetails(final ProblemCollectionDetails details) {
    ProblemCollectionDetails result = new ProblemCollectionDetails(getTitle(), getDescription(), getVisibility(), getDifficulty(), getTags());
    result.setId(details.getId());
    return result;
}
Also used : ProblemCollectionDetails(com.playshogi.website.gwt.shared.models.ProblemCollectionDetails)

Example 3 with ProblemCollectionDetails

use of com.playshogi.website.gwt.shared.models.ProblemCollectionDetails in project playshogi by Tellmarch.

the class KifuTable method createCollectionsDropdown.

private ListBox createCollectionsDropdown(final KifuDetails.KifuType type) {
    ListBox list = new ListBox();
    if (type == KifuDetails.KifuType.PROBLEM) {
        for (ProblemCollectionDetails collection : myProblemCollections) {
            list.addItem(collection.getName(), collection.getId());
        }
    } else {
        for (GameCollectionDetails collection : myGameCollections) {
            list.addItem(collection.getName(), collection.getId());
        }
    }
    list.setVisibleItemCount(1);
    return list;
}
Also used : GameCollectionDetails(com.playshogi.website.gwt.shared.models.GameCollectionDetails) ProblemCollectionDetails(com.playshogi.website.gwt.shared.models.ProblemCollectionDetails)

Example 4 with ProblemCollectionDetails

use of com.playshogi.website.gwt.shared.models.ProblemCollectionDetails in project playshogi by Tellmarch.

the class ProblemCollectionsTable method getTableConfig.

private TableConfig<ProblemCollectionDetails> getTableConfig(final AppPlaceHistoryMapper historyMapper) {
    TableConfig<ProblemCollectionDetails> tableConfig = new TableConfig<>();
    tableConfig.addColumn(ColumnConfig.<ProblemCollectionDetails>create("id", "#").styleCell(element -> element.style.setProperty("vertical-align", "top")).textAlign("right").asHeader().setCellRenderer(cell -> TextNode.of(String.valueOf(cell.getTableRow().getIndex() + 1 + PAGE_SIZE * (simplePaginationPlugin.getSimplePagination().activePage() - 1))))).addColumn(ColumnConfig.<ProblemCollectionDetails>create("name", "Name").styleCell(element -> element.style.setProperty("vertical-align", "top")).setCellRenderer(cell -> TextNode.of(cell.getRecord().getName())).setSortable(true)).addColumn(ColumnConfig.<ProblemCollectionDetails>create("practice", "Practice").styleCell(element -> element.style.setProperty("vertical-align", "top")).setCellRenderer(cell -> {
        String href = "#" + historyMapper.getToken(new ProblemsPlace(cell.getRecord().getId(), 0));
        return Elements.a(href).add(Button.createSuccess(Icons.ALL.timer()).setContent("Practice / Speedrun")).element();
    })).addColumn(ColumnConfig.<ProblemCollectionDetails>create("difficulty", "Difficulty").styleCell(element -> element.style.setProperty("vertical-align", "top")).setCellRenderer(cell -> getDifficulty(cell.getRecord())).setSortable(true));
    if (!isAuthor) {
        tableConfig.addColumn(ColumnConfig.<ProblemCollectionDetails>create("author", "Author").styleCell(element -> element.style.setProperty("vertical-align", "top")).setCellRenderer(cell -> TextNode.of(cell.getRecord().getAuthor())).setSortable(true));
    }
    if (isAuthor || canEdit) {
        tableConfig.addColumn(ColumnConfig.<ProblemCollectionDetails>create("visibility", "Visibility").styleCell(element -> element.style.setProperty("vertical-align", "top")).setCellRenderer(cell -> TextNode.of(cell.getRecord().getVisibility())));
    }
    tableConfig.addColumn(ColumnConfig.<ProblemCollectionDetails>create("solved", "Solved").styleCell(element -> element.style.setProperty("vertical-align", "top")).setCellRenderer(cell -> getSolved(cell.getRecord()))).addColumn(ColumnConfig.<ProblemCollectionDetails>create("besttime", "Personal Best Time").styleCell(element -> element.style.setProperty("vertical-align", "top")).setCellRenderer(cell -> getPersonalBest(cell.getRecord())).setSortable(true)).addColumn(ColumnConfig.<ProblemCollectionDetails>create("leaderboard", "Leaderboard").styleCell(element -> element.style.setProperty("vertical-align", "top")).setCellRenderer(cell -> getLeaderboard(cell.getRecord())));
    if (isAuthor) {
        tableConfig.addColumn(ColumnConfig.<ProblemCollectionDetails>create("open", "Open Collection").styleCell(element -> element.style.setProperty("vertical-align", "top")).setCellRenderer(cell -> {
            String href = "#" + historyMapper.getToken(new ProblemCollectionPlace(cell.getRecord().getId()));
            return Elements.a(href).add(Button.createPrimary("Open")).element();
        }));
    }
    return tableConfig;
}
Also used : DeleteProblemCollectionEvent(com.playshogi.website.gwt.client.events.collections.DeleteProblemCollectionEvent) Icons(org.dominokit.domino.ui.icons.Icons) ColumnConfig(org.dominokit.domino.ui.datatable.ColumnConfig) RecordsSorter(org.dominokit.domino.ui.datatable.store.RecordsSorter) ASC(org.dominokit.domino.ui.datatable.plugins.SortDirection.ASC) LocalListDataStore(org.dominokit.domino.ui.datatable.store.LocalListDataStore) Elements(org.jboss.elemento.Elements) Column(org.dominokit.domino.ui.grid.Column) GWT(com.google.gwt.core.client.GWT) AppPlaceHistoryMapper(com.playshogi.website.gwt.client.mvp.AppPlaceHistoryMapper) ProblemsPlace(com.playshogi.website.gwt.client.place.ProblemsPlace) DataTable(org.dominokit.domino.ui.datatable.DataTable) ProblemCollectionPlace(com.playshogi.website.gwt.client.place.ProblemCollectionPlace) TextHeaderFilter(org.dominokit.domino.ui.datatable.plugins.filter.header.TextHeaderFilter) SelectHeaderFilter(org.dominokit.domino.ui.datatable.plugins.filter.header.SelectHeaderFilter) Row(org.dominokit.domino.ui.grid.Row) Window(com.google.gwt.user.client.Window) SelectOption(org.dominokit.domino.ui.forms.SelectOption) TextNode(org.dominokit.domino.ui.utils.TextNode) ProblemCollectionDetails(com.playshogi.website.gwt.shared.models.ProblemCollectionDetails) org.dominokit.domino.ui.datatable.plugins(org.dominokit.domino.ui.datatable.plugins) TableConfig(org.dominokit.domino.ui.datatable.TableConfig) EventBus(com.google.web.bindery.event.shared.EventBus) ProblemCollectionPropertiesForm(com.playshogi.website.gwt.client.widget.collections.ProblemCollectionPropertiesForm) List(java.util.List) Row_12(org.dominokit.domino.ui.grid.Row_12) elemental2.dom(elemental2.dom) HtmlContentBuilder(org.jboss.elemento.HtmlContentBuilder) Comparator(java.util.Comparator) TagsElement(com.playshogi.website.gwt.client.widget.problems.TagsElement) Button(org.dominokit.domino.ui.button.Button) ProblemCollectionPlace(com.playshogi.website.gwt.client.place.ProblemCollectionPlace) ProblemCollectionDetails(com.playshogi.website.gwt.shared.models.ProblemCollectionDetails) TableConfig(org.dominokit.domino.ui.datatable.TableConfig) ProblemsPlace(com.playshogi.website.gwt.client.place.ProblemsPlace)

Aggregations

ProblemCollectionDetails (com.playshogi.website.gwt.shared.models.ProblemCollectionDetails)4 GameCollectionDetails (com.playshogi.website.gwt.shared.models.GameCollectionDetails)2 GWT (com.google.gwt.core.client.GWT)1 Window (com.google.gwt.user.client.Window)1 AsyncCallback (com.google.gwt.user.client.rpc.AsyncCallback)1 EventBus (com.google.web.bindery.event.shared.EventBus)1 EventHandler (com.google.web.bindery.event.shared.binder.EventHandler)1 DeleteProblemCollectionEvent (com.playshogi.website.gwt.client.events.collections.DeleteProblemCollectionEvent)1 AppPlaceHistoryMapper (com.playshogi.website.gwt.client.mvp.AppPlaceHistoryMapper)1 ProblemCollectionPlace (com.playshogi.website.gwt.client.place.ProblemCollectionPlace)1 ProblemsPlace (com.playshogi.website.gwt.client.place.ProblemsPlace)1 ProblemCollectionPropertiesForm (com.playshogi.website.gwt.client.widget.collections.ProblemCollectionPropertiesForm)1 TagsElement (com.playshogi.website.gwt.client.widget.problems.TagsElement)1 elemental2.dom (elemental2.dom)1 Comparator (java.util.Comparator)1 List (java.util.List)1 Button (org.dominokit.domino.ui.button.Button)1 ColumnConfig (org.dominokit.domino.ui.datatable.ColumnConfig)1 DataTable (org.dominokit.domino.ui.datatable.DataTable)1 TableConfig (org.dominokit.domino.ui.datatable.TableConfig)1