Skip to content

Commit a8d74da

Browse files
author
Hugo David Farji
authored
Merge pull request #544 from instedd/template-selector
Template selector
2 parents aef047a + d58fe86 commit a8d74da

File tree

12 files changed

+202
-15
lines changed

12 files changed

+202
-15
lines changed

resources/planwise/sql/projects2.sql

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
-- :name db-create-project! :<! :1
22
INSERT INTO projects2
3-
("owner-id", name, config, "provider-set-id", state)
4-
VALUES (:owner-id, :name, NULL, NULL, :state)
3+
("owner-id", name, config, "region-id", "provider-set-id", "source-set-id", state)
4+
VALUES (:owner-id, :name, :config, :region-id, :provider-set-id, :source-set-id, :state)
55
RETURNING id;
66

77
-- :name db-update-project :!

resources/sass/site2.scss

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -836,6 +836,61 @@ form.vertical, .fields-vertical {
836836
padding: 10px;
837837
}
838838

839+
.template-container {
840+
display: flex;
841+
justify-content: center;
842+
align-items: center;
843+
width: 100%;
844+
border-radius: 4px;
845+
background-color: #FFFFFF;
846+
box-shadow: 0 1px 2px 0 rgba(0,0,0,0.2), 0 1px 3px 0 rgba(0,0,0,0.1);
847+
flex-direction: column;
848+
padding: 60px;
849+
850+
h2 {
851+
color: #999999;
852+
font-size: 1rem;
853+
text-transform: uppercase;
854+
margin-bottom: 45px;
855+
}
856+
857+
i {
858+
font-size: 48px;
859+
color: #FF5722;
860+
display: block;
861+
padding: 15px;
862+
border: 1px solid rgba(0,0,0,0.1);
863+
border-radius: 48px;
864+
height: 48px;
865+
width: 48px
866+
}
867+
868+
.action {
869+
display: flex;
870+
flex-direction: column;
871+
align-items: center;
872+
width: 20%;
873+
cursor: pointer;
874+
875+
div {
876+
text-align: center;
877+
margin: 1rem 0;
878+
}
879+
}
880+
881+
.row {
882+
display: flex;
883+
justify-content: space-around;
884+
width: 100%;
885+
}
886+
887+
hr {
888+
border: 1px solid rgba(0,0,0,0.1);
889+
width: calc(100% + 118px);
890+
margin: 60px 0;
891+
}
892+
}
893+
839894
.loader {
840895
position: absolute;
841896
left: 50%;

src/planwise/client/projects2/api.cljs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@
44
;; API methods
55

66
(defn- create-project!
7-
[]
7+
[defaults]
88
{:method :post
99
:section :index
10+
:params {:project defaults}
1011
:uri "/api/projects2"})
1112

1213
(defn- list-projects
@@ -15,6 +16,12 @@
1516
:section :index
1617
:uri (str "/api/projects2")})
1718

19+
(defn- list-templates
20+
[]
21+
{:method :get
22+
:section :index
23+
:uri (str "/api/projects2/templates")})
24+
1825
(defn- update-project
1926
[project-id project]
2027
{:method :put
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
(ns planwise.client.projects2.components.create
2+
(:require [re-frame.core :refer [subscribe dispatch] :as rf]
3+
[planwise.client.asdf :as asdf]
4+
[reagent.core :as r]
5+
[re-com.core :as rc]
6+
[planwise.client.components.common2 :as common2]
7+
[planwise.client.routes :as routes]
8+
[planwise.client.utils :as utils]
9+
[planwise.client.ui.common :as ui]
10+
[planwise.client.ui.rmwc :as m]
11+
[planwise.client.mapping :refer [static-image fullmap-region-geo]]
12+
[planwise.client.components.common :as common]))
13+
(def project-templates
14+
[{:description "Plan facilities based on ground access"
15+
:icon "directions_walk"
16+
:key "plan"
17+
:defaults {:name "ground"}}
18+
{:description "Plan diagonostic devices & sample referrals"
19+
:icon "call_split"
20+
:key "diagnosis"
21+
:defaults {:name "sample"}}])
22+
23+
(defn project-section-template-selector
24+
[]
25+
[ui/fixed-width (common2/nav-params)
26+
(let [templates (subscribe [:projects2/templates])
27+
scratch-template (first (filter #(not (contains? % :description)) @templates))
28+
sample-templates (filter #(contains? % :description) @templates)]
29+
(dispatch [:projects2/get-templates-list])
30+
[:div.template-container
31+
(if (some? sample-templates)
32+
[:h2 "Start from a template"])
33+
(if (some? sample-templates)
34+
[:div.row
35+
(map (fn [template]
36+
[:a.action {:key (:key template) :onClick #(dispatch [:projects2/new-project (:defaults template)])}
37+
[m/Icon {} (:icon template)]
38+
[:div (:description template)]])
39+
sample-templates)])
40+
[:hr]
41+
[:h2 "Start from scratch"]
42+
[:div.row
43+
[:a.action {:onClick #(dispatch [:projects2/new-project (:defaults scratch-template)])}
44+
[m/Icon {} "folder_open"]
45+
[:div "Follow a wizard through all available settings"]]]])])

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,6 @@
5151
[projects-list @projects])))
5252

5353
(defn project-section-index []
54-
(let [create-project-button (ui/main-action {:icon "add" :on-click #(dispatch [:projects2/new-project])})]
54+
(let [create-project-button (ui/main-action {:icon "add" :on-click #(dispatch [:projects2/template-project])})]
5555
[ui/fixed-width (merge {:action create-project-button} (common2/nav-params))
5656
[listing-component]]))

src/planwise/client/projects2/handlers.cljs

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,30 @@
1717
(rf/reg-event-fx
1818
:projects2/new-project
1919
in-projects2
20-
(fn [_ [_]]
21-
{:api (assoc (api/create-project!)
20+
(fn [_ [_ defaults]]
21+
{:api (assoc (api/create-project! defaults)
2222
:on-success [:projects2/project-created])}))
2323

24+
(rf/reg-event-fx
25+
:projects2/template-project
26+
in-projects2
27+
(fn [_ [_]]
28+
{:navigate (routes/projects2-new {})}))
29+
30+
(rf/reg-event-fx
31+
:projects2/get-templates-list
32+
in-projects2
33+
(fn [_ [_]]
34+
{:api (assoc (api/list-templates) :on-success [:projects2/templates-fetched])}))
35+
; {:api (assoc (api/create-project!)
36+
; :on-success [:projects2/project-created])}))
37+
(rf/reg-event-fx
38+
:projects2/templates-fetched
39+
in-projects2
40+
(fn [{:keys [db]} [_ templates]]
41+
{:db (-> db
42+
(assoc :templates templates))}))
43+
2444
(rf/reg-event-fx
2545
:projects2/project-created
2646
in-projects2

src/planwise/client/projects2/subs.cljs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@
99
(fn [db _]
1010
(get-in db [:projects2 :current-project])))
1111

12+
(rf/reg-sub
13+
:projects2/templates
14+
(fn [db _]
15+
(get-in db [:projects2 :templates])))
16+
1217
(rf/reg-sub
1318
:projects2/list
1419
(fn [db _]
@@ -29,4 +34,3 @@
2934
:projects2/upgrade-actions :<- [:projects2/current-project]
3035
(fn [current-project [_]]
3136
(get-in current-project [:config :actions :upgrade])))
32-

src/planwise/client/projects2/views.cljs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
[planwise.client.projects2.components.dashboard :as dashboard]
88
[planwise.client.projects2.components.listings :as listings]
99
[planwise.client.projects2.components.settings :as settings]
10+
[planwise.client.projects2.components.create :as create]
1011
[planwise.client.routes :as routes]
1112
[planwise.client.ui.common :as ui]))
1213

@@ -37,6 +38,7 @@
3738
(let [section (:section @page-params)]
3839
(case section
3940
:index [listings/project-section-index]
41+
:new [create/project-section-template-selector]
4042
:show [project-section-show :scenarios]
4143
:project-scenarios [project-section-show :scenarios]
4244
:project-settings [project-section-show :settings]

src/planwise/client/routes.cljs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
(dispatch [:navigate {:page :sources}]))
1515
(defroute projects2 "/projects2" []
1616
(dispatch [:navigate {:page :projects2, :section :index}]))
17+
(defroute projects2-new "/projects2/new" []
18+
(dispatch [:navigate {:page :projects2, :section :new}]))
1719
(defroute projects2-show "/projects2/:id" [id]
1820
(dispatch [:navigate {:page :projects2, :id (js/parseInt id), :section :show}]))
1921
(defroute projects2-show-with-step "/projects2/:id/steps/:step" [id step]

src/planwise/component/projects2.clj

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,10 @@
2828
;; Service definition
2929

3030
(defn create-project
31-
[store owner-id]
32-
(db-create-project! (get-db store) {:owner-id owner-id
33-
:name ""
34-
:state "draft"}))
31+
[store params]
32+
(db-create-project! (get-db store) (-> (merge params {:state "draft" :config {}})
33+
(assoc :config (pr-str (:config params)))
34+
(assoc :providers (pr-str (:providers params))))))
3535

3636
(defn update-project
3737
[store {:keys [config provider-set-id] :as project}]

0 commit comments

Comments
 (0)