Subversion Repositories eFlore/Applications.del

Rev

Rev 1467 | Rev 1501 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
9 benjamin 1
package org.tela_botanica.del.client.cache;
2
 
1467 aurelien 3
import java.util.Arrays;
814 aurelien 4
import java.util.List;
5
 
1467 aurelien 6
import org.tela_botanica.del.client.config.Config;
1092 gduche 7
import org.tela_botanica.del.client.gestionhistorique.ConstantesNavigation;
147 benjamin 8
import org.tela_botanica.del.client.modeles.Image;
335 benjamin 9
import org.tela_botanica.del.client.modeles.InformationsRecherche;
1496 aurelien 10
import org.tela_botanica.del.client.modeles.ModeTri;
9 benjamin 11
import org.tela_botanica.del.client.modeles.Observation;
178 benjamin 12
import org.tela_botanica.del.client.modeles.Protocole;
537 gduche 13
import org.tela_botanica.del.client.modeles.Utilisateur;
9 benjamin 14
 
1467 aurelien 15
import com.google.gwt.core.client.GWT;
16
import com.google.gwt.user.client.Window;
1118 gduche 17
import com.google.gwt.user.client.Window.Location;
18
 
14 benjamin 19
public class CacheClient {
9 benjamin 20
 
814 aurelien 21
	private List<Protocole> listeProtocoles;
22
 
1092 gduche 23
	private String home = ConstantesNavigation.PAGE_RECHERCHE_OBSERVATIONS;
230 gduche 24
	private Observation observationCourante;
147 benjamin 25
	private Image imageCourante;
73 benjamin 26
	private String taxonPourRechercheEflore;
178 benjamin 27
	private Protocole protocoleCourant;
1367 aurelien 28
	private String referentielCourant;
147 benjamin 29
	private int numPageRechercheImage = 0;
349 aurelien 30
	private int nbTotalImagesRecherchees = 0;
1367 aurelien 31
 
32
	private boolean referentielNonModifiable = false;
335 benjamin 33
 
579 gduche 34
	private int pasPagination = 12;
445 benjamin 35
	private int pageCouranteRechercheImage = 1;
36
	private int pageCouranteRechercheObservations = 1;
335 benjamin 37
	private InformationsRecherche informationsRechercheImage;
38
	private InformationsRecherche informationsRechercheObservation;
537 gduche 39
	private Utilisateur utilisateur;
1129 gduche 40
	private String pageCourante = home;
1234 gduche 41
	private String statut;
1467 aurelien 42
	private String[] statutsPossibles = {ConstantesNavigation.PARAM_TYPE_TOUS,
43
										ConstantesNavigation.PARAM_TYPE_A_DETERMINER,
44
										ConstantesNavigation.PARAM_TYPE_EN_DISCUSSION,
45
										ConstantesNavigation.PARAM_TYPE_VALIDEES};
1129 gduche 46
 
1234 gduche 47
	public void supprimerFiltreStatut() {
48
		this.statut = null;
49
	}
50
 
51
	public void setFiltreStatut(String statut) {
52
		this.statut = statut;
53
	}
54
 
55
	public String getFiltreStatut() {
56
		return this.statut;
57
	}
58
 
1129 gduche 59
	public String getPageCourante() {
60
		return pageCourante;
61
	}
335 benjamin 62
 
1129 gduche 63
	public void setPageCourante(String pageCourante) {
64
		this.pageCourante = pageCourante;
65
	}
66
 
14 benjamin 67
	private static CacheClient instance;
9 benjamin 68
 
14 benjamin 69
	private CacheClient() {
9 benjamin 70
		instance = this;
71
	}
72
 
1118 gduche 73
	public void initialiserAvecParametres() {
1129 gduche 74
		String rechercheLibre = Location.getParameter("masque");
75
		String famille = Location.getParameter("masque.famille");
76
		String taxon = Location.getParameter("masque.ns");
77
		String genre = Location.getParameter("masque.genre");
78
		String commune = Location.getParameter("masque.commune");
79
		String dept = Location.getParameter("masque.departement");
80
		String auteur = Location.getParameter("masque.auteur");
81
		String date = Location.getParameter("masque.date");
82
		String tag = Location.getParameter("masque.tag");
1426 aurelien 83
		String tagCel = Location.getParameter("masque.tag_cel");
84
		String tagDel = Location.getParameter("masque.tag_pictoflora");
1367 aurelien 85
		String referentiel = Location.getParameter("masque.referentiel");
1118 gduche 86
 
1467 aurelien 87
		String statutParam = Location.getParameter("masque.type");
88
 
1118 gduche 89
		InformationsRecherche rechercheParArguments = new InformationsRecherche();
90
		rechercheParArguments.setRechercheLibre(rechercheLibre);
91
		rechercheParArguments.setFamille(famille);
92
		rechercheParArguments.setTaxon(taxon);
93
		rechercheParArguments.setGenre(genre);
94
		rechercheParArguments.setCommune(commune);
95
		rechercheParArguments.setDepartement(dept);
96
		rechercheParArguments.setAuteur(auteur);
97
		rechercheParArguments.setDate(date);
98
		rechercheParArguments.setTag(tag);
1426 aurelien 99
		if(pageCourante.equals(ConstantesNavigation.PAGE_RECHERCHE_IMAGES)) {
100
			rechercheParArguments.setMotClefCel(tagCel);
101
			rechercheParArguments.setMotClefDel(tagDel);
102
		}
1467 aurelien 103
 
1496 aurelien 104
 
105
		String tri = Location.getParameter("tri");
106
		String ordre = Location.getParameter("ordre");
107
 
108
		if(tri != null) {
109
			ModeTri modeTri = ModeTri.TRI_ASCENDANT;
110
			if(ordre.equals("asc")) {
111
				modeTri = ModeTri.TRI_ASCENDANT;
112
			}
113
 
114
			if(ordre.equals("desc")) {
115
				modeTri = ModeTri.TRI_DESCENDANT;
116
			}
117
 
118
			if(tri.equals("votes")) {
119
				rechercheParArguments.setTriParNbVotes(modeTri);
120
			}
121
 
122
			if(tri.equals("tags")) {
123
				rechercheParArguments.setTriParNbTags(modeTri);
124
			}
125
 
126
			if(tri.equals("date_observation")) {
127
				rechercheParArguments.setTriParDate(modeTri);
128
			}
129
 
130
		}
131
 
1118 gduche 132
		rechercheParArguments.setMotClef(tag);
133
 
1367 aurelien 134
		// si le référentiel est passé dans l'url alors il ne doit pas être modifiable
135
		if(referentiel != null && !referentiel.equals("")) {
136
			setReferentielCourant(referentiel);
137
			rechercheParArguments.setReferentiel(referentiel);
138
			referentielNonModifiable = true;
139
		}
140
 
1467 aurelien 141
		if(Location.getParameterMap().size() == 0) {
142
			// par défaut l'application s'ouvre sur l'onglet à déterminer
143
			statut = ConstantesNavigation.PARAM_TYPE_DEFAUT;
144
		} else {
145
			if(Arrays.asList(statutsPossibles).contains(statutParam)) {
146
				statut = statutParam;
147
			} else {
148
				statut = ConstantesNavigation.PARAM_TYPE_DEFAUT;
149
			}
150
		}
151
 
1118 gduche 152
		informationsRechercheImage = rechercheParArguments;
153
		informationsRechercheObservation = rechercheParArguments;
154
	}
155
 
537 gduche 156
	public Utilisateur getUtilisateur() {
157
		if (this.utilisateur == null) {
1496 aurelien 158
			this.utilisateur = new Utilisateur(null, null);
537 gduche 159
		}
160
		return this.utilisateur;
161
	}
162
 
163
	public void setUtilisateur(Utilisateur utilisateur) {
164
		this.utilisateur = utilisateur;
165
	}
166
 
1092 gduche 167
	public void setHome(String home) {
168
		this.home = home;
1129 gduche 169
		setPageCourante(home);
1092 gduche 170
	}
171
 
172
	public String getHome() {
173
		return home;
174
	}
175
 
230 gduche 176
	public Observation getObservationCourante() {
177
		return observationCourante;
9 benjamin 178
	}
179
 
230 gduche 180
	public void setObservationCourante(Observation observationCourante) {
181
		this.observationCourante = observationCourante;
9 benjamin 182
	}
183
 
14 benjamin 184
	public static CacheClient getInstance() {
9 benjamin 185
		if (instance == null) {
14 benjamin 186
			instance = new CacheClient();
9 benjamin 187
		}
188
		return instance;
189
	}
190
 
73 benjamin 191
	public String getTaxonPourRechercheEflore() {
192
		return taxonPourRechercheEflore;
193
	}
194
 
195
	public void setTaxonPourRechercheEflore(String taxonPourRechercheEflore) {
196
		this.taxonPourRechercheEflore = taxonPourRechercheEflore;
197
	}
198
 
147 benjamin 199
	public int getNumPageRechercheImage() {
200
		return numPageRechercheImage;
201
	}
202
 
335 benjamin 203
	// Pour la recherche :
311 gduche 204
	public int getPasPagination() {
205
		return pasPagination;
147 benjamin 206
	}
335 benjamin 207
 
311 gduche 208
	public void setPasPagination(int pasPagination) {
209
		this.pasPagination = pasPagination;
147 benjamin 210
	}
335 benjamin 211
 
358 benjamin 212
	public void setPageCouranteRechercheImages(int pageCouranteRecherche) {
213
		this.pageCouranteRechercheImage = pageCouranteRecherche;
311 gduche 214
	}
335 benjamin 215
 
358 benjamin 216
	public int getPageCouranteRechercheImage() {
217
		return this.pageCouranteRechercheImage;
311 gduche 218
	}
147 benjamin 219
 
349 aurelien 220
	public void setNbTotalImagesRecherchees(int nbTotalImagesRecherchees) {
221
		this.nbTotalImagesRecherchees = nbTotalImagesRecherchees;
222
	}
361 benjamin 223
 
349 aurelien 224
	public int getNbTotalImagesRecherchees() {
225
		return this.nbTotalImagesRecherchees;
226
	}
147 benjamin 227
 
228
	public Image getImageCourante() {
229
		return imageCourante;
230
	}
231
 
232
	public void setImageCourante(Image imageCourante) {
233
		this.imageCourante = imageCourante;
234
	}
814 aurelien 235
 
236
	public void setListeProtocoles(List<Protocole> listeProtocole) {
237
		this.listeProtocoles = listeProtocole;
238
	}
239
 
240
	public List<Protocole> getListeProtocoles() {
241
		return this.listeProtocoles;
242
	}
147 benjamin 243
 
178 benjamin 244
	public Protocole getProtocoleCourant() {
245
		return protocoleCourant;
246
	}
247
 
248
	public void setProtocoleCourant(Protocole protocoleCourant) {
249
		this.protocoleCourant = protocoleCourant;
250
	}
251
 
335 benjamin 252
	public InformationsRecherche getInformationsRechercheImage() {
467 aurelien 253
		if(informationsRechercheImage == null) {
254
			informationsRechercheImage = new InformationsRecherche();
255
		}
335 benjamin 256
		return informationsRechercheImage;
257
	}
258
 
259
	public InformationsRecherche getInformationsRechercheObservation() {
467 aurelien 260
		if(informationsRechercheObservation == null) {
261
			informationsRechercheObservation = new InformationsRecherche();
262
		}
335 benjamin 263
		return informationsRechercheObservation;
264
	}
265
 
266
	public void setInformationsRechercheImage(InformationsRecherche informationsRechercheImage) {
267
		this.informationsRechercheImage = informationsRechercheImage;
268
	}
269
 
270
	public void setInformationsRechercheObservation(InformationsRecherche informationsRechercheObservation) {
271
		this.informationsRechercheObservation = informationsRechercheObservation;
272
	}
273
 
358 benjamin 274
	public int getPageCouranteRechercheObservations() {
275
		return pageCouranteRechercheObservations;
276
	}
277
 
278
	public void setPageCouranteRechercheObservations(int pageCouranteRechercheObservations) {
279
		this.pageCouranteRechercheObservations = pageCouranteRechercheObservations;
280
	}
1367 aurelien 281
 
282
	public void setReferentielCourant(String referentielCourant) {
283
		this.referentielCourant = referentielCourant;
284
	}
285
 
286
	public String getReferentielCourant() {
287
		return referentielCourant;
288
	}
289
 
290
	public void setReferentielNonModifiable(boolean referentielNonModifiable) {
291
		this.referentielNonModifiable = referentielNonModifiable;
292
	}
293
 
294
	public boolean getReferentielNonModifiable() {
295
		return referentielNonModifiable;
296
	}
1467 aurelien 297
 
298
	public String genererUrlCourante() {
299
		String url = Window.Location.getHref();
300
		CacheClient cache = CacheClient.getInstance();
301
 
302
		String arguments = "";
303
		String argumentsRecherche = "";
304
		if (cache.getPageCourante().equals(ConstantesNavigation.PAGE_RECHERCHE_IMAGES)) {
305
 
306
			InformationsRecherche infoRecherche;
307
			infoRecherche = cache.getInformationsRechercheImage();
308
			argumentsRecherche = infoRecherche.versChaineRequete();
309
 
310
			if(!GWT.isScript()) {
311
				argumentsRecherche += "&gwt.codesvr="+Location.getParameter("gwt.codesvr")+"";
312
			}
313
 
314
			argumentsRecherche = (argumentsRecherche.isEmpty()) ? argumentsRecherche : "?" + argumentsRecherche;
315
			arguments = argumentsRecherche + "#" + ConstantesNavigation.PAGE_RECHERCHE_IMAGES;
316
			url = new Config().getUrl("del") + arguments;
317
 
318
			if (CacheClient.getInstance().getProtocoleCourant() != null) {
319
				url += "~"+String.valueOf(CacheClient.getInstance().getProtocoleCourant().getId());
320
			}
321
		} else if (cache.getPageCourante().equals(ConstantesNavigation.PAGE_RECHERCHE_OBSERVATIONS) || cache.getPageCourante().equals("")) {
322
 
323
			InformationsRecherche infoRecherche;
324
			infoRecherche = cache.getInformationsRechercheObservation();
325
			argumentsRecherche = "masque.type="+statut;
326
			argumentsRecherche += "&"+infoRecherche.versChaineRequete();
327
 
328
			if(!GWT.isScript()) {
329
				argumentsRecherche += "&gwt.codesvr="+Location.getParameter("gwt.codesvr")+"";
330
			}
331
			arguments = "?"+argumentsRecherche + "#" + ConstantesNavigation.PAGE_RECHERCHE_OBSERVATIONS;
332
			url = new Config().getUrl("del") + arguments;
333
		} else if (cache.getPageCourante().contains(ConstantesNavigation.PAGE_VALIDATION) || cache.getPageCourante().contains(ConstantesNavigation.PAGE_VALIDATION_PICTOFLORA)) {
334
			url = new Config().getUrl("del");
335
			if(!GWT.isScript()) {
336
				url += "?gwt.codesvr="+Location.getParameter("gwt.codesvr");
337
			}
338
			url += "#"+cache.getPageCourante();
339
		}
340
		// remplacements batards pour corriger l'url
341
		// TODO: factoriser toute la fonction
342
		url = url.replaceAll("&#", "#");
343
		url = url.replaceAll("&&", "&");
344
		url = url.replaceAll("\\?&", "?");
345
 
346
		return url;
347
	}
348
 
349
 
350
	public void mettreAjourUrlCourante() {
351
		mettreAJourUrlCouranteSansRecharger(genererUrlCourante());
352
	}
353
 
354
	private static native void mettreAJourUrlCouranteSansRecharger(String nouvelleUrl) /*-{
355
    	$wnd.history.pushState(nouvelleUrl, "", nouvelleUrl);
356
	}-*/;
357
 
9 benjamin 358
}