Add static files
This commit is contained in:
parent
0cb5336663
commit
447670973d
20
Cargo.lock
generated
20
Cargo.lock
generated
|
@ -930,6 +930,25 @@ dependencies = [
|
||||||
"unicode-normalization",
|
"unicode-normalization",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "include_dir"
|
||||||
|
version = "0.7.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "482a2e29200b7eed25d7fdbd14423326760b7f6658d21a4cf12d55a50713c69f"
|
||||||
|
dependencies = [
|
||||||
|
"include_dir_macros",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "include_dir_macros"
|
||||||
|
version = "0.7.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "5e074c19deab2501407c91ba1860fa3d6820bfde307db6d8cb851b55a10be89b"
|
||||||
|
dependencies = [
|
||||||
|
"proc-macro2",
|
||||||
|
"quote",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "indexmap"
|
name = "indexmap"
|
||||||
version = "1.8.1"
|
version = "1.8.1"
|
||||||
|
@ -1761,6 +1780,7 @@ dependencies = [
|
||||||
"async-sqlx-session",
|
"async-sqlx-session",
|
||||||
"chrono",
|
"chrono",
|
||||||
"dotenv",
|
"dotenv",
|
||||||
|
"include_dir",
|
||||||
"rand_core",
|
"rand_core",
|
||||||
"serde",
|
"serde",
|
||||||
"sqlx",
|
"sqlx",
|
||||||
|
|
|
@ -17,6 +17,7 @@ dotenv = "0.15"
|
||||||
argon2 = "0.4"
|
argon2 = "0.4"
|
||||||
askama = "0.11"
|
askama = "0.11"
|
||||||
actix-web = "4.0"
|
actix-web = "4.0"
|
||||||
|
include_dir = "0.7"
|
||||||
|
|
||||||
rand_core = { version = "0.6", features = ["std"] }
|
rand_core = { version = "0.6", features = ["std"] }
|
||||||
serde = { version = "1.0", features = ["derive"] }
|
serde = { version = "1.0", features = ["derive"] }
|
||||||
|
|
|
@ -7,7 +7,7 @@ create table if not exists users(
|
||||||
create table if not exists boards(
|
create table if not exists boards(
|
||||||
id serial primary key,
|
id serial primary key,
|
||||||
name varchar(32) not null,
|
name varchar(32) not null,
|
||||||
description varchar(256),
|
description varchar(256)
|
||||||
);
|
);
|
||||||
|
|
||||||
create table if not exists categories(
|
create table if not exists categories(
|
||||||
|
@ -29,7 +29,7 @@ create table if not exists tasks(
|
||||||
|
|
||||||
create table if not exists task_assigned(
|
create table if not exists task_assigned(
|
||||||
id serial primary key,
|
id serial primary key,
|
||||||
task integer references task(id) on delete cascade,
|
task integer references tasks(id) on delete cascade,
|
||||||
member integer references users(id) on delete cascade
|
member integer references users(id) on delete cascade
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
37
src/web.rs
37
src/web.rs
|
@ -20,8 +20,10 @@
|
||||||
// TODO: use the authentification for the logged in status
|
// TODO: use the authentification for the logged in status
|
||||||
|
|
||||||
use crate::{database::Database, task, templates};
|
use crate::{database::Database, task, templates};
|
||||||
|
use actix_web::HttpRequest;
|
||||||
use actix_web::{http::StatusCode, web, HttpResponse, HttpResponseBuilder, HttpServer, Responder};
|
use actix_web::{http::StatusCode, web, HttpResponse, HttpResponseBuilder, HttpServer, Responder};
|
||||||
use askama::Template;
|
use askama::Template;
|
||||||
|
use include_dir::{Dir, include_dir};
|
||||||
use std::net::SocketAddr;
|
use std::net::SocketAddr;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
|
@ -29,27 +31,28 @@ pub struct App {
|
||||||
pub server: actix_web::dev::Server,
|
pub server: actix_web::dev::Server,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static STATIC_DIR: Dir = include_dir!("$CARGO_MANIFEST_DIR/static");
|
||||||
|
|
||||||
impl App {
|
impl App {
|
||||||
pub async fn new(addr: SocketAddr, db: Arc<Database>) -> anyhow::Result<Self> {
|
pub async fn new(addr: SocketAddr, db: Arc<Database>) -> anyhow::Result<Self> {
|
||||||
let db = db.clone();
|
let db = db.clone();
|
||||||
let server = HttpServer::new(move || {
|
let server = HttpServer::new(move || {
|
||||||
actix_web::App::new()
|
actix_web::App::new()
|
||||||
.app_data(web::Data::new(db.clone()))
|
.app_data(web::Data::new(db.clone()))
|
||||||
.service((
|
.route("/", web::get().to(index))
|
||||||
web::resource("/").route(web::get().to(index)),
|
.route("/static/{file}", web::get().to(static_file))
|
||||||
web::resource("/users").route(web::get().to(users)),
|
.route("/users", web::get().to(users))
|
||||||
web::resource("/task").route(web::get().to(tasks)),
|
.route("/task", web::get().to(tasks))
|
||||||
web::resource("/admin").route(web::get().to(admin)),
|
.route("/admin", web::get().to(admin))
|
||||||
web::resource("/create").route(web::get().to(create)),
|
.route("/create", web::get().to(create))
|
||||||
web::resource("/login").route(web::get().to(login)),
|
.route("/login", web::get().to(login))
|
||||||
web::resource("/register").route(web::get().to(register)),
|
.route("/register", web::get().to(register))
|
||||||
web::resource("/api/task/create").route(web::post().to(create_task)),
|
.route("/api/task/create", web::post().to(create_task))
|
||||||
web::resource("/api/task/move").route(web::post().to(move_task)),
|
.route("/api/task/move", web::post().to(move_task))
|
||||||
//web::resource("/api/task/sort").route(web::post().to(sort_task)),
|
//.route("/api/task/sort", web::post().to(sort_task)),
|
||||||
web::resource("/api/login").route(web::post().to(login_user)),
|
.route("/api/login", web::post().to(login_user))
|
||||||
web::resource("/api/register").route(web::post().to(register_user)),
|
.route("/api/register", web::post().to(register_user))
|
||||||
web::resource("/api/logout").route(web::get().to(logout)),
|
.route("/api/logout", web::get().to(logout))
|
||||||
))
|
|
||||||
})
|
})
|
||||||
.bind(addr)?
|
.bind(addr)?
|
||||||
.run();
|
.run();
|
||||||
|
@ -57,6 +60,10 @@ impl App {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async fn static_file(file: web::Path<String>) -> impl Responder {
|
||||||
|
STATIC_DIR.get_file(file.into_inner()).map(|v| v.contents())
|
||||||
|
}
|
||||||
|
|
||||||
async fn index(db: web::Data<Arc<Database>>) -> impl Responder {
|
async fn index(db: web::Data<Arc<Database>>) -> impl Responder {
|
||||||
let index = templates::Index { logged_in: None };
|
let index = templates::Index { logged_in: None };
|
||||||
let html = index.render().unwrap();
|
let html = index.render().unwrap();
|
||||||
|
|
23
static/style.css
Normal file
23
static/style.css
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
form {
|
||||||
|
margin-left: 2%;
|
||||||
|
margin-right: 2%;
|
||||||
|
}
|
||||||
|
input[type=text] {
|
||||||
|
width: 100%;
|
||||||
|
padding: 2px 2px;
|
||||||
|
border-radius: 4px;
|
||||||
|
}
|
||||||
|
input[type=submit] {
|
||||||
|
padding: 2px 2px;
|
||||||
|
border-radius: 4px;
|
||||||
|
}
|
||||||
|
select {
|
||||||
|
width: 100%;
|
||||||
|
padding: 2px 2px;
|
||||||
|
border-radius: 4px;
|
||||||
|
}
|
||||||
|
textarea {
|
||||||
|
width: 100%;
|
||||||
|
padding: 2px 2px;
|
||||||
|
border-radius: 4px;
|
||||||
|
}
|
|
@ -3,31 +3,7 @@
|
||||||
<head>
|
<head>
|
||||||
<meta charset="UTF-8">
|
<meta charset="UTF-8">
|
||||||
<title>tmtd</title>
|
<title>tmtd</title>
|
||||||
<style>
|
<link rel="stylesheet" href="/static/style.css">
|
||||||
form {
|
|
||||||
margin-left: 2%;
|
|
||||||
margin-right: 2%;
|
|
||||||
}
|
|
||||||
input[type=text] {
|
|
||||||
width: 100%;
|
|
||||||
padding: 2px 2px;
|
|
||||||
border-radius: 4px;
|
|
||||||
}
|
|
||||||
input[type=submit] {
|
|
||||||
padding: 2px 2px;
|
|
||||||
border-radius: 4px;
|
|
||||||
}
|
|
||||||
select {
|
|
||||||
width: 100%;
|
|
||||||
padding: 2px 2px;
|
|
||||||
border-radius: 4px;
|
|
||||||
}
|
|
||||||
textarea {
|
|
||||||
width: 100%;
|
|
||||||
padding: 2px 2px;
|
|
||||||
border-radius: 4px;
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
{% block content %} {% endblock %}
|
{% block content %} {% endblock %}
|
||||||
|
|
Loading…
Reference in a new issue