Makes company search work much more like the react one.
This commit is contained in:
@@ -3,6 +3,7 @@
|
|||||||
[auto-ap.datomic :refer [conn]]
|
[auto-ap.datomic :refer [conn]]
|
||||||
[auto-ap.graphql.utils :refer [assert-can-see-client can-see-client?]]
|
[auto-ap.graphql.utils :refer [assert-can-see-client can-see-client?]]
|
||||||
[auto-ap.ssr-routes :as ssr-routes]
|
[auto-ap.ssr-routes :as ssr-routes]
|
||||||
|
[auto-ap.ssr.components.navbar-dropdown :refer [navbar-dropdown]]
|
||||||
[auto-ap.ssr.utils :refer [html-response]]
|
[auto-ap.ssr.utils :refer [html-response]]
|
||||||
[bidi.bidi :as bidi]
|
[bidi.bidi :as bidi]
|
||||||
[datomic.api :as d]
|
[datomic.api :as d]
|
||||||
@@ -20,13 +21,20 @@
|
|||||||
"value" v})))]
|
"value" v})))]
|
||||||
(html-response
|
(html-response
|
||||||
[:div.navbar-dropdown {:style {:width "20em"}}
|
[:div.navbar-dropdown {:style {:width "20em"}}
|
||||||
[:div.navbar-item "All"]
|
[:a.navbar-item {:hx-put (bidi/path-for ssr-routes/only-routes
|
||||||
|
:active-client
|
||||||
|
:request-method :put)
|
||||||
|
:hx-target "#company-dropdown"
|
||||||
|
:hx-swap "outerHTML"
|
||||||
|
:hx-trigger "click"}
|
||||||
|
"All"]
|
||||||
[:hr.navbar-divider]
|
[:hr.navbar-divider]
|
||||||
[:input#company-search.input.navbar-item {:placeholder "Company name"
|
[:input#company-search.input.navbar-item {:placeholder "Company name"
|
||||||
:name "search"
|
:name "search-text"
|
||||||
:autoFocus true} ]
|
:autoFocus true} ]
|
||||||
[:input#company-search-value {:type "hidden"
|
[:input#company-search-value {:type "hidden"
|
||||||
:name "search"
|
:autocomplete "off"
|
||||||
|
:name "search-client"
|
||||||
:hx-put (bidi/path-for ssr-routes/only-routes
|
:hx-put (bidi/path-for ssr-routes/only-routes
|
||||||
:active-client
|
:active-client
|
||||||
:request-method :put)
|
:request-method :put)
|
||||||
@@ -66,14 +74,7 @@ document.getElementById(\"company-search-value\").dispatchEvent(new Event('chang
|
|||||||
});
|
});
|
||||||
"))]])))
|
"))]])))
|
||||||
|
|
||||||
(defn dropdown [request]
|
#_{:hx-get
|
||||||
(let [client (get-in request [:session :client])]
|
|
||||||
[:div#company-dropdown.navbar-item.has-dropdown {:tabIndex 0 "_" (hiccup/raw
|
|
||||||
"on click elsewhere
|
|
||||||
remove .is-active from <#company-dropdown />
|
|
||||||
end "
|
|
||||||
)} ;; remove .is-active from <#company-dropdown />
|
|
||||||
[:a.navbar-link {:hx-get
|
|
||||||
(bidi/path-for ssr-routes/only-routes
|
(bidi/path-for ssr-routes/only-routes
|
||||||
:company-dropdown-contents)
|
:company-dropdown-contents)
|
||||||
:hx-target "#company-dropdown .navbar-dropdown"
|
:hx-target "#company-dropdown .navbar-dropdown"
|
||||||
@@ -84,23 +85,48 @@ document.getElementById(\"company-search-value\").dispatchEvent(new Event('chang
|
|||||||
end
|
end
|
||||||
")
|
")
|
||||||
}
|
}
|
||||||
|
(defn dropdown [request]
|
||||||
|
|
||||||
|
(let [client (get-in request [:session :client])]
|
||||||
|
|
||||||
|
(navbar-dropdown
|
||||||
|
"company-dropdown"
|
||||||
(if client
|
(if client
|
||||||
(str "Company: " (:client/name client))
|
(str "Company: " (:client/name client))
|
||||||
"Company")
|
"Company")
|
||||||
[:div.navbar-dropdown]]
|
[:div {:hx-get
|
||||||
|
(bidi/path-for ssr-routes/only-routes
|
||||||
|
:company-dropdown-contents)
|
||||||
|
:hx-swap "outerHTML"
|
||||||
|
:hx-trigger "intersect delay:150ms"
|
||||||
|
:hx-target "closest .navbar-dropdown"
|
||||||
|
: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]
|
||||||
]))
|
]))
|
||||||
|
|
||||||
;; TODO PERMS
|
|
||||||
(defn active-client [{:keys [identity params] :as request}]
|
(defn active-client [{:keys [identity params] :as request}]
|
||||||
(auto-ap.logging/info ::searched
|
(clojure.pprint/pprint params)
|
||||||
:params params)
|
(let [client-id (some-> (or (:search-client params) (get params "search-client")) Long/parseLong)]
|
||||||
(assert-can-see-client identity (Long/parseLong (or (:search params) (get params "search"))))
|
(when client-id
|
||||||
|
(assert-can-see-client identity client-id))
|
||||||
(let [new-session (assoc (:session request) :client
|
(let [new-session (assoc (:session request) :client
|
||||||
(d/pull (d/db conn) [:db/id :client/name :client/code] (Long/parseLong (or (:search params) (get params "search")))))]
|
(when client-id
|
||||||
|
(d/pull (d/db conn) [:db/id :client/name :client/code] client-id)))]
|
||||||
(assoc
|
(assoc
|
||||||
(html-response
|
(html-response
|
||||||
(dropdown (assoc request :session new-session)))
|
(dropdown (assoc request :session new-session)))
|
||||||
:session
|
:session
|
||||||
new-session
|
new-session
|
||||||
:headers
|
:headers
|
||||||
{"hx-trigger" "clientSelected"})))
|
{"hx-trigger" "clientSelected"}))))
|
||||||
|
|||||||
14
src/clj/auto_ap/ssr/components/navbar_dropdown.clj
Normal file
14
src/clj/auto_ap/ssr/components/navbar_dropdown.clj
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
(ns auto-ap.ssr.components.navbar-dropdown
|
||||||
|
(:require [hiccup2.core :as hiccup]))
|
||||||
|
|
||||||
|
(defn navbar-dropdown [id header children]
|
||||||
|
[:div {
|
||||||
|
:id id
|
||||||
|
:class (str "navbar-item has-dropdown")
|
||||||
|
"_" (hiccup/raw "on click elsewhere remove .is-active from me")
|
||||||
|
|
||||||
|
}
|
||||||
|
[:a {:class "navbar-link login"
|
||||||
|
"_" (hiccup/raw "on click toggle .is-active on the parentElement of me then add .appear to next <.navbar-dropdown />")} header]
|
||||||
|
(into [:div {:class "navbar-dropdown"}
|
||||||
|
children])])
|
||||||
22
src/clj/auto_ap/ssr/login_dropdown.clj
Normal file
22
src/clj/auto_ap/ssr/login_dropdown.clj
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
(ns auto-ap.ssr.login-dropdown
|
||||||
|
(:require
|
||||||
|
[auto-ap.client-routes :as client-routes]
|
||||||
|
[auto-ap.ssr.components.navbar-dropdown :refer [navbar-dropdown]]
|
||||||
|
[bidi.bidi :as bidi]))
|
||||||
|
|
||||||
|
(defn dropdown [{:keys [identity]}]
|
||||||
|
(if identity
|
||||||
|
(navbar-dropdown
|
||||||
|
"login-dropdown"
|
||||||
|
[:span [:span.icon [:i.fa.fa-user] ]
|
||||||
|
[:span (:user/name identity)]]
|
||||||
|
[:div
|
||||||
|
[:a {:class "navbar-item"
|
||||||
|
:href (bidi/path-for client-routes/routes :reports)} "My company"]
|
||||||
|
#_[:a.dropdown-item {:on-click (dispatch-event-with-propagation [:vendor-dialog/started {}])} "New Vendor"] ;; double colorn
|
||||||
|
#_[: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"]])
|
||||||
|
[:a.navbar-item {:href (bidi/path-for client-routes/routes :login )} "Login"]))
|
||||||
@@ -3,7 +3,8 @@
|
|||||||
[auto-ap.logging :as alog]
|
[auto-ap.logging :as alog]
|
||||||
[auto-ap.ssr.company-dropdown :as company-dropdown]
|
[auto-ap.ssr.company-dropdown :as company-dropdown]
|
||||||
[config.core :refer [env]]
|
[config.core :refer [env]]
|
||||||
[hiccup2.core :as hiccup]))
|
[hiccup2.core :as hiccup]
|
||||||
|
[auto-ap.ssr.login-dropdown :as login-dropdown]))
|
||||||
|
|
||||||
(defn html-page [hiccup]
|
(defn html-page [hiccup]
|
||||||
{:status 200
|
{:status 200
|
||||||
@@ -53,17 +54,19 @@
|
|||||||
[:div.navbar-start
|
[:div.navbar-start
|
||||||
[:a.navbar-item {:href "/"}
|
[:a.navbar-item {:href "/"}
|
||||||
"Home" ]
|
"Home" ]
|
||||||
[:a.navbar-item {:href "/invoices/"}
|
[:a.navbar-item {:href "/invoices"}
|
||||||
"Invoices" ]
|
"Invoices" ]
|
||||||
[:a.navbar-item {:href "/payments/"}
|
[:a.navbar-item {:href "/payments"}
|
||||||
"Payments" ]
|
"Payments" ]
|
||||||
[:a.navbar-item {:href "/pos/sales-orders/"}
|
[:a.navbar-item {:href "/pos/sales-orders"}
|
||||||
"POS" ]
|
"POS" ]
|
||||||
[:a.navbar-item {:href "/transactions/"}
|
[:a.navbar-item {:href "/transactions"}
|
||||||
"Transactions" ]
|
"Transactions" ]
|
||||||
[:a.navbar-item {:href "/ledger/"}
|
[:a.navbar-item {:href "/ledger"}
|
||||||
"Ledger" ]
|
"Ledger" ]]
|
||||||
(company-dropdown/dropdown request)]]]]
|
[:div.navbar-end
|
||||||
|
(company-dropdown/dropdown request)
|
||||||
|
(login-dropdown/dropdown request)]]]]
|
||||||
[:div {:class "columns has-shadow", :id "mail-app", :style "margin-bottom: 0px; height: calc(100vh - 46px);"}
|
[:div {:class "columns has-shadow", :id "mail-app", :style "margin-bottom: 0px; height: calc(100vh - 46px);"}
|
||||||
[:aside {:class "column aside menu is-2 "}
|
[:aside {:class "column aside menu is-2 "}
|
||||||
[:div {:class "main left-nav"}
|
[:div {:class "main left-nav"}
|
||||||
|
|||||||
Reference in New Issue
Block a user