From 6cbafbd5a82039167c5e0825e7d6943808d151d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hern=C3=A1n=20Vargas?= Date: Wed, 8 Sep 2021 21:22:32 -0300 Subject: [PATCH] Added button to delete hypothesis --- .../components/hypothesis/ExecutionList.java | 34 ++++++++++--------- .../components/hypothesis/HypothesisItem.java | 25 +++++++++++++- .../hypothesis/HypothesisItem.ui.xml | 13 +++++-- 3 files changed, 53 insertions(+), 19 deletions(-) diff --git a/portal/client/src/main/java/org/diskproject/client/components/hypothesis/ExecutionList.java b/portal/client/src/main/java/org/diskproject/client/components/hypothesis/ExecutionList.java index 858cca8..2c653f3 100644 --- a/portal/client/src/main/java/org/diskproject/client/components/hypothesis/ExecutionList.java +++ b/portal/client/src/main/java/org/diskproject/client/components/hypothesis/ExecutionList.java @@ -281,23 +281,25 @@ public void onBrowserEvent(Event event) { options.appendChild(el); } - IronIcon iconNarrative = new IronIcon(); - iconNarrative.addStyleName("inline-button"); - iconNarrative.setIcon("assignment"); - el = iconNarrative.getElement(); - Event.sinkEvents(el, Event.ONCLICK); - Event.setEventListener(el, new EventListener() { - @Override - public void onBrowserEvent(Event event) { - CloseableDialog dialog = new CloseableDialog(); - Narrative narrativeEl = new Narrative(tloi); - dialog.setText("Execution narrative"); - dialog.add(narrativeEl); - dialog.centerAndShow(); - } - }); + if (curStatus == Status.SUCCESSFUL) { + IronIcon iconNarrative = new IronIcon(); + iconNarrative.addStyleName("inline-button"); + iconNarrative.setIcon("assignment"); + el = iconNarrative.getElement(); + Event.sinkEvents(el, Event.ONCLICK); + Event.setEventListener(el, new EventListener() { + @Override + public void onBrowserEvent(Event event) { + CloseableDialog dialog = new CloseableDialog(); + Narrative narrativeEl = new Narrative(tloi); + dialog.setText("Execution narrative"); + dialog.add(narrativeEl); + dialog.centerAndShow(); + } + }); - options.appendChild(el); + options.appendChild(el); + } IronIcon iconDelete = new IronIcon(); iconDelete.addStyleName("delete-button"); diff --git a/portal/client/src/main/java/org/diskproject/client/components/hypothesis/HypothesisItem.java b/portal/client/src/main/java/org/diskproject/client/components/hypothesis/HypothesisItem.java index 0c3e9c4..bcd2a1b 100644 --- a/portal/client/src/main/java/org/diskproject/client/components/hypothesis/HypothesisItem.java +++ b/portal/client/src/main/java/org/diskproject/client/components/hypothesis/HypothesisItem.java @@ -6,9 +6,12 @@ import org.diskproject.client.components.searchpanel.SearchableItem; import org.diskproject.client.place.NameTokens; +import org.diskproject.client.rest.AppNotification; +import org.diskproject.client.rest.DiskREST; import org.diskproject.shared.classes.common.TreeItem; import org.diskproject.shared.classes.loi.TriggeredLOI; +import com.google.gwt.core.client.Callback; import com.google.gwt.core.client.GWT; import com.google.gwt.dom.client.DivElement; import com.google.gwt.dom.client.LabelElement; @@ -20,6 +23,7 @@ import com.google.gwt.user.client.DOM; import com.google.gwt.user.client.ui.Widget; import com.google.gwt.user.client.History; +import com.google.gwt.user.client.Window; import com.vaadin.polymer.paper.widget.PaperIconButton; public class HypothesisItem extends SearchableItem { @@ -27,7 +31,7 @@ interface Binder extends UiBinder {}; private static Binder uiBinder = GWT.create(Binder.class); @UiField DivElement title, description, info, executions; - @UiField PaperIconButton editButton; + @UiField PaperIconButton editButton, deleteButton; @UiField LabelElement tloiLabel; private String strTitle, strDescription, strAuthor, strDate; private String id; @@ -117,4 +121,23 @@ void onEditButtonClicked(ClickEvent event) { String token = NameTokens.hypotheses + "/" + HypothesisItem.username +"/" + HypothesisItem.domain + "/" + this.id; History.newItem(token); } + + @UiHandler("deleteButton") + void onDelButtonClicked(ClickEvent event) { + HypothesisItem me = this; + if (Window.confirm("Are you sure you want to delete " + this.strTitle)) { + DiskREST.deleteHypothesis(this.id, new Callback() { + @Override + public void onFailure(Throwable reason) { + AppNotification.notifyFailure(reason.getMessage()); + } + @Override + public void onSuccess(Void result) { + AppNotification.notifySuccess("Deleted", 500); + //TODO: do some kind of update to remove this element + me.setVisible(false); + } + }); + } + } } diff --git a/portal/client/src/main/java/org/diskproject/client/components/hypothesis/HypothesisItem.ui.xml b/portal/client/src/main/java/org/diskproject/client/components/hypothesis/HypothesisItem.ui.xml index 3e5a45f..f4b3b90 100644 --- a/portal/client/src/main/java/org/diskproject/client/components/hypothesis/HypothesisItem.ui.xml +++ b/portal/client/src/main/java/org/diskproject/client/components/hypothesis/HypothesisItem.ui.xml @@ -52,11 +52,19 @@ .hyp-desc-row { padding: 0px 5px 5px 30px; } - .edit-hyp-button { + .edit-button-hyp { width: 32px; height: 32px; padding: 3px; } + .del-button-hyp { + width: 32px; + height: 32px; + padding: 5px; + } + .del-button-hyp:hover { + color: darkred; + }
@@ -64,7 +72,8 @@
- + +