Project

General

Profile

1
package eu.dnetlib.repo.manager.client.enrichcontent;
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.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.Widget;
11
import eu.dnetlib.domain.data.Repository;
12
import eu.dnetlib.gwt.client.help.HelpService;
13
import eu.dnetlib.gwt.client.help.HelpServiceAsync;
14
import eu.dnetlib.repo.manager.client.AbstractRepositoryManagerWidget;
15
import eu.dnetlib.repo.manager.client.HelpCallback;
16
import eu.dnetlib.repo.manager.client.RepositoryManager;
17
import eu.dnetlib.repo.manager.client.RepositoryManagerWidget;
18
import eu.dnetlib.repo.manager.client.services.BrokerService;
19
import eu.dnetlib.repo.manager.client.services.BrokerServiceAsync;
20
import eu.dnetlib.repo.manager.shared.DatasourcesCollection;
21
import eu.dnetlib.repo.manager.shared.Tuple;
22
import eu.dnetlib.repo.manager.shared.broker.BrowseEntry;
23
import eu.dnetlib.repo.manager.shared.broker.DatasourcesBroker;
24
import org.gwtbootstrap3.client.ui.Alert;
25
import org.gwtbootstrap3.client.ui.Anchor;
26
import org.gwtbootstrap3.client.ui.constants.AlertType;
27

    
28
/**
29
 * Created by stefania on 4/4/16.
30
 */
31
public class EnrichContentWidget extends AbstractRepositoryManagerWidget implements RepositoryManagerWidget {
32

    
33
    private String parentToken = "";
34
    private String restToken = "";
35

    
36
    private FlowPanel enrichContentBoxContent = new FlowPanel();
37

    
38
    private Alert errorAlert = new Alert();
39

    
40
    private static HelpServiceAsync helpService = GWT.create(HelpService.class);
41
    private static BrokerServiceAsync brokerService = GWT.create(BrokerService.class);
42

    
43
    public EnrichContentWidget() {
44

    
45
        super();
46

    
47
        HTML title = new HTML("<h1 class=\"uk-article-title\">Enrich Your Content - Browse Events</h1>");
48
        title.addStyleName("uk-margin-medium-bottom");
49
        contentPanel.add(title);
50

    
51
        errorAlert.setType(AlertType.DANGER);
52
        errorAlert.setDismissable(false);
53
        errorAlert.setVisible(false);
54
        enrichContentBoxContent.add(errorAlert);
55

    
56
        contentPanel.add(enrichContentBoxContent);
57
    }
58

    
59
    @Override
60
    public void clear() {
61

    
62
        enrichContentBoxContent.clear();
63
        errorAlert.setVisible(false);
64
        gridPanel.remove(helpPanel);
65
    }
66

    
67
    @Override
68
    public void reload() {
69

    
70
        Document.get().getElementById("headerNoTransparent").removeClassName("tm-header-transparent");
71
        enrichContentBoxContent.add(errorAlert);
72

    
73
        helpService.getHelpById(parentToken, new HelpCallback(helpPanel, gridPanel));
74

    
75
        final HTML loadingWheel = new HTML("<div class=\"loader-big\" style=\"text-align: center; padding-top: 170px; " +
76
                "color: rgb(47, 64, 80); font-weight: bold;\">Retrieving repositories...</div>" +
77
                "<div class=\"whiteFilm\"></div>");
78
        enrichContentBoxContent.addStyleName("loading-big");
79
        enrichContentBoxContent.add(loadingWheel);
80

    
81
        brokerService.getDatasourcesOfUser(RepositoryManager.currentUser.getEmail(), false, false, new AsyncCallback<DatasourcesBroker>() {
82

    
83
            @Override
84
            public void onFailure(Throwable caught) {
85

    
86
                enrichContentBoxContent.removeStyleName("loading-big");
87
                enrichContentBoxContent.remove(loadingWheel);
88

    
89
                errorAlert.setText("System error retrieving repositories.");
90
                errorAlert.setVisible(true);
91
            }
92

    
93
            @Override
94
            public void onSuccess(DatasourcesBroker datasourcesBroker) {
95

    
96
                enrichContentBoxContent.removeStyleName("loading-big");
97
                enrichContentBoxContent.remove(loadingWheel);
98

    
99
                FlowPanel titlePanel = new FlowPanel();
100
                enrichContentBoxContent.add(titlePanel);
101

    
102
                //CONTENT
103

    
104
                final FlowPanel contentPanel = new FlowPanel();
105
                enrichContentBoxContent.add(contentPanel);
106

    
107
                final FlowPanel reposList = new FlowPanel();
108
                createReposList(datasourcesBroker, reposList);
109

    
110
                final FlowPanel reposGrid = new FlowPanel();
111
                createReposGrid(datasourcesBroker, reposGrid);
112
                contentPanel.add(reposGrid);
113

    
114
                // TITLE
115

    
116
                FlowPanel showOptions = new FlowPanel();
117
                showOptions.addStyleName("showOptions");
118
                titlePanel.add(showOptions);
119

    
120
                final Anchor gridView = new Anchor();
121
                final Anchor listView = new Anchor();
122

    
123
                gridView.addStyleName("grid-view active");
124
                gridView.setHTML("<i class=\"fa fa-th\"></i>");
125
                gridView.addClickHandler(new ClickHandler() {
126
                    @Override
127
                    public void onClick(ClickEvent event) {
128
                        listView.removeStyleName("active");
129
                        gridView.addStyleName("active");
130
                        contentPanel.clear();
131
                        contentPanel.add(reposGrid);
132
                    }
133
                });
134
                showOptions.add(gridView);
135

    
136
                listView.addStyleName("grid-view");
137
                listView.setHTML("<i class=\"fa fa-th-list\"></i>");
138
                listView.addClickHandler(new ClickHandler() {
139
                    @Override
140
                    public void onClick(ClickEvent event) {
141
                        gridView.removeStyleName("active");
142
                        listView.addStyleName("active");
143
                        contentPanel.clear();
144
                        contentPanel.add(reposList);
145
                    }
146
                });
147
                showOptions.add(listView);
148

    
149
                HTML titleElement = new HTML("<h4 class=\"uk-h4 uk-text-primary uk-scrollspy-inview uk-animation-slide-top-medium\"" +
150
                        "uk-scrollspy-class=\"\"><span>Choose the Datasource for which you would like to view events</span></h4>");
151
                titleElement.addStyleName("m-b-md");
152
                titlePanel.add(titleElement);
153
            }
154
        });
155
    }
156

    
157
    @Override
158
    public void setToken(String parentToken, String rest) {
159
        this.parentToken = parentToken;
160
        this.restToken = rest;
161
    }
162

    
163
    @Override
164
    public void afterAdditionToRootPanel() {
165

    
166
    }
167

    
168
    private void createReposList(DatasourcesBroker datasourcesBroker, FlowPanel reposList) {
169

    
170
        reposList.addStyleName("uk-grid-margin uk-grid uk-grid-stack repos-list");
171

    
172
        if(datasourcesBroker.getDatasourcesOfUser().isEmpty()) {
173

    
174
            reposList.add(new HTML("No Datasources are registered under your account"));
175

    
176
        } else {
177

    
178
            FlowPanel colPanel = new FlowPanel();
179
            colPanel.addStyleName("uk-width-1-1@m uk-first-column");
180
            reposList.add(colPanel);
181

    
182
            FlowPanel divPanel = new FlowPanel();
183
            divPanel.addStyleName("uk-overflow-auto uk-scrollspy-inview uk-animation-slide-top-medium");
184
            colPanel.add(divPanel);
185

    
186
            String content = "<table class=\"uk-table uk-table-striped uk-table-middle\">" +
187
                    "<thead><tr><th>Logo</th><th class=\"uk-text-nowrap\">Name</th><th class=\"uk-text-nowrap\"># of events</th>" +
188
                    "<th class=\"uk-text-nowrap\">Actions</th></tr></thead>";
189

    
190
            content += "<tbody>";
191

    
192
            for(final Tuple<BrowseEntry, String> datasource : datasourcesBroker.getDatasourcesOfUser()) {
193

    
194
                content += "<tr class=\"el-item\">" +
195
                        "<td class=\"uk-table-shrink\">";
196

    
197
                if(datasource.getSecond()==null || datasource.getSecond().trim().isEmpty())
198
                    content += "<img src=\"img/yourLogoHere.jpg\" alt=\"[Repo Logo]\" class=\"el-image uk-preserve-width\" style=\"height: 45px\">";
199
                else
200
                    content += "<img src=\"" + datasource.getSecond() + "\" alt=\"[Repo Logo]\" class=\"el-image uk-preserve-width\" style=\"height: 45px\">";
201

    
202
                content += "</td>" +
203
                        "<td class=\"uk-text-nowrap uk-table-shrink\">\n" +
204
                        "<a href=\"#" + parentToken + "/" + datasource.getFirst().getValue() + "\" class=\"el-link\">" +
205
                        datasource.getFirst().getValue() + "</a>" +
206
                        "</td>" +
207
                        "<td class=\"uk-text-nowrap uk-table-shrink\">\n" +
208
                        "<div class=\"el-title\">" + datasource.getFirst().getSize() + "</div>" +
209
                        "</td>" +
210
                        "<td class=\"uk-text-nowrap uk-table-shrink\">" +
211
                        "<a href=\"#" + parentToken + "/" + datasource.getFirst().getValue() + "\" class=\"el-link\">" +
212
                        "<i class=\"fa fa-eye\" aria-hidden=\"true\"></i></a>" +
213
                        "</td>" +
214
                        "</tr>";
215
            }
216

    
217
            content += "</tbody></table>";
218

    
219
            HTML reposListHTML = new HTML();
220
            reposListHTML.setHTML(content);
221

    
222
            divPanel.add(reposListHTML);
223
        }
224
    }
225

    
226
    private void createReposGrid(DatasourcesBroker datasourcesBroker, FlowPanel reposGrid) {
227

    
228
        reposGrid.addStyleName("uk-grid-large uk-grid-margin-large uk-grid repos-grid");
229

    
230
        if(datasourcesBroker.getDatasourcesOfUser().isEmpty()) {
231

    
232
            reposGrid.add(new HTML("No Datasources are registered under your account"));
233

    
234
        } else {
235

    
236
            if(datasourcesBroker.getDatasourcesOfUser().size()==1) {
237

    
238
                FlowPanel colPanel = new FlowPanel();
239
                colPanel.addStyleName("uk-width-expand@m uk-first-column");
240
                reposGrid.add(colPanel);
241

    
242
                FlowPanel divPanel = new FlowPanel();
243
                divPanel.addStyleName("uk-margin uk-grid-match uk-child-width-1-1 uk-grid-small uk-grid-divider uk-grid uk-scrollspy-inview uk-animation-slide-top-medium uk-grid-stack");
244
                colPanel.add(divPanel);
245

    
246
                divPanel.add(createGridItemForRepo(datasourcesBroker.getDatasourcesOfUser().get(0), false));
247

    
248
            } else if(datasourcesBroker.getDatasourcesOfUser().size()==2) {
249

    
250
                FlowPanel colPanel1 = new FlowPanel();
251
                colPanel1.addStyleName("uk-width-expand@m uk-first-column");
252
                reposGrid.add(colPanel1);
253

    
254
                FlowPanel divPanel1 = new FlowPanel();
255
                divPanel1.addStyleName("uk-margin uk-grid-match uk-child-width-1-1 uk-grid-small uk-grid-divider uk-grid uk-scrollspy-inview uk-animation-slide-top-medium uk-grid-stack");
256
                colPanel1.add(divPanel1);
257

    
258
                divPanel1.add(createGridItemForRepo(datasourcesBroker.getDatasourcesOfUser().get(0), false));
259

    
260
                FlowPanel colPanel2 = new FlowPanel();
261
                colPanel2.addStyleName("uk-width-expand@m uk-first-column");
262
                reposGrid.add(colPanel2);
263

    
264
                FlowPanel divPanel2 = new FlowPanel();
265
                divPanel2.addStyleName("uk-margin uk-grid-match uk-child-width-1-1 uk-grid-small uk-grid-divider uk-grid uk-scrollspy-inview uk-animation-slide-top-medium uk-grid-stack");
266
                colPanel2.add(divPanel2);
267

    
268
                divPanel2.add(createGridItemForRepo(datasourcesBroker.getDatasourcesOfUser().get(1), false));
269

    
270
            } else {
271

    
272
                FlowPanel colPanel1 = new FlowPanel();
273
                colPanel1.addStyleName("uk-width-expand@m uk-first-column");
274
                reposGrid.add(colPanel1);
275

    
276
                FlowPanel divPanel1 = new FlowPanel();
277
                divPanel1.addStyleName("uk-margin uk-grid-match uk-child-width-1-1 uk-grid-small uk-grid-divider uk-grid uk-scrollspy-inview uk-animation-slide-top-medium uk-grid-stack");
278
                colPanel1.add(divPanel1);
279

    
280
                FlowPanel colPanel2 = new FlowPanel();
281
                colPanel2.addStyleName("uk-width-expand@m uk-first-column");
282
                reposGrid.add(colPanel2);
283

    
284
                FlowPanel divPanel2 = new FlowPanel();
285
                divPanel2.addStyleName("uk-margin uk-grid-match uk-child-width-1-1 uk-grid-small uk-grid-divider uk-grid uk-scrollspy-inview uk-animation-slide-top-medium uk-grid-stack");
286
                colPanel2.add(divPanel2);
287

    
288
                FlowPanel colPanel3 = new FlowPanel();
289
                colPanel3.addStyleName("uk-width-expand@m uk-first-column");
290
                reposGrid.add(colPanel3);
291

    
292
                FlowPanel divPanel3 = new FlowPanel();
293
                divPanel3.addStyleName("uk-margin uk-grid-match uk-child-width-1-1 uk-grid-small uk-grid-divider uk-grid uk-scrollspy-inview uk-animation-slide-top-medium uk-grid-stack");
294
                colPanel3.add(divPanel3);
295

    
296
                for(int i=0; i<datasourcesBroker.getDatasourcesOfUser().size(); i++) {
297

    
298
                    boolean addExtraClass = false;
299
                    if(i>2)
300
                        addExtraClass = true;
301

    
302
                    if(i%3 == 0)
303
                        divPanel1.add(createGridItemForRepo(datasourcesBroker.getDatasourcesOfUser().get(i), addExtraClass));
304
                    else if(i%3 == 1)
305
                        divPanel2.add(createGridItemForRepo(datasourcesBroker.getDatasourcesOfUser().get(i), addExtraClass));
306
                    else
307
                        divPanel3.add(createGridItemForRepo(datasourcesBroker.getDatasourcesOfUser().get(i), addExtraClass));
308
                }
309

    
310
            }
311
        }
312
    }
313

    
314
    private FlowPanel createGridItemForRepo(Tuple<BrowseEntry, String> datasource, boolean addExtraClass) {
315

    
316
        FlowPanel gridItem = new FlowPanel();
317
        if(addExtraClass)
318
            gridItem.addStyleName("uk-grid-margin uk-first-column");
319
        else
320
            gridItem.addStyleName("uk-first-column");
321

    
322

    
323
        String gridItemContent = "";
324

    
325
        gridItemContent += "<div uk-scrollspy-class=\"\" class=\"el-item uk-panel uk-scrollspy-inview uk-animation-slide-top-medium\" style=\"\">" +
326
                "<div class=\"uk-child-width-expand uk-grid-medium uk-flex-middle uk-grid\" uk-grid=\"\">";
327

    
328

    
329
        gridItemContent += "<div class=\"uk-width-1-3@m uk-first-column\">" +
330
                "<a href=\"#" + parentToken + "/" + datasource.getFirst().getValue() + "\" class=\"el-link\">";
331

    
332
        if(datasource.getSecond()==null || datasource.getSecond().trim().isEmpty())
333
            gridItemContent += "<img src=\"img/yourLogoHere.jpg\" class=\"el-image uk-border-rounded\" alt=\"\">";
334
        else
335
            gridItemContent += "<img src=\"" + datasource.getSecond() + "\" class=\"el-image uk-border-rounded\" alt=\"\">";
336

    
337
        gridItemContent += "</a></div>";
338

    
339
        gridItemContent += "<div><h3 class=\"el-title uk-margin uk-h5 uk-margin-remove-adjacent uk-margin-small-bottom\">" + datasource.getFirst().getValue() + "</h3>" +
340
                "<div class=\"el-meta uk-margin uk-text-meta\">(" + datasource.getFirst().getSize() + " events)</div>" +
341
                "</div>";
342

    
343
        gridItemContent += "</div></div>";
344

    
345
        gridItem.add(new HTML(gridItemContent));
346

    
347
        return gridItem;
348
    }
349
}
(5-5/8)