Skip to content

Commit 8eb5428

Browse files
committed
Ensure route-ids
1 parent f7de313 commit 8eb5428

File tree

2 files changed

+40
-20
lines changed

2 files changed

+40
-20
lines changed

webapp/src/cljc/lipas/data/activities.cljc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -614,7 +614,7 @@
614614
(mu/dissoc :latest-updates)
615615
(mu/dissoc :rules))
616616
[:map
617-
[:id [:string]]
617+
[:id {:optional true} [:string]]
618618
[:fids {:optional true} fids-schema]
619619
[:geometries {:optional true} common-schema/line-string-feature-collection]
620620
[:accessibility-categorized {:optional true}
@@ -1058,7 +1058,7 @@
10581058
(mu/merge
10591059
common-route-props-schema
10601060
[:map
1061-
[:id [:string]]
1061+
[:id {:optional true} [:string]]
10621062
[:fids {:optional true} fids-schema]
10631063
[:geometries {:optional true} common-schema/line-string-feature-collection]
10641064
[:route-name {:optional true} common-schema/localized-string]
@@ -1442,7 +1442,7 @@
14421442
(mu/merge
14431443
common-route-props-schema
14441444
[:map
1445-
[:id [:string]]
1445+
[:id {:optional true} [:string]]
14461446
[:fids {:optional true} fids-schema]
14471447
[:geometries {:optional true} common-schema/line-string-feature-collection]
14481448
[:route-name {:optional true} common-schema/localized-string]

webapp/src/cljs/lipas/ui/utils.cljs

Lines changed: 37 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -172,12 +172,12 @@
172172
"Removes nil values and empty entries recursively from maps."
173173
[m]
174174
(walk/postwalk
175-
(fn [x]
176-
(cond
177-
(map? x) (not-empty (into {} (filter (comp some? val)) x))
178-
(and (coll? x) (empty? x)) nil
179-
:else x))
180-
m))
175+
(fn [x]
176+
(cond
177+
(map? x) (not-empty (into {} (filter (comp some? val)) x))
178+
(and (coll? x) (empty? x)) nil
179+
:else x))
180+
m))
181181

182182
(defn- make-comparable [rev]
183183
(-> rev
@@ -268,7 +268,7 @@
268268
;; duplicates from :location :geometries and can be dereferenced
269269
;; using :fids
270270
(cond->
271-
(:activities sports-site)
271+
(:activities sports-site)
272272
(update :activities (fn [activities]
273273
(into (empty activities)
274274
(map (fn [[k v]]
@@ -280,6 +280,23 @@
280280

281281
clean))
282282

283+
(defn- ensure-route-ids
284+
"Ensure all routes in activities have an :id field"
285+
[activities]
286+
(when activities
287+
(reduce-kv
288+
(fn [acc activity-k activity-v]
289+
(if-let [routes (:routes activity-v)]
290+
(assoc-in acc [activity-k :routes]
291+
(mapv (fn [route]
292+
(if (:id route)
293+
route
294+
(assoc route :id (str (random-uuid)))))
295+
routes))
296+
(assoc acc activity-k activity-v)))
297+
{}
298+
activities)))
299+
283300
(defn make-editable [sports-site]
284301
(-> sports-site
285302

@@ -301,7 +318,10 @@
301318
(update-in [:locker-rooms] ->indexed-map)
302319

303320
;; Audits
304-
(update-in [:audits] ->indexed-map)))
321+
(update-in [:audits] ->indexed-map)
322+
323+
;; Activities routes
324+
(update :activities ensure-route-ids)))
305325

306326
;; TODO used only in legacy energy consumption view
307327
;; Should be removed
@@ -354,13 +374,13 @@
354374

355375
(defn ->excel-row [headers m]
356376
(reduce
357-
(fn [res [k _]]
358-
(let [v (get m k)]
359-
(conj res {:value v
360-
:type (if (number? v)
361-
"number"
362-
"string")})))
363-
[] headers))
377+
(fn [res [k _]]
378+
(let [v (get m k)]
379+
(conj res {:value v
380+
:type (if (number? v)
381+
"number"
382+
"string")})))
383+
[] headers))
364384

365385
(defn ->excel-data [headers coll]
366386
(let [header-row (->excel-row headers (into {} headers))]
@@ -433,8 +453,8 @@
433453
(defn link? [x]
434454
(and (string? x)
435455
(or
436-
(str/starts-with? x "http")
437-
(str/starts-with? x "www"))))
456+
(str/starts-with? x "http")
457+
(str/starts-with? x "www"))))
438458

439459
(defn link-strict? [x]
440460
(and (string? x) (str/starts-with? x "http")))

0 commit comments

Comments
 (0)