Skip to content

Commit

Permalink
roastmi
Browse files Browse the repository at this point in the history
  • Loading branch information
pontaoski committed Sep 28, 2023
1 parent 034ddd6 commit c6561e3
Show file tree
Hide file tree
Showing 8 changed files with 403 additions and 44 deletions.
308 changes: 297 additions & 11 deletions Cargo.lock

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions server/web_ui/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,13 @@ yew-router = { workspace = true }
time = { workspace = true }
gloo-timers = "0.3.0"
wasm-timer = "0.2.5"
i18n-embed = { version = "0.14.0", features = ["fluent-system", "web-sys-requester"]}
i18n-embed-fl = "0.7.0"
rust-embed = "8"
unic-langid = "0.9.1"
fluent = "0.16.0"
fluent-bundle = "0.15.2"
fluent-fallback = "0.7.0"
regex.workspace = true
lazy_static.workspace = true

Expand Down
4 changes: 4 additions & 0 deletions server/web_ui/i18n.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
fallback_language = "en-US"

[fluent]
assets_dir = "i18n"
1 change: 1 addition & 0 deletions server/web_ui/i18n/en-US/kanidmd_web_ui.ftl
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
women = i have committed 40 counts of arson to get to this point
28 changes: 16 additions & 12 deletions server/web_ui/pkg/kanidmd_web_ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ function makeMutClosure(arg0, arg1, dtor, f) {
return real;
}
function __wbg_adapter_48(arg0, arg1) {
wasm._dyn_core__ops__function__FnMut_____Output___R_as_wasm_bindgen__closure__WasmClosure___describe__invoke__hee64a599f575a1b3(arg0, arg1);
wasm._dyn_core__ops__function__FnMut_____Output___R_as_wasm_bindgen__closure__WasmClosure___describe__invoke__hd5062f8742a3e5bf(arg0, arg1);
}

let stack_pointer = 128;
Expand All @@ -237,19 +237,19 @@ function addBorrowedObject(obj) {
}
function __wbg_adapter_51(arg0, arg1, arg2) {
try {
wasm._dyn_core__ops__function__FnMut___A____Output___R_as_wasm_bindgen__closure__WasmClosure___describe__invoke__h6821a64a8b32b54e(arg0, arg1, addBorrowedObject(arg2));
wasm._dyn_core__ops__function__FnMut___A____Output___R_as_wasm_bindgen__closure__WasmClosure___describe__invoke__h3973ccc10169b3e2(arg0, arg1, addBorrowedObject(arg2));
} finally {
heap[stack_pointer++] = undefined;
}
}

function __wbg_adapter_54(arg0, arg1, arg2) {
wasm._dyn_core__ops__function__FnMut__A____Output___R_as_wasm_bindgen__closure__WasmClosure___describe__invoke__h578c1a08304759e7(arg0, arg1, addHeapObject(arg2));
wasm._dyn_core__ops__function__FnMut__A____Output___R_as_wasm_bindgen__closure__WasmClosure___describe__invoke__hf0d692ef0f316208(arg0, arg1, addHeapObject(arg2));
}

function __wbg_adapter_57(arg0, arg1, arg2) {
try {
wasm._dyn_core__ops__function__FnMut___A____Output___R_as_wasm_bindgen__closure__WasmClosure___describe__invoke__hb3016357f235b290(arg0, arg1, addBorrowedObject(arg2));
wasm._dyn_core__ops__function__FnMut___A____Output___R_as_wasm_bindgen__closure__WasmClosure___describe__invoke__he09faeaf47590909(arg0, arg1, addBorrowedObject(arg2));
} finally {
heap[stack_pointer++] = undefined;
}
Expand Down Expand Up @@ -724,6 +724,10 @@ function __wbg_get_imports() {
const ret = getObject(arg0).credentials;
return addHeapObject(ret);
};
imports.wbg.__wbg_languages_4ab80469955a57f7 = function(arg0) {
const ret = getObject(arg0).languages;
return addHeapObject(ret);
};
imports.wbg.__wbg_parentNode_9e53f8b17eb98c9d = function(arg0) {
const ret = getObject(arg0).parentNode;
return isLikeNone(ret) ? 0 : addHeapObject(ret);
Expand Down Expand Up @@ -1146,20 +1150,20 @@ function __wbg_get_imports() {
const ret = wasm.memory;
return addHeapObject(ret);
};
imports.wbg.__wbindgen_closure_wrapper659 = function(arg0, arg1, arg2) {
const ret = makeMutClosure(arg0, arg1, 380, __wbg_adapter_48);
imports.wbg.__wbindgen_closure_wrapper673 = function(arg0, arg1, arg2) {
const ret = makeMutClosure(arg0, arg1, 387, __wbg_adapter_48);
return addHeapObject(ret);
};
imports.wbg.__wbindgen_closure_wrapper4175 = function(arg0, arg1, arg2) {
const ret = makeMutClosure(arg0, arg1, 1999, __wbg_adapter_51);
imports.wbg.__wbindgen_closure_wrapper4684 = function(arg0, arg1, arg2) {
const ret = makeMutClosure(arg0, arg1, 2258, __wbg_adapter_51);
return addHeapObject(ret);
};
imports.wbg.__wbindgen_closure_wrapper4941 = function(arg0, arg1, arg2) {
const ret = makeMutClosure(arg0, arg1, 2306, __wbg_adapter_54);
imports.wbg.__wbindgen_closure_wrapper5454 = function(arg0, arg1, arg2) {
const ret = makeMutClosure(arg0, arg1, 2565, __wbg_adapter_54);
return addHeapObject(ret);
};
imports.wbg.__wbindgen_closure_wrapper5000 = function(arg0, arg1, arg2) {
const ret = makeMutClosure(arg0, arg1, 2330, __wbg_adapter_57);
imports.wbg.__wbindgen_closure_wrapper5513 = function(arg0, arg1, arg2) {
const ret = makeMutClosure(arg0, arg1, 2589, __wbg_adapter_57);
return addHeapObject(ret);
};

Expand Down
Binary file modified server/web_ui/pkg/kanidmd_web_ui_bg.wasm
Binary file not shown.
Binary file modified server/web_ui/pkg/kanidmd_web_ui_bg.wasm.br
Binary file not shown.
99 changes: 78 additions & 21 deletions server/web_ui/src/manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@
//! not authenticated, this will determine that and send you to authentication first, then
//! will allow you to proceed with the oauth flow.

use std::rc::Rc;

use gloo::console;
use i18n_embed::LanguageLoader;
use i18n_embed::unic_langid::LanguageIdentifier;
use i18n_embed_fl::fl;
use serde::{Deserialize, Serialize};
use wasm_bindgen::UnwrapThrowExt;
use yew::functional::*;
Expand All @@ -16,6 +21,15 @@ use crate::login::{LoginApp, LoginWorkflow};
use crate::oauth2::Oauth2App;
use crate::views::{ViewRoute, ViewsApp};

use i18n_embed::{WebLanguageRequester, fluent::{
FluentLanguageLoader, fluent_language_loader
}};
use rust_embed::RustEmbed;

#[derive(RustEmbed)]
#[folder = "i18n"]
struct Localizations;

// router to decide on state.
#[derive(Routable, PartialEq, Eq, Clone, Debug, Serialize, Deserialize)]
pub enum Route {
Expand Down Expand Up @@ -53,6 +67,28 @@ fn landing() -> Html {
html! { <main></main> }
}

#[function_component]
fn NotFound() -> Html {
let i18n = use_context::<Rc<I18n>>().unwrap();

html! {
<>
<main class="flex-shrink-0 form-signin text-center">
<img src="/pkg/img/logo-square.svg" alt="Kanidm" class="kanidm_logo"/>
// TODO: replace this with a call to domain info
<h3>{ "404 - Page not found" }</h3>

<div class="container">
<Link<ViewRoute> to={ ViewRoute::Apps }>
{ fl!(i18n.i18n, "women") }
</Link<ViewRoute>>
</div>
</main>
{ crate::utils::do_footer() }
</>
}
}

// Needed for yew to pass by value
#[allow(clippy::needless_pass_by_value)]
fn switch(route: Route) -> Html {
Expand All @@ -74,27 +110,46 @@ fn switch(route: Route) -> Html {
Route::NotFound => {
add_body_form_classes!();

html! {
<>
<main class="flex-shrink-0 form-signin text-center">
<img src="/pkg/img/logo-square.svg" alt="Kanidm" class="kanidm_logo"/>
// TODO: replace this with a call to domain info
<h3>{ "404 - Page not found" }</h3>

<div class="container">
<Link<ViewRoute> to={ ViewRoute::Apps }>
{ "Home" }
</Link<ViewRoute>>
</div>
</main>
{ crate::utils::do_footer() }
</>
}
html! { <NotFound /> }
}
}
}

pub struct ManagerApp {}
#[derive(Clone, Debug)]
pub struct I18n {
pub i18n: Rc<FluentLanguageLoader>
}

impl I18n {
fn new() -> I18n {
let loader: FluentLanguageLoader = fluent_language_loader!();
let requested_languages = {
let mut it = WebLanguageRequester::requested_languages();
it.push(loader.fallback_language().clone());
it
};

let languages_vec = requested_languages.iter().map(|it| it).collect::<Vec<&LanguageIdentifier>>();
let languages = languages_vec.as_slice();
let _ = loader
.load_languages(&Localizations, &languages)
.map_err(|err| {
console::warn!("issue loading i18n: {}", err.to_string());
});

I18n { i18n: loader.into() }
}
}

impl PartialEq for I18n {
fn eq(&self, _rhs: &I18n) -> bool {
true
}
}

pub struct ManagerApp {
i18n: Rc<I18n>
}

impl Component for ManagerApp {
type Message = ();
Expand All @@ -103,7 +158,7 @@ impl Component for ManagerApp {
fn create(_ctx: &Context<Self>) -> Self {
#[cfg(debug_assertions)]
console::debug!("manager::create");
ManagerApp {}
ManagerApp { i18n: I18n::new().into() }
}

fn changed(&mut self, _ctx: &Context<Self>, _props: &Self::Properties) -> bool {
Expand All @@ -127,9 +182,11 @@ impl Component for ManagerApp {

fn view(&self, _ctx: &Context<Self>) -> Html {
html! {
<BrowserRouter>
<Switch<Route> render={ switch } />
</BrowserRouter>
<ContextProvider<Rc<I18n>> context={self.i18n.clone()}>
<BrowserRouter>
<Switch<Route> render={ switch } />
</BrowserRouter>
</ContextProvider<Rc<I18n>>>
}
}
}

0 comments on commit c6561e3

Please sign in to comment.