Actual navigation WIP.
This commit is contained in:
parent
0e29dc5df6
commit
05f751dd21
@ -18,15 +18,19 @@ import Halogen.HTML as HH
|
|||||||
import Type.Proxy (Proxy(..))
|
import Type.Proxy (Proxy(..))
|
||||||
import Effect.Aff.Class (class MonadAff)
|
import Effect.Aff.Class (class MonadAff)
|
||||||
|
|
||||||
|
data Page = Home | LoginRegister | DomainList | Zone | AuthAdmin
|
||||||
|
|
||||||
data Action
|
data Action
|
||||||
= AuthenticationComponentEvent AF.Output
|
= AuthenticationComponentEvent AF.Output
|
||||||
| AuthenticationDaemonAdminComponentEvent AAI.Output -- Admin interface for authd.
|
| AuthenticationDaemonAdminComponentEvent AAI.Output -- Admin interface for authd.
|
||||||
| DomainListComponentEvent DomainListInterface.Output
|
| DomainListComponentEvent DomainListInterface.Output
|
||||||
| AuthenticationDaemonEvent WS.Output
|
| AuthenticationDaemonEvent WS.Output
|
||||||
| DNSManagerDaemonEvent WS.Output
|
| DNSManagerDaemonEvent WS.Output
|
||||||
|
| Routing Page
|
||||||
|
|
||||||
type State = { token :: Maybe String
|
type State = { token :: Maybe String
|
||||||
, uid :: Maybe Int
|
, uid :: Maybe Int
|
||||||
|
, current_page :: Page
|
||||||
}
|
}
|
||||||
|
|
||||||
type ChildSlots =
|
type ChildSlots =
|
||||||
@ -56,22 +60,39 @@ component =
|
|||||||
initialState :: forall i. i -> State
|
initialState :: forall i. i -> State
|
||||||
initialState _ = { token: Nothing
|
initialState _ = { token: Nothing
|
||||||
, uid: Nothing
|
, uid: Nothing
|
||||||
|
, current_page: Home
|
||||||
}
|
}
|
||||||
|
|
||||||
render :: forall m. MonadAff m => State -> H.ComponentHTML Action ChildSlots m
|
render :: forall m. MonadAff m => State -> H.ComponentHTML Action ChildSlots m
|
||||||
render state
|
render state
|
||||||
= HH.div_ $
|
= HH.div_ $
|
||||||
[ render_nav
|
[ render_header
|
||||||
, render_header
|
, render_nav
|
||||||
, render_auth_form
|
, case state.current_page of
|
||||||
, render_newdomain_interface
|
Home -> render_home
|
||||||
|
LoginRegister -> render_auth_form
|
||||||
|
DomainList -> render_newdomain_interface
|
||||||
|
Zone -> render_zone
|
||||||
|
AuthAdmin -> render_authd_admin_interface
|
||||||
, Bulma.columns_ [ Bulma.column_ [ render_logs ], Bulma.column_ [ render_auth_WS, render_dnsmanager_WS ] ]
|
, Bulma.columns_ [ Bulma.column_ [ render_logs ], Bulma.column_ [ render_auth_WS, render_dnsmanager_WS ] ]
|
||||||
, render_authd_admin_interface
|
|
||||||
]
|
]
|
||||||
where
|
where
|
||||||
|
|
||||||
|
-- TODO
|
||||||
|
render_home = render_nothing
|
||||||
|
|
||||||
|
-- TODO
|
||||||
|
render_zone = render_nothing
|
||||||
|
|
||||||
|
authenticated = case state.token of
|
||||||
|
Nothing -> false
|
||||||
|
Just _ -> true
|
||||||
|
|
||||||
|
-- TODO: this is needed to show the authd admin button
|
||||||
|
admin = true
|
||||||
|
|
||||||
render_nav :: forall monad. MonadAff monad => H.ComponentHTML Action ChildSlots monad
|
render_nav :: forall monad. MonadAff monad => H.ComponentHTML Action ChildSlots monad
|
||||||
render_nav = Nav.netlibre_navbar
|
render_nav = Nav.netlibre_navbar authenticated admin (Routing Home) (Routing DomainList) (Routing AuthAdmin) (Routing LoginRegister) (Routing LoginRegister)
|
||||||
|
|
||||||
render_header :: forall monad. MonadAff monad => H.ComponentHTML Action ChildSlots monad
|
render_header :: forall monad. MonadAff monad => H.ComponentHTML Action ChildSlots monad
|
||||||
render_header = case state.token of
|
render_header = case state.token of
|
||||||
@ -113,6 +134,8 @@ render state
|
|||||||
|
|
||||||
handleAction :: forall o monad. MonadAff monad => Action -> H.HalogenM State Action ChildSlots o monad Unit
|
handleAction :: forall o monad. MonadAff monad => Action -> H.HalogenM State Action ChildSlots o monad Unit
|
||||||
handleAction = case _ of
|
handleAction = case _ of
|
||||||
|
Routing page -> H.modify_ _ { current_page = page }
|
||||||
|
|
||||||
AuthenticationComponentEvent ev -> case ev of
|
AuthenticationComponentEvent ev -> case ev of
|
||||||
AF.AuthToken (Tuple uid token) -> H.modify_ _ { uid = Just uid, token = Just token }
|
AF.AuthToken (Tuple uid token) -> H.modify_ _ { uid = Just uid, token = Just token }
|
||||||
AF.MessageToSend message -> H.tell _ws_auth unit (WS.ToSend message)
|
AF.MessageToSend message -> H.tell _ws_auth unit (WS.ToSend message)
|
||||||
|
@ -3,30 +3,37 @@ module App.Nav where
|
|||||||
import Prelude
|
import Prelude
|
||||||
import CSSClasses as C
|
import CSSClasses as C
|
||||||
import Halogen.HTML as HH
|
import Halogen.HTML as HH
|
||||||
|
import Halogen.HTML.Events as HE
|
||||||
import Halogen.HTML.Properties as HP
|
import Halogen.HTML.Properties as HP
|
||||||
import Halogen.HTML.Properties.ARIA as ARIA
|
import Halogen.HTML.Properties.ARIA as ARIA
|
||||||
import Bulma as Bulma
|
import Bulma as Bulma
|
||||||
|
|
||||||
netlibre_navbar :: forall w i. HH.HTML w i
|
netlibre_navbar :: forall w i. Boolean -> Boolean -> i -> i -> i -> i -> i -> HH.HTML w i
|
||||||
netlibre_navbar =
|
netlibre_navbar authenticated admin actionHome actionDomainList actionAuthdAdmin actionRegister actionLogin =
|
||||||
main_nav
|
main_nav
|
||||||
[ nav_brand [ logo, burger_menu ]
|
[ nav_brand [ logo, burger_menu ]
|
||||||
, nav_menu
|
, nav_menu
|
||||||
[ navbar_start
|
[ navbar_start
|
||||||
[ link_domains
|
[ link_home
|
||||||
, dropdown "List of something"
|
, case authenticated of
|
||||||
[ dropdown_element "something 1"
|
false -> HH.div_ []
|
||||||
, dropdown_element "something 2"
|
true -> link_domains
|
||||||
, dropdown_element "something 3"
|
, case authenticated, admin of
|
||||||
, dropdown_separator
|
true, true -> link_authd_admin
|
||||||
, dropdown_element "something 4"
|
_, _ -> HH.div_ []
|
||||||
]
|
--, dropdown "List of something"
|
||||||
|
-- [ dropdown_element "something 1"
|
||||||
|
-- , dropdown_element "something 2"
|
||||||
|
-- , dropdown_element "something 3"
|
||||||
|
-- , dropdown_separator
|
||||||
|
-- , dropdown_element "something 4"
|
||||||
|
-- ]
|
||||||
]
|
]
|
||||||
, navbar_end
|
, navbar_end
|
||||||
[ navbar_item
|
[ navbar_item
|
||||||
[ HH.div [HP.classes C.buttons]
|
[ HH.div [HP.classes C.buttons]
|
||||||
[ nav_button_strong "Register"
|
[ nav_button_strong "Register" actionRegister
|
||||||
, nav_button_light "Login"
|
, nav_button_light "Login" actionLogin
|
||||||
]
|
]
|
||||||
]
|
]
|
||||||
]
|
]
|
||||||
@ -45,13 +52,17 @@ netlibre_navbar =
|
|||||||
nav_menu = HH.div [HP.id "navbarExample", HP.classes C.navbar_menu]
|
nav_menu = HH.div [HP.id "navbarExample", HP.classes C.navbar_menu]
|
||||||
navbar_start = HH.div [HP.classes C.navbar_start]
|
navbar_start = HH.div [HP.classes C.navbar_start]
|
||||||
navbar_end = HH.div [HP.classes C.navbar_end]
|
navbar_end = HH.div [HP.classes C.navbar_end]
|
||||||
link_domains = HH.a [HP.classes C.navbar_item] [HH.text "My Domains"]
|
link_home = HH.a [HP.classes C.navbar_item, HE.onClick (\_ -> actionHome)] [HH.text "Home"]
|
||||||
|
link_domains = HH.a [HP.classes C.navbar_item, HE.onClick (\_ -> actionDomainList)] [HH.text "Domain List"]
|
||||||
|
link_authd_admin = HH.a [HP.classes C.navbar_item, HE.onClick (\_ -> actionAuthdAdmin)] [HH.text "Authd Admin"]
|
||||||
dropdown title dropdown_elements
|
dropdown title dropdown_elements
|
||||||
= HH.div [HP.classes (C.navbar_item <> C.has_dropdown <> C.is_hoverable)]
|
= HH.div [HP.classes (C.navbar_item <> C.has_dropdown <> C.is_hoverable)]
|
||||||
[ dropdown_title title, HH.div [HP.classes C.navbar_dropdown] dropdown_elements ]
|
[ dropdown_title title, HH.div [HP.classes C.navbar_dropdown] dropdown_elements ]
|
||||||
dropdown_title str = HH.a [HP.classes C.navbar_link] [HH.text str]
|
dropdown_title str = HH.a [HP.classes C.navbar_link] [HH.text str]
|
||||||
dropdown_element str = HH.a [HP.classes C.navbar_item] [HH.text str]
|
dropdown_element str = HH.a [HP.classes C.navbar_item] [HH.text str]
|
||||||
dropdown_separator = HH.hr [HP.classes C.navbar_divider]
|
dropdown_separator = HH.hr [HP.classes C.navbar_divider]
|
||||||
nav_button_strong str = HH.a [HP.classes (C.button <> C.is_primary)] [HH.strong [] [HH.text str]]
|
nav_button_strong str action
|
||||||
nav_button_light str = HH.a [HP.classes (C.button <> C.is_light)] [HH.text str]
|
= HH.a [HP.classes (C.button <> C.is_primary), HE.onClick (\_ -> action)] [HH.strong [] [HH.text str]]
|
||||||
|
nav_button_light str action
|
||||||
|
= HH.a [HP.classes (C.button <> C.is_light), HE.onClick (\_ -> action)] [HH.text str]
|
||||||
navbar_item = HH.div [HP.classes C.navbar_item]
|
navbar_item = HH.div [HP.classes C.navbar_item]
|
||||||
|
Loading…
Reference in New Issue
Block a user