1
0
Fork 0
mirror of https://github.com/heyarne/airsonic-ui.git synced 2026-05-06 18:33:38 +02:00

Add user role checks, see #14

Squashed commit of the following:

commit 393c481a21fa97881be2b6859e9acaa8ab7abb7f
Author: Arne Schlüter <arne@schlueter.is>
Date:   Wed Sep 5 12:04:56 2018 +0200

    Consider user roles when building up the navigation

commit d631cba1174ecf42b682664bf57c41b88b7f5ed4
Author: Arne Schlüter <arne@schlueter.is>
Date:   Wed Sep 5 11:52:05 2018 +0200

    Save user roles on login

commit e68ced335ccc11a2daebbf12bb4061a53935c268
Author: Arne Schlüter <arne@schlueter.is>
Date:   Wed Sep 5 10:25:19 2018 +0200

    Rename dispatch to muted-dispatch for easier disambiguation
This commit is contained in:
Arne Schlüter 2018-09-05 12:05:43 +02:00
commit 5cbb83a22d
12 changed files with 180 additions and 53 deletions

View file

@ -21,12 +21,18 @@
(defn navbar-top
"Contains search, some navigational links and the logo"
[_]
[]
(let [active? (r/atom false)
toggle-active #(swap! active? not)
navbar-item (fn navbar-item [{:keys [href]} label]
[:a.navbar-item {:href href :on-click toggle-active} label])]
(fn [{:keys [user]}]
[:a.navbar-item {:href href :on-click toggle-active} label])
user @(subscribe [:user/info])
stream-role @(subscribe [:user/roles :stream])
podcast-role @(subscribe [:user/roles :podcast])
playlist-role @(subscribe [:user/roles :playlist])
share-role @(subscribe [:user/roles :share])
settings-role @(subscribe [:user/roles :settings])]
(fn []
[:nav.navbar.is-fixed-top.is-dark {:role "navigation", :aria-label "search and navigation"}
;; user is `nil` when we're not logged in, we can hide the extended navigation
[:div.navbar-brand
@ -37,25 +43,30 @@
[:div.navbar-start
[:div.navbar-item [search/form]]]
[:div.navbar-end
[:div.navbar-item.has-dropdown.is-hoverable
[:div.navbar-link "Library"]
[:div.navbar-dropdown
[navbar-item {:href (url-for ::routes/library {:criteria "recent"})} "Recently played"]
[navbar-item {:href (url-for ::routes/library {:criteria "newest"})} "Newest additions"]
[navbar-item {:href (url-for ::routes/library {:criteria "starred"})} "Starred"]]]
[navbar-item {} "Podcasts"]
[navbar-item {} "Playlists"]
[navbar-item {} "Shares"]
(when stream-role
[:div.navbar-item.has-dropdown.is-hoverable
[:div.navbar-link "Library"]
[:div.navbar-dropdown
[navbar-item {:href (url-for ::routes/library {:criteria "recent"})} "Recently played"]
[navbar-item {:href (url-for ::routes/library {:criteria "newest"})} "Newest additions"]
[navbar-item {:href (url-for ::routes/library {:criteria "starred"})} "Starred"]]])
(when podcast-role
[navbar-item {} "Podcasts"])
(when playlist-role
[navbar-item {} "Playlists"])
(when share-role
[navbar-item {} "Shares"])
[:div.navbar-item.has-dropdown.is-hoverable
[:div.navbar-link "More"]
[:div.navbar-dropdown.is-right
[navbar-item "Settings"]
(when settings-role
[navbar-item "Settings"])
[:a.navbar-item
{:on-click (fn [_]
(toggle-active)
(dispatch [::events/logout]))
:href "#"}
(str "Logout (" (:name user) ")")]]]]])])))
(str "Logout (" (:username user) ")")]]]]])])))
(defn media-content
"Provides the complete UI to browse the media library, interact with search
@ -77,14 +88,13 @@
(defn main-panel []
(let [notifications @(subscribe [::subs/notifications])
is-booting? @(subscribe [::subs/is-booting?])
[route-id params query] @(subscribe [:routes/current-route])
user @(subscribe [::subs/user])]
[route-id params query] @(subscribe [:routes/current-route])]
[(add-classes :div route-id)
[notification-list notifications]
(if is-booting?
[:div.app-loading>div.loader]
[:div
[navbar-top {:user user}]
[navbar-top]
(case route-id
::routes/login [login-form]
[media-content route-id params query])])]))