Skip to content
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
2 changes: 1 addition & 1 deletion behave-lib/behave-mirror
415 changes: 188 additions & 227 deletions behave-lib/include/cpp/emscripten/glue.cpp

Large diffs are not rendered by default.

4,764 changes: 1,949 additions & 2,815 deletions behave-lib/include/js/glue.js

Large diffs are not rendered by default.

7 changes: 6 additions & 1 deletion components/schema_migrate/src/schema_migrate/core.clj
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,8 @@
(spec/explain :behave/action payload))))

(defn ->variable
[_conn {:keys [nname domain-uuid list-eid translation-key help-key kind bp6-label bp6-code map-units-convertible?] :as params}]
[_conn {:keys [nname domain-uuid list-eid translation-key help-key kind bp6-label bp6-code map-units-convertible?
dimension-uuid native-unit-uuid metric-unit-uuid english-unit-uuid] :as params}]
(let [payload (cond-> {}
(nil? (:bp/uuid params)) (assoc :bp/uuid (rand-uuid))
(not (:bp/nid params)) (assoc :bp/nid (nano-id))
Expand All @@ -387,6 +388,10 @@
nname (assoc :variable/name nname)
kind (assoc :variable/kind kind)
domain-uuid (assoc :variable/domain-uuid domain-uuid)
dimension-uuid (assoc :variable/dimension-uuid dimension-uuid)
native-unit-uuid (assoc :variable/native-unit-uuid native-unit-uuid)
english-unit-uuid (assoc :variable/english-unit-uuid english-unit-uuid)
metric-unit-uuid (assoc :variable/metric-unit-uuid metric-unit-uuid)
list-eid (assoc :variable/list list-eid)
translation-key (assoc :variable/translation-key translation-key)
help-key (assoc :variable/help-translation-key help-key)
Expand Down
93 changes: 93 additions & 0 deletions development/migrations/2025_12_15_update_slope_tool.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
(ns migrations.2025-12-15-update-slope-tool
(:require [schema-migrate.interface :as sm]
[datomic.api :as d]
[behave-cms.store :refer [default-conn]]
[behave-cms.server :as cms]))

;; ===========================================================================================================
;; Overview
;; ===========================================================================================================

;; ===========================================================================================================
;; Initialize
;; ===========================================================================================================

(cms/init-db!)

#_{:clj-kondo/ignore [:missing-docstring]}
(def conn (default-conn))

(def existing-slope-steepness-deg-variable-ied
(sm/name->eid conn :variable/name "Slope Steepness Deg"))

;; ===========================================================================================================
;; Payload
;; ===========================================================================================================

#_{:clj-kondo/ignore [:missing-docstring]}
(def payload
(concat
[;; Add new slope variable
(sm/->variable conn {:db/id -1
:nname "Slope Steepness Percent"
:dimension-uuid (:bp/uuid (d/entity (d/db conn) (sm/name->eid conn :dimension/name "Slope")))
:native-unit-uuid (:bp/uuid (d/entity (d/db conn) (sm/name->eid conn :unit/name "Percent (%)")))
:kind :continuous})


;; update existing slope variable
[:db/retract existing-slope-steepness-deg-variable-ied :variable/domain-uuid]
{:db/id existing-slope-steepness-deg-variable-ied
:variable/dimension-uuid (:bp/uuid (d/entity (d/db conn) (sm/name->eid conn :dimension/name "Slope")))
:variable/native-unit-uuid (:bp/uuid (d/entity (d/db conn) (sm/name->eid conn :unit/name "Degrees (deg)")))}

;; delete existing slope tool variable
[:db/retractEntity (sm/t-key->eid conn "behaveplus:slope-tool:slope-from-map-measurements:slope-steepness-")]

;; add new slope tool variables
{:db/id (sm/name->eid conn :subtool/name "Slope from Map Measurements")
:subtool/variables [(sm/postwalk-insert
{:subtool-variable/io :output
:variable/_subtool-variables -1
:subtool-variable/order 4
:subtool-variable/cpp-namespace-uuid (sm/cpp-ns->uuid conn "global")
:subtool-variable/cpp-class-uuid (sm/cpp-class->uuid conn "global" "SIGSlopeTool")
:subtool-variable/cpp-function-uuid (sm/cpp-fn->uuid conn "global" "SIGSlopeTool" "getSlopeFromMapMeasurementsInPercent")
:subtool-variable/translation-key "behaveplus:slope-tool:slope-from-map-measurements:slope-steepness-percent"
:subtool-variable/help-key "behaveplus:slope-tool:slope-from-map-measurements:slope-steepness-percent:help"})

(sm/postwalk-insert
{:subtool-variable/io :output
:variable/_subtool-variables existing-slope-steepness-deg-variable-ied
:subtool-variable/order 5
:subtool-variable/cpp-namespace-uuid (sm/cpp-ns->uuid conn "global")
:subtool-variable/cpp-class-uuid (sm/cpp-class->uuid conn "global" "SIGSlopeTool")
:subtool-variable/cpp-function-uuid (sm/cpp-fn->uuid conn "global" "SIGSlopeTool" "getSlopeFromMapMeasurementsInDegrees")
:subtool-variable/translation-key "behaveplus:slope-tool:slope-from-map-measurements:slope-steepness-deg"
:subtool-variable/help-key "behaveplus:slope-tool:slope-from-map-measurements:slope-steepness-deg:help"})]}

;;reorder existing subtool variables
{:db/id (sm/t-key->eid conn "behaveplus:slope-tool:slope-from-map-measurements:slope-elevation-change")
:subtool-variable/order 6}
{:db/id (sm/t-key->eid conn "behaveplus:slope-tool:slope-from-map-measurements:slope-horizontal-distance")
:subtool-variable/order 7}]

;; add translations
(sm/build-translations-payload conn {"behaveplus:slope-tool:slope-from-map-measurements:slope-steepness-percent" "Slope"
"behaveplus:slope-tool:slope-from-map-measurements:slope-steepness-deg" "Slope"})))

;; ===========================================================================================================
;; Transact Payload
;; ===========================================================================================================

(comment
#_{:clj-kondo/ignore [:missing-docstring]}
(try (def tx-data @(d/transact conn payload))
(catch Exception e (str "caught exception: " (.getMessage e)))))

;; ===========================================================================================================
;; In case we need to rollback.
;; ===========================================================================================================

(comment
(sm/rollback-tx! conn tx-data))
Loading