Added license notices to every source file

This commit is contained in:
Johannes Randerath
2024-08-28 23:29:32 +02:00
parent 0c2c428ce4
commit c7ec089d06
98 changed files with 879 additions and 1882 deletions

View File

@@ -1,3 +1,20 @@
/* Simple web app using rocket to help maintain inventory data.
* Copyright (C) 2024 Johannes Randerath
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
use crate::Db;
use rocket::response::Redirect;

View File

View File

@@ -1,10 +1,26 @@
/* Simple web app using rocket to help maintain inventory data.
* Copyright (C) 2024 Johannes Randerath
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#[macro_use] extern crate rocket;
mod auth;
mod table;
use auth::AuthUser;
// TODO: filter (ajax, spinning circle), show options as in excel
use rocket::fs::{FileServer, relative};
use rocket_dyn_templates::{Template, context};
use rocket::request;

View File

@@ -1,10 +0,0 @@
// @generated automatically by Diesel CLI.
diesel::table! {
jrtables (id) {
id -> Integer,
#[max_length = 255]
name -> Varchar,
num_fields -> Integer,
}
}

View File

@@ -1,3 +1,20 @@
/* Simple web app using rocket to help maintain inventory data.
* Copyright (C) 2024 Johannes Randerath
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
use crate::auth;
use auth::AuthUser;

View File

@@ -1,120 +0,0 @@
#[get("/<tid>")]
async fn table(conn: Db, tid: i32, user: AuthUser) -> Option<Template> {
let uid = user.uid;
let table = conn.run(move |c| inventur_db::get_table(c, tid, uid)).await;
if table.is_none() {
return None;
}
let table = table.unwrap();
let tname = table.name;
let columns = table.column_names;
let trows = table.rows;
let mut rows = Vec::new();
for trow in trows {
rows.push(trow.cells);
let index = rows.len()-1;
rows[index].insert(0, trow.row_pos.to_string());
}
let rows = rows;
let mut tids = conn.run(move |c| inventur_db::get_user_tblids(c, uid)).await;
let tnames;
if tids.is_none() {
tids = Some(Vec::new());
tnames = Some(Vec::new());
}else {
let tids = tids.clone().unwrap();
tnames = conn.run(move |c| inventur_db::get_tblnames(c, tids)).await;
}
let tids = tids.unwrap();
if tnames.is_none() {
return None;
}
Some(
Template::render("table",
context!{
sort_field: 0,
sort_dir: 0,
tblid: tid,
tblname: tname,
tids: tids,
tnames: tnames,
columns: columns,
rows: rows,
}
)
)
}
#[derive(FromForm)]
struct NewEntry {
tblid: i32,
cells: Vec<String>,
}
#[post("/new", data="<data>")]
async fn new_entry(conn: Db, data: Form<NewEntry>, user: AuthUser) -> Result<Redirect, Status> {
let uid = user.uid;
let cells = data.cells.clone();
let tblid = data.tblid;
if conn.run(move |c| inventur_db::add_row(c, data.tblid, cells, uid)).await.is_none() {
return Err(Status::Forbidden);
}
Ok(Redirect::to(uri!("/table", table(tblid))))
}
#[derive(FromForm)]
struct EditTname {
tblid: i32,
new_name: String,
}
#[post("/name/edit", data="<data>")]
async fn edit_tname(conn: Db, data: Form<EditTname>, user: AuthUser) -> Result<Redirect, Status> {
let uid = user.uid;
let tblid = data.tblid;
if conn.run(move |c| inventur_db::rename_table(c, data.tblid, data.new_name.clone(), uid)).await.is_none() {
return Err(Status::Forbidden);
}
Ok(Redirect::to(uri!("/table", table(tblid))))
}
#[derive(FromForm)]
struct NewTable {
name: String,
fields: Vec<String>,
}
#[post("/create", data="<data>")]
async fn create(conn: Db, data: Form<NewTable>, user: AuthUser) -> Result<Redirect, Status> {
let uid = user.uid;
let tblid = conn.run(move |c| inventur_db::create_table(c, data.name.clone(), data.fields.clone(), uid)).await;
if tblid.is_none() {
return Err(Status::Forbidden);
}
Ok(Redirect::to(uri!("/table", table(tblid.unwrap()))))
}
#[derive(Deserialize)]
#[serde(crate = "rocket::serde")]
struct ImportTable {
name: String,
columns: Vec<String>,
rows: Vec<Vec<String>>,
}
#[post("/import", data="<data>")]
pub async fn import_table(conn: Db, data: Json<ImportTable>, user: AuthUser) -> Result<Redirect, Status> {
let uid = user.uid;
let columns = data.columns.clone();
let rows = data.rows.clone();
let tblid = conn.run(move |c| inventur_db::create_table(c, data.name.clone(), columns, uid)).await;
if tblid.is_none() {
return Err(Status::UnprocessableEntity);
}
let tblid = tblid.unwrap();
for row in rows {
conn.run(move |c| inventur_db::add_row(c, tblid, row, uid)).await;
}
Ok(Redirect::to(uri!("/table", table(tblid))))
}