1
|
package eu.dnetlib.repo.manager.client.admin.metrics;
|
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.i18n.client.DateTimeFormat;
|
8
|
import com.google.gwt.query.client.Function;
|
9
|
import com.google.gwt.user.client.Event;
|
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 eu.dnetlib.gwt.client.help.HelpService;
|
14
|
import eu.dnetlib.gwt.client.help.HelpServiceAsync;
|
15
|
import eu.dnetlib.repo.manager.client.AbstractRepositoryManagerWidget;
|
16
|
import eu.dnetlib.repo.manager.client.HelpCallback;
|
17
|
import eu.dnetlib.repo.manager.client.RepositoryManagerWidget;
|
18
|
import eu.dnetlib.repo.manager.client.services.RepositoryService;
|
19
|
import eu.dnetlib.repo.manager.client.services.RepositoryServiceAsync;
|
20
|
import eu.dnetlib.repo.manager.shared.PiwikInfo;
|
21
|
import org.gwtbootstrap3.client.ui.Alert;
|
22
|
import org.gwtbootstrap3.client.ui.Button;
|
23
|
import org.gwtbootstrap3.client.ui.Modal;
|
24
|
import org.gwtbootstrap3.client.ui.ModalBody;
|
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
|
|
32
|
import static com.google.gwt.query.client.GQuery.$;
|
33
|
|
34
|
/**
|
35
|
* Created by stefania on 10/18/17.
|
36
|
*/
|
37
|
public class MetricsAdminWidget extends AbstractRepositoryManagerWidget implements RepositoryManagerWidget {
|
38
|
|
39
|
private String parentToken = "";
|
40
|
private String restToken = "";
|
41
|
|
42
|
private FlowPanel metricsAdminBoxContent = new FlowPanel();
|
43
|
|
44
|
private Alert errorAlert = new Alert();
|
45
|
|
46
|
private static HelpServiceAsync helpService = GWT.create(HelpService.class);
|
47
|
private static RepositoryServiceAsync repositoryService = GWT.create(RepositoryService.class);
|
48
|
|
49
|
private DateTimeFormat dtf = DateTimeFormat.getFormat("yyyy-MM-dd");
|
50
|
|
51
|
public MetricsAdminWidget() {
|
52
|
|
53
|
super();
|
54
|
|
55
|
HTML title = new HTML("<h1 class=\"uk-article-title\">Metrics Admin</h1>");
|
56
|
title.addStyleName("uk-margin-medium-bottom");
|
57
|
contentPanel.add(title);
|
58
|
|
59
|
errorAlert.setType(AlertType.DANGER);
|
60
|
errorAlert.setDismissable(false);
|
61
|
errorAlert.setVisible(false);
|
62
|
metricsAdminBoxContent.add(errorAlert);
|
63
|
|
64
|
contentPanel.add(metricsAdminBoxContent);
|
65
|
}
|
66
|
|
67
|
@Override
|
68
|
public void clear() {
|
69
|
|
70
|
metricsAdminBoxContent.clear();
|
71
|
errorAlert.setVisible(false);
|
72
|
gridPanel.remove(helpPanel);
|
73
|
}
|
74
|
|
75
|
@Override
|
76
|
public void reload() {
|
77
|
|
78
|
Document.get().getElementById("headerNoTransparent").removeClassName("tm-header-transparent");
|
79
|
metricsAdminBoxContent.add(errorAlert);
|
80
|
|
81
|
helpService.getHelpById(parentToken, new HelpCallback(helpPanel, gridPanel));
|
82
|
|
83
|
final HTML loadingWheel = new HTML("<div class=\"loader-big\" style=\"text-align: center; padding-top: 170px; " +
|
84
|
"color: rgb(47, 64, 80); font-weight: bold;\">Retrieving piwik sites info...</div>" +
|
85
|
"<div class=\"whiteFilm\"></div>");
|
86
|
metricsAdminBoxContent.addStyleName("loading-big");
|
87
|
metricsAdminBoxContent.add(loadingWheel);
|
88
|
|
89
|
repositoryService.getPiwikSitesForRepositories(new AsyncCallback<List<PiwikInfo>>() {
|
90
|
|
91
|
@Override
|
92
|
public void onFailure(Throwable caught) {
|
93
|
|
94
|
metricsAdminBoxContent.removeStyleName("loading-big");
|
95
|
metricsAdminBoxContent.remove(loadingWheel);
|
96
|
|
97
|
errorAlert.setText("System error retrieving piwik sites info.");
|
98
|
errorAlert.setVisible(true);
|
99
|
}
|
100
|
|
101
|
@Override
|
102
|
public void onSuccess(List<PiwikInfo> results) {
|
103
|
|
104
|
metricsAdminBoxContent.removeStyleName("loading-big");
|
105
|
metricsAdminBoxContent.remove(loadingWheel);
|
106
|
|
107
|
if(results!=null) {
|
108
|
createPiwikSitesInfoList(results, metricsAdminBoxContent);
|
109
|
} else {
|
110
|
errorAlert.setText("System error retrieving piwik sites info.");
|
111
|
errorAlert.setVisible(true);
|
112
|
}
|
113
|
}
|
114
|
});
|
115
|
}
|
116
|
|
117
|
@Override
|
118
|
public void setToken(String parentToken, String rest) {
|
119
|
this.parentToken = parentToken;
|
120
|
this.restToken = rest;
|
121
|
}
|
122
|
|
123
|
@Override
|
124
|
public void afterAdditionToRootPanel() {
|
125
|
|
126
|
}
|
127
|
|
128
|
private void addWidgetHandlers() {
|
129
|
|
130
|
$(".approve").click(new Function() {
|
131
|
|
132
|
public boolean f(Event e) {
|
133
|
|
134
|
errorAlert.setVisible(false);
|
135
|
|
136
|
String[] idParts = $(e).get(0).getId().split("#");
|
137
|
List<String> repositoryIds = new ArrayList<String>();
|
138
|
repositoryIds.add(idParts[0]);
|
139
|
|
140
|
approvePiwikSites(repositoryIds);
|
141
|
|
142
|
return true;
|
143
|
}
|
144
|
});
|
145
|
}
|
146
|
|
147
|
private void createPiwikSitesInfoList(List<PiwikInfo> results, FlowPanel piwikInfosPanel) {
|
148
|
|
149
|
if(results.isEmpty()) {
|
150
|
piwikInfosPanel.add(new HTML("There are no piwik sites available yet."));
|
151
|
} else {
|
152
|
|
153
|
// HTML datasourceTitle = new HTML();
|
154
|
// datasourceTitle.setHTML("<h4 class=\"uk-h4 uk-text-primary uk-scrollspy-inview uk-animation-slide-top-medium\"" +
|
155
|
// "uk-scrollspy-class=\"\"><span>" + piwikInfo + "</span></h4>");
|
156
|
// piwikInfosPanel.add(datasourceTitle);
|
157
|
|
158
|
FlowPanel colPanel = new FlowPanel();
|
159
|
colPanel.addStyleName("uk-width-1-1@m uk-first-column uk-margin-medium-bottom");
|
160
|
piwikInfosPanel.add(colPanel);
|
161
|
|
162
|
FlowPanel divPanel = new FlowPanel();
|
163
|
divPanel.addStyleName("uk-overflow-auto uk-scrollspy-inview uk-animation-slide-top-medium");
|
164
|
colPanel.add(divPanel);
|
165
|
|
166
|
String content = "<table class=\"uk-table uk-table-striped uk-table-middle\" style=\"font-size: 12px\">" +
|
167
|
"<thead><tr><th class=\"uk-text-nowrap\">Repository</th><th class=\"uk-text-nowrap\">Piwik site</th>" +
|
168
|
"<th class=\"uk-text-nowrap\">Requested on</th><th class=\"uk-text-nowrap\">Requestor</th>" +
|
169
|
"<th class=\"uk-text-nowrap\">Approved</th>" +
|
170
|
"<th class=\"uk-text-nowrap\">Actions</th></tr></thead>";
|
171
|
|
172
|
content += "<tbody>";
|
173
|
|
174
|
for(PiwikInfo piwikInfo : results) {
|
175
|
|
176
|
content += "<tr class=\"el-item\">" +
|
177
|
"";
|
178
|
|
179
|
// REPOSITORY
|
180
|
content += "<td class=\"uk-table-shrink\">";
|
181
|
if(piwikInfo.getRepositoryName()!=null && !piwikInfo.getRepositoryName().trim().equals(""))
|
182
|
content += "<div class=\"el-title\">" + piwikInfo.getRepositoryName() + "</div>";
|
183
|
else
|
184
|
content += "--";
|
185
|
if(piwikInfo.getCountry()!=null && !piwikInfo.getCountry().trim().equals(""))
|
186
|
content += "<div class=\"el-title\">" + piwikInfo.getCountry() + "</div>";
|
187
|
else
|
188
|
content += "--";
|
189
|
if(piwikInfo.getRepositoryId()!=null && !piwikInfo.getRepositoryId().trim().equals(""))
|
190
|
content += "<div class=\"el-title\">(ID: " + piwikInfo.getRepositoryId() + ")</div>";
|
191
|
else
|
192
|
content += "--";
|
193
|
|
194
|
content += "</td>";
|
195
|
|
196
|
// PIWIK SITE
|
197
|
content += "<td class=\"uk-table-shrink\">";
|
198
|
if(piwikInfo.getSiteId()!=null && !piwikInfo.getSiteId().trim().equals(""))
|
199
|
content += "<div class=\"el-title\">ID: " + piwikInfo.getSiteId() + "</div>";
|
200
|
else
|
201
|
content += "--";
|
202
|
if(piwikInfo.getAuthenticationToken()!=null && !piwikInfo.getAuthenticationToken().trim().equals(""))
|
203
|
content += "<div class=\"el-title\">Authentication token: " + piwikInfo.getAuthenticationToken() + "</div>";
|
204
|
else
|
205
|
content += "--";
|
206
|
content += "</td>";
|
207
|
|
208
|
// REQUEST DATE
|
209
|
if(piwikInfo.getCreationDate()!=null)
|
210
|
content += "<td class=\"uk-text-nowrap uk-table-shrink\"><div class=\"el-title\">" + dtf.format(piwikInfo.getCreationDate()) + "</div></td>";
|
211
|
else
|
212
|
content += "<td class=\"uk-text-nowrap uk-table-shrink\"><div class=\"el-title\">--</div></td>";
|
213
|
|
214
|
// REQUESTOR
|
215
|
content += "<td class=\"uk-text-nowrap uk-table-shrink\">";
|
216
|
if(piwikInfo.getRequestorName()!=null && !piwikInfo.getRequestorName().trim().equals(""))
|
217
|
content += "<div class=\"el-title\">" + piwikInfo.getRequestorName() + "</div>";
|
218
|
else
|
219
|
content += "--";
|
220
|
if(piwikInfo.getRequestorEmail()!=null && !piwikInfo.getRequestorEmail().trim().equals(""))
|
221
|
content += "<div class=\"el-title\">" + piwikInfo.getRequestorEmail() + "</div>";
|
222
|
else
|
223
|
content += "--";
|
224
|
content += "</td>";
|
225
|
|
226
|
// APPROVED
|
227
|
if(piwikInfo.isApproved()) {
|
228
|
content += "<td class=\"uk-text-nowrap uk-table-shrink\">";
|
229
|
content += "<div class=\"el-title\">YES</div>" ;
|
230
|
if(piwikInfo.getApprovalDate()!=null)
|
231
|
content += "<div class=\"el-title\">on " + dtf.format(piwikInfo.getApprovalDate()) + "</div>" ;
|
232
|
content += "</td>";
|
233
|
} else
|
234
|
content += "<td class=\"uk-text-nowrap uk-table-shrink\"><div class=\"el-title\">NO</div></td>";
|
235
|
|
236
|
content += "<td class=\"uk-text-nowrap uk-table-shrink\">";
|
237
|
|
238
|
// ACTIONS
|
239
|
if(!piwikInfo.isApproved())
|
240
|
content += "<a href=\"javascript:;\" id=\"" + piwikInfo.getRepositoryId() + "#approve\" " +
|
241
|
"class=\"uk-button uk-button-primary approve\">Approve</button>";
|
242
|
content += "</td>" +
|
243
|
"</tr>";
|
244
|
}
|
245
|
|
246
|
content += "</tbody></table>";
|
247
|
|
248
|
HTML reposListHTML = new HTML();
|
249
|
reposListHTML.setHTML(content);
|
250
|
|
251
|
divPanel.add(reposListHTML);
|
252
|
}
|
253
|
|
254
|
addWidgetHandlers();
|
255
|
}
|
256
|
|
257
|
private void approvePiwikSites(final List<String> repositoryIds) {
|
258
|
|
259
|
final Modal approvePiwikSitesConfirmationPopup = new Modal();
|
260
|
approvePiwikSitesConfirmationPopup.setDataBackdrop(ModalBackdrop.STATIC);
|
261
|
|
262
|
FlowPanel modalContent = new FlowPanel();
|
263
|
|
264
|
HTML description = new HTML("<h2 class=\"uk-modal-title\">Approval Confirmation</h2>\n" +
|
265
|
"<p>Are you sure you want to approve the selected piwik site(s)?</p>");
|
266
|
modalContent.add(description);
|
267
|
|
268
|
FlowPanel actionButtons = new FlowPanel();
|
269
|
actionButtons.addStyleName("uk-text-right");
|
270
|
modalContent.add(actionButtons);
|
271
|
|
272
|
Button no = new Button("Cancel");
|
273
|
no.setType(ButtonType.DEFAULT);
|
274
|
no.addClickHandler(new ClickHandler() {
|
275
|
@Override
|
276
|
public void onClick(ClickEvent event) {
|
277
|
approvePiwikSitesConfirmationPopup.hide();
|
278
|
approvePiwikSitesConfirmationPopup.removeFromParent();
|
279
|
}
|
280
|
});
|
281
|
actionButtons.add(no);
|
282
|
|
283
|
Button yes = new Button("Yes, approve");
|
284
|
yes.setType(ButtonType.PRIMARY);
|
285
|
yes.addClickHandler(new ClickHandler() {
|
286
|
@Override
|
287
|
public void onClick(ClickEvent event) {
|
288
|
|
289
|
approvePiwikSitesConfirmationPopup.hide();
|
290
|
approvePiwikSitesConfirmationPopup.removeFromParent();
|
291
|
|
292
|
final HTML loadingWheel = new HTML("<div class=\"loader-big\"></div><div class=\"whiteFilm\"></div>");
|
293
|
metricsAdminBoxContent.addStyleName("loading-big");
|
294
|
metricsAdminBoxContent.add(loadingWheel);
|
295
|
|
296
|
repositoryService.approvePiwikSite(repositoryIds.get(0), new AsyncCallback<Void>() {
|
297
|
|
298
|
@Override
|
299
|
public void onFailure(Throwable caught) {
|
300
|
|
301
|
metricsAdminBoxContent.removeStyleName("loading-big");
|
302
|
metricsAdminBoxContent.remove(loadingWheel);
|
303
|
|
304
|
errorAlert.setText("System error approving the specified piwik site(s)");
|
305
|
errorAlert.setVisible(true);
|
306
|
}
|
307
|
|
308
|
@Override
|
309
|
public void onSuccess(Void result) {
|
310
|
|
311
|
metricsAdminBoxContent.removeStyleName("loading-big");
|
312
|
metricsAdminBoxContent.remove(loadingWheel);
|
313
|
|
314
|
clear();
|
315
|
reload();
|
316
|
}
|
317
|
});
|
318
|
}
|
319
|
});
|
320
|
actionButtons.add(yes);
|
321
|
|
322
|
ModalBody modalBody = new ModalBody();
|
323
|
modalBody.add(modalContent);
|
324
|
approvePiwikSitesConfirmationPopup.add(modalBody);
|
325
|
approvePiwikSitesConfirmationPopup.getElement().getChild(0).getChild(0).getChild(0).removeFromParent();
|
326
|
|
327
|
approvePiwikSitesConfirmationPopup.show();
|
328
|
}
|
329
|
}
|