Skip to content

Commit

Permalink
(wip) webapp: urls
Browse files Browse the repository at this point in the history
  • Loading branch information
pnmadelaine committed Oct 16, 2023
1 parent 1eb8816 commit a22f0ad
Show file tree
Hide file tree
Showing 13 changed files with 242 additions and 308 deletions.
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
'';
}
2 changes: 1 addition & 1 deletion nix/packages/webroot.nix
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ in
name = "typhon-webroot";
src = webapp;
buildPhase = ''
substituteInPlace ./index.html --replace "WEBROOT" "${webroot}/"
substituteInPlace ./index.html --replace '<base href="/">' '<base href="${webroot}/">'
cp ${settings} settings.json
cp ${tarball} source.tar.gz
'';
Expand Down
2 changes: 1 addition & 1 deletion typhon-webapp/index.html
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<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" />
<base href="/">
</head>
<body>
<div id="app"></div>
Expand Down
49 changes: 0 additions & 49 deletions typhon-webapp/src/appurl.rs

This file was deleted.

5 changes: 2 additions & 3 deletions typhon-webapp/src/drv_log.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,8 @@ pub fn update(msg: Msg, model: &mut Model, orders: &mut impl Orders<Msg>) {
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 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))
}
30 changes: 17 additions & 13 deletions typhon-webapp/src/job.rs
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
use crate::drv_log;
use crate::{appurl::AppUrl, perform_request, view_error, view_log, SETTINGS};
use crate::perform_request;
use crate::view_error;
use crate::view_log;
use crate::SETTINGS;

use typhon_types::*;

use seed::{prelude::*, *};

struct_urls!();

pub struct Model {
error: Option<responses::ResponseError>,
handle: handles::Job,
info: Option<responses::JobInfo>,
log_begin: Option<String>,
log_end: Option<String>,
log: drv_log::Model,
}

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

#[derive(Clone, Debug)]
Expand All @@ -36,7 +36,7 @@ pub enum Msg {
Noop,
}

pub fn init(orders: &mut impl Orders<Msg>, handle: handles::Job) -> Model {
pub fn init(base_url: Url, orders: &mut impl Orders<Msg>, handle: handles::Job) -> Model {
orders.send_msg(Msg::FetchInfo);
Model {
error: None,
Expand All @@ -45,6 +45,7 @@ pub fn init(orders: &mut impl Orders<Msg>, handle: handles::Job) -> Model {
log_begin: None,
log_end: None,
log: drv_log::init(&mut orders.proxy(Msg::LogMsg)),
base_url,
}
}

Expand Down Expand Up @@ -122,28 +123,31 @@ pub fn update(msg: Msg, model: &mut Model, orders: &mut impl Orders<Msg>) {
}

fn view_job(model: &Model) -> Node<Msg> {
let urls_1 = crate::Urls::new(model.base_url.clone());
let urls_2 = crate::Urls::new(model.base_url.clone());
let urls_3 = crate::Urls::new(model.base_url.clone());
div![
h2![
"Job",
" ",
a![
&model.handle.evaluation.jobset.project.name,
attrs! {
At::Href => crate::Urls::project(&model.handle.evaluation.jobset.project),
At::Href => urls_1.project(&model.handle.evaluation.jobset.project),
},
],
":",
a![
&model.handle.evaluation.jobset.name,
attrs! {
At::Href => crate::Urls::jobset(&model.handle.evaluation.jobset),
At::Href => urls_2.jobset(&model.handle.evaluation.jobset),
},
],
":",
a![
&model.handle.evaluation.num,
attrs! {
At::Href => crate::Urls::evaluation(&model.handle.evaluation)
At::Href => urls_3.evaluation(&model.handle.evaluation)
},
],
":",
Expand All @@ -159,7 +163,7 @@ fn view_job(model: &Model) -> Node<Msg> {
p![format!("Status (build): {}", info.build_status)],
p![format!("Status (end): {}", info.end_status)],
if info.dist {
let api_url = SETTINGS.get().unwrap().api_server.url();
let api_url = SETTINGS.get().unwrap().url();
let job = &model.handle.name;
let system = &model.handle.system;
let evaluation = &model.handle.evaluation.num;
Expand Down Expand Up @@ -200,7 +204,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_job(model),
if admin { view_admin() } else { empty![] },
Expand Down
Loading

0 comments on commit a22f0ad

Please sign in to comment.