Skip to content

Commit

Permalink
resource switch tag filters
Browse files Browse the repository at this point in the history
  • Loading branch information
andrew committed Jun 8, 2016
1 parent d3fd197 commit 93338c9
Show file tree
Hide file tree
Showing 9 changed files with 85 additions and 6 deletions.
14 changes: 12 additions & 2 deletions src/cljs/ulysses/components/header.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,16 @@
[link [:home] {} config/site-title]]
[progress]])

(defn- uconn-banner-right-menu-item [href fa-id]
(defn login []
(let [user (subscribe [:user])]
(fn []
(let [user @user]
[:div.login
(if-let [netid (:netid user)]
[:span "you are logged in as " netid]
[link "http://ulysses-api-staging.core/login" {} "log in"])]))))

(defn uconn-banner-right-menu-item [href fa-id]
[:li.nav-item
[link
href
Expand All @@ -46,7 +55,8 @@
[link ovpr-url {:class :full} "Office of the Vice President for Research"]]
[:ul.nav.navbar-nav.red-button-menu.pull-right
[uconn-banner-right-menu-item "http://uconn.edu/search" :search]
[uconn-banner-right-menu-item "http://uconn.edu/az/" :sort-alpha-asc]]]))))
[uconn-banner-right-menu-item "http://uconn.edu/az/" :sort-alpha-asc]]
[login]]))))

;; ----------------------------------------------------------------------------
;; main
Expand Down
3 changes: 2 additions & 1 deletion src/cljs/ulysses/core.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
#(dispatch [:window-scroll])))

(defn start-pollings []
(js/setInterval #(dispatch [:window-resize]) 100))
(js/setInterval #(dispatch [:window-resize]) 100)
(js/setInterval #(dispatch [:request-user-poll]) (* 30 1000)))

(defn ^:export init []
(routes/app-routes)
Expand Down
6 changes: 6 additions & 0 deletions src/cljs/ulysses/db.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@
; current window scroll position
:window-scroll-position (window-scroll-position)

;; -------------------------------------------------------------------------
;; user
;; -------------------------------------------------------------------------

:user nil

;; -------------------------------------------------------------------------
;; data
;; -------------------------------------------------------------------------
Expand Down
27 changes: 25 additions & 2 deletions src/cljs/ulysses/handlers.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
window-scroll-position
clean-incoming-grant-op
clean-incoming-grant-ops
boolean?
parse-int-id
str->int
to-id-map
Expand Down Expand Up @@ -48,7 +49,7 @@

(register-handler
:window-resize
(fn [db [_]]
(fn [db _]
(let [ws (window-size)
ds (document-size)]
(if (and (= ws (:window-size db)) (= ds (:document-size db)))
Expand All @@ -58,7 +59,7 @@

(register-handler
:window-scroll
(fn [db [_]]
(fn [db _]
(assoc db :window-scroll-position (window-scroll-position))))

(register-handler
Expand All @@ -77,6 +78,28 @@
(fn [db [_ response]]
db)) ; do nothing for now

;; ----------------------------------------------------------------------------
;; user
;; ----------------------------------------------------------------------------

(register-handler
:request-user-poll
(fn [db _]
(request db
[:login :poll]
:handler #(dispatch [:receive-user-poll %])
;; if server didn't respond or an error occurred, log out
:error-handler #(dispatch [:receive-user-poll false]))))

(register-handler
:receive-user-poll
(fn [db [_ response]]
(println "login:" response)
(if-not (and (boolean? response) response)
;; not logged in anymore, so nil the user
(assoc db :user nil)
db)))

;; ----------------------------------------------------------------------------
;; raw data
;; ----------------------------------------------------------------------------
Expand Down
9 changes: 9 additions & 0 deletions src/cljs/ulysses/subs.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,15 @@
(let [{:keys [page-current page-last]} @db]
{:current page-current :last page-last}))))

;; ----------------------------------------------------------------------------
;; user
;; ----------------------------------------------------------------------------

(register-sub
:user
(fn [db _]
(reaction (:user @db))))

;; ----------------------------------------------------------------------------
;; raw data
;; ----------------------------------------------------------------------------
Expand Down
3 changes: 3 additions & 0 deletions src/cljs/ulysses/utils.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
[& args]
nil)

(defn boolean? [x]
(or (true? x) (false? x)))

(defn ptr
"print x, then return it. useful for
debugging inside threading macros or map"
Expand Down
1 change: 1 addition & 0 deletions src/sass/app.scss
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
@import 'components/grant-op-boxes';
@import 'components/grant-op-filters';
@import 'components/grant-op-pagination';
@import 'components/login';
@import 'components/main-logo';
@import 'components/modal-alpha';
@import 'components/not-found';
Expand Down
25 changes: 25 additions & 0 deletions src/sass/components/_login.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// login

// NOTE
// this is within the relative uconn-banner

.uconn-banner {
.login {
padding: .7rem 1rem 0 0;
position: absolute;
right: 0;
top: 60px;
}

&.slim {
.login {
top: 40px;
}
}

@media screen and (max-width: 850px) {
.login {
top: 40px;
}
}
}
3 changes: 2 additions & 1 deletion src/sass/components/_uconn-banner.scss
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
left: 0;
margin-bottom: 8px;
padding: 0 1rem;
position: relative;
top: 0;
user-select: none;
width: 100%;
Expand Down Expand Up @@ -82,7 +83,7 @@
}

+ .nav-item {
margin-left: 0.3rem;
margin-left: .3rem;
}
}
}
Expand Down

0 comments on commit 93338c9

Please sign in to comment.