Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
(:require [behave.components.core :as c]
[behave.translate :refer [<t bp]]
[behave.units-conversion :refer [to-map-units]]
[cljs.math :refer [round]]
[clojure.string :as str]
[goog.string :as gstring]
[re-frame.core :refer [subscribe]]))
Expand All @@ -15,7 +16,7 @@
(fn [[gv-uuid]]
(= gv-uuid output-gv-uuid))
table-setting-filters))]
(and enabled? mmin mmax (not (<= mmin value mmax)))))
(and enabled? mmin mmax (not (<= mmin (round value) mmax)))))

(defn- header-label [label units]
(if (seq units)
Expand Down
66 changes: 42 additions & 24 deletions projects/behave/src/cljs/behave/vms/subs.cljs
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
(ns behave.vms.subs
(:require [behave.schema.core :refer [rules]]
[behave.translate :refer [<t]]
[behave.vms.store :refer [entity-from-eid
entity-from-nid
entity-from-uuid
pull
pull-many
q
vms-conn]]
[behave.translate :refer [<t]]
[map-utils.interface :refer [index-by]]
[datascript.core :as d]
[re-frame.core :refer [reg-sub subscribe]]
[re-frame.core :as rf]))
[map-utils.interface :refer [index-by]]
[re-frame.core :as rf]
[re-frame.core :refer [reg-sub subscribe]]))

(reg-sub
:vms/query
Expand Down Expand Up @@ -293,36 +293,36 @@

;; Use the subgroup rule to find all ancestor groups
;; The subgroup rule: (subgroup ?parent ?child) means ?child is a subgroup of ?parent
(let [ancestor-eids (d/q '[:find [?ancestor ...]
:in $ % ?child
:where
(subgroup ?ancestor ?child)]
db
rules
immediate-group-eid)
(let [ancestor-eids (d/q '[:find [?ancestor ...]
:in $ % ?child
:where
(subgroup ?ancestor ?child)]
db
rules
immediate-group-eid)

;; Pull all groups with their parent references to sort them
all-groups (cons immediate-group-eid ancestor-eids)
groups-with-parents (map #(d/pull db '[:db/id {:group/_children [:db/id]}] %)
all-groups)

;; Build a map of child -> parent for quick lookup
parent-map (into {} (map (fn [g]
[(:db/id g)
(when-let [parent (:group/_children g)]
(:db/id parent))])
groups-with-parents))
parent-map (into {} (map (fn [g]
[(:db/id g)
(when-let [parent (:group/_children g)]
(:db/id parent))])
groups-with-parents))

;; Sort groups from root to leaf by following parent chain
sort-groups (fn [group-eid]
(loop [current group-eid
path []]
(if-let [parent (get parent-map current)]
(recur parent (conj path current))
(reverse (conj path current)))))
sort-groups (fn [group-eid]
(loop [current group-eid
path []]
(if-let [parent (get parent-map current)]
(recur parent (conj path current))
(reverse (conj path current)))))

sorted-group-eids (sort-groups immediate-group-eid)
submodule {:db/id submodule-eid}]
sorted-group-eids (sort-groups immediate-group-eid)
submodule {:db/id submodule-eid}]

;; Return: [submodule parent-groups... immediate-group]
(cons submodule (map #(hash-map :db/id %) sorted-group-eids)))))
Expand All @@ -332,3 +332,21 @@
(fn [_ [_ gv-uuid]]
(get-group-hierarchy @@vms-conn gv-uuid)))

(defn direction-variables [gv-uuid]
(let [entity (d/entity @@vms-conn [:bp/uuid gv-uuid])]
(seq (:group-variable/direction-variables entity))))

(reg-sub
:vms/directional-children
(fn [_ [_ gv-uuid]]
(direction-variables gv-uuid)))

(defn directional-parent-entity [gv-uuid]
(let [entity (d/entity @@vms-conn [:bp/uuid gv-uuid])]
(first (:group-variable/_direction-variables entity))))

(reg-sub
:vms/directional-parent
(fn [_ [_ gv-uuid]]
(directional-parent-entity gv-uuid)))

10 changes: 7 additions & 3 deletions projects/behave/src/cljs/behave/wizard/views.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
input-value]]
[goog.string :as gstring]
[goog.string.format]
[re-frame.core :as rf]
[re-frame.core :refer [dispatch dispatch-sync subscribe]]
[reagent.core :as r]
[string-utils.core :as s]
Expand Down Expand Up @@ -392,8 +393,8 @@
*gv-order (subscribe [:vms/group-variable-order ws-uuid])
gv-uuid+min+max-entries-sorted (->> @*gv-uuid+min+max-entries
(sort-by #(.indexOf @*gv-order (first %))))
*default-max-values (subscribe [:worksheet/output-uuid->result-max-values ws-uuid])
*default-min-values (subscribe [:worksheet/output-uuid->result-min-values ws-uuid])
*default-max-values (subscribe [:worksheet/output-uuid->result-min-or-max-values ws-uuid :max])
*default-min-values (subscribe [:worksheet/output-uuid->result-min-or-max-values ws-uuid :min])
units-lookup @(subscribe [:worksheet/result-table-units ws-uuid])
maximums (number-inputs {:saved-entries (map (fn remove-min-val [[gv-uuid _min-val max-val enabled?]]
[gv-uuid max-val enabled?])
Expand All @@ -417,7 +418,10 @@
names (map (fn get-variable-name [[gv-uuid _min _max]]
(gstring/format "%s (%s)"
@(subscribe [:wizard/gv-uuid->resolve-result-variable-name gv-uuid])
(get units-lookup gv-uuid)))
(get units-lookup
(if-let [direcitonal-children (seq @(subscribe [:vms/directional-children gv-uuid]))]
(:bp/uuid (first direcitonal-children))
gv-uuid))))
gv-uuid+min+max-entries-sorted)
enabled-check-boxes (when (= rf-event-id :worksheet/update-table-filter-attr)
(map (fn [[gv-uuid _min _max enabled?]]
Expand Down
Loading