1
|
package eu.dnetlib.repo.manager.client.getimpact;
|
2
|
|
3
|
import com.google.gwt.core.client.GWT;
|
4
|
import com.google.gwt.dom.client.Document;
|
5
|
import com.google.gwt.user.client.History;
|
6
|
import com.google.gwt.user.client.rpc.AsyncCallback;
|
7
|
import com.google.gwt.user.client.ui.FlowPanel;
|
8
|
import com.google.gwt.user.client.ui.Frame;
|
9
|
import com.google.gwt.user.client.ui.HTML;
|
10
|
import eu.dnetlib.domain.data.Repository;
|
11
|
import eu.dnetlib.gwt.client.help.HelpService;
|
12
|
import eu.dnetlib.gwt.client.help.HelpServiceAsync;
|
13
|
import eu.dnetlib.repo.manager.client.AbstractRepositoryManagerWidget;
|
14
|
import eu.dnetlib.repo.manager.client.HelpCallback;
|
15
|
import eu.dnetlib.repo.manager.client.RepositoryManagerWidget;
|
16
|
import eu.dnetlib.repo.manager.client.services.RepositoryService;
|
17
|
import eu.dnetlib.repo.manager.client.services.RepositoryServiceAsync;
|
18
|
import eu.dnetlib.repo.manager.shared.PiwikInfo;
|
19
|
import org.gwtbootstrap3.client.ui.*;
|
20
|
import org.gwtbootstrap3.client.ui.constants.AlertType;
|
21
|
|
22
|
/**
|
23
|
* Created by stefania on 12/15/16.
|
24
|
*/
|
25
|
public class MetricsForDatasourceWidget extends AbstractRepositoryManagerWidget implements RepositoryManagerWidget {
|
26
|
|
27
|
private String parentToken = "";
|
28
|
private String restToken = "";
|
29
|
|
30
|
private FlowPanel metricsForDatasourceBoxContent = new FlowPanel();
|
31
|
|
32
|
private Alert errorAlert = new Alert();
|
33
|
|
34
|
private RepositoryServiceAsync repositoryService = GWT.create(RepositoryService.class);
|
35
|
private static HelpServiceAsync helpService = GWT.create(HelpService.class);
|
36
|
|
37
|
public MetricsForDatasourceWidget() {
|
38
|
|
39
|
super();
|
40
|
|
41
|
HTML title = new HTML("<h1 class=\"uk-article-title\">Metrics</h1>");
|
42
|
title.addStyleName("uk-margin-medium-bottom");
|
43
|
contentPanel.add(title);
|
44
|
|
45
|
errorAlert.setType(AlertType.DANGER);
|
46
|
errorAlert.setDismissable(false);
|
47
|
errorAlert.setVisible(false);
|
48
|
metricsForDatasourceBoxContent.add(errorAlert);
|
49
|
|
50
|
contentPanel.add(metricsForDatasourceBoxContent);
|
51
|
}
|
52
|
|
53
|
@Override
|
54
|
public void clear() {
|
55
|
|
56
|
metricsForDatasourceBoxContent.clear();
|
57
|
errorAlert.setVisible(false);
|
58
|
gridPanel.remove(helpPanel);
|
59
|
}
|
60
|
|
61
|
@Override
|
62
|
public void reload() {
|
63
|
|
64
|
Document.get().getElementById("headerNoTransparent").removeClassName("tm-header-transparent");
|
65
|
metricsForDatasourceBoxContent.add(errorAlert);
|
66
|
|
67
|
helpService.getHelpById(parentToken + "_forDatasource", new HelpCallback(helpPanel, gridPanel));
|
68
|
|
69
|
final HTML loadingWheel = new HTML("<div class=\"loader-big\" style=\"text-align: center; padding-top: 170px; " +
|
70
|
"color: rgb(47, 64, 80); font-weight: bold;\">Retrieving repository information...</div>" +
|
71
|
"<div class=\"whiteFilm\"></div>");
|
72
|
metricsForDatasourceBoxContent.addStyleName("loading-big");
|
73
|
metricsForDatasourceBoxContent.add(loadingWheel);
|
74
|
|
75
|
repositoryService.getRepository(restToken, new AsyncCallback<Repository>() {
|
76
|
|
77
|
@Override
|
78
|
public void onFailure(Throwable caught) {
|
79
|
|
80
|
metricsForDatasourceBoxContent.removeStyleName("loading-big");
|
81
|
metricsForDatasourceBoxContent.remove(loadingWheel);
|
82
|
|
83
|
errorAlert.setText("System error retrieving repository info");
|
84
|
errorAlert.setVisible(true);
|
85
|
}
|
86
|
|
87
|
@Override
|
88
|
public void onSuccess(final Repository repository) {
|
89
|
|
90
|
repositoryService.getPiwikSiteForRepository(repository.getId(), new AsyncCallback<PiwikInfo>() {
|
91
|
|
92
|
@Override
|
93
|
public void onFailure(Throwable caught) {
|
94
|
|
95
|
metricsForDatasourceBoxContent.removeStyleName("loading-big");
|
96
|
metricsForDatasourceBoxContent.remove(loadingWheel);
|
97
|
|
98
|
//TODO change text
|
99
|
errorAlert.setText("System error retrieving piwik site info");
|
100
|
errorAlert.setVisible(true);
|
101
|
}
|
102
|
|
103
|
@Override
|
104
|
public void onSuccess(PiwikInfo piwikInfo) {
|
105
|
|
106
|
metricsForDatasourceBoxContent.removeStyleName("loading-big");
|
107
|
metricsForDatasourceBoxContent.remove(loadingWheel);
|
108
|
|
109
|
if(piwikInfo==null) {
|
110
|
|
111
|
EnableMetricsWidget enableMetricsWidget = new EnableMetricsWidget(repository);
|
112
|
metricsForDatasourceBoxContent.add(enableMetricsWidget.asWidget());
|
113
|
|
114
|
} else if(!piwikInfo.isApproved()) {
|
115
|
|
116
|
History.replaceItem("getImpact/instructions/" + repository.getId());
|
117
|
|
118
|
} else {
|
119
|
|
120
|
metricsForDatasourceBoxContent.add(createMetricsPanel(piwikInfo));
|
121
|
}
|
122
|
}
|
123
|
});
|
124
|
}
|
125
|
});
|
126
|
}
|
127
|
|
128
|
@Override
|
129
|
public void setToken(String parentToken, String rest) {
|
130
|
this.parentToken = parentToken;
|
131
|
this.restToken = rest;
|
132
|
}
|
133
|
|
134
|
@Override
|
135
|
public void afterAdditionToRootPanel() {
|
136
|
|
137
|
}
|
138
|
|
139
|
private FlowPanel createMetricsPanel(PiwikInfo piwikInfo) {
|
140
|
|
141
|
FlowPanel metricsPanel = new FlowPanel();
|
142
|
|
143
|
String datasourcesMonthlyViewsURL = "https://beta.openaire.eu/stats3/merge.php?com=query&data=[{\"query\":\"dtsrcRepoViews\"," +
|
144
|
"\"dtsrcName\":\"" + piwikInfo.getOpenaireId() + "\",\"table\":\"\",\"fields\":[{\"fld\":\"sum\",\"agg\":\"sum\"," +
|
145
|
"\"type\":\"chart\",\"yaxis\":1,\"c\":false}],\"xaxis\":{\"name\":\"month\",\"agg\":\"sum\"},\"group\":\"\",\"color\":\"\"," +
|
146
|
"\"type\":\"chart\",\"size\":30,\"sort\":\"xaxis\",\"xStyle\":{\"r\":-30,\"s\":\"0\",\"l\":\"-\",\"ft\":\"-\",\"wt\":\"-\"}," +
|
147
|
"\"title\":\"\",\"subtitle\":\"\",\"xaxistitle\":\"\",\"yaxisheaders\":[\"Monthly views\"],\"generalxaxis\":\"\"," +
|
148
|
"\"theme\":0,\"in\":[]}]&info_types=[\"spline\"]&stacking=&steps=false&fontFamily=Courier&spacing=[5,0,0,0]&" +
|
149
|
"style=[{\"color\":\"rgba(0, 0, 0, 1)\",\"size\":\"18\"},{\"color\":\"rgba(0, 0, 0, 1)\",\"size\":\"18\"}," +
|
150
|
"{\"color\":\"000000\",\"size\":\"\"},{\"color\":\"000000\",\"size\":\"\"}]&backgroundColor=rgba(255,255,255,1)&colors[]=rgba(124,\n" +
|
151
|
"181, 236, 1)&colors[]=rgba(67, 67, 72, 1)&colors[]=rgba(144, 237, 125,\n" +
|
152
|
"1)&colors[]=rgba(247, 163, 92, 1)&colors[]=rgba(128, 133, 233,\n" +
|
153
|
"1)&colors[]=rgba(241, 92, 128, 1)&colors[]=rgba(228, 211, 84,\n" +
|
154
|
"1)&colors[]=rgba(43, 144, 143, 1)&colors[]=rgba(244, 91, 91,\n" +
|
155
|
"1)&colors[]=rgba(145, 232, 225,\n" +
|
156
|
"1)&xlinew=0&ylinew=1&legends=true&tooltips=true&persistent=false";
|
157
|
|
158
|
Frame datasourcesMonthlyViews = new Frame(datasourcesMonthlyViewsURL);
|
159
|
datasourcesMonthlyViews.setStyleName("statsFrame");
|
160
|
|
161
|
FlowPanel monthlyViewsPanel = new FlowPanel();
|
162
|
monthlyViewsPanel.addStyleName("uk-text-center uk-card uk-card-default uk-card-hover uk-scrollspy-inview " +
|
163
|
"uk-animation-slide-top-medium uk-margin-bottom uk-padding");
|
164
|
monthlyViewsPanel.add(datasourcesMonthlyViews);
|
165
|
metricsPanel.add(monthlyViewsPanel);
|
166
|
|
167
|
String datasourcesMonthlyDownloadsURL = "https://beta.openaire.eu/stats3/merge.php?com=query&data=[{\"query\":\"dtsrcRepoDownloads\"," +
|
168
|
"\"dtsrcName\":\"" + piwikInfo.getOpenaireId() + "\",\"table\":\"\",\"fields\":[{\"fld\":\"sum\"," +
|
169
|
"\"agg\":\"sum\",\"type\":\"chart\",\"yaxis\":1,\"c\":false}],\"xaxis\":{\"name\":\"month\",\"agg\":\"sum\"}," +
|
170
|
"\"group\":\"\",\"color\":\"\",\"type\":\"chart\",\"size\":30,\"sort\":\"xaxis\",\"xStyle\":{\"r\":-30,\"s\":\"0\",\"l\":\"-\"," +
|
171
|
"\"ft\":\"-\",\"wt\":\"-\"},\"title\":\"\",\"subtitle\":\"\",\"xaxistitle\":\"\",\"yaxisheaders\":[\"Monthly\n" +
|
172
|
"downloads\"],\"generalxaxis\":\"\",\"theme\":0,\"in\":[]}]&info_types=[\"spline\"]&stacking=&steps=false&fontFamily=Courier&" +
|
173
|
"spacing=[5,0,0,0]&style=[{\"color\":\"rgba(0, 0, 0, 1)\",\"size\":\"18\"},{\"color\":\"rgba(0, 0, 0,\n" +
|
174
|
"1)\",\"size\":\"18\"},{\"color\":\"000000\",\"size\":\"\"},{\"color\":\"000000\",\"size\":\"\"}]&backgroundColor=" +
|
175
|
"rgba(255,255,255,1)&colors[]=rgba(124, 181, 236, 1)&colors[]=rgba(67, 67, 72, 1)&colors[]=rgba(144, 237, 125,\n" +
|
176
|
"1)&colors[]=rgba(247, 163, 92, 1)&colors[]=rgba(128, 133, 233,\n" +
|
177
|
"1)&colors[]=rgba(241, 92, 128, 1)&colors[]=rgba(228, 211, 84,\n" +
|
178
|
"1)&colors[]=rgba(43, 144, 143, 1)&colors[]=rgba(244, 91, 91,\n" +
|
179
|
"1)&colors[]=rgba(145, 232, 225,\n" +
|
180
|
"1)&xlinew=0&ylinew=1&legends=true&tooltips=true&persistent=false";
|
181
|
|
182
|
Frame datasourcesMonthlyDownloads = new Frame(datasourcesMonthlyDownloadsURL);
|
183
|
datasourcesMonthlyDownloads.setStyleName("statsFrame");
|
184
|
|
185
|
FlowPanel monthlyDownloadsPanel = new FlowPanel();
|
186
|
monthlyDownloadsPanel.addStyleName("uk-text-center uk-card uk-card-default uk-card-hover uk-scrollspy-inview " +
|
187
|
"uk-animation-slide-top-medium uk-margin-bottom uk-padding");
|
188
|
monthlyDownloadsPanel.add(datasourcesMonthlyDownloads);
|
189
|
metricsPanel.add(monthlyDownloadsPanel);
|
190
|
|
191
|
return metricsPanel;
|
192
|
}
|
193
|
|
194
|
private TabPanel createMockMetricsPanel() {
|
195
|
|
196
|
TabPanel tabPanel = new TabPanel();
|
197
|
|
198
|
NavTabs navTabs = new NavTabs();
|
199
|
tabPanel.add(navTabs);
|
200
|
|
201
|
TabContent tabContent = new TabContent();
|
202
|
tabPanel.add(tabContent);
|
203
|
|
204
|
// OpenAIRE
|
205
|
|
206
|
HTML openAIREMetrics = new HTML("<div class=\"gwt-HTML\">" +
|
207
|
"<div class=\"row\">" +
|
208
|
// "<div class=\"col-lg-3\">" +
|
209
|
// "<div class=\"metrics clearfix\">" +
|
210
|
// "<div class=\"metric\"><span class=\"field\">Views</span><span class=\"data\">87</span></div>" +
|
211
|
// "</div>" +
|
212
|
// "</div>" +
|
213
|
"<div class=\"col-lg-12\">" +
|
214
|
"<div class=\"chart metricsChart\">" +
|
215
|
"<div class=\"metricsChartLabel\">Views Timeline</div>" +
|
216
|
"<div><img width=\"100%\" src=\"./img/temp/viewsTimeline-Zenodo.png\"></div>" +
|
217
|
"</div>" +
|
218
|
"</div>" +
|
219
|
"</div>" +
|
220
|
"<div class=\"row\">" +
|
221
|
"<div class=\"col-lg-6\">" +
|
222
|
"<div class=\"chart metricsChart\">" +
|
223
|
"<div class=\"metricsChartLabel\">Most Viewed Funders</div>" +
|
224
|
"<div style=\"margin-top: 20px\"><img width=\"100%\" src=\"./img/temp/mostViewedFunders-Zenodo.png\"></div>" +
|
225
|
"</div>" +
|
226
|
"</div>" +
|
227
|
"<div class=\"col-lg-6\">" +
|
228
|
"<div class=\"chart metricsChart\">" +
|
229
|
"<div class=\"metricsChartLabel\">Most Viewed Funding Level 2</div>" +
|
230
|
"<div style=\"margin-top: 20px\"><img width=\"100%\" src=\"./img/temp/mostViewedFundingLevel2-Zenodo.png\"></div>" +
|
231
|
"</div>" +
|
232
|
"</div>" +
|
233
|
"</div>" +
|
234
|
"</div>");
|
235
|
|
236
|
TabPane openAIRETabPane = new TabPane();
|
237
|
openAIRETabPane.add(openAIREMetrics);
|
238
|
openAIRETabPane.setActive(true);
|
239
|
openAIRETabPane.setIn(true);
|
240
|
openAIRETabPane.setFade(true);
|
241
|
tabContent.add(openAIRETabPane);
|
242
|
|
243
|
TabListItem openAIRETabListItem = new TabListItem();
|
244
|
openAIRETabListItem.setText("OpenAIRE");
|
245
|
openAIRETabListItem.setDataTargetWidget(openAIRETabPane);
|
246
|
openAIRETabListItem.showTab();
|
247
|
navTabs.add(openAIRETabListItem);
|
248
|
|
249
|
// Repository
|
250
|
|
251
|
HTML repositoryMetrics = new HTML("<div class=\"gwt-HTML\">" +
|
252
|
"<div class=\"row\">" +
|
253
|
// "<div class=\"col-lg-3\">" +
|
254
|
// "<div class=\"metrics clearfix\">" +
|
255
|
// "<div class=\"metric\"><span class=\"field\">Views</span><span class=\"data\">142</span></div>" +
|
256
|
// "</div>" +
|
257
|
// "</div>" +
|
258
|
"<div class=\"col-lg-12\">" +
|
259
|
"<div class=\"chart metricsChart\">" +
|
260
|
"<div class=\"metricsChartLabel\">Views Timeline</div>" +
|
261
|
"<div><img width=\"100%\" src=\"./img/temp/viewsTimeline-EPUBWU.png\"></div>" +
|
262
|
"</div>" +
|
263
|
"</div>" +
|
264
|
"</div>" +
|
265
|
"<div class=\"row\">" +
|
266
|
"<div class=\"col-lg-6\">" +
|
267
|
"<div class=\"chart metricsChart\">" +
|
268
|
"<div class=\"metricsChartLabel\">Most Viewed Funders</div>" +
|
269
|
"<div style=\"margin-top: 10px\"><img width=\"100%\" src=\"./img/temp/mostViewedFunders-EPUBWU.png\"></div>" +
|
270
|
"</div>" +
|
271
|
"</div>" +
|
272
|
"<div class=\"col-lg-6\">" +
|
273
|
"<div class=\"chart metricsChart\">" +
|
274
|
"<div class=\"metricsChartLabel\">Most Viewed Funding Level 2</div>" +
|
275
|
"<div style=\"margin-top: 10px\"><img width=\"100%\" src=\"./img/temp/mostViewedFundingLevel2-EPUBWU.png\"></div>" +
|
276
|
"</div>" +
|
277
|
"</div>" +
|
278
|
"</div>" +
|
279
|
"</div>");
|
280
|
|
281
|
TabPane repositoryTabPane = new TabPane();
|
282
|
repositoryTabPane.add(repositoryMetrics);
|
283
|
repositoryTabPane.setFade(true);
|
284
|
tabContent.add(repositoryTabPane);
|
285
|
|
286
|
TabListItem repositoriesTabListItem = new TabListItem();
|
287
|
repositoriesTabListItem.setText("Repository");
|
288
|
repositoriesTabListItem.setDataTargetWidget(repositoryTabPane);
|
289
|
navTabs.add(repositoriesTabListItem);
|
290
|
|
291
|
// Total
|
292
|
|
293
|
// HTML totalMetrics = new HTML("<div class=\"gwt-HTML\">" +
|
294
|
// "<div class=\"row\">" +
|
295
|
// "<div class=\"col-lg-3\">" +
|
296
|
// "<div class=\"metrics clearfix\">" +
|
297
|
// "<div class=\"metric\"><span class=\"field\">Views</span><span class=\"data\">305</span></div>" +
|
298
|
// "</div>" +
|
299
|
// "</div>" +
|
300
|
// "<div class=\"col-lg-9\">" +
|
301
|
// "<div class=\"chart metricsChart\">" +
|
302
|
// "<div class=\"metricsChartLabel\">Views Timeline</div>" +
|
303
|
// "<div><img width=\"100%\" src=\"./img/temp/viewsTimeline-UMINHO.png\"></div>" +
|
304
|
// "</div>" +
|
305
|
// "</div>" +
|
306
|
// "</div>" +
|
307
|
// "<div class=\"row\">" +
|
308
|
// "<div class=\"col-lg-6\">" +
|
309
|
// "<div class=\"chart metricsChart\">" +
|
310
|
// "<div class=\"metricsChartLabel\">Most Viewed Funders</div>" +
|
311
|
// "<div style=\"margin-top: 40px\"><img width=\"100%\" src=\"./img/temp/mostViewedFunders-UMINHO.png\"></div>" +
|
312
|
// "</div>" +
|
313
|
// "</div>" +
|
314
|
// "<div class=\"col-lg-6\">" +
|
315
|
// "<div class=\"chart metricsChart\">" +
|
316
|
// "<div class=\"metricsChartLabel\">Most Viewed Funding Level 2</div>" +
|
317
|
// "<div style=\"margin-top: 20px\"><img width=\"85%\" src=\"./img/temp/mostViewedFundingLevel2-UMINHO.png\"></div>" +
|
318
|
// "</div>" +
|
319
|
// "</div>" +
|
320
|
// "</div>" +
|
321
|
// "</div>");
|
322
|
//
|
323
|
// TabPane totalTabPane = new TabPane();
|
324
|
// totalTabPane.add(totalMetrics);
|
325
|
// totalTabPane.setFade(true);
|
326
|
// tabContent.add(totalTabPane);
|
327
|
//
|
328
|
// TabListItem totalTabListItem = new TabListItem();
|
329
|
// totalTabListItem.setText("Total");
|
330
|
// totalTabListItem.setDataTargetWidget(totalTabPane);
|
331
|
// navTabs.add(totalTabListItem);
|
332
|
|
333
|
return tabPanel;
|
334
|
}
|
335
|
}
|