Inventur/src/table/forms.rs
Johannes Randerath 61708e5199 Sharing tables readonly with other users
- Added sharing feature for table owners to share their tables with
  other registered users.
- Fixed a bug where the wrong entries would be deleted or modified when
  searching or filtering.
2024-09-01 20:17:14 +02:00

126 lines
2.8 KiB
Rust

/* This file is part of inventur.
* inventur is a 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/>.
*/
//! Submodule holding structs relevant to handle form data.
use rocket::serde::{Serialize, Deserialize};
//use inventur_db::ShareCard;
#[derive(FromForm)]
pub struct DeleteColumn {
pub tblid: i32,
pub id_in_table: i32,
}
#[derive(FromForm)]
pub struct EditColumn {
pub tblid: i32,
pub id_in_table: i32,
pub name: String,
pub column_type: isize,
}
#[derive(FromForm)]
pub struct NewColumn {
pub tblid: i32,
pub name: String,
pub column_type: isize,
}
#[derive(FromForm)]
pub struct NewEntry {
pub tblid: i32,
pub cells: Vec<String>,
}
#[derive(FromForm)]
pub struct EditEntry {
pub tblid: i32,
pub cells: Vec<String>,
pub row_pos: i32,
}
#[derive(FromForm)]
pub struct DeleteEntry {
pub tblid: i32,
pub row_pos: i32,
}
/// Edit a table's name
#[derive(FromForm)]
pub struct EditTname {
pub tblid: i32,
pub new_name: String,
}
#[derive(FromForm)]
pub struct NewTable {
pub name: String,
pub field_names: Vec<String>,
pub field_types: Vec<isize>,
}
#[derive(Deserialize)]
#[serde(crate = "rocket::serde")]
pub struct ImportTable {
pub name: String,
pub columns: Vec<String>,
pub rows: Vec<Vec<String>>,
}
#[derive(FromForm)]
pub struct DeleteTable {
pub tblid: i32,
}
#[derive(Serialize, Clone)]
#[serde(crate = "rocket::serde")]
pub struct Sharee {
id: i32,
username: String,
readonly: bool,
}
impl From<inventur_db::ShareCard> for Sharee {
fn from(sharecard: inventur_db::ShareCard) -> Self {
Sharee { id: sharecard.sharee_id, username: sharecard.sharee_name, readonly: sharecard.readonly}
}
}
#[derive(FromForm, Debug)]
pub struct EditShare {
pub sharees: Vec<i32>,
pub readonly: Vec<bool>,
pub delete: Vec<bool>,
pub tblid: i32,
pub new_user: Option<i32>,
}
#[derive(Serialize, Clone, Debug)]
#[serde(crate = "rocket::serde")]
pub struct UserQueryResult {
pub id: i32,
pub username: String,
}
#[derive(FromForm, Debug)]
pub struct SearchString {
pub query: String,
}