Project

General

Profile

1 35292 stefania.m
package eu.dnetlib.client;
2
3 35683 stefania.m
import com.github.gwtbootstrap.client.ui.AccordionGroup;
4 35665 stefania.m
import com.github.gwtbootstrap.client.ui.Alert;
5
import com.github.gwtbootstrap.client.ui.constants.AlertType;
6 35683 stefania.m
import com.github.gwtbootstrap.client.ui.constants.IconType;
7
import com.github.gwtbootstrap.client.ui.event.HideEvent;
8
import com.github.gwtbootstrap.client.ui.event.HideHandler;
9
import com.github.gwtbootstrap.client.ui.event.ShowEvent;
10
import com.github.gwtbootstrap.client.ui.event.ShowHandler;
11 35665 stefania.m
import com.google.gwt.core.client.GWT;
12 35842 stefania.m
import com.google.gwt.dom.client.Document;
13
import com.google.gwt.dom.client.Style;
14 35683 stefania.m
import com.google.gwt.i18n.client.DateTimeFormat;
15 35665 stefania.m
import com.google.gwt.user.client.rpc.AsyncCallback;
16 35292 stefania.m
import com.google.gwt.user.client.ui.*;
17 35791 stefania.m
import eu.dnetlib.goldoa.domain.Request;
18 35665 stefania.m
import eu.dnetlib.goldoa.domain.RequestInfo;
19 35292 stefania.m
20 35665 stefania.m
import java.util.List;
21
22 35292 stefania.m
/**
23
 * Created by stefania on 3/6/15.
24
 */
25 35933 stefania.m
public class MonitorFundingRequestsWidget implements MyWidget {
26 35292 stefania.m
27 35933 stefania.m
    private FlowPanel monitorFundingRequestsPagePanel = new FlowPanel();
28
    private Label monitorFundingRequestsTitleLabel = new Label();
29
    private Label monitorFundingRequestsInfoLabel = new Label();
30 35292 stefania.m
31 35665 stefania.m
    private Alert errorLabel = new Alert();
32 35683 stefania.m
    private Alert warningLabel = new Alert();
33 35665 stefania.m
34
    private FlowPanel requestsForApprovalPanel = new FlowPanel();
35
36 35683 stefania.m
    private DateTimeFormat dtf = DateTimeFormat.getFormat("yyyy/MM/dd");
37 35665 stefania.m
    private DataServiceAsync dataService = GWT.create(DataService.class);
38
39 35933 stefania.m
    public MonitorFundingRequestsWidget() {
40 35292 stefania.m
41 35933 stefania.m
        monitorFundingRequestsPagePanel.addStyleName("content");
42 35683 stefania.m
43 35933 stefania.m
        monitorFundingRequestsTitleLabel.setText("Monitor Funding Requests");
44
        monitorFundingRequestsTitleLabel.addStyleName("contentTitleLabel");
45 35665 stefania.m
46 35933 stefania.m
        monitorFundingRequestsInfoLabel.setText("Monitor and change the status of funding requests that are pending approval");
47
        monitorFundingRequestsInfoLabel.addStyleName("contentInfoLabel");
48 35691 stefania.m
49 35665 stefania.m
        errorLabel.addStyleName("alertLabel");
50
        errorLabel.addStyleName("width80");
51
        errorLabel.setType(AlertType.ERROR);
52
        errorLabel.setClose(false);
53
        errorLabel.setVisible(false);
54
55 35683 stefania.m
        warningLabel.addStyleName("alertLabel");
56
        warningLabel.addStyleName("width80");
57
        warningLabel.setType(AlertType.WARNING);
58
        warningLabel.setClose(false);
59
        warningLabel.setVisible(false);
60
61 35691 stefania.m
        requestsForApprovalPanel.addStyleName("requestsListPanel");
62 35683 stefania.m
63 35933 stefania.m
        monitorFundingRequestsPagePanel.add(monitorFundingRequestsTitleLabel);
64
        monitorFundingRequestsPagePanel.add(monitorFundingRequestsInfoLabel);
65
        monitorFundingRequestsPagePanel.add(errorLabel);
66
        monitorFundingRequestsPagePanel.add(warningLabel);
67
        monitorFundingRequestsPagePanel.add(requestsForApprovalPanel);
68 35292 stefania.m
    }
69
70
    @Override
71
    public Widget asWidget() {
72 35933 stefania.m
        return monitorFundingRequestsPagePanel;
73 35292 stefania.m
    }
74 35507 stefania.m
75
    @Override
76
    public void clear() {
77
78 35665 stefania.m
        errorLabel.setVisible(false);
79 35683 stefania.m
        warningLabel.setVisible(false);
80 35736 stefania.m
        requestsForApprovalPanel.clear();
81 35507 stefania.m
    }
82
83
    @Override
84 35665 stefania.m
    public void reload() {
85
86 35842 stefania.m
        Document.get().getElementById("content").removeClassName("uk-width-medium-1-1");
87
        Document.get().getElementById("content").addClassName("uk-width-medium-3-4");
88
        Document.get().getElementById("sidebar").getStyle().setDisplay(Style.Display.BLOCK);
89
90
        SidebarPanel sidebarPanel = new SidebarPanel("Help");
91
        RootPanel.get("sidebar").add(sidebarPanel.asWidget());
92
93 35757 stefania.m
        final HTML loadingWheel = new HTML("<div class=\"loader-big\"></div><div class=\"whiteFilm\"></div>");
94
        requestsForApprovalPanel.addStyleName("loading");
95
        requestsForApprovalPanel.add(loadingWheel);
96
97 35665 stefania.m
        dataService.getRequests(null, null, null, null, null, null, new AsyncCallback<List<RequestInfo>>() {
98
99
            @Override
100
            public void onFailure(Throwable throwable) {
101 35757 stefania.m
102
                requestsForApprovalPanel.removeStyleName("loading");
103
                requestsForApprovalPanel.remove(loadingWheel);
104
105 35683 stefania.m
                errorLabel.setText("System error retrieving requests");
106
                errorLabel.setVisible(true);
107 35665 stefania.m
            }
108
109
            @Override
110
            public void onSuccess(List<RequestInfo> requestInfoList) {
111
112 35757 stefania.m
                requestsForApprovalPanel.removeStyleName("loading");
113
                requestsForApprovalPanel.remove(loadingWheel);
114
115 35683 stefania.m
                if(requestInfoList.isEmpty()) {
116
                    warningLabel.setText("No available requests at the moment.");
117
                    warningLabel.setVisible(true);
118
                } else {
119
                    for(RequestInfo requestInfo : requestInfoList)
120
                        drawRequestInfo(requestInfo);
121
                }
122 35665 stefania.m
            }
123
        });
124
125
    }
126
127
    @Override
128 35507 stefania.m
    public void setToken(String token) {
129
130
    }
131 35683 stefania.m
132
    private void drawRequestInfo(final RequestInfo requestInfo) {
133
134
        final AccordionGroup dataRequestAccordionItem = new AccordionGroup();
135
136 35751 stefania.m
        String heading = "\"" + requestInfo.getPublication().getTitle() + "\"" + " (" + dtf.format(requestInfo.getDate()) + ")"
137 35791 stefania.m
                + ", STATUS: " + requestInfo.getStatus().getValue();
138 35683 stefania.m
139
        dataRequestAccordionItem.setHeading(heading);
140
        dataRequestAccordionItem.setIcon(IconType.ANGLE_DOWN);
141
142
        dataRequestAccordionItem.addShowHandler(new ShowHandler() {
143
144
            @Override
145
            public void onShow(ShowEvent showEvent) {
146
147 35856 stefania.m
                dataRequestAccordionItem.setIcon(IconType.ANGLE_UP);
148
                dataRequestAccordionItem.clear();
149
150 35788 stefania.m
                final HTML loadingWheel = new HTML("<div class=\"loader-big\"></div><div class=\"whiteFilm\"></div>");
151
                FlowPanel accordionInner = new FlowPanel();
152
                accordionInner.addStyleName("loading");
153
                accordionInner.add(loadingWheel);
154
155
                dataRequestAccordionItem.add(accordionInner);
156
157
                dataService.getRequestById(requestInfo.getId(), new AsyncCallback<RequestInfo>() {
158
159
                    @Override
160
                    public void onFailure(Throwable throwable) {
161
162
                        dataRequestAccordionItem.clear();
163
164
                        Alert errorLabel = new Alert();
165
                        errorLabel.addStyleName("alertLabel");
166
                        errorLabel.setType(AlertType.ERROR);
167
                        errorLabel.setClose(false);
168
                        errorLabel.setText("System error getting request information");
169
170
                        dataRequestAccordionItem.add(errorLabel);
171
                    }
172
173
                    @Override
174 35791 stefania.m
                    public void onSuccess(final RequestInfo requestInfo) {
175 35788 stefania.m
176
                        dataRequestAccordionItem.clear();
177 35856 stefania.m
178 35788 stefania.m
                        RequestInfoElement requestInfoElement = new RequestInfoElement(requestInfo);
179
                        dataRequestAccordionItem.add(requestInfoElement.asWidget());
180
181
                        RequestInfoElement.ActionListener actionListener = new RequestInfoElement.ActionListener() {
182
183
                            @Override
184 35791 stefania.m
                            public void actionHappened(boolean succeeded, Request.RequestStatus requestStatus) {
185
186 35788 stefania.m
                                dataRequestAccordionItem.getHeading().getElement().scrollIntoView();
187 35791 stefania.m
                                if(succeeded) {
188
                                    String heading = "\"" + requestInfo.getPublication().getTitle() + "\"" + " (" + dtf.format(requestInfo.getDate()) + ")"
189
                                            + ", STATUS: " + requestStatus.getValue();
190
191
                                    dataRequestAccordionItem.setHeading(heading);
192
                                }
193 35788 stefania.m
                            }
194
                        };
195
                        requestInfoElement.setActionListener(actionListener);
196
                    }
197
                });
198 35683 stefania.m
            }
199
        });
200
        dataRequestAccordionItem.addHideHandler(new HideHandler() {
201
202
            @Override
203
            public void onHide(HideEvent hideEvent) {
204
                dataRequestAccordionItem.setIcon(IconType.ANGLE_DOWN);
205
            }
206
        });
207
208 35736 stefania.m
        requestsForApprovalPanel.add(dataRequestAccordionItem);
209 35683 stefania.m
    }
210 35292 stefania.m
}