1
|
package eu.dnetlib.client.user;
|
2
|
|
3
|
import com.github.gwtbootstrap.client.ui.Alert;
|
4
|
import com.github.gwtbootstrap.client.ui.constants.AlertType;
|
5
|
import com.google.gwt.core.client.GWT;
|
6
|
import com.google.gwt.event.dom.client.ClickEvent;
|
7
|
import com.google.gwt.event.dom.client.ClickHandler;
|
8
|
import com.google.gwt.event.dom.client.MouseOverEvent;
|
9
|
import com.google.gwt.event.dom.client.MouseOverHandler;
|
10
|
import com.google.gwt.user.client.History;
|
11
|
import com.google.gwt.user.client.Window;
|
12
|
import com.google.gwt.user.client.rpc.AsyncCallback;
|
13
|
import com.google.gwt.user.client.ui.FlowPanel;
|
14
|
import com.google.gwt.user.client.ui.HTML;
|
15
|
import com.google.gwt.user.client.ui.IsWidget;
|
16
|
import com.google.gwt.user.client.ui.Widget;
|
17
|
import eu.dnetlib.client.*;
|
18
|
import eu.dnetlib.client.widgets.Anchor;
|
19
|
import eu.dnetlib.goldoa.domain.*;
|
20
|
|
21
|
import java.util.ArrayList;
|
22
|
import java.util.Date;
|
23
|
import java.util.List;
|
24
|
|
25
|
/**
|
26
|
* Created by stefania on 4/22/15.
|
27
|
*/
|
28
|
public class MyRecentActivityWidget implements IsWidget {
|
29
|
|
30
|
private FlowPanel recentRequestsPanel = new FlowPanel();
|
31
|
|
32
|
private Alert errorLabel = new Alert();
|
33
|
private Alert warningLabel = new Alert();
|
34
|
|
35
|
private FlowPanel requestsListPanel = new FlowPanel();
|
36
|
private Anchor viewAll = new Anchor();
|
37
|
|
38
|
private DataServiceAsync dataService = GWT.create(DataService.class);
|
39
|
private GoldOAConstants goldOAConstants = GWT.create(GoldOAConstants.class);
|
40
|
|
41
|
public MyRecentActivityWidget() {
|
42
|
|
43
|
errorLabel.addStyleName("alertLabel");
|
44
|
errorLabel.addStyleName("marginTop30");
|
45
|
errorLabel.setType(AlertType.ERROR);
|
46
|
errorLabel.setClose(false);
|
47
|
errorLabel.setVisible(false);
|
48
|
|
49
|
warningLabel.addStyleName("alertLabel");
|
50
|
warningLabel.addStyleName("marginTop30");
|
51
|
warningLabel.setType(AlertType.WARNING);
|
52
|
warningLabel.setClose(false);
|
53
|
warningLabel.setVisible(false);
|
54
|
|
55
|
viewAll.setText("View all...");
|
56
|
viewAll.addClickHandler(new ClickHandler() {
|
57
|
@Override
|
58
|
public void onClick(ClickEvent clickEvent) {
|
59
|
History.newItem("existingFundingRequests");
|
60
|
}
|
61
|
});
|
62
|
|
63
|
final HTML loadingWheel = new HTML("<div class=\"loader\"></div><div class=\"whiteFilm\"></div>");
|
64
|
requestsListPanel.addStyleName("loading-small");
|
65
|
requestsListPanel.add(loadingWheel);
|
66
|
|
67
|
if(Utils.currentUserHasRole("publisher")) {
|
68
|
loadRequestsForPublisher(null, null, RequestSort.DATE, RequestSortOrder.DESCENDING, null, null, null, 0, 4);
|
69
|
} else if(Utils.currentUserHasRole("library_staff")) {
|
70
|
loadRequestsForLibrarian(null, null, RequestSort.DATE, RequestSortOrder.DESCENDING, null, null, null, 0, 4);
|
71
|
} else {
|
72
|
loadRequestsForGeneralUser(null, null, RequestSort.DATE, RequestSortOrder.DESCENDING, null, null, null, 0, 4);
|
73
|
}
|
74
|
|
75
|
requestsListPanel.addStyleName("recentRequestsList");
|
76
|
|
77
|
recentRequestsPanel.add(errorLabel);
|
78
|
recentRequestsPanel.add(warningLabel);
|
79
|
recentRequestsPanel.add(requestsListPanel);
|
80
|
}
|
81
|
|
82
|
@Override
|
83
|
public Widget asWidget() {
|
84
|
return recentRequestsPanel;
|
85
|
}
|
86
|
|
87
|
private void loadRequestsForLibrarian(Date fromDate, Date toDate, RequestSort requestSortBy, RequestSortOrder order,
|
88
|
RequestFilter requestFilter, String term, Request.RequestStatus[] statusFilters,
|
89
|
int from, int to) {
|
90
|
|
91
|
List<String> organizationIds = new ArrayList<>();
|
92
|
for(Affiliation affiliation : GoldOAPortal.currentUser.getAffiliations()) {
|
93
|
if(affiliation.getOrganization()!=null)
|
94
|
organizationIds.add(affiliation.getOrganization().getId());
|
95
|
}
|
96
|
|
97
|
dataService.getRequestsForOrganizations(organizationIds, fromDate, toDate, requestSortBy, order, requestFilter, term, statusFilters,
|
98
|
from, to, new AsyncCallback<RequestPage>() {
|
99
|
|
100
|
@Override
|
101
|
public void onFailure(Throwable throwable) {
|
102
|
|
103
|
requestsListPanel.clear();
|
104
|
requestsListPanel.removeStyleName("loading-small");
|
105
|
|
106
|
errorLabel.setText(goldOAConstants.errorGettingListOfFundingRequests());
|
107
|
errorLabel.setVisible(true);
|
108
|
}
|
109
|
|
110
|
@Override
|
111
|
public void onSuccess(RequestPage requestInfoPage) {
|
112
|
|
113
|
requestsListPanel.clear();
|
114
|
requestsListPanel.removeStyleName("loading-small");
|
115
|
|
116
|
if(requestInfoPage.getRequests().isEmpty()) {
|
117
|
warningLabel.setText(goldOAConstants.warningNoFundingRequestsAvailable());
|
118
|
warningLabel.setVisible(true);
|
119
|
} else {
|
120
|
for(int i=0; i<requestInfoPage.getRequests().size(); i++)
|
121
|
drawRequestInfo(requestInfoPage.getRequests().get(i), i);
|
122
|
recentRequestsPanel.add(viewAll);
|
123
|
}
|
124
|
}
|
125
|
});
|
126
|
}
|
127
|
|
128
|
private void loadRequestsForPublisher(Date fromDate, Date toDate, RequestSort requestSortBy, RequestSortOrder order,
|
129
|
RequestFilter requestFilter, String term, Request.RequestStatus[] statusFilters,
|
130
|
int from, int to) {
|
131
|
|
132
|
dataService.getRequestsForPublisher(GoldOAPortal.currentUser.getPublisher().getId(), fromDate, toDate, requestSortBy, order,
|
133
|
requestFilter, term, statusFilters, from, to, new AsyncCallback<RequestPage>() {
|
134
|
|
135
|
@Override
|
136
|
public void onFailure(Throwable throwable) {
|
137
|
|
138
|
requestsListPanel.clear();
|
139
|
requestsListPanel.removeStyleName("loading-small");
|
140
|
|
141
|
errorLabel.setText(goldOAConstants.errorGettingListOfFundingRequests());
|
142
|
errorLabel.setVisible(true);
|
143
|
}
|
144
|
|
145
|
@Override
|
146
|
public void onSuccess(RequestPage requestInfoPage) {
|
147
|
|
148
|
requestsListPanel.clear();
|
149
|
requestsListPanel.removeStyleName("loading-small");
|
150
|
|
151
|
if(requestInfoPage.getRequests().isEmpty()) {
|
152
|
warningLabel.setText(goldOAConstants.warningNoFundingRequestsAvailable());
|
153
|
warningLabel.setVisible(true);
|
154
|
} else {
|
155
|
for(int i=0; i<requestInfoPage.getRequests().size(); i++)
|
156
|
drawRequestInfo(requestInfoPage.getRequests().get(i), i);
|
157
|
recentRequestsPanel.add(viewAll);
|
158
|
}
|
159
|
}
|
160
|
});
|
161
|
}
|
162
|
|
163
|
private void loadRequestsForGeneralUser(Date fromDate, Date toDate, RequestSort requestSortBy, RequestSortOrder order,
|
164
|
RequestFilter requestFilter, String term, Request.RequestStatus[] statusFilters,
|
165
|
int from, int to) {
|
166
|
|
167
|
dataService.getRequestsForUser(GoldOAPortal.currentUser.getId(), fromDate, toDate, requestSortBy, order, requestFilter,
|
168
|
term, statusFilters, from, to, new AsyncCallback<RequestPage>() {
|
169
|
|
170
|
@Override
|
171
|
public void onFailure(Throwable throwable) {
|
172
|
|
173
|
requestsListPanel.clear();
|
174
|
requestsListPanel.removeStyleName("loading-small");
|
175
|
|
176
|
errorLabel.setText(goldOAConstants.errorGettingListOfFundingRequests());
|
177
|
errorLabel.setVisible(true);
|
178
|
}
|
179
|
|
180
|
@Override
|
181
|
public void onSuccess(RequestPage requestInfoPage) {
|
182
|
|
183
|
requestsListPanel.clear();
|
184
|
requestsListPanel.removeStyleName("loading-small");
|
185
|
|
186
|
if(requestInfoPage.getRequests().isEmpty()) {
|
187
|
warningLabel.setText(goldOAConstants.warningNoFundingRequestsAvailable());
|
188
|
warningLabel.setVisible(true);
|
189
|
} else {
|
190
|
for(int i=0; i<requestInfoPage.getRequests().size(); i++)
|
191
|
drawRequestInfo(requestInfoPage.getRequests().get(i), i);
|
192
|
recentRequestsPanel.add(viewAll);
|
193
|
}
|
194
|
}
|
195
|
});
|
196
|
}
|
197
|
|
198
|
private void drawRequestInfo(final Request requestInfo, int i) {
|
199
|
|
200
|
final HTML requestInfoElement = new HTML();
|
201
|
if(((i+1)%2)==1)
|
202
|
requestInfoElement.addStyleName("odd");
|
203
|
|
204
|
String content = "";
|
205
|
|
206
|
if(requestInfo.getPublication()!=null) {
|
207
|
if(requestInfo.getPublication().getTitle().length()>50)
|
208
|
content += requestInfo.getPublication().getTitle().substring(0, 50) + " ... ";
|
209
|
else
|
210
|
content += requestInfo.getPublication().getTitle();
|
211
|
}
|
212
|
content += "<div class=\"status\">" + requestInfo.getStatus().getValue().toUpperCase() + "</div>";
|
213
|
|
214
|
requestInfoElement.setHTML(content);
|
215
|
|
216
|
requestInfoElement.addMouseOverHandler(new MouseOverHandler() {
|
217
|
@Override
|
218
|
public void onMouseOver(MouseOverEvent mouseOverEvent) {
|
219
|
if(requestInfo.getPublication()!=null && requestInfo.getPublication().getTitle().length()>50)
|
220
|
requestInfoElement.setTitle(requestInfo.getPublication().getTitle());
|
221
|
}
|
222
|
});
|
223
|
|
224
|
requestsListPanel.add(requestInfoElement);
|
225
|
}
|
226
|
}
|