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
5 changes: 5 additions & 0 deletions bases/behave_schema/src/behave/schema/group.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,11 @@
:db/valueType :db.type/long
:db/cardinality :db.cardinality/one}

{:db/ident :group/results-order
:db/doc "Group's order in Results."
:db/valueType :db.type/long
:db/cardinality :db.cardinality/one}

{:db/ident :group/repeat?
:db/doc "Whether a Group repeats."
:db/valueType :db.type/boolean
Expand Down
5 changes: 5 additions & 0 deletions bases/behave_schema/src/behave/schema/module.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@
:db/valueType :db.type/long
:db/cardinality :db.cardinality/one}

{:db/ident :module/results-order
:db/doc "Module's order in Results."
:db/valueType :db.type/long
:db/cardinality :db.cardinality/one}

{:db/ident :module/submodules
:db/doc "Module's submodules."
:db/valueType :db.type/ref
Expand Down
5 changes: 5 additions & 0 deletions bases/behave_schema/src/behave/schema/submodule.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@
:db/valueType :db.type/long
:db/cardinality :db.cardinality/one}

{:db/ident :submodule/results-order
:db/doc "Submodule's order in Results."
:db/valueType :db.type/long
:db/cardinality :db.cardinality/one}

{:db/ident :submodule/groups
:db/doc "Subodule's groups."
:db/valueType :db.type/ref
Expand Down
61 changes: 61 additions & 0 deletions development/migrations/2026_02_03_add_results_order_attr.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
(ns migrations.2026-02-03-add-results-order-attr
(:require [schema-migrate.interface :as sm]
[datomic.api :as d]
[behave-cms.store :refer [default-conn]]
[behave-cms.server :as cms]))

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

;; Adds order attr to module, submodule, and group order entities, (copied over from original order)

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

(cms/init-db!)

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

(def order-attrs
[[:module/order :module/results-order]
[:submodule/order :submodule/results-order]
[:group/order :group/results-order]])

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

#_{:clj-kondo/ignore [:missing-docstring]}
(def payload
(mapcat
(fn [[order-attr result-order-attr]]
(map
(fn [[eid order]]
{:db/id eid
result-order-attr order})
(d/q '[:find ?e ?order
:in $ ?order-attr
:where
[?e ?order-attr ?order]]
(d/db conn)
order-attr)))
order-attrs))

;; ===========================================================================================================
;; 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))
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@
conditionals)
(has-conditionally-set-group-variables? s-uuid)))))
(filter-group-variables worksheet)
(sort-by :submodule/order))))
(sort-by :submodule/results-order))))

(defn- create-formatter [variable]
(let [v-kind (:variable/kind variable)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@
:else
[])
children (->> (:group/children current-group)
(sort-by :group/order))
(sort-by :group/results-order))
next-indent (if single-var? (inc level) (+ level 2))
children-entires (when (seq children)
(groups->row-entires ws-uuid formatters gv-uuid->units children next-indent))]
Expand Down Expand Up @@ -127,16 +127,17 @@

(defn inputs-table [ws-uuid]
(let [*worksheet (subscribe [:worksheet ws-uuid])
modules (:worksheet/modules @*worksheet)
module-kws (:worksheet/modules @*worksheet)
all-inputs @(subscribe [:worksheet/all-inputs-vector ws-uuid])
formatters @(subscribe [:result.inputs/table-formatters (map #(nth % 2) all-inputs)])
gv-uuid->units @(subscribe [:worksheet/result-table-gv-uuid->units ws-uuid])]
gv-uuid->units @(subscribe [:worksheet/result-table-gv-uuid->units ws-uuid])
module-entities (->> module-kws
(map #(deref (subscribe [:wizard/*module (name %)])))
(sort-by :module/results-order))]
[:div.print__inputs_tables {:id "inputs"}
(for [module-kw modules]
(let [module-name (name module-kw)
module @(subscribe [:wizard/*module module-name])
submodules @(subscribe [:result.inputs/submodules ws-uuid (:db/id module)])]
^{:key module-kw}
(for [module module-entities]
(let [submodules @(subscribe [:result.inputs/submodules ws-uuid (:db/id module)])]
^{:key (:name module)}
[:div.print__inputs-table
(c/table {:title (gstring/format "Inputs: %s" @(<t (:module/translation-key module)))
:headers ["Input Variables" "Units" "Input Value(s)"]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -278,10 +278,11 @@
:border-bottom "3px solid black"
:padding "5px"}}
[:div {:style {:font-size "1.5rem"}} caption]
[:div [btn-sm
:primary
"Add Entry"
add-entity-fn]]]
(when add-entity-fn
[:div [btn-sm
:primary
"Add Entry"
add-entity-fn]])]
[:div.table-wrapper {:style {:height "100%"
:overflow-y "auto"
:scroll-snap-type "y mandatory"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@
display buttons to re order the list in the table.

"
[{:keys [title entity entities table-header-attrs entity-form-fields parent-id parent-field order-attr
form-state-path]}]
[{:keys [title entity entities table-header-attrs entity-form-fields parent-id parent-field order-attr on-select modify? form-state-path]
:or {modify? true}}]
(r/with-let [entity-id-atom (r/atom nil)
show-entity-form? (r/atom false)]
[:div {:style {:display "flex"
Expand All @@ -56,22 +56,25 @@
table-header-attrs
(map :field-key entity-form-fields))
(if order-attr (sort-by order-attr entities) entities)
(cond-> {:add-entity-fn #(do (when (nil? @entity-id-atom) (swap! show-entity-form? not))
(rf/dispatch [:state/set-state :editors {}])
(reset! entity-id-atom nil)
(when on-select (on-select %)))
:on-delete #(when (js/confirm (str "Are you sure you want to delete this "
(name entity)))
(rf/dispatch-sync [:api/delete-entity (:db/id %)]))
:on-select #(if (and @show-entity-form? (= @entity-id-atom (:db/id %)))
(do (reset! entity-id-atom nil)
(reset! show-entity-form? false)
(rf/dispatch [:state/set-state :editors {}])
(when on-select (on-select %)))
(do
(reset! show-entity-form? true)
(reset! entity-id-atom (:db/id %))
(when on-select (on-select %))))}
(cond-> {:add-entity-fn (when modify?
#(do (when (nil? @entity-id-atom) (swap! show-entity-form? not))
(rf/dispatch [:state/set-state :editors {}])
(reset! entity-id-atom nil)
(when on-select (on-select %))))
:on-delete (when modify?
#(when (js/confirm (str "Are you sure you want to delete this "
(name entity)))
(rf/dispatch-sync [:api/delete-entity (:db/id %)])))
:on-select (when modify?
#(if (and @show-entity-form? (= @entity-id-atom (:db/id %)))
(do (reset! entity-id-atom nil)
(reset! show-entity-form? false)
(rf/dispatch [:state/set-state :editors {}])
(when on-select (on-select %)))
(do
(reset! show-entity-form? true)
(reset! entity-id-atom (:db/id %))
(when on-select (on-select %)))))}
title (assoc :caption title)
order-attr (merge {:on-increase #(rf/dispatch [:api/reorder % entities order-attr :inc])
:on-decrease #(rf/dispatch [:api/reorder % entities order-attr :dec])}))]]
Expand Down
23 changes: 22 additions & 1 deletion projects/behave_cms/src/cljs/behave_cms/groups/views.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,22 @@
[behave-cms.help.views :refer [help-editor]]
[behave-cms.groups.subs]))


(defn- groups-results-order-table [submodule-id]
(let [groups (rf/subscribe [:groups submodule-id])]
[:div.col-12
[table-entity-form
{:entity :group
:modify? false
:entities (sort-by :group/order @groups)
:parent-id submodule-id
:parent-field :submodule/_groups
:table-header-attrs [:group/name]
:order-attr :group/order
:entity-form-fields [{:label "Name"
:required? true
:field-key :group/name}]}]]))

(defn- groups-table [submodule-id]
(let [selected-state-path [:selected :group]
editor-state-path [:editors :group]
Expand All @@ -17,7 +33,7 @@
[table-entity-form
{:entity :group
:form-state-path editor-state-path
:entities (sort-by :group/order @groups)
:entities (sort-by :group/results-order @groups)
:on-select (on-select selected-state-path)
:parent-id submodule-id
:parent-field :submodule/_groups
Expand Down Expand Up @@ -69,6 +85,11 @@
"Groups"
[groups-table (:db/id @submodule)]]
[:hr]
^{:key "group-results-order"}
[accordion
"Groups Results Order"
[groups-results-order-table (:db/id @submodule)]]
[:hr]
^{:key "conditionals"}
[accordion
"Conditionals"
Expand Down
18 changes: 18 additions & 0 deletions projects/behave_cms/src/cljs/behave_cms/modules/views.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,20 @@
:required? true
:field-key :module/name}]}]))

(defn- modules-results-order-table [app-id]
(let [entities (rf/subscribe [:application/modules app-id])]
[table-entity-form
{:entity :module
:entities (sort-by :module/results-order @entities)
:modify? false
:parent-id app-id
:parent-field :application/_modules
:table-header-attrs [:module/name]
:order-attr :module/results-order
:entity-form-fields [{:label "Name"
:required? true
:field-key :module/name}]}]))

;;; Tools

(defn- tools-table [app-id]
Expand Down Expand Up @@ -95,6 +109,10 @@
"Modules"
[modules-table app-id]]
[:hr]
[accordion
"Modules Results Order"
[modules-results-order-table app-id]]
[:hr]
[accordion
"Tools"
[tools-table app-id]]
Expand Down
18 changes: 18 additions & 0 deletions projects/behave_cms/src/cljs/behave_cms/submodules/views.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,20 @@
:options [{:label "Input" :value :input}
{:label "Output" :value :output}]}]}]))

(defn- submodules-results-order-table [module-id app-id]
(let [submodule (rf/subscribe [:submodules module-id])]
[table-entity-form
{:entity :submodule
:entities (sort-by :submodule/results-order @submodule)
:modify? false
:parent-id app-id
:parent-field :application/_submodules
:table-header-attrs [:submodule/name :submodule/io]
:order-attr :submodule/order
:entity-form-fields [{:label "Name"
:required? true
:field-key :submodule/name}]}]))

(defn submodules-page
"Display submodules page. Takes a map with:
- id [int]: Submodule entity ID."
Expand All @@ -94,6 +108,10 @@
"Submodules"
[submodules-table (:db/id @module) (:db/id application)]]
[:hr]
[accordion
"Submodules Results Order"
[submodules-results-order-table (:db/id @module) (:db/id application)]]
[:hr]
[accordion
"Translations"
[:div.col-12
Expand Down