Skip to content

Commit

Permalink
feat: make more things configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
ctron committed Aug 29, 2023
1 parent bfd9b7b commit 519a990
Show file tree
Hide file tree
Showing 8 changed files with 92 additions and 34 deletions.
30 changes: 27 additions & 3 deletions spog/model/schema/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
},
"features": {
"default": {
"dedicatedSearch": false,
"extendSection": false,
"scanner": false
"dedicatedSearch": true,
"extendSection": true,
"scanner": true
},
"allOf": [
{
Expand All @@ -28,7 +28,10 @@
},
"global": {
"default": {
"aboutBackgroundSrc": null,
"brandImageSrc": null,
"documentationUrl": null,
"productName": null,
"supportUrl": null
},
"allOf": [
Expand Down Expand Up @@ -177,6 +180,20 @@
"description": "Global values which affect the overall console",
"type": "object",
"properties": {
"aboutBackgroundSrc": {
"default": null,
"type": [
"string",
"null"
]
},
"brandImageSrc": {
"default": null,
"type": [
"string",
"null"
]
},
"documentationUrl": {
"default": null,
"type": [
Expand All @@ -185,6 +202,13 @@
],
"format": "uri"
},
"productName": {
"default": null,
"type": [
"string",
"null"
]
},
"supportUrl": {
"default": null,
"type": [
Expand Down
30 changes: 30 additions & 0 deletions spog/model/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,36 @@ pub struct Global {

#[serde(default)]
pub support_url: Option<Url>,

#[serde(default)]
pub brand_image_src: Option<String>,

#[serde(default)]
pub about_background_src: Option<String>,

#[serde(default)]
pub product_name: Option<String>,
}

pub const DEFAULT_BRAND_SRC: &str = "assets/images/chicken-svgrepo-com.svg";
pub const DEFAULT_ABOUT_BACKGROUND_SRC: &str = "assets/images/pfbg-icon.svg";
pub const DEFAULT_PRODUCT_NAME: &str = "Chicken Coop";

impl Global {
pub fn brand_image_src(&self) -> String {
self.brand_image_src.as_deref().unwrap_or(DEFAULT_BRAND_SRC).to_string()
}

pub fn about_background_src(&self) -> String {
self.about_background_src
.as_deref()
.unwrap_or(DEFAULT_ABOUT_BACKGROUND_SRC)
.to_string()
}

pub fn product_name(&self) -> String {
self.product_name.as_deref().unwrap_or(DEFAULT_PRODUCT_NAME).to_string()
}
}

/// Configuration for the landing page
Expand Down
2 changes: 1 addition & 1 deletion spog/ui/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion spog/ui/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ features = [
#yew-nested-router = { git = "https://github.com/ctron/yew-nested-router", rev = "9689db446dee7030325884df768d0c2e84f353d6" }
#yew-more-hooks = { git = "https://github.com/ctron/yew-more-hooks", rev = "fc0af774aa925edcd5a544e562619ecb539942f8" }
#yew-more-hooks = { path = "../../../yew-more-hooks" }
patternfly-yew = { git = "https://github.com/ctron/patternfly-yew", rev = "79d8825cc3476947cd2ef0fdbb50f70211492080" } # FIXME: awaiting release
patternfly-yew = { git = "https://github.com/ctron/patternfly-yew", rev = "4169dfb7a56588f8165d3ed0c77b5a9ad6cbf804" } # FIXME: awaiting release
#patternfly-yew = { path = "../../../patternfly-yew" }

csaf = { git = "https://github.com/voteblake/csaf-rs", rev = "76cb9ede10adb1fbb495b17e5fd8d95c5cf6c900" } # FIXME: waiting for release
Expand Down
18 changes: 13 additions & 5 deletions spog/ui/src/about.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
use crate::{backend::VersionService, hooks::use_backend};
use crate::{
backend::VersionService,
hooks::{use_backend, use_config},
};
use patternfly_yew::prelude::*;
use std::rc::Rc;
use trustification_version::{version, VersionInformation};
Expand All @@ -8,6 +11,7 @@ use yew_oauth2::hook::use_latest_access_token;

#[function_component(About)]
pub fn about() -> Html {
let config = use_config();
let backend = use_backend();
let access_token = use_latest_access_token();

Expand All @@ -23,13 +27,17 @@ pub fn about() -> Html {
backend.clone(),
);

let brand_image_src = config.global.brand_image_src();
let background_image_src = config.global.about_background_src();
let product_name = config.global.product_name();

html!(
<Bullseye plain=true>
<AboutModal
brand_image_src="assets/images/chicken-svgrepo-com.svg"
brand_image_alt="Logo"
background_image_src="assets/images/pfbg-icon.svg"
product_name="Chicken Coop"
{brand_image_src}
brand_image_alt="Brand Logo"
{background_image_src}
{product_name}
trademark="Copyright © 2020, 2023 by the Chickens"
>
<Content>
Expand Down
14 changes: 8 additions & 6 deletions spog/ui/src/app.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::{
components::{backend::Backend, error::Error, theme::Themed},
components::{backend::Backend, config::Configuration, error::Error, theme::Themed},
console::Console,
hooks::use_backend,
pages::AppRoute,
Expand Down Expand Up @@ -54,11 +54,13 @@ fn application_with_backend() -> Html {
{config}
scopes={backend.endpoints.oidc.scopes.clone()}
>
<BackdropViewer>
<OAuth2Configured>
<Console />
</OAuth2Configured>
</BackdropViewer>
<Configuration>
<BackdropViewer>
<OAuth2Configured>
<Console />
</OAuth2Configured>
</BackdropViewer>
</Configuration>
</OAuth2>
</Router<AppRoute>>
)
Expand Down
1 change: 1 addition & 0 deletions spog/ui/src/components/search/toolbar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ pub fn search_toolbar(props: &SearchToolbarProperties) -> Html {
<TextInputGroup>
<TextInput
icon={Icon::Search}
size="64"
placeholder="Search"
value={props.text.clone()}
state={*props.filter_input_state}
Expand Down
29 changes: 11 additions & 18 deletions spog/ui/src/console/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ use crate::{
backend::Endpoint,
components::{
common::{ExternalLinkMarker, ExternalNavLink},
config::Configuration,
theme::DarkModeEntry,
},
hooks::{use_backend, use_config},
Expand All @@ -20,41 +19,36 @@ use yew_oauth2::{openid::*, prelude::*};
/// The main console component
#[function_component(Console)]
pub fn console() -> Html {
html!(
// wrap with the configuration, as the page switch already needs that
<Configuration>
<PageSwitch/>
</Configuration>
)
}

#[function_component(PageSwitch)]
fn page_switch() -> Html {
let config = use_config();
let render = move |route| render(route, &config);

html!(<RouterSwitch<AppRoute> {render} default={html!(<pages::NotFound />)}/>)
}

#[function_component(Brand)]
fn brand() -> Html {
let config = use_config();

let src = config.global.brand_image_src();

html! (
<MastheadBrand>
<Brand
src="assets/images/chicken-svgrepo-com.svg"
<patternfly_yew::prelude::Brand
src={src.clone()}
alt="Logo"
style={r#"
--pf-v5-c-brand--Height: var(--pf-v5-c-page__header-brand-link--c-brand--MaxHeight);
"#}
>
<BrandSource srcset="assets/images/chicken-svgrepo-com.svg" />
</Brand>
<BrandSource srcset={src} />
</patternfly_yew::prelude::Brand>
</MastheadBrand>
)
}

#[function_component(AuthenticatedPage)]
fn authenticated_page(props: &ChildrenProperties) -> Html {
let brand = brand();
let brand = html!(<Brand/>);

let backend = use_backend();
let config = use_config();
Expand Down Expand Up @@ -175,9 +169,8 @@ fn authenticated_page(props: &ChildrenProperties) -> Html {
/// a non-authenticated page
#[function_component(NonAuthenticatedPage)]
fn non_authenticated_page(props: &ChildrenProperties) -> Html {
let brand = brand();
html!(
<Page {brand}>
<Page brand={html!(<Brand/>)}>
{ for props.children.iter() }
</Page>
)
Expand Down

0 comments on commit 519a990

Please sign in to comment.