starting to break out into separate folders.
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -12,3 +12,4 @@ pom.xml.asc
|
|||||||
*.log
|
*.log
|
||||||
examples/
|
examples/
|
||||||
data/
|
data/
|
||||||
|
\#*\#
|
||||||
|
|||||||
@@ -51,7 +51,8 @@
|
|||||||
|
|
||||||
:plugins [[lein-figwheel "0.5.13"]
|
:plugins [[lein-figwheel "0.5.13"]
|
||||||
[lein-pdo "0.1.1"]]
|
[lein-pdo "0.1.1"]]
|
||||||
:jvm-opts ["-Dconfig=config/dev.edn"]}}
|
:jvm-opts ["-Dconfig=config/dev.edn"]}
|
||||||
|
:uberjar {:prep-tasks [["cljsbuild" "once" "min"] "compile"]}}
|
||||||
|
|
||||||
:cljsbuild
|
:cljsbuild
|
||||||
{:builds
|
{:builds
|
||||||
|
|||||||
@@ -45,39 +45,6 @@
|
|||||||
{}
|
{}
|
||||||
companies))))
|
companies))))
|
||||||
|
|
||||||
(re-frame/reg-event-db
|
|
||||||
::edit-company
|
|
||||||
(fn [db [_ company-id]]
|
|
||||||
(assoc-in db [:admin-companies :editing]
|
|
||||||
(get (:companies db) company-id))))
|
|
||||||
|
|
||||||
(re-frame/reg-event-fx
|
|
||||||
::save-editing-company
|
|
||||||
(fn [{:keys [db]} _]
|
|
||||||
(let [edited-company (get-in db [:admin-companies :editing])]
|
|
||||||
{:db (assoc-in db [:admin-companies :editing :saving?] true)
|
|
||||||
:http {:method :put
|
|
||||||
:token (:user db)
|
|
||||||
:body (pr-str (select-keys edited-company [:name :email :data]))
|
|
||||||
:headers {"Content-Type" "application/edn"}
|
|
||||||
:uri (str "/api/companies/" (:id edited-company))
|
|
||||||
:on-success [::finish-saving-company]}})))
|
|
||||||
|
|
||||||
(re-frame/reg-event-db
|
|
||||||
::finish-saving-company
|
|
||||||
(fn [db [_ company]]
|
|
||||||
(-> db
|
|
||||||
|
|
||||||
(assoc-in [:admin-companies :editing] nil)
|
|
||||||
(assoc-in [:companies (:id company)] company))))
|
|
||||||
|
|
||||||
(re-frame/reg-event-db
|
|
||||||
::change-editing-company
|
|
||||||
(fn [db [_ path value]]
|
|
||||||
(assoc-in db (concat [:admin-companies :editing] path)
|
|
||||||
value)))
|
|
||||||
|
|
||||||
|
|
||||||
(re-frame/reg-event-db
|
(re-frame/reg-event-db
|
||||||
::swap-company
|
::swap-company
|
||||||
(fn [db [_ company]]
|
(fn [db [_ company]]
|
||||||
|
|||||||
40
src/cljs/auto_ap/events/admin/companies.cljs
Normal file
40
src/cljs/auto_ap/events/admin/companies.cljs
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
(ns auto-ap.events.admin.companies
|
||||||
|
(:require [re-frame.core :as re-frame]
|
||||||
|
[auto-ap.db :as db]
|
||||||
|
[auto-ap.routes :as routes]
|
||||||
|
[auto-ap.effects :as effects]
|
||||||
|
[bidi.bidi :as bidi]))
|
||||||
|
|
||||||
|
(re-frame/reg-event-db
|
||||||
|
::edit
|
||||||
|
(fn [db [_ company-id]]
|
||||||
|
(assoc-in db [:admin-companies :editing]
|
||||||
|
(get (:companies db) company-id))))
|
||||||
|
|
||||||
|
(re-frame/reg-event-fx
|
||||||
|
::save
|
||||||
|
(fn [{:keys [db]} _]
|
||||||
|
(let [edited-company (get-in db [:admin-companies :editing])]
|
||||||
|
{:db (assoc-in db [:admin-companies :editing :saving?] true)
|
||||||
|
:http {:method :put
|
||||||
|
:token (:user db)
|
||||||
|
:body (pr-str (select-keys edited-company [:name :email :data]))
|
||||||
|
:headers {"Content-Type" "application/edn"}
|
||||||
|
:uri (str "/api/companies/" (:id edited-company))
|
||||||
|
:on-success [::save-complete]}})))
|
||||||
|
|
||||||
|
(re-frame/reg-event-db
|
||||||
|
::save-complete
|
||||||
|
(fn [db [_ company]]
|
||||||
|
(-> db
|
||||||
|
|
||||||
|
(assoc-in [:admin-companies :editing] nil)
|
||||||
|
(assoc-in [:companies (:id company)] company))))
|
||||||
|
|
||||||
|
(re-frame/reg-event-db
|
||||||
|
::change
|
||||||
|
(fn [db [_ path value]]
|
||||||
|
(assoc-in db (concat [:admin-companies :editing] path)
|
||||||
|
value)))
|
||||||
|
|
||||||
|
|
||||||
@@ -3,8 +3,8 @@
|
|||||||
(:require [re-frame.core :as re-frame]
|
(:require [re-frame.core :as re-frame]
|
||||||
[reagent.core :as reagent]
|
[reagent.core :as reagent]
|
||||||
[auto-ap.subs :as subs]
|
[auto-ap.subs :as subs]
|
||||||
[auto-ap.events :as events]
|
[auto-ap.events.admin.companies :as events]
|
||||||
[auto-ap.views.utils :refer [login-url]]
|
[auto-ap.views.utils :refer [login-url dispatch-value-change]]
|
||||||
[cljs.reader :as edn]
|
[cljs.reader :as edn]
|
||||||
[auto-ap.routes :as routes]
|
[auto-ap.routes :as routes]
|
||||||
[bidi.bidi :as bidi]))
|
[bidi.bidi :as bidi]))
|
||||||
@@ -19,7 +19,7 @@
|
|||||||
[:th "Email"]]]
|
[:th "Email"]]]
|
||||||
[:tbody (for [{:keys [id name email data] :as c} @companies]
|
[:tbody (for [{:keys [id name email data] :as c} @companies]
|
||||||
^{:key (str name "-" id )}
|
^{:key (str name "-" id )}
|
||||||
[:tr {:on-click (fn [] (re-frame/dispatch [::events/edit-company id]))
|
[:tr {:on-click (fn [] (re-frame/dispatch [::events/edit id]))
|
||||||
:style {"cursor" "pointer"}}
|
:style {"cursor" "pointer"}}
|
||||||
[:td name]
|
[:td name]
|
||||||
[:td email]])]]))
|
[:td email]])]]))
|
||||||
@@ -41,30 +41,26 @@
|
|||||||
|
|
||||||
(when editing-company
|
(when editing-company
|
||||||
[:div.modal.is-active
|
[:div.modal.is-active
|
||||||
[:div.modal-background {:on-click (fn [] (re-frame/dispatch [::events/edit-company nil]))}]
|
[:div.modal-background {:on-click (fn [] (re-frame/dispatch [::events/edit nil]))}]
|
||||||
|
|
||||||
[:div.modal-card
|
[:div.modal-card
|
||||||
[:header.modal-card-head
|
[:header.modal-card-head
|
||||||
[:p.modal-card-title
|
[:p.modal-card-title
|
||||||
(str "Edit " (:name editing-company))]
|
(str "Edit " (:name editing-company))]
|
||||||
[:button.delete {:on-click (fn [] (re-frame/dispatch [::events/edit-company nil]))}]]
|
[:button.delete {:on-click (fn [] (re-frame/dispatch [::events/edit nil]))}]]
|
||||||
[:section.modal-card-body
|
[:section.modal-card-body
|
||||||
[:div.field
|
[:div.field
|
||||||
[:label.label "Name"]
|
[:label.label "Name"]
|
||||||
[:div.control
|
[:div.control
|
||||||
[:input#company-name.input {:type "text" :value (:name editing-company)
|
[:input.input {:type "text" :value (:name editing-company)
|
||||||
:on-change (fn [e]
|
:on-change (dispatch-value-change [::events/change [:name]])}]]]
|
||||||
(re-frame/dispatch [::events/change-editing-company [:name]
|
|
||||||
(.. e -target -value)]))}]]]
|
|
||||||
|
|
||||||
[:div.field
|
[:div.field
|
||||||
[:label.label "Email"]
|
[:label.label "Email"]
|
||||||
[:div.control
|
[:div.control
|
||||||
[:input#email.input {:type "email"
|
[:input.input {:type "email"
|
||||||
:value (:email editing-company)
|
:value (:email editing-company)
|
||||||
:on-change (fn [e]
|
:on-change (dispatch-value-change [::events/change [:email]])}]]]
|
||||||
(re-frame/dispatch [::events/change-editing-company [:email]
|
|
||||||
(.. e -target -value)]))}]]]
|
|
||||||
[:div.field
|
[:div.field
|
||||||
[:div.control
|
[:div.control
|
||||||
[:label.radio
|
[:label.radio
|
||||||
@@ -79,7 +75,7 @@
|
|||||||
(when (:saving? editing-company) [:div.is-overlay {:style {"background-color" "rgba(150,150,150, 0.5)"}}])]
|
(when (:saving? editing-company) [:div.is-overlay {:style {"background-color" "rgba(150,150,150, 0.5)"}}])]
|
||||||
|
|
||||||
[:footer.modal-card-foot
|
[:footer.modal-card-foot
|
||||||
[:a.button.is-primary {:on-click (fn [] (re-frame/dispatch [::events/save-editing-company]))}
|
[:a.button.is-primary {:on-click (fn [] (re-frame/dispatch [::events/save]))}
|
||||||
[:span "Save"]
|
[:span "Save"]
|
||||||
(when (:saving? editing-company)
|
(when (:saving? editing-company)
|
||||||
[:span.icon
|
[:span.icon
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
(ns auto-ap.views.utils)
|
(ns auto-ap.views.utils
|
||||||
|
(:require [re-frame.core :as re-frame]))
|
||||||
|
|
||||||
(defn active-when= [active-page candidate]
|
(defn active-when= [active-page candidate]
|
||||||
(when (= active-page candidate) " active"))
|
(when (= active-page candidate) " active"))
|
||||||
@@ -7,3 +8,7 @@
|
|||||||
(let [client-id "264081895820-0nndcfo3pbtqf30sro82vgq5r27h8736.apps.googleusercontent.com"
|
(let [client-id "264081895820-0nndcfo3pbtqf30sro82vgq5r27h8736.apps.googleusercontent.com"
|
||||||
redirect-uri (js/encodeURI (str (.-origin (.-location js/window)) "/api/oauth"))]
|
redirect-uri (js/encodeURI (str (.-origin (.-location js/window)) "/api/oauth"))]
|
||||||
(str "https://accounts.google.com/o/oauth2/auth?access_type=online&client_id=" client-id "&redirect_uri=" redirect-uri "&response_type=code&scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fuserinfo.email+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fuserinfo.profile")))
|
(str "https://accounts.google.com/o/oauth2/auth?access_type=online&client_id=" client-id "&redirect_uri=" redirect-uri "&response_type=code&scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fuserinfo.email+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fuserinfo.profile")))
|
||||||
|
|
||||||
|
(defn dispatch-value-change [event]
|
||||||
|
(fn [e]
|
||||||
|
(re-frame/dispatch (conj event (.. e -target -value)))))
|
||||||
|
|||||||
Reference in New Issue
Block a user