diff --git a/bases/behave_schema/src/behave/schema/group_variable.cljc b/bases/behave_schema/src/behave/schema/group_variable.cljc index aea9b5980..f1d7e068a 100644 --- a/bases/behave_schema/src/behave/schema/group_variable.cljc +++ b/bases/behave_schema/src/behave/schema/group_variable.cljc @@ -1,6 +1,6 @@ (ns behave.schema.group-variable - (:require [clojure.spec.alpha :as s] - [behave.schema.utils :refer [valid-key? uuid-string? zero-pos?]])) + (:require [behave.schema.utils :refer [valid-key? uuid-string? zero-pos?]] + [clojure.spec.alpha :as s])) ;;; Validation Fns @@ -8,20 +8,19 @@ ;;; Spec -(s/def :bp/uuid uuid-string?) -(s/def :bp/nid string?) -(s/def :group-variable/cpp-class string?) -(s/def :group-variable/cpp-function string?) -(s/def :group-variable/cpp-namespace string?) -(s/def :group-variable/cpp-parameter string?) -(s/def :group-variable/help-key valid-key?) -(s/def :group-variable/order zero-pos?) -(s/def :group-variable/translation-key valid-key?) -(s/def :group-variable/research? boolean?) -(s/def :group-variable/hide-graph? boolean?) -(s/def :group-variable/direction valid-direction?) - - +(s/def :bp/uuid uuid-string?) +(s/def :bp/nid string?) +(s/def :group-variable/cpp-class string?) +(s/def :group-variable/cpp-function string?) +(s/def :group-variable/cpp-namespace string?) +(s/def :group-variable/cpp-parameter string?) +(s/def :group-variable/help-key valid-key?) +(s/def :group-variable/order zero-pos?) +(s/def :group-variable/translation-key valid-key?) +(s/def :group-variable/research? boolean?) +(s/def :group-variable/hide-graph? boolean?) +(s/def :group-variable/direction valid-direction?) +(s/def :group-variable/direction-variables (s/coll-of int?)) (s/def :behave/group-variable (s/keys :req [:bp/uuid :bp/nid @@ -29,6 +28,7 @@ :group-variable/translation-key :group-variable/help-key] :opt [:group-variable/research? + :group-variable/direction-variables :group-variable/hide-graph? :group-variable/direction :group-variable/cpp-class @@ -88,6 +88,11 @@ :db/cardinality :db.cardinality/many :db/isComponent true} + {:db/ident :group-variable/direction-variables + :db/doc "Group variable's reference to group variables that have directionality." + :db/valueType :db.type/ref + :db/cardinality :db.cardinality/many} + {:db/ident :group-variable/direction :db/doc "Group variable's direction." :db/valueType :db.type/keyword @@ -164,5 +169,4 @@ :group-variable/help-key "behave:contain:fire:group:var:help" :group-variable/cpp-class "BehaveContain" :group-variable/cpp-namespace "global" - :group-variable/cpp-function "setFireSize"}) - ) + :group-variable/cpp-function "setFireSize"})) diff --git a/components/schema_migrate/src/schema_migrate/core.clj b/components/schema_migrate/src/schema_migrate/core.clj index e09e7c90c..8b9cec92a 100644 --- a/components/schema_migrate/src/schema_migrate/core.clj +++ b/components/schema_migrate/src/schema_migrate/core.clj @@ -1,11 +1,11 @@ (ns schema-migrate.core (:require - [clojure.walk :as walk] + [clojure.spec.alpha :as spec] [clojure.string :as s] + [clojure.walk :as walk] [datascript.core :refer [squuid]] - [datomic.api :as d] [datomic-store.main :as ds] - [clojure.spec.alpha :as spec] + [datomic.api :as d] [nano-id.core :refer [nano-id]])) (def @@ -378,7 +378,7 @@ (defn ->variable [_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}] + 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)) @@ -406,7 +406,7 @@ "Payload for a new Group Variable." [conn {:keys [parent-group-eid order variable-eid cpp-namespace cpp-class cpp-function cpp-parameter translation-key conditionally-set? actions - hide-result-conditionals hide-result? disable-multi-valued-input-conditionals disable-multi-valued-input-conditional-operator] :as params}] + hide-result-conditionals hide-result? disable-multi-valued-input-conditionals disable-multi-valued-input-conditional-operator direction-variables] :as params}] (let [payload (if (spec/valid? :behave/group-variable params) params (cond-> {} @@ -422,6 +422,7 @@ cpp-class (assoc :group-variable/cpp-class (cpp-class->uuid conn cpp-namespace cpp-class)) cpp-function (assoc :group-variable/cpp-function (cpp-fn->uuid conn cpp-namespace cpp-class cpp-function)) cpp-parameter (assoc :group-variable/cpp-parameter (cpp-param->uuid conn cpp-namespace cpp-class cpp-function cpp-parameter)) + (seq direction-variables) (assoc :group-variable/direction-variables direction-variables) translation-key (assoc :group-variable/translation-key translation-key) translation-key (assoc :group-variable/result-translation-key (s/replace translation-key ":output:" ":result:")) translation-key (assoc :group-variable/help-key (str translation-key ":help")) diff --git a/development/migrations/2026_03_03_add_direction_variables_attr_to_group_variables.clj b/development/migrations/2026_03_03_add_direction_variables_attr_to_group_variables.clj new file mode 100644 index 000000000..fadb82206 --- /dev/null +++ b/development/migrations/2026_03_03_add_direction_variables_attr_to_group_variables.clj @@ -0,0 +1,371 @@ +(ns migrations.2026-03-03-add-direction-variables-attr-to-group-variables + (:require [behave-cms.server :as cms] + [behave-cms.store :refer [default-conn]] + [datascript.core :refer [squuid]] + [datomic.api :as d] + [nano-id.core :refer [nano-id]] + [schema-migrate.interface :as sm])) + +;; =========================================================================================================== +;; Overview +;; =========================================================================================================== + +;; Introducing a new attribute to group variables: `:group-variable/direction-variables`. These are +;; references to other group variables that are meant to be the directional version of the parent. +;; These "directional children" are group variables that have it's `:group-variable/direction` set and +;; also has the associated cpp functions. We have a few existing group variables in the surface module +;; (i.e. rate of spread, flame length, fireline intensity) that served as a directional parent +;; (i.e. they trigger the enabling of its directional variants via conditionals). +;; Instead of relying on the conditionals on the children, we will now explicity link the parent to the +;; child via this new attribute. This way, the UI has a way to easily group these children. + +;; 1. Link Directional Versions of Group Variable to it's Parent + +;; There are a few outputs in Mortality (i.e. probability of mortality, scorch height, tree crown +;; length scorched, tree crown volume scorched) which do not follow the pattern of having a +;; direcitonal parent setting all the children since there are no output checkboxes for these, and +;; instead rely soley on being conditionally set. We need to create directional parent group +;; variables for each of these. This requires some renaming of translation key for the existing +;; heading direciton of the outputs, create the directional group variables, and finally link them +;; as we did in step 1. + +;; 2. Rename Translation keys +;; 3. Add new Group Variables + +;; We can now delete all variable entities that was created for each directional variant (i.e. +;; Heading Rate of Spread, Flanking Rate of Spread, etc). Now all directional childrens of the same +;; output should refer to the same variable (i.e. Rate of Spread) + +;; 4. Clean up Variables + +;; 5. Add translations for the group variables with translation keys renamed from step 1. +;; 6. Fix Variables, missing bp/uuid and bp/nid + +;; =========================================================================================================== +;; Initialize +;; =========================================================================================================== + +(cms/init-db!) + +#_{:clj-kondo/ignore [:missing-docstring]} +(def conn (default-conn)) + +;; ;; =========================================================================================================== +;; ;; 3. Exploare and find out what directional group variables we need to process +;; ;; =========================================================================================================== + +;; ;; Existing directional group variables should all point to the same variable instead a specific variable for it's direction +;; ;; Remove essentially duplicated variables for each direction (i.e. Scorch Height Heading, Scorch Height Backing, Scorch Height Flanking). Should only be one variable called Scorch Height that all group variables, regardless of directionally should point to. + +#_{:clj-kondo/ignore [(:missing-docstring)]} +(def direction-variable-pairs + (d/q '[:find ?parent-eid ?dir-gv-eid + :where + [?dir-gv-eid :group-variable/direction _] + [?dir-gv-eid :group-variable/actions ?action] + [?action :action/conditionals ?conditional] + [?conditional :conditional/type :group-variable] + [?conditional :conditional/group-variable-uuid ?parent-uuid] + [?parent-eid :bp/uuid ?parent-uuid]] + (d/db conn))) + +#_{:clj-kondo/ignore [(:missing-docstring)]} +(defn gv-eid->translation-key [eid] + (:group-variable/translation-key (d/entity (d/db conn) eid))) + +(->> direction-variable-pairs + (group-by first) + (map (fn [[parent-eid pairs]] + {:db/id (gv-eid->translation-key parent-eid) + :group-variable/direction-variables (mapv #(gv-eid->translation-key (second %)) pairs)}))) + +;; =========================================================================================================== +;; 1. Link Directional Versions of Group Variable to it's Parent +;; =========================================================================================================== + +#_{:clj-kondo/ignore [(:missing-docstring)]} +(def links-to-add-payload + [{:db/id (sm/t-key->eid conn "behaveplus:surface:output:fire_behavior:surface_fire:rate_of_spread"), + :group-variable/direction-variables [(sm/t-key->eid conn "behaveplus:surface:output:fire_behavior:surface_fire:heading_rate_of_spread") + (sm/t-key->eid conn "behaveplus:surface:output:fire_behavior:surface_fire:flanking_rate_of_spread") + (sm/t-key->eid conn "behaveplus:surface:output:fire_behavior:surface_fire:backing_rate_of_spread")]} + + {:db/id (sm/t-key->eid conn "behaveplus:surface:output:fire_behavior:surface_fire:fireline_intensity"), + :group-variable/direction-variables [(sm/t-key->eid conn "behaveplus:surface:output:fire_behavior:surface_fire:heading_fireline_intensity") + (sm/t-key->eid conn "behaveplus:surface:output:fire_behavior:surface_fire:flanking_fireline_intensity") + (sm/t-key->eid conn "behaveplus:surface:output:fire_behavior:surface_fire:backing_fireline_intensity")]} + + {:db/id (sm/t-key->eid conn "behaveplus:surface:output:fire_behavior:surface_fire:flame_length"), + :group-variable/direction-variables [(sm/t-key->eid conn "behaveplus:surface:output:fire_behavior:surface_fire:heading_flame_length") + (sm/t-key->eid conn "behaveplus:surface:output:fire_behavior:surface_fire:flanking_flame_length") + (sm/t-key->eid conn "behaveplus:surface:output:fire_behavior:surface_fire:backing_flame_length")]} + + {:db/id (sm/t-key->eid conn "behaveplus:surface:output:size:surface___fire_size:spread-distance"), + :group-variable/direction-variables [(sm/t-key->eid conn "behaveplus:surface:output:size:surface___fire_size:heading-spread-distance") + (sm/t-key->eid conn "behaveplus:surface:output:size:surface___fire_size:backing-spread-distance") + (sm/t-key->eid conn "behaveplus:surface:output:size:surface___fire_size:flanking-spread-distance")]}]) + +;; =========================================================================================================== +;; 2. Rename Translation keys +;; =========================================================================================================== + +;; These group variables should have their keys updated for the heading direction. + +#_{:clj-kondo/ignore [(:missing-docstring)]} +(def t-keys-to-process ["behaveplus:mortality:output:tree_mortality:tree_mortality:probability_of_mortality" + "behaveplus:mortality:output:tree_mortality:tree_mortality:bole_char_height" + "behaveplus:mortality:output:tree_mortality:tree_mortality:scorch-height" + "behaveplus:mortality:output:tree_mortality:tree_mortality:tree_crown_length_scorched" + "behaveplus:mortality:output:tree_mortality:tree_mortality:tree_crown_volume_scorched"]) + +#_{:clj-kondo/ignore [(:missing-docstring)]} +(defn generate-new-t-keys + [s] + (let [last-colon (clojure.string/last-index-of s ":") + prefix (subs s 0 (inc last-colon)) + last-seg (clojure.string/replace (subs s (inc last-colon)) "-" "_") + normalized (str prefix last-seg) + heading (str normalized "_heading") + result-heading (clojure.string/replace heading ":output:" ":result:")] + [heading result-heading])) + +#_{:clj-kondo/ignore [(:missing-docstring)]} +(defn t-key->new-t-key-payload [t-key] + (let [[new-t-key new-result-key] (generate-new-t-keys t-key)] + {:db/id (sm/t-key->eid conn t-key) + :group-variable/translation-key new-t-key + :group-variable/result-translation-key new-result-key + :group-variable/help-key (str new-t-key ":help")})) + +#_{:clj-kondo/ignore [(:missing-docstring)]} +(def update-translation-key-payload + (map t-key->new-t-key-payload t-keys-to-process)) + +;; =========================================================================================================== +;; 3. Add new Group Variables +;; =========================================================================================================== + +;; Add new group variables that mimic the Surface > Fire Behavior (output) > Surface Fire > Rate of Spread +;; - no cpp functions +;; - hide from results +;; - has references to directional variables +;; - copy actions from the existing heading group variable + +#_{:clj-kondo/ignore [(:missing-docstring)]} +(def tree-mortality-eid (sm/t-key->eid conn "behaveplus:mortality:output:tree_mortality:tree_mortality")) + +#_{:clj-kondo/ignore [(:missing-docstring)]} +(defn actions-copy-payload [t-key] + (map (fn [action] + (let [conditionals (:action/conditionals action)] + (cond-> + {:nname (:action/name action) + :ttype (:action/type action) + :conditionals (map (fn [conditional] + (cond-> {:ttype (:conditional/type conditional) + :operator (:conditional/operator conditional) + :values (:conditional/values conditional)} + (:conditional/group-variable-uuid conditional) (assoc :group-variable-uuid (:conditional/group-variable-uuid conditional)))) + conditionals)} + (:action/value action) (assoc :target-value (:action/value action))))) + (:group-variable/actions (sm/t-key->entity conn t-key)))) + +#_{:clj-kondo/ignore [(:missing-docstring)]} +(def new-group-variables-payload + [(sm/->group-variable conn + {:parent-group-eid tree-mortality-eid + :order 0 + :variable-eid (sm/name->eid conn :variable/name "Probability of Mortality") + :direction-variables [(sm/t-key->eid conn "behaveplus:mortality:output:tree_mortality:tree_mortality:probability_of_mortality") + (sm/t-key->eid conn "behaveplus:mortality:output:tree_mortality:tree_mortality:probability-of-mortality-backing") + (sm/t-key->eid conn "behaveplus:mortality:output:tree_mortality:tree_mortality:probability-of-mortality-flanking")] + :translation-key "behaveplus:mortality:output:tree_mortality:tree_mortality:probability_of_mortality" + :conditionally-set? true + :actions (actions-copy-payload "behaveplus:mortality:output:tree_mortality:tree_mortality:probability_of_mortality") + :hide-result? true}) + + (sm/->group-variable conn + {:parent-group-eid tree-mortality-eid + :order 0 + :variable-eid (sm/name->eid conn :variable/name "Bole Char Height") + :direction-variables [(sm/t-key->eid conn "behaveplus:mortality:output:tree_mortality:tree_mortality:bole_char_height") + (sm/t-key->eid conn "behaveplus:mortality:output:tree_mortality:tree_mortality:bole_char_height_backing") + (sm/t-key->eid conn "behaveplus:mortality:output:tree_mortality:tree_mortality:bole_char_height_flanking")] + :translation-key "behaveplus:mortality:output:tree_mortality:tree_mortality:bole_char_height" + :conditionally-set? true + :actions (actions-copy-payload "behaveplus:mortality:output:tree_mortality:tree_mortality:bole_char_height") + :hide-result? true}) + + (sm/->group-variable conn + {:parent-group-eid tree-mortality-eid + :order 0 + :variable-eid (sm/name->eid conn :variable/name "Scorch Height") + :direction-variables [(sm/t-key->eid conn "behaveplus:mortality:output:tree_mortality:tree_mortality:scorch-height") + (sm/t-key->eid conn "behaveplus:mortality:output:tree_mortality:tree_mortality:scorch-height-backing") + (sm/t-key->eid conn "behaveplus:mortality:output:tree_mortality:tree_mortality:scorch-height-flanking")] + :translation-key "behaveplus:mortality:output:tree_mortality:tree_mortality:scorch-height" + :conditionally-set? true + :actions (actions-copy-payload "behaveplus:mortality:output:tree_mortality:tree_mortality:scorch-height") + :hide-result? true}) + + (sm/->group-variable conn + {:parent-group-eid tree-mortality-eid + :order 0 + :variable-eid (sm/name->eid conn :variable/name "Tree Crown Length Scorched") + :direction-variables [(sm/t-key->eid conn "behaveplus:mortality:output:tree_mortality:tree_mortality:tree_crown_length_scorched") + (sm/t-key->eid conn "behaveplus:mortality:output:tree_mortality:tree_mortality:tree_crown_length_scorched_backing") + (sm/t-key->eid conn "behaveplus:mortality:output:tree_mortality:tree_mortality:tree_crown_length_scorched_flanking")] + :translation-key "behaveplus:mortality:output:tree_mortality:tree_mortality:tree_crown_length_scorched" + :conditionally-set? true + :actions (actions-copy-payload "behaveplus:mortality:output:tree_mortality:tree_mortality:tree_crown_length_scorched") + :hide-result? true}) + + (sm/->group-variable conn + {:parent-group-eid tree-mortality-eid + :order 0 + :variable-eid (sm/name->eid conn :variable/name "Tree Crown Volume Scorched") + :direction-variables [(sm/t-key->eid conn "behaveplus:mortality:output:tree_mortality:tree_mortality:tree_crown_volume_scorched") + (sm/t-key->eid conn "behaveplus:mortality:output:tree_mortality:tree_mortality:tree_crown_volume_scorched_backing") + (sm/t-key->eid conn "behaveplus:mortality:output:tree_mortality:tree_mortality:tree_crown_volume_scorched_flanking")] + :translation-key "behaveplus:mortality:output:tree_mortality:tree_mortality:tree_crown_volume_scorched" + :conditionally-set? true + :actions (actions-copy-payload "behaveplus:mortality:output:tree_mortality:tree_mortality:tree_crown_volume_scorched") + :hide-result? true})]) + +;; =========================================================================================================== +;; 4. Clean up Variables +;; =========================================================================================================== + +;; These variables should no longer be in the system. + +(def variables-to-clean + [["Heading Rate of Spread" "Rate of Spread" "behaveplus:surface:output:fire_behavior:surface_fire:heading_rate_of_spread"] + ["Backing Rate of Spread" "Rate of Spread" "behaveplus:surface:output:fire_behavior:surface_fire:backing_rate_of_spread"] + ["Flanking Rate of Spread" "Rate of Spread" "behaveplus:surface:output:fire_behavior:surface_fire:flanking_rate_of_spread"] + ["Heading Fireline Intensity" "Fireline Intensity" "behaveplus:surface:output:fire_behavior:surface_fire:heading_fireline_intensity"] + ["Backing Fireline Intensity" "Fireline Intensity" "behaveplus:surface:output:fire_behavior:surface_fire:backing_fireline_intensity"] + ["Flanking Fireline Intensity" "Fireline Intensity" "behaveplus:surface:output:fire_behavior:surface_fire:flanking_fireline_intensity"] + ["Heading Flame Length" "Flame Length" "behaveplus:surface:output:fire_behavior:surface_fire:heading_flame_length"] + ["Backing Flame Length" "Flame Length" "behaveplus:surface:output:fire_behavior:surface_fire:backing_flame_length"] + ["Flanking Flame Length" "Flame Length" "behaveplus:surface:output:fire_behavior:surface_fire:flanking_flame_length"] + ["Heading Spread Distance" "Spread Distance" "behaveplus:surface:output:size:surface___fire_size:heading-spread-distance"] + ["Flanking Spread Distance" "Spread Distance" "behaveplus:surface:output:size:surface___fire_size:flanking-spread-distance"] + ["Backing Spread Distance" "Spread Distance" "behaveplus:surface:output:size:surface___fire_size:backing-spread-distance"] + ["Probability of Mortality Backing" "Probability of Mortality" "behaveplus:mortality:output:tree_mortality:tree_mortality:probability-of-mortality-backing"] + ["Probability of Mortality Flanking" "Probability of Mortality" "behaveplus:mortality:output:tree_mortality:tree_mortality:probability-of-mortality-flanking"] + ["Bole Char Height Backing" "Bole Char Height" "behaveplus:mortality:output:tree_mortality:tree_mortality:bole_char_height_backing"] + ["Bole Char Height Flanking" "Bole Char Height" "behaveplus:mortality:output:tree_mortality:tree_mortality:bole_char_height_flanking"] + ["Scorch Height Backing" "Scorch Height" "behaveplus:mortality:output:tree_mortality:tree_mortality:scorch-height-backing"] + ["Scorch Height Flanking" "Scorch Height" "behaveplus:mortality:output:tree_mortality:tree_mortality:scorch-height-flanking"] + ["Tree Crown Length Scorched Backing" "Tree Crown Length Scorched" "behaveplus:mortality:output:tree_mortality:tree_mortality:tree_crown_length_scorched_backing"] + ["Tree Crown Length Scorched Flanking" "Tree Crown Length Scorched" "behaveplus:mortality:output:tree_mortality:tree_mortality:tree_crown_length_scorched_flanking"] + ["Tree Crown Volume Scorched Backing" "Tree Crown Volume Scorched" "behaveplus:mortality:output:tree_mortality:tree_mortality:tree_crown_volume_scorched_backing"] + ["Tree Crown Volume Scorched Flanking" "Tree Crown Volume Scorched" "behaveplus:mortality:output:tree_mortality:tree_mortality:tree_crown_volume_scorched_flanking"]]) + +(def clean-variables-payload + (mapcat (fn [[current-var-name new-var-name t-key]] + [[:db/retract (sm/name->eid conn :variable/name current-var-name) :variable/group-variables (sm/t-key->eid conn t-key)] + [:db/add (sm/name->eid conn :variable/name new-var-name) :variable/group-variables (sm/t-key->eid conn t-key)]]) + variables-to-clean)) + +(def add-missing-result-translation + [{:db/id (sm/t-key->eid conn "behaveplus:surface:output:fire_behavior:surface_fire:flame_length") + :group-variable/result-translation-key "behaveplus:surface:result:fire_behavior:surface_fire:flame_length"} + {:db/id (sm/t-key->eid conn "behaveplus:surface:output:fire_behavior:surface_fire:rate_of_spread") + :group-variable/result-translation-key "behaveplus:surface:result:fire_behavior:surface_fire:rate_of_spread"} + {:db/id (sm/t-key->eid conn "behaveplus:surface:output:fire_behavior:surface_fire:heading_fireline_intensity") + :group-variable/result-translation-key "behaveplus:surface:result:fire_behavior:surface_fire:heading_fireline_intensity"}]) + +;; =========================================================================================================== +;; 5. Add translations for the group variables with translation keys renamed from step 1. +;; =========================================================================================================== + +#_{:clj-kondo/ignore [(:missing-docstring)]} +(defn t-key->translation [s] + (let [last-seg (subs s (inc (clojure.string/last-index-of s ":"))) + stripped (clojure.string/replace last-seg #"_heading$" "") + words (clojure.string/split stripped #"_")] + (->> words + (map clojure.string/capitalize) + (clojure.string/join " ")))) + +#_{:clj-kondo/ignore [(:missing-docstring)]} +(def translations-payload + (sm/build-translations-payload conn 100 + (into + {"behaveplus:surface:result:fire_behavior:surface_fire:flame_length" "Flame Length" + "behaveplus:surface:result:fire_behavior:surface_fire:rate_of_spread" "Rate of Spread" + "behaveplus:surface:result:fire_behavior:surface_fire:heading_fireline_intensity" "Fireline Intensity"} + (map #(let [t-key (:group-variable/translation-key %)] + [t-key (t-key->translation t-key)]) + update-translation-key-payload)))) + +;; =========================================================================================================== +;; 6. Fix Variables, missing bp/uuid and bp/nid +;; =========================================================================================================== + +;; These prevously created variables are missing some of the necessary attributes we need. It was not necessary before because the actual variables that were used +;; were (i.e. Heading Rate of Spread, Backing Rate of Spread, etc) which had this info. Now that we are deleting those variables, we need to add these backin. All directional group variables will point to the same variable now + +(def fix-variable-missing-bp-uuid-payload + [{:db/id (sm/name->eid conn :variable/name "Rate of Spread") + :bp/uuid (str (squuid)) + :bp/nid (nano-id) + :variable/kind :continuous + :variable/domain-uuid (:bp/uuid (d/entity (d/db conn) (sm/name->eid conn :domain/name "Surface Rate of Spread"))) + :variable/dimension-uuid (:bp/uuid (d/entity (d/db conn) (sm/name->eid conn :dimension/name "Length")))} + + {:db/id (sm/name->eid conn :variable/name "Flame Length") + :bp/uuid (str (squuid)) + :bp/nid (nano-id) + :variable/kind :continuous + :variable/domain-uuid (:bp/uuid (d/entity (d/db conn) (sm/name->eid conn :domain/name "Flame Length & Scorch Ht"))) + :variable/dimension-uuid (:bp/uuid (d/entity (d/db conn) (sm/name->eid conn :dimension/name "Length")))} + + {:db/id (sm/name->eid conn :variable/name "Fireline Intensity") + :bp/uuid (str (squuid)) + :bp/nid (nano-id) + :variable/kind :continuous + :variable/domain-uuid (:bp/uuid (d/entity (d/db conn) (sm/name->eid conn :domain/name "Fireline Intensity"))) + :variable/dimension-uuid (:bp/uuid (d/entity (d/db conn) (sm/name->eid conn :dimension/name "Fireline Intensity")))}]) + +;; =========================================================================================================== +;; Payload +;; =========================================================================================================== + +#_{:clj-kondo/ignore [(:missing-docstring)]} +;; (def payload +;; (concat clear-attrs-fn-payload update-settings-hide-from-result-payload)) + +#_{:clj-kondo/ignore [(:missing-docstring)]} +(def first-payload + (concat + fix-variable-missing-bp-uuid-payload + links-to-add-payload + update-translation-key-payload + add-missing-result-translation + translations-payload)) + +#_{:clj-kondo/ignore [(:missing-docstring)]} +(def second-payload + (concat new-group-variables-payload + clean-variables-payload)) + +;; =========================================================================================================== +;; Transact Payload +;; =========================================================================================================== + +(comment + #_{:clj-kondo/ignore [:missing-docstring]} + (try (def tx-data @(d/transact conn first-payload)) + (def tx-data-2 @(d/transact conn second-payload)) + (catch Exception e (str "caught exception: " (.getMessage e))))) + +;; =========================================================================================================== +;; In case we need to rollback. +;; =========================================================================================================== + +(comment + (do + (sm/rollback-tx! conn tx-data-2) + (sm/rollback-tx! conn tx-data))) diff --git a/projects/behave_cms/src/cljs/behave_cms/group_variables/views.cljs b/projects/behave_cms/src/cljs/behave_cms/group_variables/views.cljs index b6cdc6c0f..8d5c19132 100644 --- a/projects/behave_cms/src/cljs/behave_cms/group_variables/views.cljs +++ b/projects/behave_cms/src/cljs/behave_cms/group_variables/views.cljs @@ -1,18 +1,20 @@ (ns behave-cms.group-variables.views - (:require [re-frame.core :as rf] + (:require [behave-cms.components.actions :refer [actions-table manage-action]] [behave-cms.components.common :refer [accordion checkbox dropdown simple-table window]] - [behave-cms.components.actions :refer [actions-table manage-action]] - [behave-cms.components.conditionals.views :refer [conditionals-graph manage-conditionals]] + [behave-cms.components.conditionals.views :refer [conditionals-graph manage-conditionals]] [behave-cms.components.cpp-editor :refer [cpp-editor-form]] + [behave-cms.components.group-variable-selector :refer [group-variable-selector]] [behave-cms.components.sidebar :refer [sidebar sidebar-width]] [behave-cms.components.translations :refer [all-translations]] [behave-cms.help.views :refer [help-editor]] + [behave-cms.routes :refer [app-routes]] [behave-cms.utils :as u] - [behave-cms.components.group-variable-selector :refer [group-variable-selector]])) + [bidi.bidi :refer [path-for]] + [re-frame.core :as rf])) ;;; Constants @@ -94,12 +96,28 @@ ;;; Public Views +(defn- direction-variables-table [gv-id direction-variables] + [:div.col-6 + [simple-table + [:variable/name :group-variable/direction] + (map (fn [dv] + {:db/id (:db/id dv) + :bp/nid (:bp/nid dv) + :variable/name (get-in dv [:variable/_group-variables 0 :variable/name]) + :group-variable/direction (:group-variable/direction dv)}) + direction-variables) + {:on-select #(rf/dispatch [:navigate (path-for app-routes :get-group-variable :nid (:bp/nid %))]) + :on-delete #(when (js/confirm "Are you sure you want to remove this direction variable?") + (rf/dispatch [:api/retract-entity-attr-value + gv-id :group-variable/direction-variables (:db/id %)]))}]]) + (defn group-variable-page "Renders the group-variable page. Takes in a group-variable UUID." [{nid :nid}] - (let [group-variable (rf/subscribe [:entity [:bp/nid nid] '[* {:variable/_group-variables [*] - :group/_group-variables [*] - :group-variable/actions [*]}]]) + (let [group-variable (rf/subscribe [:entity [:bp/nid nid] '[* {:variable/_group-variables [*] + :group/_group-variables [*] + :group-variable/actions [*] + :group-variable/direction-variables [* {:variable/_group-variables [*]}]}]]) gv-id (:db/id @group-variable) is-output? (rf/subscribe [:group-variable/output? gv-id]) actions (:group-variable/actions @group-variable) @@ -107,6 +125,7 @@ group (:group/_group-variables @group-variable) variable (get-in @group-variable [:variable/_group-variables 0]) group-variables (rf/subscribe [:sidebar/variables (:db/id group)]) + direction-variables (:group-variable/direction-variables @group-variable) link-id (rf/subscribe [:state :link]) destination-link-id (-> (rf/subscribe [:entity @link-id]) deref @@ -161,6 +180,20 @@ opposite-io (fn [{io :submodule/io}] (= io (if is-output? :input :output)))] opposite-io)}]]]] + [:hr] + [accordion + "Direction Variables" + [:div.col-12 + [:div.row + [direction-variables-table gv-id direction-variables] + [group-variable-selector + {:app-id @(rf/subscribe [:group-variable/_app-module-id gv-id]) + :state-path [:editors :direction-variable-lookup] + :title "Direction Variable" + :on-submit #(rf/dispatch [:api/update-entity + {:db/id gv-id + :group-variable/direction-variables %}])}]]]] + [:hr] [accordion "Actions" diff --git a/projects/behave_cms/src/cljs/behave_cms/subgroups/subs.cljs b/projects/behave_cms/src/cljs/behave_cms/subgroups/subs.cljs index b3543006d..63ff9a13a 100644 --- a/projects/behave_cms/src/cljs/behave_cms/subgroups/subs.cljs +++ b/projects/behave_cms/src/cljs/behave_cms/subgroups/subs.cljs @@ -5,6 +5,7 @@ [bidi.bidi :refer [path-for]] [clojure.string :as str] [datascript.core :as d] + [goog.string :as gstring] [re-frame.core :refer [reg-sub subscribe]])) ;;; Applications, Modules, Submodules @@ -171,9 +172,12 @@ (fn [variables] (->> variables (map (fn [variable] - (let [nid (:bp/nid variable) - name (get-in variable [:variable/_group-variables 0 :variable/name])] - {:label name + (let [nid (:bp/nid variable) + direction (:group-variable/direction variable) + v-name (get-in variable [:variable/_group-variables 0 :variable/name])] + {:label (if direction + (gstring/format "%s (%s)" v-name (name direction)) + v-name) :link (path-for app-routes :get-group-variable :nid nid)}))) (sort-by :label)))) diff --git a/projects/behave_cms/src/cljs/behave_cms/subgroups/views.cljs b/projects/behave_cms/src/cljs/behave_cms/subgroups/views.cljs index 20f6b5c95..5816840e4 100644 --- a/projects/behave_cms/src/cljs/behave_cms/subgroups/views.cljs +++ b/projects/behave_cms/src/cljs/behave_cms/subgroups/views.cljs @@ -36,7 +36,7 @@ (defn- variables-table [group-id] (let [group-variables (rf/subscribe [:group/variables group-id])] [simple-table - [:variable/name] + [:variable/name :group-variable/direction :group-variable/conditionally-set?] (sort-by :group-variable/order @group-variables) {:on-increase #(rf/dispatch [:api/reorder % @group-variables :group-variable/order :inc]) :on-decrease #(rf/dispatch [:api/reorder % @group-variables :group-variable/order :dec]) @@ -122,7 +122,7 @@ [:h2 (:group/name @group)]] ^{:key "variables"} [accordion - "Variables" + "Group Variables" [:div.col-6 [variables-table id]] [:div.col-6