Project

General

Profile

1
package eu.dnetlib.repo.manager.client.enrichcontent;
2

    
3
import com.google.gwt.user.client.ui.FlowPanel;
4
import com.google.gwt.user.client.ui.HTML;
5
import com.google.gwt.user.client.ui.IsWidget;
6
import com.google.gwt.user.client.ui.Widget;
7
import eu.dnetlib.gwt.client.MyFormGroup;
8
import eu.dnetlib.repo.manager.client.RepositoryManager;
9
import eu.dnetlib.repo.manager.shared.broker.AdvQueryObject;
10
import eu.dnetlib.repo.manager.shared.broker.NotificationFrequency;
11
import eu.dnetlib.repo.manager.shared.broker.NotificationMode;
12
import eu.dnetlib.repo.manager.shared.broker.OpenaireSubscription;
13
import org.gwtbootstrap3.client.ui.Alert;
14
import org.gwtbootstrap3.client.ui.Form;
15
import org.gwtbootstrap3.client.ui.ListBox;
16
import org.gwtbootstrap3.client.ui.constants.AlertType;
17

    
18
/**
19
 * Created by stefania on 3/17/17.
20
 */
21
public class EventsSubscriptionForm implements IsWidget {
22

    
23
    private FlowPanel subscriptionFormPanel = new FlowPanel();
24

    
25
    private Alert errorLabel = new Alert();
26

    
27
    private Form subscriptionForm = new Form();
28
    private ListBox frequencyListBox = new ListBox();
29
    private MyFormGroup frequencyListFormGroup = new MyFormGroup(false, "Frequency (*)", frequencyListBox);
30
    private ListBox modeListBox = new ListBox();
31
    private MyFormGroup modeListFormGroup = new MyFormGroup(false, "Mode (*)", modeListBox);
32

    
33
    private AdvQueryObject advQueryObject;
34

    
35
    public EventsSubscriptionForm(AdvQueryObject advQueryObject) {
36

    
37
        this.advQueryObject = advQueryObject;
38

    
39
        errorLabel.setType(AlertType.DANGER);
40
        errorLabel.setVisible(false);
41
        errorLabel.setDismissable(false);
42
        subscriptionFormPanel.add(errorLabel);
43

    
44
        subscriptionFormPanel.add(new HTML("<h4 class=\"uk-h4\">" + this.advQueryObject.getDatasource() + "</h4>" +
45
                "<div class=\"uk-text uk-text-small uk-text-secondary\">" + this.advQueryObject.getTopic().replace("/", "  |  ") + "</div>"));
46

    
47
        subscriptionFormPanel.add(subscriptionForm);
48

    
49
        HTML userEmail = new HTML(RepositoryManager.currentUser.getEmail());
50
        MyFormGroup userEmailFormGroup = new MyFormGroup(false, "Email", userEmail);
51
        subscriptionForm.add(userEmailFormGroup);
52

    
53
        frequencyListBox.addItem("-- none selected --", "noneSelected");
54
        for(NotificationFrequency notificationFrequency : NotificationFrequency.values())
55
            frequencyListBox.addItem(notificationFrequency.name(), notificationFrequency.name());
56
        subscriptionForm.add(frequencyListFormGroup);
57

    
58
//        modeListBox.addItem("-- none selected --", "noneSelected");
59
//        for(NotificationMode notificationMode : NotificationMode.values())
60
//            modeListBox.addItem(notificationMode.name(), notificationMode.name());
61
//        subscriptionForm.add(modeListFormGroup);
62

    
63
        HTML options = new HTML();
64
        options.setHTML(generateOptionsContent());
65
        MyFormGroup optionsFormGroup = new MyFormGroup(false, "Options", options);
66
        subscriptionForm.add(optionsFormGroup);
67
    }
68

    
69
    @Override
70
    public Widget asWidget() {
71
        return subscriptionFormPanel;
72
    }
73

    
74
    public boolean validate() {
75

    
76
        errorLabel.setVisible(false);
77

    
78
        if(!frequencyListBox.getSelectedValue().equals("noneSelected"))
79
//                && !modeListBox.getSelectedValue().equals("noneSelected"))
80
            return true;
81
        else {
82
            errorLabel.setVisible(true);
83
            errorLabel.setText("All asterisk (*) fields are mandatory");
84
            return false;
85
        }
86
    }
87

    
88
    public OpenaireSubscription getOpenAIRESubscription() {
89

    
90
        OpenaireSubscription openaireSubscription = new OpenaireSubscription();
91

    
92
        openaireSubscription.setSubscriber(RepositoryManager.currentUser.getEmail());
93
        openaireSubscription.setFrequency(NotificationFrequency.valueOf(frequencyListBox.getSelectedValue()));
94
        openaireSubscription.setMode(NotificationMode.valueOf(modeListBox.getSelectedValue()));
95
        openaireSubscription.setQuery(advQueryObject);
96

    
97
        return openaireSubscription;
98
    }
99

    
100
    private String generateOptionsContent() {
101

    
102
        String optionsContent = "<table class=\"table table-bordered\">";
103

    
104
//        optionsContent += "<thead><tr><th>Name</th><th>Values</th></tr></thead>";
105
        optionsContent += "<tbody>";
106

    
107
//        if(advQueryObject.getDatasource()!=null && !advQueryObject.getDatasource().equals(""))
108
//            optionsContent += "<tr><td>Datasource</td><td>" + advQueryObject.getDatasource() + "</td></tr>";
109
//
110
//        if(advQueryObject.getTopic()!=null && !advQueryObject.getTopic().equals(""))
111
//            optionsContent += "<tr><td>Topic</td><td>" + advQueryObject.getTopic() + "</td></tr>";
112

    
113
        if(advQueryObject.getTrust()!=null)
114
            optionsContent += "<tr><td>Trust</td><td>[" + advQueryObject.getTrust().getMin() + ", " + advQueryObject.getTrust().getMax() + "]</td></tr>";
115

    
116
        if(advQueryObject.getTitles()!=null && !advQueryObject.getTitles().isEmpty()) {
117
            optionsContent += "<tr><td>Titles</td><td>";
118
            for(int i=0; i<advQueryObject.getTitles().size(); i++) {
119
                optionsContent += advQueryObject.getTitles().get(i);
120
                if(i!=advQueryObject.getTitles().size()-1)
121
                    optionsContent += "<br>";
122
            }
123
            optionsContent += "</td></tr>";
124
        }
125

    
126
        if(advQueryObject.getAuthors()!=null && !advQueryObject.getAuthors().isEmpty()) {
127
            optionsContent += "<tr><td>Authors</td><td>";
128
            for(int i=0; i<advQueryObject.getAuthors().size(); i++) {
129
                optionsContent += advQueryObject.getAuthors().get(i);
130
                if(i!=advQueryObject.getAuthors().size()-1)
131
                    optionsContent += "<br>";
132
            }
133
            optionsContent += "</td></tr>";
134
        }
135

    
136
        if(advQueryObject.getSubjects()!=null && !advQueryObject.getSubjects().isEmpty()) {
137
            optionsContent += "<tr><td>Subjects</td><td>";
138
            for(int i=0; i<advQueryObject.getSubjects().size(); i++) {
139
                optionsContent += advQueryObject.getSubjects().get(i);
140
                if(i!=advQueryObject.getSubjects().size()-1)
141
                    optionsContent += "<br>";
142
            }
143
            optionsContent += "</td></tr>";
144
        }
145

    
146
        optionsContent += "</tbody>";
147
        optionsContent += "</table>";
148

    
149
        return optionsContent;
150
    }
151
}
(6-6/8)