Synchronizes selected company on 1099 page to everything else.

This commit is contained in:
2023-01-23 16:08:35 -08:00
parent 1fb037e4f4
commit 63ea83af9b
8 changed files with 60 additions and 53 deletions

View File

@@ -0,0 +1,6 @@
(ns auto-ap.ssr.auth)
(defn logout [request]
{:status 301
:headers {"Location" "/login"}
:session {}})

View File

@@ -87,7 +87,6 @@
[?p :payment/vendor ?v]]
(d/db conn))
:else
(d/q '[:find
(pull ?c [:client/code :db/id])

View File

@@ -71,29 +71,23 @@ z.input.addEventListener(\"selection\", function (event) {
z.input.value = event.detail.selection.value.value;
document.getElementById(\"company-search-value\").value= event.detail.selection.value.key;
document.getElementById(\"company-search-value\").dispatchEvent(new Event('change'));
});
"))]])))
#_{:hx-get
(bidi/path-for ssr-routes/only-routes
:company-dropdown-contents)
:hx-target "#company-dropdown .navbar-dropdown"
:hx-swap "outerHTML"
"_" (hiccup/raw
"on click
toggle .is-active on <#company-dropdown />
end
")
}
(defn dropdown [request]
(let [client (get-in request [:session :client])]
(navbar-dropdown
"company-dropdown"
(if client
(str "Company: " (:client/name client))
"Company")
[:span
(if client
(str "Company: " (:client/name client))
"Company")
[:script
(hiccup/raw
"localStorage.setItem(\"last-client-id\", \""(:db/id client)"\")")]]
[:div {:hx-get
(bidi/path-for ssr-routes/only-routes
:company-dropdown-contents)
@@ -103,17 +97,7 @@ document.getElementById(\"company-search-value\").dispatchEvent(new Event('chang
:style {:width "20em"
:height "80px"}
}
[:div.loader.is-loading.is-active.is-centered]]
)
#_[:div#company-dropdown.navbar-item.has-dropdown
{"_" (hiccup/raw
"on click elsewhere
remove .is-active from <#company-dropdown />
end "
)} ;; remove .is-active from <#company-dropdown />
[:div.navbar-dropdown]
]))
[:div.loader.is-loading.is-active.is-centered]])))
(defn active-client [{:keys [identity params] :as request}]
(clojure.pprint/pprint params)

View File

@@ -3,17 +3,21 @@
[auto-ap.routes.utils
:refer [wrap-admin wrap-client-redirect-unauthenticated wrap-secure]]
[auto-ap.ssr.admin :as admin]
[auto-ap.ssr.auth :as auth]
[auto-ap.ssr.company.company-1099 :as company-1099]
[auto-ap.ssr.company-dropdown :as company-dropdown]))
;; from auto-ap.ssr-routes, because they're shared
(def key->handler {:admin-history (wrap-client-redirect-unauthenticated (wrap-secure (wrap-admin admin/history)))
:admin-history-search (wrap-client-redirect-unauthenticated (wrap-secure (wrap-admin admin/history-search)))
:admin-history-inspect (wrap-client-redirect-unauthenticated (wrap-secure (wrap-admin admin/inspect)))
:active-client (wrap-client-redirect-unauthenticated (wrap-secure (wrap-admin company-dropdown/active-client)))
:company-dropdown-contents (wrap-client-redirect-unauthenticated (wrap-secure company-dropdown/dropdown-contents))
:company-1099 (wrap-client-redirect-unauthenticated (wrap-secure company-1099/page))
:company-1099-vendor-table (wrap-client-redirect-unauthenticated (wrap-secure company-1099/vendor-table))
:company-1099-vendor-dialog (wrap-client-redirect-unauthenticated (wrap-secure company-1099/vendor-dialog))
:company-1099-vendor-save (wrap-client-redirect-unauthenticated (wrap-secure company-1099/vendor-save))})
(def key->handler {:logout auth/logout
:admin-history (wrap-client-redirect-unauthenticated (wrap-secure (wrap-admin admin/history)))
:admin-history-search (wrap-client-redirect-unauthenticated (wrap-secure (wrap-admin admin/history-search)))
:admin-history-inspect (wrap-client-redirect-unauthenticated (wrap-secure (wrap-admin admin/inspect)))
:active-client (wrap-client-redirect-unauthenticated (wrap-secure (wrap-admin company-dropdown/active-client)))
:company-dropdown-contents (wrap-client-redirect-unauthenticated (wrap-secure company-dropdown/dropdown-contents))
:company-1099 (wrap-client-redirect-unauthenticated (wrap-secure company-1099/page))
:company-1099-vendor-table (wrap-client-redirect-unauthenticated (wrap-secure company-1099/vendor-table))
:company-1099-vendor-dialog (wrap-client-redirect-unauthenticated (wrap-secure company-1099/vendor-dialog))
:company-1099-vendor-save (wrap-client-redirect-unauthenticated (wrap-secure company-1099/vendor-save))})

View File

@@ -2,7 +2,9 @@
(:require
[auto-ap.client-routes :as client-routes]
[auto-ap.ssr.components.navbar-dropdown :refer [navbar-dropdown]]
[bidi.bidi :as bidi]))
[bidi.bidi :as bidi]
[hiccup2.core :as hiccup]
[auto-ap.ssr-routes :as ssr-routes]))
(defn dropdown [{:keys [identity]}]
(if identity
@@ -17,6 +19,8 @@
#_[:a.dropdown-item {:on-click (dispatch-event-with-propagation [:vendor-dialog/edit {}])} "Edit Vendor"]
(when (= "admin" (:user/role identity))
[:a {:class "navbar-item" :href (bidi/path-for client-routes/routes :admin)} "Administration"])
#_[:hr {:class "navbar-divider"}]
#_[:a.navbar-item {:on-click (fn [e] (.preventDefault e) (re-frame/dispatch [:events/logout]))} "Logout"]])
[:hr {:class "navbar-divider"}]
[:a.navbar-item {"_" (hiccup/raw "on click call localStorage.removeItem(\"jwt\")")
:href (bidi/path-for ssr-routes/only-routes :logout)}
"Logout"]])
[:a.navbar-item {:href (bidi/path-for client-routes/routes :login )} "Login"]))

View File

@@ -1,10 +1,10 @@
(ns auto-ap.ssr.ui
(:require
[auto-ap.logging :as alog]
[auto-ap.client-routes :as client-routes]
[auto-ap.ssr.company-dropdown :as company-dropdown]
[config.core :refer [env]]
[hiccup2.core :as hiccup]
[auto-ap.ssr.login-dropdown :as login-dropdown]))
[auto-ap.ssr.login-dropdown :as login-dropdown]
[bidi.bidi :as bidi]
[hiccup2.core :as hiccup]))
(defn html-page [hiccup]
{:status 200
@@ -15,7 +15,6 @@
{}
hiccup))})
(defn base-page [request contents side-bar-contents]
(html-page
[:html.has-navbar-fixed-top
@@ -54,15 +53,15 @@
[:div.navbar-start
[:a.navbar-item {:href "/"}
"Home" ]
[:a.navbar-item {:href "/invoices"}
[:a.navbar-item {:href (bidi/path-for client-routes/routes :unpaid-invoices)}
"Invoices" ]
[:a.navbar-item {:href "/payments"}
[:a.navbar-item {:href (bidi/path-for client-routes/routes :payments)}
"Payments" ]
[:a.navbar-item {:href "/pos/sales-orders"}
[:a.navbar-item {:href (bidi/path-for client-routes/routes :sales-orders)}
"POS" ]
[:a.navbar-item {:href "/transactions"}
[:a.navbar-item {:href (bidi/path-for client-routes/routes :transactions)}
"Transactions" ]
[:a.navbar-item {:href "/ledger"}
[:a.navbar-item {:href (bidi/path-for client-routes/routes :ledger)}
"Ledger" ]]
[:div.navbar-end
(company-dropdown/dropdown request)

View File

@@ -1,6 +1,7 @@
(ns auto-ap.ssr-routes)
(def routes {"admin" {"/history" {"" :admin-history
(def routes {"logout" :logout
"admin" {"/history" {"" :admin-history
"/" :admin-history
#"/search/?" :admin-history-search
["/" [#"\d+" :entity-id] #"/?"] :admin-history-search

View File

@@ -8,7 +8,9 @@
[bidi.bidi :as bidi]
[clojure.string :as str]
[goog.crypt.base64 :as b64]
[re-frame.core :as re-frame]))
[re-frame.core :as re-frame]
[auto-ap.ssr-routes :as ssr-routes]
[cemerick.url :as url]))
(defn jwt->data [token]
(js->clj (.parse js/JSON (b64/decodeString (second (str/split token #"\." ))))))
@@ -114,11 +116,19 @@
:is-initial-loading? false
:active-route :initial-error)))
(re-frame/reg-event-db
(re-frame/reg-event-fx
::swap-client
(fn [db [_ client]]
[with-user]
(fn [{:keys [db user]} [_ client]]
(.setItem js/localStorage "last-client-id" (:id client))
(assoc db :client (:id client))))
{:db (assoc db :client (:id client))
:http {:token user
:method :put
:uri (str (bidi/path-for ssr-routes/only-routes
:active-client
:request-method :put)
"?"
(url/map->query {:search-client (:id client)}))}}))
(re-frame/reg-event-fx
::set-active-route