From c1a76525c3c05a5e2b50611c6bad62b101b7e578 Mon Sep 17 00:00:00 2001 From: Christopher Tate Date: Sun, 19 Jan 2025 04:10:05 +0000 Subject: [PATCH] Adding a default location for smart data models --- .../org/computate/frFR/java/EcrireGenClasse.java | 6 +++--- .../computate/frFR/java/EcrirePageClasse.java | 16 +++++++--------- .../org/computate/frFR/java/IndexerClasse.java | 6 +++++- 3 files changed, 15 insertions(+), 13 deletions(-) diff --git a/src/main/java/org/computate/frFR/java/EcrireGenClasse.java b/src/main/java/org/computate/frFR/java/EcrireGenClasse.java index dea7e72..f59830d 100644 --- a/src/main/java/org/computate/frFR/java/EcrireGenClasse.java +++ b/src/main/java/org/computate/frFR/java/EcrireGenClasse.java @@ -5553,15 +5553,15 @@ else if(entiteIndexe wNgsiMethode.tl(2, "case VAR_", entiteVar, ":"); if("Point".equals(entiteNomSimple)) { - wNgsiMethode.tl(3, "return new JsonObject().put(\"type\", \"Point\").put(\"coordinates\", new JsonArray().add(Double.valueOf(o.get", entiteVarCapitalise, "().getX())).add(Double.valueOf(o.get", entiteVarCapitalise, "().getY()))).toString();"); + wNgsiMethode.tl(3, "return new JsonObject().put(\"type\", \"Point\").put(\"coordinates\", new JsonArray().add(Double.valueOf(o.get", entiteVarCapitalise, "().getX())).add(Double.valueOf(o.get", entiteVarCapitalise, "().getY())));"); } else if("Path".equals(entiteNomSimple)) { wNgsiMethode.tl(3, "JsonArray pointsArray", entiteVarCapitalise, " = new JsonArray();"); wNgsiMethode.tl(3, "o.get", entiteVarCapitalise, "().getPoints().stream().map(point -> new JsonArray().add(Double.valueOf(point.getX())).add(Double.valueOf(point.getY()))).collect(Collectors.toList()).forEach(pointArray -> pointsArray", entiteVarCapitalise, ".add(pointArray));"); - wNgsiMethode.tl(3, "return new JsonObject().put(\"type\", \"LineString\").put(\"coordinates\", pointsArray", entiteVarCapitalise, ").toString();"); + wNgsiMethode.tl(3, "return new JsonObject().put(\"type\", \"LineString\").put(\"coordinates\", pointsArray", entiteVarCapitalise, ");"); } else if("Polygon".equals(entiteNomSimple)) { wNgsiMethode.tl(3, "JsonArray pointsArray", entiteVarCapitalise, " = new JsonArray();"); wNgsiMethode.tl(3, "o.get", entiteVarCapitalise, "().getPoints().stream().map(point -> new JsonArray().add(Double.valueOf(point.getX())).add(Double.valueOf(point.getY()))).collect(Collectors.toList()).forEach(pointArray -> pointsArray", entiteVarCapitalise, ".add(pointArray));"); - wNgsiMethode.tl(3, "return new JsonObject().put(\"type\", \"LineString\").put(\"coordinates\", pointsArray", entiteVarCapitalise, ").toString();"); + wNgsiMethode.tl(3, "return new JsonObject().put(\"type\", \"LineString\").put(\"coordinates\", pointsArray", entiteVarCapitalise, ");"); } else { wNgsiMethode.tl(3, "return o.get", entiteVarCapitalise, "();"); } diff --git a/src/main/java/org/computate/frFR/java/EcrirePageClasse.java b/src/main/java/org/computate/frFR/java/EcrirePageClasse.java index 8aa8790..75729b4 100644 --- a/src/main/java/org/computate/frFR/java/EcrirePageClasse.java +++ b/src/main/java/org/computate/frFR/java/EcrirePageClasse.java @@ -1919,12 +1919,10 @@ public void pageCodeClasseJava(String langueNom, JsonObject langueConfig) throws if(classePageSuperNomSimple != null) tl(1, "@Override"); tl(1, "protected void _DEFAULT_MAP_LOCATION(", classePartsCouverture.nomSimple(langueNom), " ", langueConfig.getString(I18n.var_cVar), ") {"); - tl(2, "String pointStr = Optional.ofNullable(", langueConfig.getString(I18n.var_requeteSite), "_.get", langueConfig.getString(I18n.var_Requete), "Vars().get(VAR_DEFAULT_MAP_LOCATION)).orElse(", langueConfig.getString(I18n.var_requeteSite), "_.getConfig().getString(", classePartsConfigCles.nomSimple(langueNom), ".DEFAULT_MAP_LOCATION));"); - tl(2, "if(pointStr != null) {"); - tl(3, "String[] parts = pointStr.replace(\"[\", \"\").replace(\"]\", \"\").replace(\"\\\"\", \"\").split(\",\");"); - tl(3, "JsonObject point = new JsonObject().put(\"lat\", Double.parseDouble(parts[0])).put(\"lon\", Double.parseDouble(parts[1]));"); - tl(3, langueConfig.getString(I18n.var_cVar), ".o(point);"); - tl(2, "}"); + if(classeVarEmplacement != null) { + tl(2, "Point point = ", classeNomSimple, ".staticSet", StringUtils.capitalize(classeVarEmplacement), "(", langueConfig.getString(I18n.var_requeteSite), "_, Optional.ofNullable(", langueConfig.getString(I18n.var_requeteSite), "_.get", langueConfig.getString(I18n.var_Requete), "Vars().get(VAR_DEFAULT_MAP_LOCATION)).orElse(", langueConfig.getString(I18n.var_requeteSite), "_.getConfig().getString(", classePartsConfigCles.nomSimple(langueNom), ".DEFAULT_MAP_LOCATION)));"); + tl(2, "w.o(new JsonObject().put(\"type\", \"Point\").put(\"coordinates\", new JsonArray().add(Double.valueOf(point.getX())).add(Double.valueOf(point.getY()))));"); + } tl(1, "}"); l(); if(classePageSuperNomSimple != null) @@ -2884,7 +2882,7 @@ public void ecrirePageHeadJinja(String langueNom, JsonObject i18nPage, Boolean e // tl(3, "document.querySelector('#site-calendar-box').accordion({ collapsible: true, active: false });"); l("{% if DEFAULT_MAP_LOCATION is defined %}"); - tl(3, "window.DEFAULT_MAP_LOCATION = { lat: {{ DEFAULT_MAP_LOCATION.lat }}, lon: {{ DEFAULT_MAP_LOCATION.lon }} };"); + tl(3, "window.DEFAULT_MAP_LOCATION = { type: 'Point', coordinates: [ {{ DEFAULT_MAP_LOCATION.coordinates[0] }}, {{ DEFAULT_MAP_LOCATION.coordinates[1] }} ]};"); l("{% endif %}"); l("{% if DEFAULT_MAP_ZOOM is defined %}"); tl(3, "window.DEFAULT_MAP_ZOOM = {{ DEFAULT_MAP_ZOOM }};"); @@ -3833,11 +3831,11 @@ else if(entiteAttribuer) { auteurPageJs.tl(3, "}).addTo(window.map", classeNomSimple, ");"); auteurPageJs.l(); auteurPageJs.tl(3, "if(window['DEFAULT_MAP_LOCATION'] && window['DEFAULT_MAP_ZOOM'])"); - auteurPageJs.tl(4, "window.map", classeNomSimple, ".setView([window['DEFAULT_MAP_LOCATION']['lat'], window['DEFAULT_MAP_LOCATION']['lon']], window['DEFAULT_MAP_ZOOM']);"); + auteurPageJs.tl(4, "window.map", classeNomSimple, ".setView([window['DEFAULT_MAP_LOCATION']['coordinates'][1], window['DEFAULT_MAP_LOCATION']['coordinates'][0]], window['DEFAULT_MAP_ZOOM']);"); auteurPageJs.tl(3, "else if(window['DEFAULT_MAP_ZOOM'])"); auteurPageJs.tl(4, "window.map", classeNomSimple, ".setView(null, window['DEFAULT_MAP_ZOOM']);"); auteurPageJs.tl(3, "else if(window['DEFAULT_MAP_LOCATION'])"); - auteurPageJs.tl(4, "window.map", classeNomSimple, ".setView([window['DEFAULT_MAP_LOCATION']['lat'], window['DEFAULT_MAP_LOCATION']['lon']]);"); + auteurPageJs.tl(4, "window.map", classeNomSimple, ".setView([window['DEFAULT_MAP_LOCATION']['coordinates'][1], window['DEFAULT_MAP_LOCATION']['coordinates'][0]]);"); auteurPageJs.l(); auteurPageJs.tl(3, "layout['margin'] = { r: 0, t: 0, b: 0, l: 0 };"); auteurPageJs.tl(3, "window.geoJSON", classeNomSimple, " = L.geoJSON().addTo(window.map", classeNomSimple, ");"); diff --git a/src/main/java/org/computate/frFR/java/IndexerClasse.java b/src/main/java/org/computate/frFR/java/IndexerClasse.java index 7b349df..5f2b943 100644 --- a/src/main/java/org/computate/frFR/java/IndexerClasse.java +++ b/src/main/java/org/computate/frFR/java/IndexerClasse.java @@ -6417,7 +6417,11 @@ else if("location".equals(fieldName)) wSmartDataModel.l(" * HtmCell: ", cell, ""); wSmartDataModel.l(" * Facet: true"); wSmartDataModel.l(" **/"); - wSmartDataModel.l(" protected void _", fieldName, "(Wrap<", javaType, "> w) {}"); + wSmartDataModel.l(" protected void _", fieldName, "(Wrap<", javaType, "> w) {"); + if("location".equals(fieldName)) { + wSmartDataModel.l(" w.o(staticSetLocation(siteRequest_, siteRequest_.getConfig().getString(ComputateConfigKeys.DEFAULT_MAP_LOCATION)));"); + } + wSmartDataModel.l(" }"); } cell++; // if(cell > 3) {