Starting to restructure the module space to allow for cleaner route additions

This commit is contained in:
R Tyler Croy 2021-07-05 12:21:33 -07:00
parent 75fb8cf760
commit 6af9c32de4
No known key found for this signature in database
GPG Key ID: E5C92681BEF6CEA2
7 changed files with 90 additions and 43 deletions

1
Cargo.lock generated
View File

@ -2036,6 +2036,7 @@ checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
[[package]]
name = "y10n"
version = "0.1.0"
source = "git+https://github.com/rtyler/y10n?branch=main#877a3c95dd2de2f1796c2e6e587dc1dcbcd64520"
dependencies = [
"glob",
"lazy_static",

View File

@ -14,7 +14,7 @@ glob = "0"
handlebars = { version = "4", features = ["dir_source"] }
log = "*"
pretty_env_logger = "0.3"
# Used for embedding templates
# Used for embedding templates, etc for an all in one binary
rust-embed = "5"
# All the object serialization for APIs and persisting data on disk
@ -28,4 +28,4 @@ serde_yaml = "0.8"
tide = "*"
# Localization support
y10n = { "path" = "../y10n" }
y10n = { "git" = "https://github.com/rtyler/y10n", branch = "main" }

View File

@ -7,6 +7,7 @@ extern crate serde_json;
use log::*;
mod dao;
mod routes;
mod state;
#[async_std::main]
@ -23,21 +24,7 @@ async fn main() -> Result<(), std::io::Error> {
let state = AppState::new();
let mut app = tide::with_state(state);
app.at("/")
.get(|req: tide::Request<AppState<'static>>| async move {
let data = json!({
"projects" : dao::v1::Project::load_all(),
});
let lang = match req.header("Accept-Language") {
Some(l) => l.as_str(),
None => "en",
};
let langs = y10n::parse_accept_language(lang);
info!("Lang: {:?}", langs);
req.state().render("index", &langs, Some(data)).await
});
routes::views::register(&mut app);
if let Some(fd) = std::env::var("LISTEN_FD")
.ok()

4
src/routes/mod.rs Normal file
View File

@ -0,0 +1,4 @@
/**
* This module contains all the re-exported routes for different aspects of Geoffrey
*/
pub mod views;

25
src/routes/views.rs Normal file
View File

@ -0,0 +1,25 @@
use crate::dao::v1::*;
/**
* View routes
*/
use crate::state::*;
use log::*;
use tide::{Body, Request, Server};
pub fn register(app: &mut Server<AppState<'static>>) {
app.at("/").get(index);
}
async fn index(req: Request<AppState<'static>>) -> tide::Result<Body> {
let data = json!({
"projects" : Project::load_all(),
});
let lang = match req.header("Accept-Language") {
Some(l) => l.as_str(),
None => "en",
};
let langs = y10n::parse_accept_language(lang);
info!("Lang: {:?}", langs);
req.state().render("index", &langs, Some(data)).await
}

View File

@ -1,41 +1,65 @@
<html>
<head>
<title>Geoffrey</title>
<style type="text/css">
.project {
float: left;
}
.project {
margin-right: 2em;
padding: 1em;
border: 1px solid #cecece;
}
.project h3 {
margin: 0;
}
.actions ul {
padding: 0;
}
.actions li {
list-style: none;
float: left;
font-size: 0.6em;
margin-right: 1em;
}
</style>
</head>
<body>
<div class="banner">
{{t.banner}}
</div>
{{> partials/_header}}
<div class="projects">
<ul>
<h2>
Projects
</h2>
{{#each projects}}
<li>
<a href="project/{{slug}}">
{{name}}
</a>
<div class="project" id="project-{{slug}}">
<a href="project/{{slug}}">
<h3>
{{name}}
</h3>
</a>
<p>
{{description}}
</p>
<p>
{{description}}
</p>
<div class="actions">
<ul>
<li>
<a href="project/{{slug}}/run">
{{../t.actions.run}}
</a>
</li>
<li>
<a href="project/{{slug}}/edit">
{{../t.actions.edit}}
</a>
</li>
</ul>
<div class="actions">
<ul>
<li>
<a href="api/project/{{slug}}/run?return=/">
{{../t.actions.run}}
</a>
</li>
<li>
<a href="api/project/{{slug}}/edit?return=/">
{{../t.actions.edit}}
</a>
</li>
</ul>
</div>
</div>
</li>
{{/each}}
</ul>
</div>
</body>

View File

@ -0,0 +1,6 @@
<div class="banner">
<h1>
{{t.banner}}
</h1>
</div>