Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support passing POST data to start a region search #443

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion project.clj
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@
:profiles {:dev {:dependencies [[binaryage/devtools "0.9.10"]
[day8.re-frame/re-frame-10x "0.4.4"]
[figwheel-sidecar "0.5.19"]
[cider/piggieback "0.4.1"]]
[cider/piggieback "0.4.2"]]
:resource-paths ["config/dev" "tools" "config/defaults"]
:plugins [[lein-figwheel "0.5.19"]
[lein-doo "0.1.8"]]}
Expand Down
9 changes: 5 additions & 4 deletions src/clj/bluegenes/index.clj
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
[:style
"#csscompiling{position:fixed;bottom:0;right:0;padding:20px;height:100px;width:400px;background-color:#FFA726;}"])

(defn head []
(defn head [& [req]]
[:head
loader-style
css-compiling-style
Expand All @@ -56,7 +56,8 @@
:serviceRoot (:bluegenes-default-service-root env)
:mineName (:bluegenes-default-mine-name env)
:version (or (second (re-find #"app-(.*)\.js" bundle-path))
"dev")})
"dev")
:postData (:params req)})
";")]
; Javascript:
[:link {:rel "shortcut icon" :href "https://raw.githubusercontent.com/intermine/design-materials/f5f00be4/logos/intermine/fav32x32.png" :type "image/png"}]
Expand Down Expand Up @@ -90,9 +91,9 @@

(defn index
"Hiccup markup that generates the landing page and loads the necessary assets."
[]
[& [req]]
(html5
(head)
(head req)
[:body
(css-compiler)
(loader)
Expand Down
8 changes: 5 additions & 3 deletions src/clj/bluegenes/routes.clj
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
(ns bluegenes.routes
(:require [compojure.core :refer [GET defroutes context]]
(:require [compojure.core :refer [GET POST defroutes context]]
[compojure.route :refer [resources]]
[ring.util.response :refer [response]]
[bluegenes.ws.auth :as auth]
[bluegenes.ws.ids :as ids]
[bluegenes.index :as index]))
[bluegenes.index :as index]
[ring.middleware.params :refer [wrap-params]]))

; Define the top level URL routes for the server
(defroutes routes
Expand All @@ -18,4 +19,5 @@
(context "/auth" [] auth/routes)
(context "/ids" [] ids/routes))

(GET "*" [] (index/index)))
(GET "*" [] (index/index))
(wrap-params (POST "*" req (index/index req))))
23 changes: 22 additions & 1 deletion src/cljs/bluegenes/events/boot.cljs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
(ns bluegenes.events.boot
(:require [re-frame.core :refer [reg-event-db reg-event-fx subscribe inject-cofx]]
[clojure.string :as string]
[bluegenes.db :as db]
[imcljs.fetch :as fetch]
[imcljs.auth :as auth]
Expand Down Expand Up @@ -65,7 +66,11 @@
;; no organisms when I initialise the component. I have a workaround
;; so it doesn't matter in this case, but it is something to be aware of.
[:cache/fetch-organisms]
[:regions/select-all-feature-types]]
[:regions/select-all-feature-types]
;; Handle any POST data passed from the backend. This is
;; usually done to pass data and open a specific page/result
;; from an external page.
[:handle-link-in]]
(not wait-registry?) (conj [::registry/load-other-mines]))
:halt? true}])})

Expand Down Expand Up @@ -409,3 +414,19 @@
:assets/success-fetch-web-service-version
(fn [db [_ mine-kw version]]
(assoc-in db [:assets :web-service-version mine-kw] version)))

(reg-event-fx
:handle-link-in
(fn [{db :db} [_]]
(let [{:keys [regions features]} (:postData (->clj js/serverVars))]
(cond
regions {:dispatch-n (concat [[::route/navigate ::route/regions]
[:regions/set-to-search regions]
(when (not-empty features)
[:regions/deselect-all-feature-types])]
(map (fn [f]
[:regions/toggle-feature-type {:name f}])
(some-> (not-empty features)
(string/split #",")))
[[:regions/run-query]])}
:else {}))))
2 changes: 2 additions & 0 deletions src/cljs/bluegenes/pages/regions/events.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@
(reg-event-db
:regions/toggle-feature-type
(fn [db [_ class]]
;; If you're going to grab more properties out of `class`, make sure to
;; check all uses of this event handler! (Some might not pass all.)
(let [class-kw (keyword (:name class))
m (get-in db [:mines (get db :current-mine) :service :model])
descendants (keys (entity/extended-by m class-kw))
Expand Down
21 changes: 9 additions & 12 deletions src/cljs/bluegenes/pages/regions/views.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -159,15 +159,12 @@
[checkboxes to-search settings]]))

(defn main []
(reagent/create-class
{:component-did-mount #(dispatch [:regions/select-all-feature-types])
:reagent-render
(fn []
[:div.container.regionsearch
[:div.headerwithguidance
[:h1 "Region Search"]
[:a.guidance
{:on-click #(dispatch [:regions/set-to-search (ex)])}
"[Show me an example]"]]
[input-section]
[results-section]])}))
(fn []
[:div.container.regionsearch
[:div.headerwithguidance
[:h1 "Region Search"]
[:a.guidance
{:on-click #(dispatch [:regions/set-to-search (ex)])}
"[Show me an example]"]]
[input-section]
[results-section]]))