901 |
aurelien |
1 |
package org.tela_botanica.del.client.composants.votes.details;
|
|
|
2 |
|
1104 |
gduche |
3 |
import java.util.Date;
|
901 |
aurelien |
4 |
import java.util.Iterator;
|
|
|
5 |
import java.util.List;
|
|
|
6 |
import java.util.Map;
|
|
|
7 |
|
|
|
8 |
import org.tela_botanica.del.client.i18n.I18n;
|
1102 |
gduche |
9 |
import org.tela_botanica.del.client.modeles.MoyenneVote;
|
901 |
aurelien |
10 |
import org.tela_botanica.del.client.modeles.PropositionDetermination;
|
|
|
11 |
import org.tela_botanica.del.client.modeles.VoteDetermination;
|
1102 |
gduche |
12 |
import org.tela_botanica.del.client.services.CalculVoteDeterminationService;
|
901 |
aurelien |
13 |
|
|
|
14 |
import com.google.gwt.core.client.GWT;
|
|
|
15 |
import com.google.gwt.i18n.client.DateTimeFormat;
|
|
|
16 |
import com.google.gwt.i18n.client.DateTimeFormat.PredefinedFormat;
|
|
|
17 |
import com.google.gwt.uibinder.client.UiBinder;
|
|
|
18 |
import com.google.gwt.uibinder.client.UiField;
|
1765 |
mathias |
19 |
import com.google.gwt.user.client.Window;
|
901 |
aurelien |
20 |
import com.google.gwt.user.client.ui.Composite;
|
|
|
21 |
import com.google.gwt.user.client.ui.FlexTable;
|
|
|
22 |
import com.google.gwt.user.client.ui.HTML;
|
|
|
23 |
import com.google.gwt.user.client.ui.HTMLPanel;
|
1102 |
gduche |
24 |
import com.google.gwt.user.client.ui.HasWidgets;
|
|
|
25 |
import com.google.gwt.user.client.ui.Label;
|
901 |
aurelien |
26 |
import com.google.gwt.user.client.ui.Panel;
|
|
|
27 |
import com.google.gwt.user.client.ui.Widget;
|
|
|
28 |
|
|
|
29 |
public class DetailListeVotesDeterminationVue extends Composite implements DetailListeVotesDeterminationPresenteur.Vue {
|
|
|
30 |
|
|
|
31 |
private static DetailListeVotesDeterminationVueUIiBinder uiBinder = GWT.create(DetailListeVotesDeterminationVueUIiBinder.class);
|
|
|
32 |
|
|
|
33 |
interface DetailListeVotesDeterminationVueUIiBinder extends UiBinder<Widget, DetailListeVotesDeterminationVue> {
|
|
|
34 |
};
|
|
|
35 |
|
|
|
36 |
@UiField
|
1102 |
gduche |
37 |
HTMLPanel titre, auteur, aucuneDonnees, detailVotePour, detailVoteContre;
|
901 |
aurelien |
38 |
|
|
|
39 |
@UiField
|
1104 |
gduche |
40 |
Label scorePour, scoreContre, date;
|
1102 |
gduche |
41 |
|
|
|
42 |
@UiField
|
901 |
aurelien |
43 |
Panel panneauChargement;
|
|
|
44 |
|
|
|
45 |
public DetailListeVotesDeterminationVue() {
|
|
|
46 |
initWidget(uiBinder.createAndBindUi(this));
|
|
|
47 |
}
|
1104 |
gduche |
48 |
|
|
|
49 |
public String formaterDate(String dateNonFormatee) {
|
|
|
50 |
try {
|
1765 |
mathias |
51 |
DateTimeFormat parseur = DateTimeFormat.getFormat("yyyy-dd-MM HH:mm:ss");
|
|
|
52 |
Date date = parseur.parse(dateNonFormatee);
|
|
|
53 |
|
|
|
54 |
DateTimeFormat formateur = DateTimeFormat.getFormat("dd/MM/yyyy");
|
|
|
55 |
return formateur.format(date);
|
1104 |
gduche |
56 |
} catch (IllegalArgumentException e) {
|
|
|
57 |
return "";
|
|
|
58 |
}
|
|
|
59 |
}
|
1765 |
mathias |
60 |
|
|
|
61 |
public String formaterDateQuiEstVraimentUneDateEtPasUnString(Date dateNonFormatee) {
|
|
|
62 |
String retour = "";
|
|
|
63 |
try {
|
|
|
64 |
DateTimeFormat formateur = DateTimeFormat.getFormat("dd/MM/yyyy");
|
|
|
65 |
retour = formateur.format(dateNonFormatee);
|
|
|
66 |
} catch (IllegalArgumentException e) {
|
|
|
67 |
}
|
|
|
68 |
return retour;
|
|
|
69 |
}
|
901 |
aurelien |
70 |
|
|
|
71 |
@Override
|
|
|
72 |
public void afficherVotes(PropositionDetermination propositionDetermination) {
|
|
|
73 |
|
|
|
74 |
HTML htmlTitre = new HTML(propositionDetermination.getEspece());
|
|
|
75 |
titre.add(htmlTitre);
|
|
|
76 |
|
973 |
aurelien |
77 |
HTML htmlAuteur = new HTML(I18n.getVocabulary().proposePar()+propositionDetermination.getAuteur());
|
|
|
78 |
auteur.add(htmlAuteur);
|
1765 |
mathias |
79 |
|
|
|
80 |
Date datePropDet = propositionDetermination.getDate();
|
|
|
81 |
String date = formaterDateQuiEstVraimentUneDateEtPasUnString(datePropDet);
|
1104 |
gduche |
82 |
this.date.setText(date);
|
|
|
83 |
|
901 |
aurelien |
84 |
Map<String, VoteDetermination> listeVotes = propositionDetermination.getVotesDeterminations();
|
|
|
85 |
|
1102 |
gduche |
86 |
int votesAnonymesPour = 0;
|
|
|
87 |
int votesAnonymesContre = 0;
|
1139 |
aurelien |
88 |
MoyenneVote moyenne = CalculVoteDeterminationService.calculerMoyenneVoteDetermination(propositionDetermination, listeVotes.size());
|
1150 |
aurelien |
89 |
scorePour.setText(moyenne.getScore()+"%");
|
|
|
90 |
scoreContre.setText((100 - moyenne.getScore())+"%");
|
1102 |
gduche |
91 |
|
901 |
aurelien |
92 |
for (Iterator<String> iterator = listeVotes.keySet().iterator(); iterator.hasNext();) {
|
1102 |
gduche |
93 |
VoteDetermination voteDetermination = listeVotes.get(iterator.next());
|
|
|
94 |
if (voteDetermination.getVote() == 1) {
|
|
|
95 |
//Votes pour
|
|
|
96 |
if (voteDetermination.getAuteur() != null) {
|
|
|
97 |
ajouterVote(voteDetermination, detailVotePour);
|
|
|
98 |
} else {
|
|
|
99 |
votesAnonymesPour++;
|
|
|
100 |
}
|
|
|
101 |
} else {
|
|
|
102 |
//Votes contre
|
|
|
103 |
if (voteDetermination.getAuteur() != null) {
|
|
|
104 |
ajouterVote(voteDetermination, detailVoteContre);
|
|
|
105 |
} else {
|
|
|
106 |
votesAnonymesContre++;
|
|
|
107 |
}
|
|
|
108 |
}
|
901 |
aurelien |
109 |
}
|
|
|
110 |
|
1102 |
gduche |
111 |
if (votesAnonymesPour > 0) {
|
|
|
112 |
LigneVotePresenteur presenteurVote= new LigneVotePresenteur(new LigneVoteVue(), votesAnonymesPour);
|
|
|
113 |
presenteurVote.go(detailVotePour);
|
901 |
aurelien |
114 |
}
|
|
|
115 |
|
1102 |
gduche |
116 |
if (votesAnonymesContre > 0) {
|
|
|
117 |
LigneVotePresenteur presenteurVote= new LigneVotePresenteur(new LigneVoteVue(), votesAnonymesContre);
|
|
|
118 |
presenteurVote.go(detailVoteContre);
|
901 |
aurelien |
119 |
}
|
|
|
120 |
}
|
|
|
121 |
|
1102 |
gduche |
122 |
public void ajouterVote(VoteDetermination vote, HasWidgets panel) {
|
|
|
123 |
LigneVotePresenteur presenteurVote = new LigneVotePresenteur(new LigneVoteVue(), vote);
|
|
|
124 |
presenteurVote.go(panel);
|
|
|
125 |
}
|
|
|
126 |
|
901 |
aurelien |
127 |
@Override
|
|
|
128 |
public void startChargement() {
|
|
|
129 |
panneauChargement.setHeight((this.getOffsetHeight()/2)+"px");
|
|
|
130 |
panneauChargement.setWidth((this.getOffsetWidth()/2)+"px");
|
|
|
131 |
panneauChargement.setVisible(true);
|
|
|
132 |
}
|
|
|
133 |
|
|
|
134 |
@Override
|
|
|
135 |
public void stopChargement() {
|
|
|
136 |
panneauChargement.setVisible(false);
|
|
|
137 |
}
|
909 |
aurelien |
138 |
|
|
|
139 |
@Override
|
|
|
140 |
public void afficherAucuneDonnees() {
|
|
|
141 |
aucuneDonnees.setVisible(true);
|
|
|
142 |
}
|
901 |
aurelien |
143 |
}
|