Flat file database editor and browser with web interface
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
rocket-inv/src/main.rs

57 lines
1.5 KiB

#![feature(proc_macro_hygiene, decl_macro)]
#[macro_use] extern crate rocket;
#[macro_use] extern crate serde;
//use rocket::request::FromSegments;
//use rocket::http::uri::Segments;
use rocket_contrib::serve::StaticFiles;
use rocket_contrib::templates::Template;
mod store;
use crate::store::Store;
use rocket::State;
use parking_lot::RwLock;
use rocket::response::Redirect;
use rocket::http::Status;
use rocket::request::Form;
use std::collections::HashMap;
use std::env;
use crate::store::form::RenderedField;
#[derive(Serialize)]
struct FormContext<'a> {
pub fields : Vec<RenderedField<'a>>,
}
#[get("/")]
fn index(store : State<RwLock<Store>>) -> Template {
let rg = store.read();
let indexes = &rg.index;
let context = FormContext {
fields: rg.model.fields.iter().map(|(key, field)| {
RenderedField::from_template_field(key, field, None, indexes)
}).collect()
};
Template::render("index", context)
}
//#[post("/add", data="<record>")]
//fn add_part(store : State<RwLock<Store>>, record : Form<store::Part>) -> Redirect {
// store.write().add(record.into_inner());
// Redirect::to(uri!(index))
//}
fn main() {
let cwd = env::current_dir().unwrap();
let data_dir = cwd.join("data");
let store = Store::new(data_dir);
rocket::ignite()
.attach(Template::fairing())
.manage(RwLock::new(store))
.mount("/", StaticFiles::from(cwd.join("templates/static/")))
.mount("/", routes![index]).launch();
}