Add description to item and item class
This commit is contained in:
parent
0db2acf408
commit
22e284c34f
|
@ -37,6 +37,11 @@
|
|||
"ordinal": 6,
|
||||
"name": "original_packaging",
|
||||
"type_info": "Uuid"
|
||||
},
|
||||
{
|
||||
"ordinal": 7,
|
||||
"name": "description",
|
||||
"type_info": "Varchar"
|
||||
}
|
||||
],
|
||||
"parameters": {
|
||||
|
@ -51,7 +56,8 @@
|
|||
false,
|
||||
false,
|
||||
false,
|
||||
true
|
||||
true,
|
||||
false
|
||||
]
|
||||
},
|
||||
"hash": "1e9045f52c002a19b815351fee1c7ee7520478ff4f5886b4523fb0dc4df0e204"
|
||||
|
|
|
@ -37,6 +37,11 @@
|
|||
"ordinal": 6,
|
||||
"name": "original_packaging",
|
||||
"type_info": "Uuid"
|
||||
},
|
||||
{
|
||||
"ordinal": 7,
|
||||
"name": "description",
|
||||
"type_info": "Varchar"
|
||||
}
|
||||
],
|
||||
"parameters": {
|
||||
|
@ -51,7 +56,8 @@
|
|||
false,
|
||||
false,
|
||||
false,
|
||||
true
|
||||
true,
|
||||
false
|
||||
]
|
||||
},
|
||||
"hash": "2e9619ce6db1047e2f5447c4925f28fd05f18706f70220b6ebb7354d2a0a9e3b"
|
||||
|
|
|
@ -22,6 +22,11 @@
|
|||
"ordinal": 3,
|
||||
"name": "created_at",
|
||||
"type_info": "Timestamptz"
|
||||
},
|
||||
{
|
||||
"ordinal": 4,
|
||||
"name": "description",
|
||||
"type_info": "Varchar"
|
||||
}
|
||||
],
|
||||
"parameters": {
|
||||
|
@ -33,6 +38,7 @@
|
|||
false,
|
||||
false,
|
||||
true,
|
||||
false,
|
||||
false
|
||||
]
|
||||
},
|
||||
|
|
|
@ -37,6 +37,11 @@
|
|||
"ordinal": 6,
|
||||
"name": "original_packaging",
|
||||
"type_info": "Uuid"
|
||||
},
|
||||
{
|
||||
"ordinal": 7,
|
||||
"name": "description",
|
||||
"type_info": "Varchar"
|
||||
}
|
||||
],
|
||||
"parameters": {
|
||||
|
@ -49,7 +54,8 @@
|
|||
false,
|
||||
false,
|
||||
false,
|
||||
true
|
||||
true,
|
||||
false
|
||||
]
|
||||
},
|
||||
"hash": "58969747bdccae4a2d3ad8d8117aa92283151d67f52fbb22e5d976b1c6a5c367"
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"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": {
|
||||
"columns": [
|
||||
{
|
||||
|
@ -22,21 +22,27 @@
|
|||
"ordinal": 3,
|
||||
"name": "created_at",
|
||||
"type_info": "Timestamptz"
|
||||
},
|
||||
{
|
||||
"ordinal": 4,
|
||||
"name": "description",
|
||||
"type_info": "Varchar"
|
||||
}
|
||||
],
|
||||
"parameters": {
|
||||
"Left": [
|
||||
"Uuid",
|
||||
"Varchar",
|
||||
"Uuid"
|
||||
"Uuid",
|
||||
"Varchar"
|
||||
]
|
||||
},
|
||||
"nullable": [
|
||||
false,
|
||||
false,
|
||||
true,
|
||||
false,
|
||||
false
|
||||
]
|
||||
},
|
||||
"hash": "408a171b46d5c615ff846547f463dc0b18360644234fb01b24c4c047bebb3a10"
|
||||
"hash": "68d93c71840f87d5f5bb14b4d7fc34edd6be47cd1706b3612a332bbfd4bb54b4"
|
||||
}
|
|
@ -22,6 +22,11 @@
|
|||
"ordinal": 3,
|
||||
"name": "created_at",
|
||||
"type_info": "Timestamptz"
|
||||
},
|
||||
{
|
||||
"ordinal": 4,
|
||||
"name": "description",
|
||||
"type_info": "Varchar"
|
||||
}
|
||||
],
|
||||
"parameters": {
|
||||
|
@ -31,6 +36,7 @@
|
|||
false,
|
||||
false,
|
||||
true,
|
||||
false,
|
||||
false
|
||||
]
|
||||
},
|
||||
|
|
|
@ -37,6 +37,11 @@
|
|||
"ordinal": 6,
|
||||
"name": "original_packaging",
|
||||
"type_info": "Uuid"
|
||||
},
|
||||
{
|
||||
"ordinal": 7,
|
||||
"name": "description",
|
||||
"type_info": "Varchar"
|
||||
}
|
||||
],
|
||||
"parameters": {
|
||||
|
@ -51,7 +56,8 @@
|
|||
false,
|
||||
false,
|
||||
false,
|
||||
true
|
||||
true,
|
||||
false
|
||||
]
|
||||
},
|
||||
"hash": "79d8bfe2ed76ee550cdc31f282f598749d931af69a80d24f4575a4bc2c740f3b"
|
||||
|
|
|
@ -37,6 +37,11 @@
|
|||
"ordinal": 6,
|
||||
"name": "original_packaging",
|
||||
"type_info": "Uuid"
|
||||
},
|
||||
{
|
||||
"ordinal": 7,
|
||||
"name": "description",
|
||||
"type_info": "Varchar"
|
||||
}
|
||||
],
|
||||
"parameters": {
|
||||
|
@ -51,7 +56,8 @@
|
|||
false,
|
||||
false,
|
||||
false,
|
||||
true
|
||||
true,
|
||||
false
|
||||
]
|
||||
},
|
||||
"hash": "7eeb752c8b00ac4000104f0254186f1f9fdb076e8f8b98f10fc1b981cfe8038c"
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"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": {
|
||||
"columns": [
|
||||
{
|
||||
|
@ -37,6 +37,11 @@
|
|||
"ordinal": 6,
|
||||
"name": "original_packaging",
|
||||
"type_info": "Uuid"
|
||||
},
|
||||
{
|
||||
"ordinal": 7,
|
||||
"name": "description",
|
||||
"type_info": "Varchar"
|
||||
}
|
||||
],
|
||||
"parameters": {
|
||||
|
@ -45,7 +50,8 @@
|
|||
"Varchar",
|
||||
"Uuid",
|
||||
"Uuid",
|
||||
"Uuid"
|
||||
"Uuid",
|
||||
"Varchar"
|
||||
]
|
||||
},
|
||||
"nullable": [
|
||||
|
@ -55,8 +61,9 @@
|
|||
false,
|
||||
false,
|
||||
false,
|
||||
true
|
||||
true,
|
||||
false
|
||||
]
|
||||
},
|
||||
"hash": "fa9770ac99749cc4255da6172e5082b29931e992a08534b315a2935978e827e8"
|
||||
"hash": "82df5c0633a655d376b8a91e9f11981cfee40fd04cb4e3552cc5f4ebf4ed0572"
|
||||
}
|
|
@ -37,6 +37,11 @@
|
|||
"ordinal": 6,
|
||||
"name": "original_packaging",
|
||||
"type_info": "Uuid"
|
||||
},
|
||||
{
|
||||
"ordinal": 7,
|
||||
"name": "description",
|
||||
"type_info": "Varchar"
|
||||
}
|
||||
],
|
||||
"parameters": {
|
||||
|
@ -51,7 +56,8 @@
|
|||
false,
|
||||
false,
|
||||
false,
|
||||
true
|
||||
true,
|
||||
false
|
||||
]
|
||||
},
|
||||
"hash": "94958a3a57c3178e6b0de5723b1fbc5433e972b5522b367098afe6cb90a30bf2"
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"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": {
|
||||
"columns": [
|
||||
{
|
||||
|
@ -37,6 +37,11 @@
|
|||
"ordinal": 6,
|
||||
"name": "original_packaging",
|
||||
"type_info": "Uuid"
|
||||
},
|
||||
{
|
||||
"ordinal": 7,
|
||||
"name": "description",
|
||||
"type_info": "Varchar"
|
||||
}
|
||||
],
|
||||
"parameters": {
|
||||
|
@ -44,7 +49,8 @@
|
|||
"Varchar",
|
||||
"Uuid",
|
||||
"Uuid",
|
||||
"Uuid"
|
||||
"Uuid",
|
||||
"Varchar"
|
||||
]
|
||||
},
|
||||
"nullable": [
|
||||
|
@ -54,8 +60,9 @@
|
|||
false,
|
||||
false,
|
||||
false,
|
||||
true
|
||||
true,
|
||||
false
|
||||
]
|
||||
},
|
||||
"hash": "30a7f461d0a20179d08436d9d2c69b33ea9d0775ef1e2b37a1d7fd0109f98b27"
|
||||
"hash": "b80bb07ab582b0705b5c0370066730edf887d66a4196a0834c59f0df9f9314d3"
|
||||
}
|
|
@ -22,6 +22,11 @@
|
|||
"ordinal": 3,
|
||||
"name": "created_at",
|
||||
"type_info": "Timestamptz"
|
||||
},
|
||||
{
|
||||
"ordinal": 4,
|
||||
"name": "description",
|
||||
"type_info": "Varchar"
|
||||
}
|
||||
],
|
||||
"parameters": {
|
||||
|
@ -33,6 +38,7 @@
|
|||
false,
|
||||
false,
|
||||
true,
|
||||
false,
|
||||
false
|
||||
]
|
||||
},
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"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": {
|
||||
"columns": [
|
||||
{
|
||||
|
@ -22,20 +22,28 @@
|
|||
"ordinal": 3,
|
||||
"name": "created_at",
|
||||
"type_info": "Timestamptz"
|
||||
},
|
||||
{
|
||||
"ordinal": 4,
|
||||
"name": "description",
|
||||
"type_info": "Varchar"
|
||||
}
|
||||
],
|
||||
"parameters": {
|
||||
"Left": [
|
||||
"Uuid",
|
||||
"Varchar",
|
||||
"Uuid"
|
||||
"Uuid",
|
||||
"Varchar"
|
||||
]
|
||||
},
|
||||
"nullable": [
|
||||
false,
|
||||
false,
|
||||
true,
|
||||
false,
|
||||
false
|
||||
]
|
||||
},
|
||||
"hash": "7e2e1460a2c946ba909c50d4cf1beacf50ebf5fbfead379340f9f72614958e78"
|
||||
"hash": "e0129afa95f896d79f772fb177a8f9229dfbbfd289039db7b733c7d1d050f4bf"
|
||||
}
|
|
@ -37,6 +37,11 @@
|
|||
"ordinal": 6,
|
||||
"name": "original_packaging",
|
||||
"type_info": "Uuid"
|
||||
},
|
||||
{
|
||||
"ordinal": 7,
|
||||
"name": "description",
|
||||
"type_info": "Varchar"
|
||||
}
|
||||
],
|
||||
"parameters": {
|
||||
|
@ -51,7 +56,8 @@
|
|||
false,
|
||||
false,
|
||||
false,
|
||||
true
|
||||
true,
|
||||
false
|
||||
]
|
||||
},
|
||||
"hash": "e45160a73a18d870f592989349057d6852d2d3f63dc055442125a6a92950729d"
|
||||
|
|
|
@ -37,6 +37,11 @@
|
|||
"ordinal": 6,
|
||||
"name": "original_packaging",
|
||||
"type_info": "Uuid"
|
||||
},
|
||||
{
|
||||
"ordinal": 7,
|
||||
"name": "description",
|
||||
"type_info": "Varchar"
|
||||
}
|
||||
],
|
||||
"parameters": {
|
||||
|
@ -51,7 +56,8 @@
|
|||
false,
|
||||
false,
|
||||
false,
|
||||
true
|
||||
true,
|
||||
false
|
||||
]
|
||||
},
|
||||
"hash": "efe2258db42b60f732d562d106842b19308d9a558703b02e758f60e7d8644d00"
|
||||
|
|
9
migrations/20240714122901_add_description.down.sql
Normal file
9
migrations/20240714122901_add_description.down.sql
Normal 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;
|
9
migrations/20240714122901_add_description.up.sql
Normal file
9
migrations/20240714122901_add_description.up.sql
Normal 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 '';
|
|
@ -130,6 +130,10 @@ async fn show(
|
|||
}
|
||||
}
|
||||
}
|
||||
tr {
|
||||
th { "Description" }
|
||||
td style="white-space: pre-wrap" { (item.description) }
|
||||
}
|
||||
}
|
||||
|
||||
@if !children.is_empty() {
|
||||
|
@ -296,6 +300,13 @@ async fn add_form(
|
|||
datalist: Some(&datalist_items),
|
||||
..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" }
|
||||
}
|
||||
|
@ -401,6 +412,13 @@ async fn edit_form(
|
|||
datalist: Some(&datalist_items),
|
||||
..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" }
|
||||
}
|
||||
|
|
|
@ -109,6 +109,10 @@ async fn show(
|
|||
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() {
|
||||
|
@ -233,6 +237,13 @@ async fn add_form(
|
|||
datalist: Some(&datalist_item_classes),
|
||||
..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" }
|
||||
}
|
||||
|
@ -309,6 +320,13 @@ async fn edit_form(
|
|||
datalist: Some(&datalist_item_classes),
|
||||
..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" }
|
||||
}
|
||||
|
|
|
@ -11,12 +11,14 @@ use super::datalist::Datalist;
|
|||
#[derive(Clone)]
|
||||
pub enum InputType {
|
||||
Text,
|
||||
Textarea,
|
||||
}
|
||||
|
||||
impl fmt::Display for InputType {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
match self {
|
||||
Self::Text => write!(f, "text"),
|
||||
Self::Textarea => write!(f, "textarea"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -50,15 +52,25 @@ impl Default for InputGroup<'_> {
|
|||
impl InputGroup<'_> {
|
||||
fn main_input(&self, force_required: bool) -> Markup {
|
||||
html! {
|
||||
input
|
||||
@match self.r#type {
|
||||
InputType::Textarea => textarea
|
||||
.form-control
|
||||
#(self.name)
|
||||
name={ (self.name) }
|
||||
type={ (self.r#type) }
|
||||
name=(self.name)
|
||||
required[self.required || force_required]
|
||||
disabled[self.disabled]
|
||||
value=[self.value.clone()]
|
||||
list=[self.datalist.map(|dl| format!("{}-datalist", dl.name()))];
|
||||
rows="5" // FIXME hardcoded
|
||||
{ (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()))];,
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,11 +12,12 @@ use crate::models::{Item, NewItem};
|
|||
pub async fn add(pool: &PgPool, new_item: NewItem) -> Result<Item, sqlx::Error> {
|
||||
query_as!(
|
||||
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.parent,
|
||||
new_item.class,
|
||||
new_item.original_packaging
|
||||
new_item.original_packaging,
|
||||
new_item.description
|
||||
)
|
||||
.fetch_one(pool)
|
||||
.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> {
|
||||
query_as!(
|
||||
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,
|
||||
modified_item.name,
|
||||
modified_item.parent,
|
||||
modified_item.class,
|
||||
modified_item.original_packaging
|
||||
modified_item.original_packaging,
|
||||
modified_item.description
|
||||
)
|
||||
.fetch_one(pool)
|
||||
.await
|
||||
|
|
|
@ -12,9 +12,10 @@ use crate::models::{Item, ItemClass, NewItemClass};
|
|||
pub async fn add(pool: &PgPool, new_item_class: NewItemClass) -> Result<ItemClass, sqlx::Error> {
|
||||
query_as!(
|
||||
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.parent
|
||||
new_item_class.parent,
|
||||
new_item_class.description
|
||||
)
|
||||
.fetch_one(pool)
|
||||
.await
|
||||
|
@ -47,10 +48,11 @@ pub async fn update(
|
|||
) -> Result<ItemClass, sqlx::Error> {
|
||||
query_as!(
|
||||
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,
|
||||
modified_item_class.name,
|
||||
modified_item_class.parent
|
||||
modified_item_class.parent,
|
||||
modified_item_class.description
|
||||
)
|
||||
.fetch_one(pool)
|
||||
.await
|
||||
|
|
|
@ -22,6 +22,7 @@ pub struct Item {
|
|||
pub created_at: OffsetDateTime,
|
||||
pub short_id: i32,
|
||||
pub original_packaging: Option<Uuid>,
|
||||
pub description: String,
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
|
@ -32,6 +33,7 @@ pub struct NewItem {
|
|||
pub parent: Option<Uuid>,
|
||||
pub class: Uuid,
|
||||
pub original_packaging: Option<Uuid>,
|
||||
pub description: String,
|
||||
}
|
||||
|
||||
// Its structure is not how it could ideally be
|
||||
|
@ -46,6 +48,7 @@ pub struct NewItemForm {
|
|||
pub parent: Option<Uuid>,
|
||||
pub class: Option<Uuid>,
|
||||
pub original_packaging: Option<Uuid>,
|
||||
pub description: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Serialize)]
|
||||
|
@ -56,6 +59,7 @@ pub struct ItemClass {
|
|||
pub parent: Option<Uuid>,
|
||||
#[serde(with = "time::serde::iso8601")]
|
||||
pub created_at: OffsetDateTime,
|
||||
pub description: String,
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
|
@ -63,6 +67,7 @@ pub struct NewItemClass {
|
|||
pub name: String,
|
||||
#[serde(default)]
|
||||
pub parent: Option<Uuid>,
|
||||
pub description: String,
|
||||
}
|
||||
|
||||
// see NewItemForm
|
||||
|
@ -71,4 +76,5 @@ pub struct NewItemClassForm {
|
|||
pub name: Option<String>,
|
||||
#[serde(default)]
|
||||
pub parent: Option<Uuid>,
|
||||
pub description: Option<String>,
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue