kanidm/kanidmd_web_ui/src/manager.rs

98 lines
2.5 KiB
Rust
Raw Normal View History

2021-07-25 02:51:37 +02:00
//! This is the top level router of the web ui for kanidm. It decides based on the incoming
//! request, where to direct this too, and if the requirements for that request have been
//! met before rendering. For example, if you land here with an oauth request, but you are
//! not atuhenticated, this will determine that and send you to authentication first, then
//! will allow you to proceed with the oauth flow.
2021-12-31 00:11:20 +01:00
use gloo::console;
use yew::functional::*;
2021-07-25 02:51:37 +02:00
use yew::prelude::*;
use yew_router::prelude::*;
use crate::login::LoginApp;
use crate::oauth2::Oauth2App;
use crate::views::ViewsApp;
// router to decide on state.
#[derive(Routable, PartialEq, Clone, Debug)]
pub enum Route {
#[at("/")]
Landing,
#[at("/ui/view")]
Index,
#[at("/ui/login")]
Login,
#[at("/ui/oauth2")]
Oauth2,
#[not_found]
#[at("/404")]
NotFound,
}
2021-12-31 00:11:20 +01:00
#[function_component(Landing)]
fn landing() -> Html {
// Do this to allow use_history to work because lol.
use_history().unwrap().push(Route::Index);
html! { <main></main> }
2021-12-31 00:11:20 +01:00
}
2021-07-25 02:51:37 +02:00
fn switch(routes: &Route) -> Html {
2021-12-31 00:11:20 +01:00
console::log!("manager::switch");
2021-07-25 02:51:37 +02:00
match routes {
2021-12-31 00:11:20 +01:00
Route::Landing => html! { <Landing /> },
2021-07-25 02:51:37 +02:00
Route::Index => html! { <ViewsApp /> },
Route::Login => html! { <LoginApp /> },
Route::Oauth2 => html! { <Oauth2App /> },
Route::NotFound => {
html! {
<main>
2021-07-25 02:51:37 +02:00
<h1>{ "404" }</h1>
2021-12-31 00:11:20 +01:00
<Link<Route> to={ Route::Index }>
2021-07-25 02:51:37 +02:00
{ "Home" }
</Link<Route>>
</main>
2021-07-25 02:51:37 +02:00
}
}
}
}
pub struct ManagerApp {}
2021-07-25 02:51:37 +02:00
impl Component for ManagerApp {
type Message = ();
2021-07-25 02:51:37 +02:00
type Properties = ();
2021-12-31 00:11:20 +01:00
fn create(_ctx: &Context<Self>) -> Self {
console::log!("manager::create");
ManagerApp {}
2021-07-25 02:51:37 +02:00
}
2021-12-31 00:11:20 +01:00
fn changed(&mut self, _ctx: &Context<Self>) -> bool {
console::log!("manager::change");
2021-07-25 02:51:37 +02:00
false
}
fn update(&mut self, _ctx: &Context<Self>, _msg: Self::Message) -> bool {
2021-12-31 00:11:20 +01:00
console::log!("manager::update");
2021-07-25 02:51:37 +02:00
true
}
fn rendered(&mut self, _ctx: &Context<Self>, _first_render: bool) {
2021-12-31 00:11:20 +01:00
console::log!("manager::rendered");
// Can only access the current_route AFTER it renders.
// console::log!(format!("{:?}", yew_router::current_route::<Route>()).as_str())
2021-07-25 02:51:37 +02:00
}
2021-12-31 00:11:20 +01:00
fn view(&self, _ctx: &Context<Self>) -> Html {
2021-07-25 02:51:37 +02:00
html! {
<BrowserRouter>
<Switch<Route> render={ Switch::render(switch) } />
</BrowserRouter>
2021-07-25 02:51:37 +02:00
}
}
}