Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Calculate fields #137

Merged
merged 3 commits into from
Nov 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions webapp/src/cljc/lipas/i18n/generated.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down
10 changes: 7 additions & 3 deletions webapp/src/cljs/lipas/ui/map/views.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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}]
Expand Down
67 changes: 58 additions & 9 deletions webapp/src/cljs/lipas/ui/sports_sites/views.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -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)))

Expand Down Expand Up @@ -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]}]
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion webapp/src/cljs/lipas/ui/swimming_pools/views.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Loading