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.event.dom.client.ClickEvent;
|
6
|
import com.google.gwt.event.dom.client.ClickHandler;
|
7
|
import com.google.gwt.user.client.History;
|
8
|
import com.google.gwt.user.client.Window;
|
9
|
import com.google.gwt.user.client.rpc.AsyncCallback;
|
10
|
import com.google.gwt.user.client.ui.FlowPanel;
|
11
|
import com.google.gwt.user.client.ui.HTML;
|
12
|
import com.google.gwt.user.client.ui.Widget;
|
13
|
import eu.dnetlib.domain.data.Repository;
|
14
|
import eu.dnetlib.gwt.client.help.HelpService;
|
15
|
import eu.dnetlib.gwt.client.help.HelpServiceAsync;
|
16
|
import eu.dnetlib.repo.manager.client.AbstractRepositoryManagerWidget;
|
17
|
import eu.dnetlib.repo.manager.client.HelpCallback;
|
18
|
import eu.dnetlib.repo.manager.client.RepositoryManager;
|
19
|
import eu.dnetlib.repo.manager.client.RepositoryManagerWidget;
|
20
|
import eu.dnetlib.repo.manager.client.services.RepositoryService;
|
21
|
import eu.dnetlib.repo.manager.client.services.RepositoryServiceAsync;
|
22
|
import eu.dnetlib.repo.manager.shared.PiwikInfo;
|
23
|
import org.gwtbootstrap3.client.ui.Alert;
|
24
|
import org.gwtbootstrap3.client.ui.Button;
|
25
|
import org.gwtbootstrap3.client.ui.constants.AlertType;
|
26
|
import org.gwtbootstrap3.client.ui.constants.ButtonType;
|
27
|
|
28
|
/**
|
29
|
* Created by stefania on 12/19/16.
|
30
|
*/
|
31
|
public class InstructionsForMetricsWidget extends AbstractRepositoryManagerWidget implements RepositoryManagerWidget {
|
32
|
|
33
|
private String parentToken = "";
|
34
|
private String restToken = "";
|
35
|
|
36
|
private String repositoryId = "";
|
37
|
|
38
|
private FlowPanel instructionsForMetricsBoxContent = new FlowPanel();
|
39
|
|
40
|
private Alert errorAlert = new Alert();
|
41
|
|
42
|
private RepositoryServiceAsync repositoryService = GWT.create(RepositoryService.class);
|
43
|
private static HelpServiceAsync helpService = GWT.create(HelpService.class);
|
44
|
|
45
|
public InstructionsForMetricsWidget() {
|
46
|
|
47
|
super();
|
48
|
|
49
|
HTML title = new HTML("<h1 class=\"uk-article-title\">Metrics</h1>");
|
50
|
title.addStyleName("uk-margin-medium-bottom");
|
51
|
contentPanel.add(title);
|
52
|
|
53
|
errorAlert.setType(AlertType.DANGER);
|
54
|
errorAlert.setDismissable(false);
|
55
|
errorAlert.setVisible(false);
|
56
|
instructionsForMetricsBoxContent.add(errorAlert);
|
57
|
|
58
|
contentPanel.add(instructionsForMetricsBoxContent);
|
59
|
}
|
60
|
|
61
|
@Override
|
62
|
public void clear() {
|
63
|
|
64
|
instructionsForMetricsBoxContent.clear();
|
65
|
errorAlert.setVisible(false);
|
66
|
gridPanel.remove(helpPanel);
|
67
|
}
|
68
|
|
69
|
@Override
|
70
|
public void reload() {
|
71
|
|
72
|
Document.get().getElementById("headerNoTransparent").removeClassName("tm-header-transparent");
|
73
|
instructionsForMetricsBoxContent.add(errorAlert);
|
74
|
|
75
|
helpService.getHelpById(parentToken + "_forDatasource_instructions", new HelpCallback(helpPanel, gridPanel));
|
76
|
|
77
|
final HTML loadingWheel = new HTML("<div class=\"loader-big\" style=\"text-align: center; padding-top: 170px; " +
|
78
|
"color: rgb(47, 64, 80); font-weight: bold;\">Retrieving repository information...</div>" +
|
79
|
"<div class=\"whiteFilm\"></div>");
|
80
|
instructionsForMetricsBoxContent.addStyleName("loading-big");
|
81
|
instructionsForMetricsBoxContent.add(loadingWheel);
|
82
|
|
83
|
repositoryService.getRepository(repositoryId, new AsyncCallback<Repository>() {
|
84
|
|
85
|
@Override
|
86
|
public void onFailure(Throwable caught) {
|
87
|
|
88
|
instructionsForMetricsBoxContent.removeStyleName("loading-big");
|
89
|
instructionsForMetricsBoxContent.remove(loadingWheel);
|
90
|
|
91
|
errorAlert.setText("System error retrieving repository information");
|
92
|
errorAlert.setVisible(true);
|
93
|
}
|
94
|
|
95
|
@Override
|
96
|
public void onSuccess(final Repository repository) {
|
97
|
|
98
|
instructionsForMetricsBoxContent.add(showInstructions());
|
99
|
|
100
|
instructionsForMetricsBoxContent.removeStyleName("loading-big");
|
101
|
instructionsForMetricsBoxContent.remove(loadingWheel);
|
102
|
|
103
|
Window.moveTo(0,0);
|
104
|
|
105
|
// repositoryService.getPiwikScriptForRepository(repositoryId, new AsyncCallback<String>() {
|
106
|
//
|
107
|
// @Override
|
108
|
// public void onFailure(Throwable caught) {
|
109
|
//
|
110
|
// instructionsForMetricsBoxContent.removeStyleName("loading-big");
|
111
|
// instructionsForMetricsBoxContent.remove(loadingWheel);
|
112
|
//
|
113
|
// errorAlert.setText("System error retrieving piwik script for this repository");
|
114
|
// errorAlert.setVisible(true);
|
115
|
// }
|
116
|
//
|
117
|
// @Override
|
118
|
// public void onSuccess(String piwikScript) {
|
119
|
//
|
120
|
//// RepositoryManager.pageHeader.clear();
|
121
|
//// String logoURLSource = "";
|
122
|
//// if(repository.getLogoUrl()==null || repository.getLogoUrl().isEmpty())
|
123
|
//// logoURLSource = "img/yourLogoHere.jpg";
|
124
|
//// else
|
125
|
//// logoURLSource = repository.getLogoUrl();
|
126
|
////
|
127
|
//// RepositoryManager.pageHeader.add(new HTML("<div class=\"col-sm-9\"><h2><img src=\"" + logoURLSource + "\" alt=[Repo Logo]" +
|
128
|
//// "width=\"35px\" height=\"35px\" style=\"margin-right: 15px; margin-top:-2px\">Enable metrics for " + repository.getOfficialName() + "</h2>" +
|
129
|
//// "<ol class=\"breadcrumb\"><li><a href=\"#dashboard\">Home</a></li><li><a href=\"#" + parentToken +
|
130
|
//// "\">Metrics</a></li><li><a href=\"#" + parentToken + "/" + repositoryId + "\">" + repository.getOfficialName() + "</a>" +
|
131
|
//// "</li><li class=\"active\"><strong>Instructions</strong></li></ol></div><div class=\"col-sm-3\"></div>"));
|
132
|
//
|
133
|
// instructionsForMetricsBoxContent.removeStyleName("loading-big");
|
134
|
// instructionsForMetricsBoxContent.remove(loadingWheel);
|
135
|
//
|
136
|
// if(piwikScript!=null)
|
137
|
// instructionsForMetricsBoxContent.add(showInstructions(piwikScript));
|
138
|
// else {
|
139
|
//
|
140
|
// Alert infoAlert = new Alert();
|
141
|
// infoAlert.setType(AlertType.WARNING);
|
142
|
// infoAlert.setDismissable(false);
|
143
|
// infoAlert.setText("Metrics have not yet been enabled for this repository.");
|
144
|
// instructionsForMetricsBoxContent.add(infoAlert);
|
145
|
//
|
146
|
// Button goToEnableMetrics = new Button();
|
147
|
// goToEnableMetrics.setText("I would like to enable metrics");
|
148
|
// goToEnableMetrics.setType(ButtonType.PRIMARY);
|
149
|
// goToEnableMetrics.addClickHandler(new ClickHandler() {
|
150
|
//
|
151
|
// @Override
|
152
|
// public void onClick(ClickEvent event) {
|
153
|
// History.newItem("getImpact/" + repository.getId());
|
154
|
// }
|
155
|
// });
|
156
|
// instructionsForMetricsBoxContent.add(goToEnableMetrics);
|
157
|
// }
|
158
|
// }
|
159
|
// });
|
160
|
}
|
161
|
});
|
162
|
}
|
163
|
|
164
|
@Override
|
165
|
public void setToken(String parentToken, String rest) {
|
166
|
this.parentToken = parentToken;
|
167
|
this.restToken = rest;
|
168
|
|
169
|
String[] tokenSplit = restToken.split("/", 2);
|
170
|
repositoryId = tokenSplit[1];
|
171
|
}
|
172
|
|
173
|
@Override
|
174
|
public void afterAdditionToRootPanel() {
|
175
|
|
176
|
}
|
177
|
|
178
|
private FlowPanel showInstructions() {
|
179
|
|
180
|
FlowPanel instructionsPanel = new FlowPanel();
|
181
|
|
182
|
String instructions = "<p>OpenAIRE's usage statistics service tracking code is maintained on Github as a patch for " +
|
183
|
"various versions of DSpace (<a target=\"_blank\" href=\"https://github.com/dimitrispie/OpenAIRE-Piwik-DSpace\">" +
|
184
|
"https://github.com/dimitrispie/OpenAIRE-Piwik-DSpace</a>) and as an Eprints plugin for version 3 " +
|
185
|
"(<a target=\"_blank\" href=\"https://github.com/dimitrispie/EPrints-OAPiwik\">https://github.com/dimitrispie/EPrints-OAPiwik</a>).</p>";
|
186
|
|
187
|
HTML instructionsHTML = new HTML();
|
188
|
instructionsHTML.setHTML(instructions);
|
189
|
instructionsPanel.add(instructionsHTML);
|
190
|
|
191
|
return instructionsPanel;
|
192
|
}
|
193
|
|
194
|
// private FlowPanel showInstructions(String piwikScript) {
|
195
|
//
|
196
|
// FlowPanel instructionsPanel = new FlowPanel();
|
197
|
//
|
198
|
// String instructions = "<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum ac nulla eget ligula " +
|
199
|
// "ultrices finibus. Integer eu convallis sapien. Fusce sit amet quam lacus. In dictum, ante sed mattis vulputate, " +
|
200
|
// "orci dolor suscipit quam, faucibus blandit enim tellus et tellus. Duis quis sem orci. Integer non tortor sed " +
|
201
|
// "elit sagittis vestibulum. Aenean pulvinar accumsan turpis, ut aliquam dolor aliquam eu. Integer enim dui, " +
|
202
|
// "mollis in lacinia id, sagittis interdum nibh. Suspendisse ullamcorper, diam sed consequat finibus, justo odio " +
|
203
|
// "iaculis elit, non bibendum mauris sem ut dolor.</p>";
|
204
|
//
|
205
|
// instructions += "<pre>" + piwikScript + "</pre>";
|
206
|
//
|
207
|
// instructions += "<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum ac nulla eget ligula " +
|
208
|
// "ultrices finibus. Integer eu convallis sapien. Fusce sit amet quam lacus. In dictum, ante sed mattis vulputate, " +
|
209
|
// "orci dolor suscipit quam, faucibus blandit enim tellus et tellus. Duis quis sem orci. Integer non tortor sed " +
|
210
|
// "elit sagittis vestibulum. Aenean pulvinar accumsan turpis, ut aliquam dolor aliquam eu. Integer enim dui, " +
|
211
|
// "mollis in lacinia id, sagittis interdum nibh. Suspendisse ullamcorper, diam sed consequat finibus, justo odio " +
|
212
|
// "iaculis elit, non bibendum mauris sem ut dolor.</p>";
|
213
|
//
|
214
|
// HTML instructionsHTML = new HTML();
|
215
|
// instructionsHTML.setHTML(instructions);
|
216
|
// instructionsPanel.add(instructionsHTML);
|
217
|
//
|
218
|
// return instructionsPanel;
|
219
|
// }
|
220
|
}
|