Skip to content

Commit

Permalink
webapp: urls, settings
Browse files Browse the repository at this point in the history
  • Loading branch information
pnmadelaine committed Oct 16, 2023
1 parent 1eb8816 commit 1e50191
Show file tree
Hide file tree
Showing 15 changed files with 261 additions and 347 deletions.
1 change: 0 additions & 1 deletion Cargo.lock

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

1 change: 0 additions & 1 deletion nix/packages/webapp.nix
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,5 @@ in
trunkIndexPath = "typhon-webapp/index.html";
preBuild = ''
ln -s ${nodeDependencies}/lib/node_modules typhon-webapp/node_modules
echo "build.public_url = \"WEBROOT\"" >> Trunk.toml
'';
}
13 changes: 7 additions & 6 deletions nix/packages/webroot.nix
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,18 @@ in
baseurl ? "127.0.0.1:8000/api",
https ? false,
}: let
settings = pkgs.writeTextFile {
name = "settings.json";
text = builtins.toJSON {inherit baseurl https;};
};
settings = builtins.toJSON {inherit baseurl https;};
in
pkgs.stdenv.mkDerivation {
name = "typhon-webroot";
src = webapp;
buildPhase = ''
substituteInPlace ./index.html --replace "WEBROOT" "${webroot}/"
cp ${settings} settings.json
substituteInPlace ./index.html --replace \
'<base href="/">' \
'<base href="${webroot}/">'
substituteInPlace ./index.html --replace \
'<script type="application/json" id="settings">null</script>' \
'<script type="application/json" id="settings">${settings}</script>'
cp ${tarball} source.tar.gz
'';
installPhase = ''
Expand Down
1 change: 0 additions & 1 deletion typhon-webapp/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ gloo-console.workspace = true
gloo-net.workspace = true
gloo-storage.workspace = true
gloo-utils.workspace = true
once_cell.workspace = true
seed.workspace = true
serde-wasm-bindgen.workspace = true
serde.workspace = true
Expand Down
3 changes: 2 additions & 1 deletion typhon-webapp/index.html
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<base href="/">
<title>Typhon</title>
<link data-trunk rel="copy-dir" href="node_modules/@fontsource" data-target-path="@fontsource" />
<link data-trunk rel="sass" href="index.scss" />
<script type="application/json" id="settings">null</script>
</head>
<body>
<div id="app"></div>
Expand Down
49 changes: 0 additions & 49 deletions typhon-webapp/src/appurl.rs

This file was deleted.

9 changes: 4 additions & 5 deletions typhon-webapp/src/drv_log.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ pub fn init(_orders: &mut impl Orders<Msg>) -> Model {
pub fn update(msg: Msg, model: &mut Model, orders: &mut impl Orders<Msg>) {
use crate::get_token;
use crate::streams;
use crate::SETTINGS;
use crate::Settings;

use gloo_net::http;

Expand All @@ -31,10 +31,9 @@ pub fn update(msg: Msg, model: &mut Model, orders: &mut impl Orders<Msg>) {
model.drv = Some(drv.clone());
model.log = Vec::new();

let settings = SETTINGS.get().unwrap();
let req =
http::RequestBuilder::new(&format!("{}/drv-log{}", settings.api_server.url(), drv))
.method(http::Method::GET);
let settings = Settings::load();
let req = http::RequestBuilder::new(&format!("{}/drv-log{}", settings.url(), drv))
.method(http::Method::GET);
let req = match get_token() {
None => req,
Some(token) => req.header(&"token", &token),
Expand Down
52 changes: 28 additions & 24 deletions typhon-webapp/src/evaluation.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
use crate::{appurl::AppUrl, perform_request, view_error};
use crate::perform_request;
use crate::view_error;
use seed::{prelude::*, *};
use typhon_types::*;

struct_urls!();

pub struct Model {
error: Option<responses::ResponseError>,
handle: handles::Evaluation,
info: Option<responses::EvaluationInfo>,
log: Option<String>,
}

impl Model {
pub fn app_url(&self) -> AppUrl {
Vec::<String>::from(self.handle.clone()).into()
}
base_url: Url,
}

#[derive(Clone, Debug)]
Expand All @@ -28,13 +26,14 @@ pub enum Msg {
Noop,
}

pub fn init(orders: &mut impl Orders<Msg>, handle: handles::Evaluation) -> Model {
pub fn init(base_url: Url, orders: &mut impl Orders<Msg>, handle: handles::Evaluation) -> Model {
orders.send_msg(Msg::FetchInfo);
Model {
error: None,
handle: handle.clone(),
info: None,
log: None,
base_url,
}
}

Expand Down Expand Up @@ -93,21 +92,23 @@ pub fn update(msg: Msg, model: &mut Model, orders: &mut impl Orders<Msg>) {
}

fn view_evaluation(model: &Model) -> Node<Msg> {
let urls_1 = crate::Urls::new(model.base_url.clone());
let urls_2 = crate::Urls::new(model.base_url.clone());
div![
h2![
"Evaluation",
" ",
a![
&model.handle.jobset.project.name,
attrs! {
At::Href => crate::Urls::project(&model.handle.jobset.project),
At::Href => urls_1.project(&model.handle.jobset.project),
},
],
":",
a![
&model.handle.jobset.name,
attrs! {
At::Href => crate::Urls::jobset(&model.handle.jobset),
At::Href => urls_2.jobset(&model.handle.jobset),
},
],
":",
Expand All @@ -125,19 +126,22 @@ fn view_evaluation(model: &Model) -> Node<Msg> {
if info.status == "success" {
div![
h3!["Jobs"],
ul![info.jobs.iter().map(|job| li![a![
job.system.clone(),
" / ",
job.name.clone(),
attrs! {
At::Href => crate::Urls::job(
&handles::Job {
evaluation: model.handle.clone(),
system: job.system.clone(),
name: job.name.clone(),
})
}
]])]
ul![info.jobs.iter().map(|job| {
let urls = crate::Urls::new(model.base_url.clone());
li![a![
job.system.clone(),
" / ",
job.name.clone(),
attrs! {
At::Href => urls.job(
&handles::Job {
evaluation: model.handle.clone(),
system: job.system.clone(),
name: job.name.clone(),
})
}
]]
})]
]
} else {
empty![]
Expand All @@ -162,7 +166,7 @@ pub fn view(model: &Model, admin: bool) -> Node<Msg> {
model
.error
.as_ref()
.map(|err| view_error(err, Msg::ErrorIgnored))
.map(|err| view_error(&model.base_url, err, Msg::ErrorIgnored))
.unwrap_or(div![
view_evaluation(model),
if admin { view_admin() } else { empty![] },
Expand Down
42 changes: 24 additions & 18 deletions typhon-webapp/src/home.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
use crate::{appurl::AppUrl, perform_request, view_error};
use crate::perform_request;
use crate::view_error;
use seed::{prelude::*, *};
use typhon_types::*;

struct_urls!();

#[derive(Clone, Default)]
pub struct Model {
error: Option<responses::ResponseError>,
projects: Vec<(String, responses::ProjectMetadata)>,
new_project: (String, String, bool),
}

impl From<Model> for AppUrl {
fn from(_: Model) -> AppUrl {
AppUrl::default()
}
base_url: Url,
}

#[derive(Debug, Clone)]
Expand All @@ -29,9 +27,14 @@ pub enum Msg {
UpdateNewProjectFlake,
}

pub fn init(orders: &mut impl Orders<Msg>) -> Model {
pub fn init(base_url: Url, orders: &mut impl Orders<Msg>) -> Model {
orders.send_msg(Msg::FetchProjects);
Model::default()
Model {
error: None,
projects: Vec::new(),
new_project: ("".to_string(), "".to_string(), false),
base_url,
}
}

pub fn update(msg: Msg, model: &mut Model, orders: &mut impl Orders<Msg>) {
Expand Down Expand Up @@ -91,14 +94,17 @@ fn view_home(model: &Model, admin: bool) -> Node<Msg> {
h2!["Projects"],
table![
tr![th!["Id"], th!["Name"], th!["Description"],],
model.projects.iter().map(|(name, meta)| tr![
td![a![
name,
attrs! { At::Href => crate::Urls::project(&handles::project(name.into())) }
]],
td![String::from(meta.title.clone())],
td![String::from(meta.description.clone())],
])
model.projects.iter().map(|(name, meta)| {
let urls = crate::Urls::new(model.base_url.clone());
tr![
td![a![
name,
attrs! { At::Href => urls.project(&handles::project(name.into())) }
]],
td![String::from(meta.title.clone())],
td![String::from(meta.description.clone())],
]
})
],
admin.then(|| {
let empty = model.new_project == <_>::default();
Expand Down Expand Up @@ -157,6 +163,6 @@ pub fn view(model: &Model, admin: bool) -> Node<Msg> {
model
.error
.as_ref()
.map(|err| view_error(err, Msg::ErrorIgnored))
.map(|err| view_error(&model.base_url, err, Msg::ErrorIgnored))
.unwrap_or_else(|| view_home(model, admin))
}
Loading

0 comments on commit 1e50191

Please sign in to comment.