1
|
package eu.dnetlib.repo.manager.client.enrichcontent;
|
2
|
|
3
|
import com.google.gwt.core.client.GWT;
|
4
|
import com.google.gwt.dom.client.Document;
|
5
|
import com.google.gwt.event.dom.client.ClickEvent;
|
6
|
import com.google.gwt.event.dom.client.ClickHandler;
|
7
|
import com.google.gwt.query.client.Function;
|
8
|
import com.google.gwt.user.client.Event;
|
9
|
import com.google.gwt.user.client.Window;
|
10
|
import com.google.gwt.user.client.rpc.AsyncCallback;
|
11
|
import com.google.gwt.user.client.ui.FlowPanel;
|
12
|
import com.google.gwt.user.client.ui.HTML;
|
13
|
import com.google.gwt.user.client.ui.Widget;
|
14
|
import eu.dnetlib.domain.data.Repository;
|
15
|
import eu.dnetlib.gwt.client.help.HelpService;
|
16
|
import eu.dnetlib.gwt.client.help.HelpServiceAsync;
|
17
|
import eu.dnetlib.repo.manager.client.AbstractRepositoryManagerWidget;
|
18
|
import eu.dnetlib.repo.manager.client.HelpCallback;
|
19
|
import eu.dnetlib.repo.manager.client.RepositoryManager;
|
20
|
import eu.dnetlib.repo.manager.client.RepositoryManagerWidget;
|
21
|
import eu.dnetlib.repo.manager.client.services.BrokerService;
|
22
|
import eu.dnetlib.repo.manager.client.services.BrokerServiceAsync;
|
23
|
import eu.dnetlib.repo.manager.shared.broker.SimpleSubscriptionDesc;
|
24
|
import org.gwtbootstrap3.client.ui.*;
|
25
|
import org.gwtbootstrap3.client.ui.constants.AlertType;
|
26
|
import org.gwtbootstrap3.client.ui.constants.ButtonType;
|
27
|
import org.gwtbootstrap3.client.ui.constants.ModalBackdrop;
|
28
|
|
29
|
import java.util.ArrayList;
|
30
|
import java.util.List;
|
31
|
import java.util.Map;
|
32
|
|
33
|
import static com.google.gwt.query.client.GQuery.$;
|
34
|
|
35
|
/**
|
36
|
* Created by stefania on 3/16/17.
|
37
|
*/
|
38
|
public class BrowseSubscriptionsWidget extends AbstractRepositoryManagerWidget implements RepositoryManagerWidget {
|
39
|
|
40
|
private String parentToken = "";
|
41
|
private String restToken = "";
|
42
|
|
43
|
private FlowPanel browseSubscriptionsBoxContent = new FlowPanel();
|
44
|
|
45
|
private Alert errorAlert = new Alert();
|
46
|
|
47
|
private static HelpServiceAsync helpService = GWT.create(HelpService.class);
|
48
|
private static BrokerServiceAsync brokerService = GWT.create(BrokerService.class);
|
49
|
|
50
|
public BrowseSubscriptionsWidget() {
|
51
|
|
52
|
super();
|
53
|
|
54
|
HTML title = new HTML("<h1 class=\"uk-article-title\">Enrich Your Content - Browse Subscriptions</h1>");
|
55
|
title.addStyleName("uk-margin-medium-bottom");
|
56
|
contentPanel.add(title);
|
57
|
|
58
|
errorAlert.setType(AlertType.DANGER);
|
59
|
errorAlert.setDismissable(false);
|
60
|
errorAlert.setVisible(false);
|
61
|
browseSubscriptionsBoxContent.add(errorAlert);
|
62
|
|
63
|
contentPanel.add(browseSubscriptionsBoxContent);
|
64
|
}
|
65
|
|
66
|
@Override
|
67
|
public void clear() {
|
68
|
|
69
|
browseSubscriptionsBoxContent.clear();
|
70
|
errorAlert.setVisible(false);
|
71
|
gridPanel.remove(helpPanel);
|
72
|
}
|
73
|
|
74
|
@Override
|
75
|
public void reload() {
|
76
|
|
77
|
Document.get().getElementById("headerNoTransparent").removeClassName("tm-header-transparent");
|
78
|
browseSubscriptionsBoxContent.add(errorAlert);
|
79
|
|
80
|
helpService.getHelpById(parentToken, new HelpCallback(helpPanel, gridPanel));
|
81
|
|
82
|
final HTML loadingWheel = new HTML("<div class=\"loader-big\" style=\"text-align: center; padding-top: 170px; " +
|
83
|
"color: rgb(47, 64, 80); font-weight: bold;\">Retrieving subscriptions...</div>" +
|
84
|
"<div class=\"whiteFilm\"></div>");
|
85
|
browseSubscriptionsBoxContent.addStyleName("loading-big");
|
86
|
browseSubscriptionsBoxContent.add(loadingWheel);
|
87
|
|
88
|
brokerService.getSimpleSubscriptionsOfUser(RepositoryManager.currentUser.getEmail(),
|
89
|
new AsyncCallback<Map<String, List<SimpleSubscriptionDesc>>>() {
|
90
|
@Override
|
91
|
public void onFailure(Throwable caught) {
|
92
|
|
93
|
browseSubscriptionsBoxContent.removeStyleName("loading-big");
|
94
|
browseSubscriptionsBoxContent.remove(loadingWheel);
|
95
|
|
96
|
errorAlert.setText("System error retrieving subscriptions.");
|
97
|
errorAlert.setVisible(true);
|
98
|
}
|
99
|
|
100
|
@Override
|
101
|
public void onSuccess(Map<String, List<SimpleSubscriptionDesc>> subscriptionsList) {
|
102
|
|
103
|
browseSubscriptionsBoxContent.removeStyleName("loading-big");
|
104
|
browseSubscriptionsBoxContent.remove(loadingWheel);
|
105
|
|
106
|
createSubscriptionsList(subscriptionsList, browseSubscriptionsBoxContent);
|
107
|
}
|
108
|
});
|
109
|
}
|
110
|
|
111
|
@Override
|
112
|
public void setToken(String parentToken, String rest) {
|
113
|
this.parentToken = parentToken;
|
114
|
this.restToken = rest;
|
115
|
}
|
116
|
|
117
|
@Override
|
118
|
public void afterAdditionToRootPanel() {
|
119
|
|
120
|
}
|
121
|
|
122
|
private void addWidgetHandlers() {
|
123
|
|
124
|
$(".delete").click(new Function() {
|
125
|
|
126
|
public boolean f(Event e) {
|
127
|
|
128
|
errorAlert.setVisible(false);
|
129
|
|
130
|
String[] idParts = $(e).get(0).getId().split("#");
|
131
|
List<String> subscriptionIds = new ArrayList<String>();
|
132
|
subscriptionIds.add(idParts[0]);
|
133
|
|
134
|
deleteSubscriptions(subscriptionIds);
|
135
|
|
136
|
return true;
|
137
|
}
|
138
|
});
|
139
|
}
|
140
|
|
141
|
private void createSubscriptionsList(Map<String, List<SimpleSubscriptionDesc>> subscriptionsList, FlowPanel subscriptionsPanel) {
|
142
|
|
143
|
if(subscriptionsList.isEmpty()) {
|
144
|
subscriptionsPanel.add(new HTML("No subscriptions found for your account"));
|
145
|
} else {
|
146
|
|
147
|
for(String key : subscriptionsList.keySet()) {
|
148
|
|
149
|
HTML datasourceTitle = new HTML();
|
150
|
datasourceTitle.setHTML("<h4 class=\"uk-h4 uk-text-primary uk-scrollspy-inview uk-animation-slide-top-medium\"" +
|
151
|
"uk-scrollspy-class=\"\"><span>" + key + "</span></h4>");
|
152
|
subscriptionsPanel.add(datasourceTitle);
|
153
|
|
154
|
FlowPanel colPanel = new FlowPanel();
|
155
|
colPanel.addStyleName("uk-width-1-1@m uk-first-column uk-margin-medium-bottom");
|
156
|
subscriptionsPanel.add(colPanel);
|
157
|
|
158
|
FlowPanel divPanel = new FlowPanel();
|
159
|
divPanel.addStyleName("uk-overflow-auto uk-scrollspy-inview uk-animation-slide-top-medium");
|
160
|
colPanel.add(divPanel);
|
161
|
|
162
|
String content = "<table class=\"uk-table uk-table-striped uk-table-middle\">" +
|
163
|
"<thead><tr><th>Topic</th><th class=\"uk-text-nowrap\"># of notifications</th><th class=\"uk-text-nowrap\">Actions</th></tr></thead>";
|
164
|
|
165
|
content += "<tbody>";
|
166
|
|
167
|
for(SimpleSubscriptionDesc simpleSubscriptionDesc : subscriptionsList.get(key)) {
|
168
|
|
169
|
content += "<tr class=\"el-item\">" +
|
170
|
"<td class=\"uk-table-shrink\">";
|
171
|
|
172
|
content += "<div class=\"el-title\">" + simpleSubscriptionDesc.getTopic() + "</div>";
|
173
|
|
174
|
content += "</td>" +
|
175
|
"<td class=\"uk-text-nowrap uk-table-shrink\">\n" +
|
176
|
"<div class=\"el-title\">" + simpleSubscriptionDesc.getCount() + "</div>" +
|
177
|
"</td>" +
|
178
|
"<td class=\"uk-text-nowrap uk-table-shrink\">" +
|
179
|
"<a href=\"javascript:;\" id=\"" + simpleSubscriptionDesc.getId() + "#delete\" class=\"el-link delete\">" +
|
180
|
"<i class=\"fa fa-remove\" aria-hidden=\"true\"></i></a>" +
|
181
|
"</td>" +
|
182
|
"</tr>";
|
183
|
}
|
184
|
|
185
|
content += "</tbody></table>";
|
186
|
|
187
|
HTML reposListHTML = new HTML();
|
188
|
reposListHTML.setHTML(content);
|
189
|
|
190
|
divPanel.add(reposListHTML);
|
191
|
}
|
192
|
}
|
193
|
|
194
|
addWidgetHandlers();
|
195
|
}
|
196
|
|
197
|
private void deleteSubscriptions(final List<String> subscriptionIds) {
|
198
|
|
199
|
final Modal deleteSubscriptionsConfirmationPopup = new Modal();
|
200
|
deleteSubscriptionsConfirmationPopup.setDataBackdrop(ModalBackdrop.STATIC);
|
201
|
|
202
|
FlowPanel modalContent = new FlowPanel();
|
203
|
|
204
|
HTML description = new HTML("<h2 class=\"uk-modal-title\">Delete Confirmation</h2>\n" +
|
205
|
"<p>Are you sure you want to delete the selected subscription(s)?</p>");
|
206
|
modalContent.add(description);
|
207
|
|
208
|
FlowPanel actionButtons = new FlowPanel();
|
209
|
actionButtons.addStyleName("uk-text-right");
|
210
|
modalContent.add(actionButtons);
|
211
|
|
212
|
Button no = new Button("Cancel");
|
213
|
no.setType(ButtonType.DEFAULT);
|
214
|
no.addClickHandler(new ClickHandler() {
|
215
|
@Override
|
216
|
public void onClick(ClickEvent event) {
|
217
|
deleteSubscriptionsConfirmationPopup.hide();
|
218
|
deleteSubscriptionsConfirmationPopup.removeFromParent();
|
219
|
}
|
220
|
});
|
221
|
actionButtons.add(no);
|
222
|
|
223
|
Button yes = new Button("Yes, delete them");
|
224
|
yes.setType(ButtonType.PRIMARY);
|
225
|
yes.addClickHandler(new ClickHandler() {
|
226
|
@Override
|
227
|
public void onClick(ClickEvent event) {
|
228
|
|
229
|
deleteSubscriptionsConfirmationPopup.hide();
|
230
|
deleteSubscriptionsConfirmationPopup.removeFromParent();
|
231
|
|
232
|
final HTML loadingWheel = new HTML("<div class=\"loader-big\"></div><div class=\"whiteFilm\"></div>");
|
233
|
browseSubscriptionsBoxContent.addStyleName("loading-big");
|
234
|
browseSubscriptionsBoxContent.add(loadingWheel);
|
235
|
|
236
|
brokerService.unsubscribe(subscriptionIds.get(0), new AsyncCallback<Void>() {
|
237
|
|
238
|
@Override
|
239
|
public void onFailure(Throwable caught) {
|
240
|
|
241
|
browseSubscriptionsBoxContent.removeStyleName("loading-big");
|
242
|
browseSubscriptionsBoxContent.remove(loadingWheel);
|
243
|
|
244
|
errorAlert.setText("System error deleting the specified subscription(s)");
|
245
|
errorAlert.setVisible(true);
|
246
|
}
|
247
|
|
248
|
@Override
|
249
|
public void onSuccess(Void result) {
|
250
|
|
251
|
browseSubscriptionsBoxContent.removeStyleName("loading-big");
|
252
|
browseSubscriptionsBoxContent.remove(loadingWheel);
|
253
|
|
254
|
clear();
|
255
|
reload();
|
256
|
|
257
|
Window.scrollTo(0, 0);
|
258
|
}
|
259
|
});
|
260
|
}
|
261
|
});
|
262
|
actionButtons.add(yes);
|
263
|
|
264
|
ModalBody modalBody = new ModalBody();
|
265
|
modalBody.add(modalContent);
|
266
|
deleteSubscriptionsConfirmationPopup.add(modalBody);
|
267
|
deleteSubscriptionsConfirmationPopup.getElement().getChild(0).getChild(0).getChild(0).removeFromParent();
|
268
|
|
269
|
deleteSubscriptionsConfirmationPopup.show();
|
270
|
}
|
271
|
}
|