1
|
package eu.dnetlib.client;
|
2
|
|
3
|
import java.util.ArrayList;
|
4
|
|
5
|
import com.github.gwtbootstrap.client.ui.Heading;
|
6
|
import com.google.gwt.event.dom.client.LoadEvent;
|
7
|
import com.google.gwt.event.dom.client.LoadHandler;
|
8
|
import com.google.gwt.http.client.URL;
|
9
|
import com.google.gwt.user.client.Timer;
|
10
|
import com.google.gwt.user.client.ui.FlowPanel;
|
11
|
import com.google.gwt.user.client.ui.Frame;
|
12
|
import com.google.gwt.user.client.ui.HTML;
|
13
|
import com.google.gwt.user.client.ui.RootPanel;
|
14
|
|
15
|
import eu.dnetlib.client.rightColumn.DataBox;
|
16
|
import eu.dnetlib.shared.ValuesOfFields;
|
17
|
|
18
|
public class Generate {
|
19
|
|
20
|
private static Generate instance = new Generate();
|
21
|
private Frame theme1 = new Frame();
|
22
|
private Frame themeForTable = new Frame();
|
23
|
private FlowPanel loader_big = new FlowPanel();
|
24
|
private FlowPanel whiteFilm = new FlowPanel();
|
25
|
|
26
|
private FlowPanel loader_big_table = new FlowPanel();
|
27
|
private FlowPanel whiteFilm_table = new FlowPanel();
|
28
|
|
29
|
private Heading infoHeading = new Heading(3);
|
30
|
private Heading infoHeading_table = new Heading(3);
|
31
|
private Timer timer;
|
32
|
private HTML loadingWheel = new HTML("<div class=\"loader-big\"></div><div class=\"whiteFilm\"></div>");
|
33
|
|
34
|
private Generate(){
|
35
|
theme1.addLoadHandler(new LoadHandler() {
|
36
|
|
37
|
@Override
|
38
|
public void onLoad(LoadEvent event) {
|
39
|
|
40
|
RootPanel.get("highchart").removeStyleName("loading");
|
41
|
RootPanel.get("highchart").remove(loader_big);
|
42
|
RootPanel.get("highchart").remove(whiteFilm);
|
43
|
timer.cancel();
|
44
|
infoHeading.setText("");
|
45
|
}
|
46
|
});
|
47
|
|
48
|
themeForTable.addLoadHandler(new LoadHandler() {
|
49
|
|
50
|
@Override
|
51
|
public void onLoad(LoadEvent event) {
|
52
|
// TODO Auto-generated method stub
|
53
|
|
54
|
RootPanel.get("tableChart").removeStyleName("loading");
|
55
|
RootPanel.get("tableChart").remove(loader_big_table);
|
56
|
RootPanel.get("tableChart").remove(whiteFilm_table);
|
57
|
timer.cancel();
|
58
|
infoHeading_table.setText("");
|
59
|
}
|
60
|
});
|
61
|
}
|
62
|
|
63
|
public static Generate getInstance() {
|
64
|
return instance;
|
65
|
}
|
66
|
|
67
|
public Frame getThemeForTable(){
|
68
|
return this.themeForTable;
|
69
|
}
|
70
|
|
71
|
public Frame getTheme1() {
|
72
|
return this.theme1;
|
73
|
}
|
74
|
|
75
|
|
76
|
public void setTheme1(Frame theme1) {
|
77
|
this.theme1 = theme1;
|
78
|
}
|
79
|
|
80
|
public String generateURLs(final ValuesOfFields fieldsValues ,int WhoToReturn){
|
81
|
|
82
|
loader_big.setStyleName("loader-big");
|
83
|
whiteFilm.setStyleName("whiteFilm");
|
84
|
loader_big_table.setStyleName("loader-big");
|
85
|
whiteFilm_table.setStyleName("whiteFilm");
|
86
|
loader_big.add(infoHeading);
|
87
|
loader_big_table.add(infoHeading_table);
|
88
|
infoHeading_table.addStyleName("info-preview");
|
89
|
infoHeading_table.setText("");
|
90
|
infoHeading.addStyleName("info-preview");
|
91
|
infoHeading.setText("");
|
92
|
|
93
|
|
94
|
String URL_theme1="http://dl114.madgik.di.uoa.gr/stats/merge.php?com=query&data=[";
|
95
|
String URL_theme2;
|
96
|
String URL_theme3;
|
97
|
ArrayList<Integer> whoToEnable = new ArrayList<Integer>();
|
98
|
for(int y=0;y<ValuesOfFields.getInstance().getColumnsDataList().size();y++){
|
99
|
if(fieldsValues.getColumnsDataList().get(y).isEnabled()){
|
100
|
whoToEnable.add(y);
|
101
|
}
|
102
|
}
|
103
|
for(int y=0;y<whoToEnable.size();y++){
|
104
|
//if(fieldsValues.getColumnsDataList().get(y).isEnabled()){
|
105
|
if(fieldsValues!=null){
|
106
|
|
107
|
URL_theme1=URL_theme1.concat("{\"table\":\""+fieldsValues.getColumnsDataList().get(whoToEnable.get(y)).getDataSource()+"\",");
|
108
|
URL_theme1=URL_theme1.concat("\"fields\":[");
|
109
|
URL_theme1=URL_theme1.concat("{\"fld\":\""+fieldsValues.getColumnsDataList().get(whoToEnable.get(y)).getY_values()+"\",\"agg\":\""+fieldsValues.getColumnsDataList().get(whoToEnable.get(y)).getTypeOf().replaceAll(" of", "")+"\",\"type\":\"column\",\"yaxis\":"+(1)+",\"c\":"+fieldsValues.isCumulative()+"}");
|
110
|
|
111
|
|
112
|
URL_theme1=URL_theme1.concat("],");
|
113
|
|
114
|
|
115
|
//font weights for title and subtitle
|
116
|
String fontWeightStartTitle = new String();
|
117
|
String fontWeightEndTitle = new String();
|
118
|
if(fieldsValues.isFontBoldTitle()){
|
119
|
fontWeightEndTitle = fontWeightEndTitle.concat("</b>");
|
120
|
}
|
121
|
if(fieldsValues.isFontItalicTitle()){
|
122
|
fontWeightEndTitle = fontWeightEndTitle.concat("</i>");
|
123
|
}
|
124
|
if(fieldsValues.isFontItalicTitle()){
|
125
|
fontWeightStartTitle = fontWeightStartTitle.concat("<i>");
|
126
|
}
|
127
|
if(fieldsValues.isFontBoldTitle()){
|
128
|
fontWeightStartTitle = fontWeightStartTitle.concat("<b>");
|
129
|
}
|
130
|
|
131
|
String finalTitle = fontWeightStartTitle + fieldsValues.getTitle() + fontWeightEndTitle;
|
132
|
|
133
|
String fontWeightStartSubTitle = new String();
|
134
|
String fontWeightEndSubTitle = new String();
|
135
|
if(fieldsValues.isFontBoldSubtitle()){
|
136
|
|
137
|
fontWeightEndSubTitle = fontWeightEndSubTitle.concat("</b>");
|
138
|
}
|
139
|
if(fieldsValues.isFontItalicSubtitle()){
|
140
|
|
141
|
fontWeightEndSubTitle = fontWeightEndSubTitle.concat("</i>");
|
142
|
}
|
143
|
if(fieldsValues.isFontItalicSubtitle()){
|
144
|
fontWeightStartSubTitle = fontWeightStartSubTitle.concat("<i>");
|
145
|
}
|
146
|
if(fieldsValues.isFontBoldSubtitle()){
|
147
|
fontWeightStartSubTitle = fontWeightStartSubTitle.concat("<b>");
|
148
|
}
|
149
|
String finalSubTitle = fontWeightStartSubTitle + fieldsValues.getSubtitle() + fontWeightEndSubTitle;
|
150
|
|
151
|
URL_theme1=URL_theme1.concat("\"xaxis\":{\"name\":\""+fieldsValues.getColumnsDataList().get(whoToEnable.get(y)).getX_values()+"\",\"agg\":\""+fieldsValues.getColumnsDataList().get(whoToEnable.get(y)).getTypeOf().replaceAll(" of", "")+"\"},");
|
152
|
URL_theme1=URL_theme1.concat("\"group\":\""+fieldsValues.getColumnsDataList().get(whoToEnable.get(y)).getSplitBy()+"\",\"color\":\"\",\"type\":\"chart\",\"size\":"+fieldsValues.getNumberOfResults()+",\"sort\":\"xaxis\",\"xStyle\":{\"r\":"+fieldsValues.getRotation()+",\"s\":\""+fieldsValues.getUseSteps()+"\",\"l\":\"-\",\"ft\":\"-\",\"wt\":\"-\"},");
|
153
|
URL_theme1=URL_theme1.concat("\"title\":\""+finalTitle+"\",\"subtitle\":\""+finalSubTitle +"\",\"xaxistitle\":\""+fieldsValues.getColumnsDataList().get(whoToEnable.get(y)).getXaxisTitle()+"\",\"yaxisheaders\":[\""+fieldsValues.getYaxis()+"\"],\"generalxaxis\":\""+fieldsValues.getXaxis()+"\",");
|
154
|
|
155
|
}
|
156
|
|
157
|
|
158
|
if(fieldsValues.getColumnsDataList().get(whoToEnable.get(y)).getFilters().size()==0){
|
159
|
URL_theme1=URL_theme1.concat("\"theme\":"+0+",\"in\":[]");
|
160
|
}else{
|
161
|
URL_theme1=URL_theme1.concat("\"theme\":"+0+",\"in\":[],\"filters\":[");
|
162
|
|
163
|
for(int filtNum=0;filtNum<fieldsValues.getColumnsDataList().get(whoToEnable.get(y)).getFilters().size();filtNum++){
|
164
|
if(fieldsValues.getColumnsDataList().get(whoToEnable.get(y)).getFilters().get(filtNum).isEnabled()){
|
165
|
if(filtNum!=0){
|
166
|
URL_theme1 = URL_theme1.concat(",");
|
167
|
}
|
168
|
int counter=0;
|
169
|
URL_theme1=URL_theme1.concat("{\"name\":\""+fieldsValues.getColumnsDataList().get(whoToEnable.get(y)).getFilters().get(filtNum).getFieldValue()+"\",");
|
170
|
if(fieldsValues.getColumnsDataList().get(whoToEnable.get(y)).getFilters().get(filtNum).getType().equals("Discrete")){
|
171
|
URL_theme1 = URL_theme1.concat("\"values\":[");
|
172
|
for(int discNum=0;discNum<fieldsValues.getColumnsDataList().get(whoToEnable.get(y)).getFilters().get(filtNum).getDiscreteValues().size();discNum++){
|
173
|
if(counter>0){
|
174
|
URL_theme1 = URL_theme1.concat(",");
|
175
|
}
|
176
|
URL_theme1 = URL_theme1.concat("\""+fieldsValues.getColumnsDataList().get(whoToEnable.get(y)).getFilters().get(filtNum).getDiscreteValues().get(discNum)+"\"");
|
177
|
counter++;
|
178
|
}
|
179
|
|
180
|
URL_theme1 = URL_theme1.concat("],");
|
181
|
}else if(fieldsValues.getColumnsDataList().get(whoToEnable.get(y)).getFilters().get(filtNum).getType().equals("Continuous")){
|
182
|
URL_theme1 = URL_theme1.concat("\"max\":\""+fieldsValues.getColumnsDataList().get(whoToEnable.get(y)).getFilters().get(filtNum).getValueTo()+"\",\"min\":\""+fieldsValues.getColumnsDataList().get(whoToEnable.get(y)).getFilters().get(filtNum).getValueFrom()+"\",");
|
183
|
}
|
184
|
URL_theme1 = URL_theme1.concat("\"to\":\"-1\"}");
|
185
|
|
186
|
}
|
187
|
}
|
188
|
URL_theme1=URL_theme1.concat("]");
|
189
|
}
|
190
|
|
191
|
|
192
|
if(y!=whoToEnable.size()-1){
|
193
|
URL_theme1=URL_theme1.concat("},");
|
194
|
}else{
|
195
|
URL_theme1=URL_theme1.concat("}");
|
196
|
}
|
197
|
|
198
|
}
|
199
|
|
200
|
URL_theme1=URL_theme1.concat("]");
|
201
|
|
202
|
int option = fieldsValues.getOptionSelected();
|
203
|
|
204
|
URL_theme1 = URL_theme1.concat("&info_types=[");
|
205
|
boolean percent = false;
|
206
|
boolean normal = false;
|
207
|
boolean steps = false;
|
208
|
boolean threeD = false;
|
209
|
boolean donut = false;
|
210
|
boolean none = false;
|
211
|
|
212
|
for(int i=0;i<whoToEnable.size();i++){
|
213
|
URL_theme1 = URL_theme1.concat("\""+fieldsValues.getColumnsDataList().get(whoToEnable.get(i)).getTypeOfChart()+"\"");
|
214
|
if(i!=whoToEnable.size()-1){
|
215
|
URL_theme1 = URL_theme1.concat(",");
|
216
|
}else{
|
217
|
URL_theme1 = URL_theme1.concat("]");
|
218
|
}
|
219
|
if(ValuesOfFields.getInstance().getColumnsDataList().get(whoToEnable.get(i)).getStacking().equals("donut")){
|
220
|
donut=true;
|
221
|
}else if(ValuesOfFields.getInstance().getColumnsDataList().get(whoToEnable.get(i)).getStacking().equals("normal")){
|
222
|
normal=true;
|
223
|
}else if(ValuesOfFields.getInstance().getColumnsDataList().get(whoToEnable.get(i)).getStacking().equals("percent")){
|
224
|
percent = true;
|
225
|
}else if(ValuesOfFields.getInstance().getColumnsDataList().get(whoToEnable.get(i)).getStacking().equals("steps")){
|
226
|
steps = true;
|
227
|
}else if(ValuesOfFields.getInstance().getColumnsDataList().get(whoToEnable.get(i)).getStacking().equals("3D")){
|
228
|
threeD=true;
|
229
|
}else if(ValuesOfFields.getInstance().getColumnsDataList().get(whoToEnable.get(i)).getStacking().equals("none")){
|
230
|
none=true;
|
231
|
}
|
232
|
}
|
233
|
|
234
|
if(percent){
|
235
|
URL_theme1 = URL_theme1.concat("&stacking=percent");
|
236
|
}else if(normal){
|
237
|
URL_theme1 = URL_theme1.concat("&stacking=normal");
|
238
|
}else if(donut){
|
239
|
URL_theme1 = URL_theme1.concat("&stacking=donut");
|
240
|
}else if(none){
|
241
|
URL_theme1 = URL_theme1.concat("&stacking=");
|
242
|
}
|
243
|
|
244
|
percent = false;
|
245
|
normal = false;
|
246
|
steps = false;
|
247
|
threeD = false;
|
248
|
donut = false;
|
249
|
|
250
|
if(steps){
|
251
|
URL_theme1 = URL_theme1.concat("&steps=true");
|
252
|
}else{
|
253
|
URL_theme1 = URL_theme1.concat("&steps=false");
|
254
|
}
|
255
|
URL_theme1 = URL_theme1.concat("&fontFamily="+fieldsValues.getFontFamily());
|
256
|
URL_theme1 = URL_theme1.concat("&spacing=["+fieldsValues.getSpacingTop()+","+fieldsValues.getSpacingRight()+","+fieldsValues.getSpacingBottom()+","+fieldsValues.getSpacingLeft()+"]");
|
257
|
URL_theme1 = URL_theme1.concat("&style=[{\"color\":\""+fieldsValues.getColorTitle()+"\",\"size\":\""+fieldsValues.getSizeTitle()+"\"},{\"color\":\""+fieldsValues.getColorSubtitle()+"\",\"size\":\""+fieldsValues.getSizeSubtitle()+"\"},{\"color\":\""+fieldsValues.getColorXaxis()+"\",\"size\":\""+fieldsValues.getSizeXaxis()+"\"},{\"color\":\""+fieldsValues.getColorYaxis()+"\",\"size\":\""+fieldsValues.getSizeYaxis()+"\"}]");
|
258
|
if(fieldsValues.getChartBackgroundColor().equals("")){
|
259
|
URL_theme1 = URL_theme1.concat("&backgroundColor=rgba(255,255,255,1)");
|
260
|
}else{
|
261
|
URL_theme1 = URL_theme1.concat("&backgroundColor="+fieldsValues.getChartBackgroundColor()+"");
|
262
|
}
|
263
|
|
264
|
// URL_theme1 = URL_theme1.concat("&colors[");
|
265
|
for(int colors=0;colors<10;colors++){
|
266
|
URL_theme1 = URL_theme1.concat("&colors[]="+fieldsValues.getColors()[colors]);
|
267
|
// if(colors!=9){
|
268
|
// URL_theme1 = URL_theme1.concat(",");
|
269
|
// }
|
270
|
}
|
271
|
// URL_theme1 = URL_theme1.concat("]");
|
272
|
|
273
|
URL_theme2=URL_theme1;
|
274
|
URL_theme3=URL_theme1;
|
275
|
|
276
|
|
277
|
RootPanel.get("highchart").addStyleName("loading");
|
278
|
|
279
|
RootPanel.get("highchart").add(loader_big);
|
280
|
RootPanel.get("highchart").add(whiteFilm);
|
281
|
|
282
|
RootPanel.get("tableChart").addStyleName("loading");
|
283
|
|
284
|
RootPanel.get("tableChart").add(whiteFilm_table);
|
285
|
RootPanel.get("tableChart").add(loader_big_table);
|
286
|
|
287
|
|
288
|
timer = new Timer() {
|
289
|
|
290
|
@Override
|
291
|
public void run() {
|
292
|
infoHeading.setText("We are processing your request, please wait..");
|
293
|
}
|
294
|
};
|
295
|
timer.schedule(10000);
|
296
|
|
297
|
|
298
|
this.getTheme1().setUrl(URL.encode(URL_theme1));
|
299
|
this.getThemeForTable().setUrl(URL.encode(URL_theme1.replace("merge.php", "infoForTable_new.php")));
|
300
|
//generateTableURLs(fieldsValues,URL_theme1);
|
301
|
|
302
|
|
303
|
|
304
|
if(WhoToReturn==1){
|
305
|
return URL_theme1;
|
306
|
}else if(WhoToReturn==2){
|
307
|
return URL_theme2;
|
308
|
}else if(WhoToReturn==3){
|
309
|
return URL_theme3;
|
310
|
}else{
|
311
|
return null;
|
312
|
}
|
313
|
|
314
|
}
|
315
|
|
316
|
public String generateTableURLs(ValuesOfFields fieldsValues,String URL){
|
317
|
|
318
|
new DataBox(URL.replace("merge.php", "infoForTable.php"));
|
319
|
|
320
|
return URL;
|
321
|
|
322
|
}
|
323
|
|
324
|
}
|