Skip to content

Commit fde618b

Browse files
authored
Set default source type in templates (#650)
1 parent a8b4421 commit fde618b

File tree

4 files changed

+35
-29
lines changed

4 files changed

+35
-29
lines changed

client/src/planwise/client/projects2/components/listings.cljs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
[:p.message-margin "You have no projects yet"]
4242
[m/Button {:type "button"
4343
:unelevated "unelevated"
44-
:on-click (utils/prevent-default #(dispatch [:projects2/new-project]))}
44+
:on-click (utils/prevent-default #(dispatch [:projects2/template-project]))}
4545
"Create one"]]])
4646

4747
(defn- listing-component []

client/src/planwise/client/projects2/components/settings.cljs

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -190,14 +190,20 @@
190190
:model (:region-id @current-project)
191191
:disabled? read-only}]]))
192192

193-
(defn- consumer-source-type-checkbox
194-
[label type]
195-
(let [source-types (subscribe [:projects2/source-types])]
196-
[m/Checkbox {:label label
197-
:checked (some? (@source-types type))
198-
:value type
199-
:on-change #(rf/dispatch-sync
200-
[:projects2/toggle-source-type type])}]))
193+
(defn- sources-type-component
194+
[{:keys [label]}]
195+
(let [source-types (subscribe [:projects2/source-types])
196+
options [{:label "Raster (population)" :type "raster"}
197+
{:label "Points" :type "points"}]]
198+
[:div.source-type-settings
199+
[:p label]
200+
[:div
201+
(doall (for [{:keys [label type]} options]
202+
[m/Checkbox {:key (str "consumer-source-" type)
203+
:label label
204+
:checked (some? (@source-types type))
205+
:value type
206+
:on-change #(rf/dispatch-sync [:projects2/toggle-source-type type])}]))]]))
201207

202208
(defn- current-project-step-consumers
203209
[read-only]
@@ -207,11 +213,7 @@
207213
[:section {:class-name "project-settings-section"}
208214
[section-header 2 "Consumers"]
209215
(when-not read-only
210-
[:div.source-type-settings
211-
[:p "Data type"]
212-
[:div
213-
[consumer-source-type-checkbox "Raster (population)" "raster"]
214-
[consumer-source-type-checkbox "Points" "points"]]])
216+
[sources-type-component {:label "Data type"}])
215217
[sources-dropdown-component {:label "Consumer Dataset"
216218
:value (:source-set-id @current-project)
217219
:on-change #(dispatch [:projects2/save-key :source-set-id %])

client/src/planwise/client/projects2/handlers.cljs

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -99,19 +99,21 @@
9999
:projects2/save-project-data
100100
in-projects2
101101
(fn [db [_ current-project]]
102-
(-> db
103-
(clear-current-project) ;; Just to clear source type selection
104-
105-
(assoc :current-project current-project)
106-
;; Keep list in sync with current project
107-
(update :list
108-
(fn [list]
109-
(some-> list
110-
(utils/update-by-id (:id current-project)
111-
#(-> %
112-
(assoc :state (:state current-project))
113-
(assoc :name (:name current-project))
114-
(assoc :region-id (:region-id current-project))))))))))
102+
(let [source-type (get-in current-project [:config :source-type])]
103+
(-> db
104+
(assoc :source-types (if (some? source-type)
105+
#{source-type}
106+
#{"raster" "points"}))
107+
(assoc :current-project current-project)
108+
;; Keep list in sync with current project
109+
(update :list
110+
(fn [list]
111+
(some-> list
112+
(utils/update-by-id (:id current-project)
113+
#(-> %
114+
(assoc :state (:state current-project))
115+
(assoc :name (:name current-project))
116+
(assoc :region-id (:region-id current-project)))))))))))
115117

116118

117119
(rf/reg-event-fx

src/planwise/configuration/templates.clj

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@
2222
:investment 10000}
2323
{:id "upgrade-1"
2424
:capacity 300
25-
:investment 40000}]}}
25+
:investment 40000}]}
26+
:source-type "raster"}
2627

2728
:source-set-id nil
2829
:region-id nil
@@ -33,7 +34,8 @@
3334
:defaults {:name "sample"
3435
:config {:coverage {}
3536
:demographics {}
36-
:actions {}}
37+
:actions {}
38+
:source-type "points"}
3739

3840
:source-set-id nil
3941
:region-id nil

0 commit comments

Comments
 (0)