1
|
package eu.dnetlib.repo.manager.client.getimpact;
|
2
|
|
3
|
import com.google.gwt.core.client.GWT;
|
4
|
import com.google.gwt.event.dom.client.ClickEvent;
|
5
|
import com.google.gwt.event.dom.client.ClickHandler;
|
6
|
import com.google.gwt.user.client.History;
|
7
|
import com.google.gwt.user.client.rpc.AsyncCallback;
|
8
|
import com.google.gwt.user.client.ui.FlowPanel;
|
9
|
import com.google.gwt.user.client.ui.HTML;
|
10
|
import com.google.gwt.user.client.ui.IsWidget;
|
11
|
import com.google.gwt.user.client.ui.Widget;
|
12
|
import eu.dnetlib.domain.data.Repository;
|
13
|
import eu.dnetlib.repo.manager.client.RepositoryManager;
|
14
|
import eu.dnetlib.repo.manager.client.services.RepositoryService;
|
15
|
import eu.dnetlib.repo.manager.client.services.RepositoryServiceAsync;
|
16
|
import org.gwtbootstrap3.client.ui.*;
|
17
|
import org.gwtbootstrap3.client.ui.constants.AlertType;
|
18
|
import org.gwtbootstrap3.client.ui.constants.ButtonType;
|
19
|
import org.gwtbootstrap3.client.ui.constants.ModalBackdrop;
|
20
|
import org.gwtbootstrap3.client.ui.constants.Toggle;
|
21
|
|
22
|
/**
|
23
|
* Created by stefania on 12/19/16.
|
24
|
*/
|
25
|
public class EnableMetricsWidget implements IsWidget {
|
26
|
|
27
|
private FlowPanel enableMetricsPanel = new FlowPanel();
|
28
|
private Alert errorAlert = new Alert();
|
29
|
|
30
|
private FlowPanel modal = new FlowPanel();
|
31
|
|
32
|
private RepositoryServiceAsync repositoryService = GWT.create(RepositoryService.class);
|
33
|
|
34
|
public EnableMetricsWidget(final Repository repository) {
|
35
|
|
36
|
errorAlert.setDismissable(false);
|
37
|
errorAlert.setType(AlertType.DANGER);
|
38
|
errorAlert.setVisible(false);
|
39
|
enableMetricsPanel.add(errorAlert);
|
40
|
|
41
|
HTML enableMetricsText = new HTML("<h4>You don't have metrics enabled for this repository yet. Would you like to " +
|
42
|
"enable them?</h4>" +
|
43
|
"<p><img src=\"./img/metricsWorkflow.png\" style=\"display:block; margin: 0 auto;\" width=\"50%\"></p>" +
|
44
|
"<p>Usage Statistics about items and content providers support the assessment of their popularity and use. " +
|
45
|
"They are an important complement to other kinds of metrics.</p>" +
|
46
|
"<p>OpenAIRE Usage Statistics aims to gather usage events (metadata views and downloads) of items from " +
|
47
|
"participating content providers. By utilizing open standards and protocols reliable, consolidated and " +
|
48
|
"comparable usage reports are generated that are conformant to the COUNTER Code of Practice.</p>" +
|
49
|
"<p>To participate in this service Content Provider Managers need to install platform specific patches or " +
|
50
|
"plugins that enable the tracking of usage events to the OpenAIRE Usage Statistics Service.</p>" +
|
51
|
"<p>Usage statistics are presented in the Content Provider Dashboard, in the OpenAIRE portal and can be " +
|
52
|
"retrieved by the OpenAIRE API.</p>" +
|
53
|
"<p>For more details about the workflows and tools please consult the <a target=\"_blank\" " +
|
54
|
"href=\"./pdf/OpenAIRE_usage_stats_Guidelinesv1.pdf\">“Guidelines for Collecting Usage Events and Provision " +
|
55
|
"of Usage Statistics”</a>.</p>");
|
56
|
enableMetricsPanel.add(enableMetricsText);
|
57
|
|
58
|
final Button enableMetricsButton = new Button();
|
59
|
enableMetricsButton.setType(ButtonType.PRIMARY);
|
60
|
enableMetricsButton.setText("Enable Metrics");
|
61
|
enableMetricsButton.addClickHandler(new ClickHandler() {
|
62
|
|
63
|
@Override
|
64
|
public void onClick(ClickEvent event) {
|
65
|
|
66
|
errorAlert.setVisible(false);
|
67
|
enableMetrics(repository);
|
68
|
}
|
69
|
});
|
70
|
enableMetricsPanel.add(enableMetricsButton);
|
71
|
|
72
|
// UsageStatisticsGuidelinesWidget usageStatisticsGuidelinesWidget = new UsageStatisticsGuidelinesWidget();
|
73
|
// enableMetricsPanel.add(usageStatisticsGuidelinesWidget.asWidget());
|
74
|
}
|
75
|
|
76
|
@Override
|
77
|
public Widget asWidget() {
|
78
|
return enableMetricsPanel;
|
79
|
}
|
80
|
|
81
|
private void enableMetrics(final Repository repository) {
|
82
|
|
83
|
final Modal enableMetricsConfirmationPopup = new Modal();
|
84
|
enableMetricsConfirmationPopup.setDataBackdrop(ModalBackdrop.STATIC);
|
85
|
// enableMetricsConfirmationPopup.removeStyleName("modal");
|
86
|
|
87
|
FlowPanel modalContent = new FlowPanel();
|
88
|
|
89
|
HTML description = new HTML("<h2 class=\"uk-modal-title\">Confirmation</h2>\n" +
|
90
|
"<p>Are you sure you want to enable metrics for this repository?</p>");
|
91
|
modalContent.add(description);
|
92
|
|
93
|
FlowPanel actionButtons = new FlowPanel();
|
94
|
actionButtons.addStyleName("uk-text-right");
|
95
|
modalContent.add(actionButtons);
|
96
|
|
97
|
Button no = new Button("Cancel");
|
98
|
no.setType(ButtonType.DEFAULT);
|
99
|
no.addClickHandler(new ClickHandler() {
|
100
|
@Override
|
101
|
public void onClick(ClickEvent event) {
|
102
|
enableMetricsConfirmationPopup.hide();
|
103
|
enableMetricsConfirmationPopup.removeFromParent();
|
104
|
}
|
105
|
});
|
106
|
actionButtons.add(no);
|
107
|
|
108
|
Button yes = new Button("Yes, enable them");
|
109
|
yes.setType(ButtonType.PRIMARY);
|
110
|
yes.addClickHandler(new ClickHandler() {
|
111
|
@Override
|
112
|
public void onClick(ClickEvent event) {
|
113
|
|
114
|
enableMetricsConfirmationPopup.hide();
|
115
|
enableMetricsConfirmationPopup.removeFromParent();
|
116
|
|
117
|
final HTML loadingWheel = new HTML("<div class=\"loader-big\"></div><div class=\"whiteFilm\"></div>");
|
118
|
enableMetricsPanel.addStyleName("loading-big");
|
119
|
enableMetricsPanel.add(loadingWheel);
|
120
|
|
121
|
repositoryService.enableMetricsForRepository(repository, RepositoryManager.currentUser, new AsyncCallback<Void>() {
|
122
|
|
123
|
@Override
|
124
|
public void onFailure(Throwable caught) {
|
125
|
|
126
|
enableMetricsPanel.removeStyleName("loading-big");
|
127
|
enableMetricsPanel.remove(loadingWheel);
|
128
|
|
129
|
errorAlert.setText("System error enabling metrics for this repository.");
|
130
|
errorAlert.setVisible(true);
|
131
|
}
|
132
|
|
133
|
@Override
|
134
|
public void onSuccess(Void result) {
|
135
|
|
136
|
enableMetricsPanel.removeStyleName("loading-big");
|
137
|
enableMetricsPanel.remove(loadingWheel);
|
138
|
|
139
|
History.newItem("getImpact/instructions/" + repository.getId());
|
140
|
}
|
141
|
});
|
142
|
}
|
143
|
});
|
144
|
actionButtons.add(yes);
|
145
|
|
146
|
ModalBody modalBody = new ModalBody();
|
147
|
modalBody.add(modalContent);
|
148
|
enableMetricsConfirmationPopup.add(modalBody);
|
149
|
enableMetricsConfirmationPopup.getElement().getChild(0).getChild(0).getChild(0).removeFromParent();
|
150
|
|
151
|
enableMetricsConfirmationPopup.show();
|
152
|
}
|
153
|
}
|