Started adding admin page
This commit is contained in:
@@ -41,6 +41,11 @@
|
||||
(fn [db [_ companies]]
|
||||
(assoc db :companies companies)))
|
||||
|
||||
(re-frame/reg-event-db
|
||||
::select-company
|
||||
(fn [db [_ company]]
|
||||
(assoc-in db [:admin-companies :selected] company)))
|
||||
|
||||
(re-frame/reg-event-db
|
||||
::swap-company
|
||||
(fn [db [_ company]]
|
||||
|
||||
@@ -3,6 +3,8 @@
|
||||
|
||||
(def routes ["/" {"" :index
|
||||
"login/" :login
|
||||
"admin/" {"" :admin
|
||||
"companies" :admin-companies}
|
||||
"invoices/" {"" :invoices
|
||||
"import" :import-invoices
|
||||
"unpaid" :unpaid-invoices
|
||||
|
||||
@@ -24,6 +24,14 @@
|
||||
(fn [db]
|
||||
(:user db)))
|
||||
|
||||
(re-frame/reg-sub
|
||||
::admin-companies
|
||||
(fn [db]
|
||||
(assoc
|
||||
(:admin-companies db)
|
||||
:selected
|
||||
(first (filter #(= (:id %) (:selected (:admin-companies db))) (:companies db))))))
|
||||
|
||||
(re-frame/reg-sub
|
||||
::user
|
||||
(fn [db]
|
||||
|
||||
@@ -15,6 +15,8 @@
|
||||
:import-invoices :left-panel
|
||||
:unpaid-invoices :left-panel
|
||||
:paid-invoices :left-panel
|
||||
:admin :admin-left-panel
|
||||
:admin-companies :admin-left-panel
|
||||
:new-invoice :blank} page))
|
||||
|
||||
(defn login-dropdown []
|
||||
@@ -27,13 +29,72 @@
|
||||
[:a {:class "navbar-link login" :on-click (fn [e] (re-frame/dispatch [::events/toggle-menu :account]))} (:name @user)]
|
||||
[:div {:class "navbar-dropdown"}
|
||||
[:a {:class "navbar-item"} "My profile"]
|
||||
[:a {:class "navbar-item"} "Administration"]
|
||||
[:a {:class "navbar-item" :href (bidi/path-for routes/routes :admin)} "Administration"]
|
||||
[:hr {:class "navbar-divider"}]
|
||||
[:a.navbar-item {:on-click (fn [e] (.preventDefault e) (re-frame/dispatch [::events/logout]))} "Logout"]]]
|
||||
[:a.navbar-item {:href login-url} "Login"])]]))
|
||||
|
||||
(defmulti layout page->layout)
|
||||
|
||||
(defmethod layout :admin-left-panel [ap]
|
||||
(let [company (re-frame/subscribe [::subs/company])
|
||||
companies (re-frame/subscribe [::subs/companies])
|
||||
menu (re-frame/subscribe [::subs/menu])]
|
||||
[:div
|
||||
[:nav {:class "navbar has-shadow"}
|
||||
[:div {:class "container"}
|
||||
[:div {:class "navbar-brand"}
|
||||
[:a {:class "navbar-item", :href "../"}
|
||||
[:h1 (str "Integreat")]]]
|
||||
|
||||
[:div {:class "navbar-burger burger", :data-target "navMenu"}
|
||||
[:span]
|
||||
[:span]
|
||||
[:span]]
|
||||
[login-dropdown]]]
|
||||
[:div {:class "columns", :id "mail-app"}
|
||||
[:aside {:class "column is-narrow aside menu hero is-fullheight"}
|
||||
[:div.main
|
||||
[:p.menu-label "General"]
|
||||
[:p.menu-item
|
||||
[:a {:href (bidi/path-for routes/routes :admin) , :class (str "item" (active-when= ap :admin))}
|
||||
[:span {:class "icon"}
|
||||
[:i {:class "fa fa-tachometer"}]]
|
||||
[:span {:class "name"} "Dashboard"]]]
|
||||
|
||||
[:p.menu-label "Setup"]
|
||||
[:ul.menu-list
|
||||
[:li.menu-item
|
||||
[:a {:href (bidi/path-for routes/routes :admin-companies) , :class (str "item" (active-when= ap :admin-companies))}
|
||||
[:span {:class "icon"}
|
||||
[:i {:class "fa fa-star-o"}]]
|
||||
|
||||
[:span {:class "name"} "Companies"]]]
|
||||
[:li.menu-item
|
||||
[:a {:href (bidi/path-for routes/routes :admin-users), :class (str "item" (active-when= ap :admin-users))}
|
||||
[:span {:class "icon"}
|
||||
[:i {:class "fa fa-envelope-o"}]]
|
||||
[:span {:class "name"} "Users"]]]
|
||||
|
||||
[:ul ]]]
|
||||
|
||||
[:div.left-nav
|
||||
[:div {:class "compose has-text-centered"}
|
||||
[:a {:class "button is-danger is-block is-bold" :href (bidi/path-for routes/routes :index)}
|
||||
[:span {:class "compose"} "Back"]]]]]
|
||||
[:div {:class "column messages hero is-fullheight", :id "message-feed"}
|
||||
^{:key (str "active-page-" (:name @company))} [pages/active-page ap]]]
|
||||
[:footer {:class "footer"}
|
||||
[:div {:class "container"}
|
||||
[:div {:class "content has-text-centered"}
|
||||
[:p
|
||||
[:strong "Auto-AP"]"by "
|
||||
[:a {:href "https://github.com/"} "Integreat"]"."]
|
||||
[:p
|
||||
[:a {:class "icon", :href "https://github.com/dansup/bulma-templates"}
|
||||
[:i {:class "fa fa-github"}]]]]]]
|
||||
[:div#dz-hidden]]))
|
||||
|
||||
(defmethod layout :left-panel [ap]
|
||||
(let [company (re-frame/subscribe [::subs/company])
|
||||
companies (re-frame/subscribe [::subs/companies])
|
||||
|
||||
@@ -6,6 +6,8 @@
|
||||
[auto-ap.events :as events]
|
||||
[auto-ap.views.pages.login :refer [login-page]]
|
||||
[auto-ap.views.pages.index :refer [index-page]]
|
||||
[auto-ap.views.pages.admin :refer [admin-page]]
|
||||
[auto-ap.views.pages.admin.companies :refer [admin-companies-page]]
|
||||
[auto-ap.views.pages.unpaid-invoices :refer [unpaid-invoices-page]]
|
||||
[auto-ap.views.pages.new-invoice :refer [new-invoice-page]]
|
||||
[auto-ap.views.pages.import-invoices :refer [import-invoices-page]]
|
||||
@@ -18,7 +20,6 @@
|
||||
[cljs.core.async :refer [<!]]))
|
||||
|
||||
|
||||
|
||||
(defmulti active-page identity)
|
||||
|
||||
(defmethod active-page :login []
|
||||
@@ -27,6 +28,12 @@
|
||||
(defmethod active-page :index []
|
||||
index-page)
|
||||
|
||||
(defmethod active-page :admin []
|
||||
[admin-page])
|
||||
|
||||
(defmethod active-page :admin-companies []
|
||||
[admin-companies-page])
|
||||
|
||||
(defmethod active-page :unpaid-invoices []
|
||||
[unpaid-invoices-page])
|
||||
|
||||
@@ -48,9 +55,3 @@
|
||||
|
||||
|
||||
(defmethod active-page :new-invoice [] new-invoice-page)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
17
src/cljs/auto_ap/views/pages/admin.cljs
Normal file
17
src/cljs/auto_ap/views/pages/admin.cljs
Normal file
@@ -0,0 +1,17 @@
|
||||
(ns auto-ap.views.pages.admin
|
||||
(:require-macros [cljs.core.async.macros :refer [go]])
|
||||
(:require [re-frame.core :as re-frame]
|
||||
[reagent.core :as reagent]
|
||||
[auto-ap.subs :as subs]
|
||||
[auto-ap.events :as events]
|
||||
[auto-ap.views.utils :refer [login-url]]
|
||||
[cljs.reader :as edn]
|
||||
[auto-ap.routes :as routes]
|
||||
[bidi.bidi :as bidi]))
|
||||
|
||||
(defn admin-page []
|
||||
[:div {:class "inbox-messages"}
|
||||
[:div.hero
|
||||
[:div.hero-body
|
||||
[:div.container
|
||||
[:h1.title "Admin"]]]]])
|
||||
60
src/cljs/auto_ap/views/pages/admin/companies.cljs
Normal file
60
src/cljs/auto_ap/views/pages/admin/companies.cljs
Normal file
@@ -0,0 +1,60 @@
|
||||
(ns auto-ap.views.pages.admin.companies
|
||||
(:require-macros [cljs.core.async.macros :refer [go]])
|
||||
(:require [re-frame.core :as re-frame]
|
||||
[reagent.core :as reagent]
|
||||
[auto-ap.subs :as subs]
|
||||
[auto-ap.events :as events]
|
||||
[auto-ap.views.utils :refer [login-url]]
|
||||
[cljs.reader :as edn]
|
||||
[auto-ap.routes :as routes]
|
||||
[bidi.bidi :as bidi]))
|
||||
(defn companies-table []
|
||||
(let [companies (re-frame/subscribe [::subs/companies])
|
||||
admin-companies (re-frame/subscribe [::subs/admin-companies])
|
||||
selected-company (:selected @admin-companies)]
|
||||
[:table {:class "table", :style {:width "100%"}}
|
||||
[:thead
|
||||
[:tr
|
||||
[:th ""]
|
||||
[:th "Name"]
|
||||
[:th ""]]]
|
||||
[:tbody (for [{:keys [id name data] :as c} @companies]
|
||||
^{:key (str name "-" id )}
|
||||
[:tr {:on-click (fn [] (re-frame/dispatch [::events/select-company id]))
|
||||
:style {"cursor" "pointer"}}
|
||||
[:td id]
|
||||
[:td name]
|
||||
[:td [:i.fa.fa-pencil]]])]]))
|
||||
|
||||
(defn admin-companies-page []
|
||||
[:div {:class "inbox-messages"}
|
||||
[:div.hero
|
||||
[:div.hero-body
|
||||
[:div.container
|
||||
(let [companies (re-frame/subscribe [::subs/companies])
|
||||
admin-companies (re-frame/subscribe [::subs/admin-companies])
|
||||
selected-company (:selected @admin-companies)]
|
||||
(if selected-company
|
||||
[:div
|
||||
[:h1.title "Companies > " (:name selected-company)]
|
||||
|
||||
[:label {:for "company-name"} "Name"]
|
||||
[:input#company-name.input {:type "text" :value (:name selected-company)}]
|
||||
|
||||
[:label {:for "email"} "Email"]
|
||||
[:input#email.input {:type "email" :value (:email selected-company)}]
|
||||
|
||||
[:label {:for "data"} "Data"]
|
||||
[:input#data.input {:type "text" :value (:data selected-company)}]
|
||||
|
||||
[:label {:for "check"} "Send invoice reminders?"]
|
||||
[:input#check.checkbox {:type "checkbox" :value (:send-reminders selected-company)}]
|
||||
[:div]
|
||||
|
||||
[:a.button {:on-click (fn [] (re-frame/dispatch [::events/select-company nil]))} "Back"]
|
||||
[:a.button.is-primary {:on-click (fn [] (re-frame/dispatch [::events/select-company nil]))} "Save"]]
|
||||
[:div
|
||||
[:h1.title "Companies"]
|
||||
[companies-table]
|
||||
[:a.button.is-primary "New Company"]]))]]]])
|
||||
|
||||
Reference in New Issue
Block a user