Add description to item and item class

This commit is contained in:
Simon Bruder 2024-07-14 15:17:04 +02:00
parent 512cca854b
commit a528b9fe44
Signed by: simon
GPG key ID: 347FF8699CDA0776
23 changed files with 210 additions and 40 deletions

View file

@ -37,6 +37,11 @@
"ordinal": 6, "ordinal": 6,
"name": "original_packaging", "name": "original_packaging",
"type_info": "Uuid" "type_info": "Uuid"
},
{
"ordinal": 7,
"name": "description",
"type_info": "Varchar"
} }
], ],
"parameters": { "parameters": {
@ -51,7 +56,8 @@
false, false,
false, false,
false, false,
true true,
false
] ]
}, },
"hash": "1e9045f52c002a19b815351fee1c7ee7520478ff4f5886b4523fb0dc4df0e204" "hash": "1e9045f52c002a19b815351fee1c7ee7520478ff4f5886b4523fb0dc4df0e204"

View file

@ -37,6 +37,11 @@
"ordinal": 6, "ordinal": 6,
"name": "original_packaging", "name": "original_packaging",
"type_info": "Uuid" "type_info": "Uuid"
},
{
"ordinal": 7,
"name": "description",
"type_info": "Varchar"
} }
], ],
"parameters": { "parameters": {
@ -51,7 +56,8 @@
false, false,
false, false,
false, false,
true true,
false
] ]
}, },
"hash": "2e9619ce6db1047e2f5447c4925f28fd05f18706f70220b6ebb7354d2a0a9e3b" "hash": "2e9619ce6db1047e2f5447c4925f28fd05f18706f70220b6ebb7354d2a0a9e3b"

View file

@ -22,6 +22,11 @@
"ordinal": 3, "ordinal": 3,
"name": "created_at", "name": "created_at",
"type_info": "Timestamptz" "type_info": "Timestamptz"
},
{
"ordinal": 4,
"name": "description",
"type_info": "Varchar"
} }
], ],
"parameters": { "parameters": {
@ -33,6 +38,7 @@
false, false,
false, false,
true, true,
false,
false false
] ]
}, },

View file

@ -37,6 +37,11 @@
"ordinal": 6, "ordinal": 6,
"name": "original_packaging", "name": "original_packaging",
"type_info": "Uuid" "type_info": "Uuid"
},
{
"ordinal": 7,
"name": "description",
"type_info": "Varchar"
} }
], ],
"parameters": { "parameters": {
@ -49,7 +54,8 @@
false, false,
false, false,
false, false,
true true,
false
] ]
}, },
"hash": "58969747bdccae4a2d3ad8d8117aa92283151d67f52fbb22e5d976b1c6a5c367" "hash": "58969747bdccae4a2d3ad8d8117aa92283151d67f52fbb22e5d976b1c6a5c367"

View file

@ -1,6 +1,6 @@
{ {
"db_name": "PostgreSQL", "db_name": "PostgreSQL",
"query": "UPDATE item_classes SET name = $2, parent = $3 WHERE id = $1 RETURNING *", "query": "INSERT INTO item_classes (name, parent, description) VALUES ($1, $2, $3) RETURNING *",
"describe": { "describe": {
"columns": [ "columns": [
{ {
@ -22,21 +22,27 @@
"ordinal": 3, "ordinal": 3,
"name": "created_at", "name": "created_at",
"type_info": "Timestamptz" "type_info": "Timestamptz"
},
{
"ordinal": 4,
"name": "description",
"type_info": "Varchar"
} }
], ],
"parameters": { "parameters": {
"Left": [ "Left": [
"Uuid",
"Varchar", "Varchar",
"Uuid" "Uuid",
"Varchar"
] ]
}, },
"nullable": [ "nullable": [
false, false,
false, false,
true, true,
false,
false false
] ]
}, },
"hash": "408a171b46d5c615ff846547f463dc0b18360644234fb01b24c4c047bebb3a10" "hash": "68d93c71840f87d5f5bb14b4d7fc34edd6be47cd1706b3612a332bbfd4bb54b4"
} }

View file

@ -22,6 +22,11 @@
"ordinal": 3, "ordinal": 3,
"name": "created_at", "name": "created_at",
"type_info": "Timestamptz" "type_info": "Timestamptz"
},
{
"ordinal": 4,
"name": "description",
"type_info": "Varchar"
} }
], ],
"parameters": { "parameters": {
@ -31,6 +36,7 @@
false, false,
false, false,
true, true,
false,
false false
] ]
}, },

View file

@ -37,6 +37,11 @@
"ordinal": 6, "ordinal": 6,
"name": "original_packaging", "name": "original_packaging",
"type_info": "Uuid" "type_info": "Uuid"
},
{
"ordinal": 7,
"name": "description",
"type_info": "Varchar"
} }
], ],
"parameters": { "parameters": {
@ -51,7 +56,8 @@
false, false,
false, false,
false, false,
true true,
false
] ]
}, },
"hash": "79d8bfe2ed76ee550cdc31f282f598749d931af69a80d24f4575a4bc2c740f3b" "hash": "79d8bfe2ed76ee550cdc31f282f598749d931af69a80d24f4575a4bc2c740f3b"

View file

@ -37,6 +37,11 @@
"ordinal": 6, "ordinal": 6,
"name": "original_packaging", "name": "original_packaging",
"type_info": "Uuid" "type_info": "Uuid"
},
{
"ordinal": 7,
"name": "description",
"type_info": "Varchar"
} }
], ],
"parameters": { "parameters": {
@ -51,7 +56,8 @@
false, false,
false, false,
false, false,
true true,
false
] ]
}, },
"hash": "7eeb752c8b00ac4000104f0254186f1f9fdb076e8f8b98f10fc1b981cfe8038c" "hash": "7eeb752c8b00ac4000104f0254186f1f9fdb076e8f8b98f10fc1b981cfe8038c"

View file

@ -1,6 +1,6 @@
{ {
"db_name": "PostgreSQL", "db_name": "PostgreSQL",
"query": "UPDATE items SET name = $2, parent = $3, class = $4, original_packaging = $5 WHERE id = $1 RETURNING *", "query": "UPDATE items SET name = $2, parent = $3, class = $4, original_packaging = $5, description = $6 WHERE id = $1 RETURNING *",
"describe": { "describe": {
"columns": [ "columns": [
{ {
@ -37,6 +37,11 @@
"ordinal": 6, "ordinal": 6,
"name": "original_packaging", "name": "original_packaging",
"type_info": "Uuid" "type_info": "Uuid"
},
{
"ordinal": 7,
"name": "description",
"type_info": "Varchar"
} }
], ],
"parameters": { "parameters": {
@ -45,7 +50,8 @@
"Varchar", "Varchar",
"Uuid", "Uuid",
"Uuid", "Uuid",
"Uuid" "Uuid",
"Varchar"
] ]
}, },
"nullable": [ "nullable": [
@ -55,8 +61,9 @@
false, false,
false, false,
false, false,
true true,
false
] ]
}, },
"hash": "fa9770ac99749cc4255da6172e5082b29931e992a08534b315a2935978e827e8" "hash": "82df5c0633a655d376b8a91e9f11981cfee40fd04cb4e3552cc5f4ebf4ed0572"
} }

View file

@ -37,6 +37,11 @@
"ordinal": 6, "ordinal": 6,
"name": "original_packaging", "name": "original_packaging",
"type_info": "Uuid" "type_info": "Uuid"
},
{
"ordinal": 7,
"name": "description",
"type_info": "Varchar"
} }
], ],
"parameters": { "parameters": {
@ -51,7 +56,8 @@
false, false,
false, false,
false, false,
true true,
false
] ]
}, },
"hash": "94958a3a57c3178e6b0de5723b1fbc5433e972b5522b367098afe6cb90a30bf2" "hash": "94958a3a57c3178e6b0de5723b1fbc5433e972b5522b367098afe6cb90a30bf2"

View file

@ -1,6 +1,6 @@
{ {
"db_name": "PostgreSQL", "db_name": "PostgreSQL",
"query": "INSERT INTO items (name, parent, class, original_packaging) VALUES ($1, $2, $3, $4) RETURNING *", "query": "INSERT INTO items (name, parent, class, original_packaging, description) VALUES ($1, $2, $3, $4, $5) RETURNING *",
"describe": { "describe": {
"columns": [ "columns": [
{ {
@ -37,6 +37,11 @@
"ordinal": 6, "ordinal": 6,
"name": "original_packaging", "name": "original_packaging",
"type_info": "Uuid" "type_info": "Uuid"
},
{
"ordinal": 7,
"name": "description",
"type_info": "Varchar"
} }
], ],
"parameters": { "parameters": {
@ -44,7 +49,8 @@
"Varchar", "Varchar",
"Uuid", "Uuid",
"Uuid", "Uuid",
"Uuid" "Uuid",
"Varchar"
] ]
}, },
"nullable": [ "nullable": [
@ -54,8 +60,9 @@
false, false,
false, false,
false, false,
true true,
false
] ]
}, },
"hash": "30a7f461d0a20179d08436d9d2c69b33ea9d0775ef1e2b37a1d7fd0109f98b27" "hash": "b80bb07ab582b0705b5c0370066730edf887d66a4196a0834c59f0df9f9314d3"
} }

View file

@ -22,6 +22,11 @@
"ordinal": 3, "ordinal": 3,
"name": "created_at", "name": "created_at",
"type_info": "Timestamptz" "type_info": "Timestamptz"
},
{
"ordinal": 4,
"name": "description",
"type_info": "Varchar"
} }
], ],
"parameters": { "parameters": {
@ -33,6 +38,7 @@
false, false,
false, false,
true, true,
false,
false false
] ]
}, },

View file

@ -1,6 +1,6 @@
{ {
"db_name": "PostgreSQL", "db_name": "PostgreSQL",
"query": "INSERT INTO item_classes (name, parent) VALUES ($1, $2) RETURNING *", "query": "UPDATE item_classes SET name = $2, parent = $3, description = $4 WHERE id = $1 RETURNING *",
"describe": { "describe": {
"columns": [ "columns": [
{ {
@ -22,20 +22,28 @@
"ordinal": 3, "ordinal": 3,
"name": "created_at", "name": "created_at",
"type_info": "Timestamptz" "type_info": "Timestamptz"
},
{
"ordinal": 4,
"name": "description",
"type_info": "Varchar"
} }
], ],
"parameters": { "parameters": {
"Left": [ "Left": [
"Uuid",
"Varchar", "Varchar",
"Uuid" "Uuid",
"Varchar"
] ]
}, },
"nullable": [ "nullable": [
false, false,
false, false,
true, true,
false,
false false
] ]
}, },
"hash": "7e2e1460a2c946ba909c50d4cf1beacf50ebf5fbfead379340f9f72614958e78" "hash": "e0129afa95f896d79f772fb177a8f9229dfbbfd289039db7b733c7d1d050f4bf"
} }

View file

@ -37,6 +37,11 @@
"ordinal": 6, "ordinal": 6,
"name": "original_packaging", "name": "original_packaging",
"type_info": "Uuid" "type_info": "Uuid"
},
{
"ordinal": 7,
"name": "description",
"type_info": "Varchar"
} }
], ],
"parameters": { "parameters": {
@ -51,7 +56,8 @@
false, false,
false, false,
false, false,
true true,
false
] ]
}, },
"hash": "e45160a73a18d870f592989349057d6852d2d3f63dc055442125a6a92950729d" "hash": "e45160a73a18d870f592989349057d6852d2d3f63dc055442125a6a92950729d"

View file

@ -37,6 +37,11 @@
"ordinal": 6, "ordinal": 6,
"name": "original_packaging", "name": "original_packaging",
"type_info": "Uuid" "type_info": "Uuid"
},
{
"ordinal": 7,
"name": "description",
"type_info": "Varchar"
} }
], ],
"parameters": { "parameters": {
@ -51,7 +56,8 @@
false, false,
false, false,
false, false,
true true,
false
] ]
}, },
"hash": "efe2258db42b60f732d562d106842b19308d9a558703b02e758f60e7d8644d00" "hash": "efe2258db42b60f732d562d106842b19308d9a558703b02e758f60e7d8644d00"

View file

@ -0,0 +1,9 @@
-- SPDX-FileCopyrightText: 2024 Simon Bruder <simon@sbruder.de>
--
-- SPDX-License-Identifier: AGPL-3.0-or-later
ALTER TABLE items
DROP description;
ALTER TABLE item_classes
DROP description;

View file

@ -0,0 +1,9 @@
-- SPDX-FileCopyrightText: 2024 Simon Bruder <simon@sbruder.de>
--
-- SPDX-License-Identifier: AGPL-3.0-or-later
ALTER TABLE items
ADD description VARCHAR NOT NULL DEFAULT '';
ALTER TABLE item_classes
ADD description VARCHAR NOT NULL DEFAULT '';

View file

@ -130,6 +130,10 @@ async fn show(
} }
} }
} }
tr {
th { "Description" }
td style="white-space: pre-wrap" { (item.description) }
}
} }
@if !children.is_empty() { @if !children.is_empty() {
@ -296,6 +300,13 @@ async fn add_form(
datalist: Some(&datalist_items), datalist: Some(&datalist_items),
..Default::default() ..Default::default()
}) })
(forms::InputGroup {
r#type: forms::InputType::Textarea,
name: "description",
title: "Description ",
value: form.description.clone(),
..Default::default()
})
button .btn.btn-primary type="submit" { "Add" } button .btn.btn-primary type="submit" { "Add" }
} }
@ -401,6 +412,13 @@ async fn edit_form(
datalist: Some(&datalist_items), datalist: Some(&datalist_items),
..Default::default() ..Default::default()
}) })
(forms::InputGroup {
r#type: forms::InputType::Textarea,
name: "description",
title: "Description ",
value: Some(item.description),
..Default::default()
})
button .btn.btn-primary type="submit" { "Edit" } button .btn.btn-primary type="submit" { "Edit" }
} }

View file

@ -109,6 +109,10 @@ async fn show(
td { a href={ "/item-class/" (parent.id) } { (parent.name) } } td { a href={ "/item-class/" (parent.id) } { (parent.name) } }
} }
} }
tr {
th { "Description" }
td style="white-space: pre-wrap" { (item_class.description) }
}
} }
@if !children.is_empty() { @if !children.is_empty() {
@ -233,6 +237,13 @@ async fn add_form(
datalist: Some(&datalist_item_classes), datalist: Some(&datalist_item_classes),
..Default::default() ..Default::default()
}) })
(forms::InputGroup {
r#type: forms::InputType::Textarea,
name: "description",
title: "Description ",
value: form.description.clone(),
..Default::default()
})
button .btn.btn-primary type="submit" { "Add" } button .btn.btn-primary type="submit" { "Add" }
} }
@ -309,6 +320,13 @@ async fn edit_form(
datalist: Some(&datalist_item_classes), datalist: Some(&datalist_item_classes),
..Default::default() ..Default::default()
}) })
(forms::InputGroup {
r#type: forms::InputType::Textarea,
name: "description",
title: "Description ",
value: Some(item_class.description),
..Default::default()
})
button .btn.btn-primary type="submit" { "Edit" } button .btn.btn-primary type="submit" { "Edit" }
} }

View file

@ -11,12 +11,14 @@ use super::datalist::Datalist;
#[derive(Clone)] #[derive(Clone)]
pub enum InputType { pub enum InputType {
Text, Text,
Textarea,
} }
impl fmt::Display for InputType { impl fmt::Display for InputType {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self { match self {
Self::Text => write!(f, "text"), Self::Text => write!(f, "text"),
Self::Textarea => write!(f, "textarea"),
} }
} }
} }
@ -50,15 +52,25 @@ impl Default for InputGroup<'_> {
impl InputGroup<'_> { impl InputGroup<'_> {
fn main_input(&self, force_required: bool) -> Markup { fn main_input(&self, force_required: bool) -> Markup {
html! { html! {
input @match self.r#type {
InputType::Textarea => textarea
.form-control .form-control
#(self.name) #(self.name)
name={ (self.name) } name=(self.name)
type={ (self.r#type) }
required[self.required || force_required] required[self.required || force_required]
disabled[self.disabled] disabled[self.disabled]
value=[self.value.clone()] rows="5" // FIXME hardcoded
list=[self.datalist.map(|dl| format!("{}-datalist", dl.name()))]; { (self.value.as_ref().unwrap_or(&"".to_string())) },
_ => input
.form-control
#(self.name)
name=(self.name)
type=(self.r#type)
required[self.required || force_required]
disabled[self.disabled]
value=[self.value.as_ref()]
list=[self.datalist.map(|dl| format!("{}-datalist", dl.name()))];,
}
} }
} }
} }

View file

@ -12,11 +12,12 @@ use crate::models::{Item, NewItem};
pub async fn add(pool: &PgPool, new_item: NewItem) -> Result<Item, sqlx::Error> { pub async fn add(pool: &PgPool, new_item: NewItem) -> Result<Item, sqlx::Error> {
query_as!( query_as!(
Item, Item,
"INSERT INTO items (name, parent, class, original_packaging) VALUES ($1, $2, $3, $4) RETURNING *", "INSERT INTO items (name, parent, class, original_packaging, description) VALUES ($1, $2, $3, $4, $5) RETURNING *",
new_item.name, new_item.name,
new_item.parent, new_item.parent,
new_item.class, new_item.class,
new_item.original_packaging new_item.original_packaging,
new_item.description
) )
.fetch_one(pool) .fetch_one(pool)
.await .await
@ -57,12 +58,13 @@ pub async fn get_all_as_map(pool: &PgPool) -> Result<HashMap<Uuid, Item>, sqlx::
pub async fn update(pool: &PgPool, id: Uuid, modified_item: NewItem) -> Result<Item, sqlx::Error> { pub async fn update(pool: &PgPool, id: Uuid, modified_item: NewItem) -> Result<Item, sqlx::Error> {
query_as!( query_as!(
Item, Item,
"UPDATE items SET name = $2, parent = $3, class = $4, original_packaging = $5 WHERE id = $1 RETURNING *", "UPDATE items SET name = $2, parent = $3, class = $4, original_packaging = $5, description = $6 WHERE id = $1 RETURNING *",
id, id,
modified_item.name, modified_item.name,
modified_item.parent, modified_item.parent,
modified_item.class, modified_item.class,
modified_item.original_packaging modified_item.original_packaging,
modified_item.description
) )
.fetch_one(pool) .fetch_one(pool)
.await .await

View file

@ -12,9 +12,10 @@ use crate::models::{Item, ItemClass, NewItemClass};
pub async fn add(pool: &PgPool, new_item_class: NewItemClass) -> Result<ItemClass, sqlx::Error> { pub async fn add(pool: &PgPool, new_item_class: NewItemClass) -> Result<ItemClass, sqlx::Error> {
query_as!( query_as!(
ItemClass, ItemClass,
"INSERT INTO item_classes (name, parent) VALUES ($1, $2) RETURNING *", "INSERT INTO item_classes (name, parent, description) VALUES ($1, $2, $3) RETURNING *",
new_item_class.name, new_item_class.name,
new_item_class.parent new_item_class.parent,
new_item_class.description
) )
.fetch_one(pool) .fetch_one(pool)
.await .await
@ -47,10 +48,11 @@ pub async fn update(
) -> Result<ItemClass, sqlx::Error> { ) -> Result<ItemClass, sqlx::Error> {
query_as!( query_as!(
ItemClass, ItemClass,
"UPDATE item_classes SET name = $2, parent = $3 WHERE id = $1 RETURNING *", "UPDATE item_classes SET name = $2, parent = $3, description = $4 WHERE id = $1 RETURNING *",
id, id,
modified_item_class.name, modified_item_class.name,
modified_item_class.parent modified_item_class.parent,
modified_item_class.description
) )
.fetch_one(pool) .fetch_one(pool)
.await .await

View file

@ -22,6 +22,7 @@ pub struct Item {
pub created_at: OffsetDateTime, pub created_at: OffsetDateTime,
pub short_id: i32, pub short_id: i32,
pub original_packaging: Option<Uuid>, pub original_packaging: Option<Uuid>,
pub description: String,
} }
#[derive(Debug, Deserialize)] #[derive(Debug, Deserialize)]
@ -32,6 +33,7 @@ pub struct NewItem {
pub parent: Option<Uuid>, pub parent: Option<Uuid>,
pub class: Uuid, pub class: Uuid,
pub original_packaging: Option<Uuid>, pub original_packaging: Option<Uuid>,
pub description: String,
} }
// Its structure is not how it could ideally be // Its structure is not how it could ideally be
@ -46,6 +48,7 @@ pub struct NewItemForm {
pub parent: Option<Uuid>, pub parent: Option<Uuid>,
pub class: Option<Uuid>, pub class: Option<Uuid>,
pub original_packaging: Option<Uuid>, pub original_packaging: Option<Uuid>,
pub description: Option<String>,
} }
#[derive(Clone, Debug, Serialize)] #[derive(Clone, Debug, Serialize)]
@ -56,6 +59,7 @@ pub struct ItemClass {
pub parent: Option<Uuid>, pub parent: Option<Uuid>,
#[serde(with = "time::serde::iso8601")] #[serde(with = "time::serde::iso8601")]
pub created_at: OffsetDateTime, pub created_at: OffsetDateTime,
pub description: String,
} }
#[derive(Debug, Deserialize)] #[derive(Debug, Deserialize)]
@ -63,6 +67,7 @@ pub struct NewItemClass {
pub name: String, pub name: String,
#[serde(default)] #[serde(default)]
pub parent: Option<Uuid>, pub parent: Option<Uuid>,
pub description: String,
} }
// see NewItemForm // see NewItemForm
@ -71,4 +76,5 @@ pub struct NewItemClassForm {
pub name: Option<String>, pub name: Option<String>,
#[serde(default)] #[serde(default)]
pub parent: Option<Uuid>, pub parent: Option<Uuid>,
pub description: Option<String>,
} }