diff --git a/webapp/src/cljc/lipas/i18n/generated.cljc b/webapp/src/cljc/lipas/i18n/generated.cljc index 2220488c8..1a5b2b53a 100644 --- a/webapp/src/cljc/lipas/i18n/generated.cljc +++ b/webapp/src/cljc/lipas/i18n/generated.cljc @@ -1018,6 +1018,7 @@ "Yksittäisiä pisteitä voi poistaa pitämällä alt-näppäintä pohjassa ja klikkaamalla pistettä.", :calculate-route-length "Laske reitin pituus automaattisesti", :calculate-area "Laske alueen pinta-ala automaattisesti", + :calculate-count "Laske lukumäärä automaattisesti", :remove-polygon "Poista alue", :modify-linestring "Muokkaa reittiä", :download-gpx "Lataa GPX", @@ -1907,6 +1908,7 @@ Utflyktsmålets administratör ansvarar för uppgifternas riktighet och utflykts "För att ta bort en punkt, tryck och håll alt-knappen och klicka på punkten", :calculate-route-length "Räkna ut längden", :calculate-area "Räkna ytlan" + :calculate-count "Beräkna antal automatiskt" :remove-polygon "Ta bort område", :modify-linestring "Modifera rutten", :download-gpx "Ladda ner GPX", @@ -2876,6 +2878,7 @@ The site administrator is responsible for the accuracy of information, safety of :route-part-difficulty "Set route section difficulty" :calculate-route-length "Calculate route length", :calculate-area "Calculate area", + :calculate-count "Calculate count automatically" :remove-polygon "Remove area", :modify-linestring "Modify route", :download-gpx "Download GPX", diff --git a/webapp/src/cljs/lipas/ui/map/views.cljs b/webapp/src/cljs/lipas/ui/map/views.cljs index c83d98ad7..7910a10aa 100644 --- a/webapp/src/cljs/lipas/ui/map/views.cljs +++ b/webapp/src/cljs/lipas/ui/map/views.cljs @@ -738,11 +738,14 @@ ;; Travel direction (limited to paddling for now) (when (and editing? - edit-activities? + (or can-edit-map? edit-activities?) (#{"LineString"} geom-type) ;; check for activity = paddling? ;; doesn't include 5150 now, but that would be Points - (#{4451 4452} type-code)) + (#{;; paddling routes + 4451 4452 + ;; ski routes + 4402 4440} type-code)) [mui/menu-item {:on-click #(do @@ -987,7 +990,8 @@ :geoms (-> edit-data :location :geometries) :geom-type geom-type :problems? problems? - :key (-> edit-data :type :type-code)}] + :key (-> edit-data :type :type-code) + :pools (:pools edit-data)}] ;; Accessibility 2 [accessibility/view {:lipas-id lipas-id}] diff --git a/webapp/src/cljs/lipas/ui/sports_sites/views.cljs b/webapp/src/cljs/lipas/ui/sports_sites/views.cljs index 60b7f8bf1..aa669c68f 100644 --- a/webapp/src/cljs/lipas/ui/sports_sites/views.cljs +++ b/webapp/src/cljs/lipas/ui/sports_sites/views.cljs @@ -401,6 +401,24 @@ {:on-click #(-> geoms map-utils/calculate-area-km2 on-change)} [:> Calculator]]]]]) +;; TODO: This can replace the previous two cases also +(defn calculate-field + [{:keys [on-change calculate-fn calculate-label]} + children] + [mui/grid + {:container true + :wrap "nowrap"} + [mui/form-group + {:sx {:flexGrow 1 + :justify-content "center"}} + children] + [mui/grid {:item true} + [mui/tooltip {:title calculate-label} + [mui/icon-button + {:on-click (fn [_e] + (on-change (calculate-fn)))} + [:> Calculator]]]]]) + (defn show-calc? [k geom-type] (and (= :route-length-km k) (#{"LineString"} geom-type))) @@ -489,6 +507,8 @@ :items (-> data :edit-data :rinks) :lipas-id (-> data :edit-data :lipas-id)}])])) +;; Used from activities -> lipas-property now +;; Regular perustiedot uses the properties-form directly, which doesn't use this (defn make-prop-field [{:keys [tr prop-k read-only? label description value set-field problems? geom-type geoms]}] @@ -571,7 +591,7 @@ (defn properties-form [{:keys [tr edit-data editing? display-data type-code on-change read-only? - key geoms geom-type problems? width]}] + key geoms geom-type problems? width pools]}] (let [locale (tr) types-props (<== [::subs/types-props type-code]) types-props (if false #_(special-case? type-code) @@ -693,14 +713,43 @@ :disabled disabled? :value-fn first :label-fn (comp locale :label second)}] - :else [lui/text-field - {:value value - :disabled disabled? - :tooltip tooltip - :spec spec - :type (when (#{"numeric" "integer"} data-type) - "number") - :on-change on-change}])}) + + :else + (let [el [lui/text-field + {;; form ->field adds the :label, but that doesn't work + ;; for text-field wrapped inside calculate-field. + ;; just add it directly here. + :label label + :value value + :disabled disabled? + :tooltip tooltip + :spec spec + :type (when (#{"numeric" "integer"} data-type) + "number") + :on-change on-change}]] + ;; Add (wrap the text field) the calculator button for specified cases + (cond + (and ;; false + (#{3110 3130} type-code) + (#{:swimming-pool-count :pool-water-area-m2} k)) + [calculate-field + {:on-change on-change + :calculate-label (case k + :swimming-pool-count (tr :map/calculate-count) + :pool-water-area-m2 (tr :map/calculate-area)) + :calculate-fn (case k + :swimming-pool-count + (fn [] + (count pools)) + :pool-water-area-m2 + (fn [] + (->> pools + vals + (map :area-m2) + (reduce + 0))))} + el] + + :else el)))}) (concat ;; Ice stadium special props diff --git a/webapp/src/cljs/lipas/ui/swimming_pools/views.cljs b/webapp/src/cljs/lipas/ui/swimming_pools/views.cljs index 2cb055301..6f6c406a5 100644 --- a/webapp/src/cljs/lipas/ui/swimming_pools/views.cljs +++ b/webapp/src/cljs/lipas/ui/swimming_pools/views.cljs @@ -136,7 +136,8 @@ (-> edit-data :type :type-code) (-> display-data :type :type-code)) :on-change (partial set-field :properties) - :read-only? (not editing?)}]] + :read-only? (not editing?) + :pools (:pools edit-data)}]] ;;; Building (let [display-data (-> display-data :building)