From 22e284c34f96c136e8d0b2ecb865101b7971f0cb Mon Sep 17 00:00:00 2001 From: Simon Bruder Date: Sun, 14 Jul 2024 15:17:04 +0200 Subject: [PATCH] Add description to item and item class --- ...c7ee7520478ff4f5886b4523fb0dc4df0e204.json | 8 ++++- ...f28fd05f18706f70220b6ebb7354d2a0a9e3b.json | 8 ++++- ...e5da76e4cf488eedd4704019b4f14b6fbafb2.json | 6 ++++ ...aa92283151d67f52fbb22e5d976b1c6a5c367.json | 8 ++++- ...34edd6be47cd1706b3612a332bbfd4bb54b4.json} | 14 ++++++--- ...1b413f804c6f3e082a818b67ebab0938acb39.json | 6 ++++ ...598749d931af69a80d24f4575a4bc2c740f3b.json | 8 ++++- ...86f1f9fdb076e8f8b98f10fc1b981cfe8038c.json | 8 ++++- ...981cfee40fd04cb4e3552cc5f4ebf4ed0572.json} | 15 +++++++--- ...fbc5433e972b5522b367098afe6cb90a30bf2.json | 8 ++++- ...30edf887d66a4196a0834c59f0df9f9314d3.json} | 15 +++++++--- ...d0c0b86eb2322035e6a720e2e6d425072a8c1.json | 6 ++++ ...f9229dfbbfd289039db7b733c7d1d050f4bf.json} | 14 +++++++-- ...57d6852d2d3f63dc055442125a6a92950729d.json | 8 ++++- ...42b19308d9a558703b02e758f60e7d8644d00.json | 8 ++++- .../20240714122901_add_description.down.sql | 9 ++++++ .../20240714122901_add_description.up.sql | 9 ++++++ src/frontend/item.rs | 18 +++++++++++ src/frontend/item_class.rs | 18 +++++++++++ src/frontend/templates/forms.rs | 30 +++++++++++++------ src/manage/item.rs | 10 ++++--- src/manage/item_class.rs | 10 ++++--- src/models.rs | 6 ++++ 23 files changed, 210 insertions(+), 40 deletions(-) rename .sqlx/{query-408a171b46d5c615ff846547f463dc0b18360644234fb01b24c4c047bebb3a10.json => query-68d93c71840f87d5f5bb14b4d7fc34edd6be47cd1706b3612a332bbfd4bb54b4.json} (66%) rename .sqlx/{query-fa9770ac99749cc4255da6172e5082b29931e992a08534b315a2935978e827e8.json => query-82df5c0633a655d376b8a91e9f11981cfee40fd04cb4e3552cc5f4ebf4ed0572.json} (77%) rename .sqlx/{query-30a7f461d0a20179d08436d9d2c69b33ea9d0775ef1e2b37a1d7fd0109f98b27.json => query-b80bb07ab582b0705b5c0370066730edf887d66a4196a0834c59f0df9f9314d3.json} (77%) rename .sqlx/{query-7e2e1460a2c946ba909c50d4cf1beacf50ebf5fbfead379340f9f72614958e78.json => query-e0129afa95f896d79f772fb177a8f9229dfbbfd289039db7b733c7d1d050f4bf.json} (63%) create mode 100644 migrations/20240714122901_add_description.down.sql create mode 100644 migrations/20240714122901_add_description.up.sql diff --git a/.sqlx/query-1e9045f52c002a19b815351fee1c7ee7520478ff4f5886b4523fb0dc4df0e204.json b/.sqlx/query-1e9045f52c002a19b815351fee1c7ee7520478ff4f5886b4523fb0dc4df0e204.json index a2397f4..7d5a7be 100644 --- a/.sqlx/query-1e9045f52c002a19b815351fee1c7ee7520478ff4f5886b4523fb0dc4df0e204.json +++ b/.sqlx/query-1e9045f52c002a19b815351fee1c7ee7520478ff4f5886b4523fb0dc4df0e204.json @@ -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" diff --git a/.sqlx/query-2e9619ce6db1047e2f5447c4925f28fd05f18706f70220b6ebb7354d2a0a9e3b.json b/.sqlx/query-2e9619ce6db1047e2f5447c4925f28fd05f18706f70220b6ebb7354d2a0a9e3b.json index 61cb75e..bd6f7f3 100644 --- a/.sqlx/query-2e9619ce6db1047e2f5447c4925f28fd05f18706f70220b6ebb7354d2a0a9e3b.json +++ b/.sqlx/query-2e9619ce6db1047e2f5447c4925f28fd05f18706f70220b6ebb7354d2a0a9e3b.json @@ -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" diff --git a/.sqlx/query-308962c26250f9312287a3f2f21e5da76e4cf488eedd4704019b4f14b6fbafb2.json b/.sqlx/query-308962c26250f9312287a3f2f21e5da76e4cf488eedd4704019b4f14b6fbafb2.json index 5c7a48e..d9eb78e 100644 --- a/.sqlx/query-308962c26250f9312287a3f2f21e5da76e4cf488eedd4704019b4f14b6fbafb2.json +++ b/.sqlx/query-308962c26250f9312287a3f2f21e5da76e4cf488eedd4704019b4f14b6fbafb2.json @@ -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 ] }, diff --git a/.sqlx/query-58969747bdccae4a2d3ad8d8117aa92283151d67f52fbb22e5d976b1c6a5c367.json b/.sqlx/query-58969747bdccae4a2d3ad8d8117aa92283151d67f52fbb22e5d976b1c6a5c367.json index ccb058b..eb09468 100644 --- a/.sqlx/query-58969747bdccae4a2d3ad8d8117aa92283151d67f52fbb22e5d976b1c6a5c367.json +++ b/.sqlx/query-58969747bdccae4a2d3ad8d8117aa92283151d67f52fbb22e5d976b1c6a5c367.json @@ -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" diff --git a/.sqlx/query-408a171b46d5c615ff846547f463dc0b18360644234fb01b24c4c047bebb3a10.json b/.sqlx/query-68d93c71840f87d5f5bb14b4d7fc34edd6be47cd1706b3612a332bbfd4bb54b4.json similarity index 66% rename from .sqlx/query-408a171b46d5c615ff846547f463dc0b18360644234fb01b24c4c047bebb3a10.json rename to .sqlx/query-68d93c71840f87d5f5bb14b4d7fc34edd6be47cd1706b3612a332bbfd4bb54b4.json index 62d1fb3..5ae565b 100644 --- a/.sqlx/query-408a171b46d5c615ff846547f463dc0b18360644234fb01b24c4c047bebb3a10.json +++ b/.sqlx/query-68d93c71840f87d5f5bb14b4d7fc34edd6be47cd1706b3612a332bbfd4bb54b4.json @@ -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" } diff --git a/.sqlx/query-6e7b3389c47091d9fc8c7638b401b413f804c6f3e082a818b67ebab0938acb39.json b/.sqlx/query-6e7b3389c47091d9fc8c7638b401b413f804c6f3e082a818b67ebab0938acb39.json index be996de..147b301 100644 --- a/.sqlx/query-6e7b3389c47091d9fc8c7638b401b413f804c6f3e082a818b67ebab0938acb39.json +++ b/.sqlx/query-6e7b3389c47091d9fc8c7638b401b413f804c6f3e082a818b67ebab0938acb39.json @@ -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 ] }, diff --git a/.sqlx/query-79d8bfe2ed76ee550cdc31f282f598749d931af69a80d24f4575a4bc2c740f3b.json b/.sqlx/query-79d8bfe2ed76ee550cdc31f282f598749d931af69a80d24f4575a4bc2c740f3b.json index f085fc2..9e9b102 100644 --- a/.sqlx/query-79d8bfe2ed76ee550cdc31f282f598749d931af69a80d24f4575a4bc2c740f3b.json +++ b/.sqlx/query-79d8bfe2ed76ee550cdc31f282f598749d931af69a80d24f4575a4bc2c740f3b.json @@ -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" diff --git a/.sqlx/query-7eeb752c8b00ac4000104f0254186f1f9fdb076e8f8b98f10fc1b981cfe8038c.json b/.sqlx/query-7eeb752c8b00ac4000104f0254186f1f9fdb076e8f8b98f10fc1b981cfe8038c.json index 403169c..1fff101 100644 --- a/.sqlx/query-7eeb752c8b00ac4000104f0254186f1f9fdb076e8f8b98f10fc1b981cfe8038c.json +++ b/.sqlx/query-7eeb752c8b00ac4000104f0254186f1f9fdb076e8f8b98f10fc1b981cfe8038c.json @@ -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" diff --git a/.sqlx/query-fa9770ac99749cc4255da6172e5082b29931e992a08534b315a2935978e827e8.json b/.sqlx/query-82df5c0633a655d376b8a91e9f11981cfee40fd04cb4e3552cc5f4ebf4ed0572.json similarity index 77% rename from .sqlx/query-fa9770ac99749cc4255da6172e5082b29931e992a08534b315a2935978e827e8.json rename to .sqlx/query-82df5c0633a655d376b8a91e9f11981cfee40fd04cb4e3552cc5f4ebf4ed0572.json index 7a9a202..5593f47 100644 --- a/.sqlx/query-fa9770ac99749cc4255da6172e5082b29931e992a08534b315a2935978e827e8.json +++ b/.sqlx/query-82df5c0633a655d376b8a91e9f11981cfee40fd04cb4e3552cc5f4ebf4ed0572.json @@ -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" } diff --git a/.sqlx/query-94958a3a57c3178e6b0de5723b1fbc5433e972b5522b367098afe6cb90a30bf2.json b/.sqlx/query-94958a3a57c3178e6b0de5723b1fbc5433e972b5522b367098afe6cb90a30bf2.json index 336949f..904cff3 100644 --- a/.sqlx/query-94958a3a57c3178e6b0de5723b1fbc5433e972b5522b367098afe6cb90a30bf2.json +++ b/.sqlx/query-94958a3a57c3178e6b0de5723b1fbc5433e972b5522b367098afe6cb90a30bf2.json @@ -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" diff --git a/.sqlx/query-30a7f461d0a20179d08436d9d2c69b33ea9d0775ef1e2b37a1d7fd0109f98b27.json b/.sqlx/query-b80bb07ab582b0705b5c0370066730edf887d66a4196a0834c59f0df9f9314d3.json similarity index 77% rename from .sqlx/query-30a7f461d0a20179d08436d9d2c69b33ea9d0775ef1e2b37a1d7fd0109f98b27.json rename to .sqlx/query-b80bb07ab582b0705b5c0370066730edf887d66a4196a0834c59f0df9f9314d3.json index a2b877b..9a7c965 100644 --- a/.sqlx/query-30a7f461d0a20179d08436d9d2c69b33ea9d0775ef1e2b37a1d7fd0109f98b27.json +++ b/.sqlx/query-b80bb07ab582b0705b5c0370066730edf887d66a4196a0834c59f0df9f9314d3.json @@ -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" } diff --git a/.sqlx/query-c552c0a40bc8995cb95726a85f1d0c0b86eb2322035e6a720e2e6d425072a8c1.json b/.sqlx/query-c552c0a40bc8995cb95726a85f1d0c0b86eb2322035e6a720e2e6d425072a8c1.json index 0c7bcd6..e91dc01 100644 --- a/.sqlx/query-c552c0a40bc8995cb95726a85f1d0c0b86eb2322035e6a720e2e6d425072a8c1.json +++ b/.sqlx/query-c552c0a40bc8995cb95726a85f1d0c0b86eb2322035e6a720e2e6d425072a8c1.json @@ -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 ] }, diff --git a/.sqlx/query-7e2e1460a2c946ba909c50d4cf1beacf50ebf5fbfead379340f9f72614958e78.json b/.sqlx/query-e0129afa95f896d79f772fb177a8f9229dfbbfd289039db7b733c7d1d050f4bf.json similarity index 63% rename from .sqlx/query-7e2e1460a2c946ba909c50d4cf1beacf50ebf5fbfead379340f9f72614958e78.json rename to .sqlx/query-e0129afa95f896d79f772fb177a8f9229dfbbfd289039db7b733c7d1d050f4bf.json index b9586ce..0635a6d 100644 --- a/.sqlx/query-7e2e1460a2c946ba909c50d4cf1beacf50ebf5fbfead379340f9f72614958e78.json +++ b/.sqlx/query-e0129afa95f896d79f772fb177a8f9229dfbbfd289039db7b733c7d1d050f4bf.json @@ -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" } diff --git a/.sqlx/query-e45160a73a18d870f592989349057d6852d2d3f63dc055442125a6a92950729d.json b/.sqlx/query-e45160a73a18d870f592989349057d6852d2d3f63dc055442125a6a92950729d.json index 59f6624..6ce9417 100644 --- a/.sqlx/query-e45160a73a18d870f592989349057d6852d2d3f63dc055442125a6a92950729d.json +++ b/.sqlx/query-e45160a73a18d870f592989349057d6852d2d3f63dc055442125a6a92950729d.json @@ -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" diff --git a/.sqlx/query-efe2258db42b60f732d562d106842b19308d9a558703b02e758f60e7d8644d00.json b/.sqlx/query-efe2258db42b60f732d562d106842b19308d9a558703b02e758f60e7d8644d00.json index 658f4f6..40f8a6c 100644 --- a/.sqlx/query-efe2258db42b60f732d562d106842b19308d9a558703b02e758f60e7d8644d00.json +++ b/.sqlx/query-efe2258db42b60f732d562d106842b19308d9a558703b02e758f60e7d8644d00.json @@ -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" diff --git a/migrations/20240714122901_add_description.down.sql b/migrations/20240714122901_add_description.down.sql new file mode 100644 index 0000000..5cf196f --- /dev/null +++ b/migrations/20240714122901_add_description.down.sql @@ -0,0 +1,9 @@ +-- SPDX-FileCopyrightText: 2024 Simon Bruder +-- +-- SPDX-License-Identifier: AGPL-3.0-or-later + +ALTER TABLE items + DROP description; + +ALTER TABLE item_classes + DROP description; diff --git a/migrations/20240714122901_add_description.up.sql b/migrations/20240714122901_add_description.up.sql new file mode 100644 index 0000000..e9e90dd --- /dev/null +++ b/migrations/20240714122901_add_description.up.sql @@ -0,0 +1,9 @@ +-- SPDX-FileCopyrightText: 2024 Simon Bruder +-- +-- 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 ''; diff --git a/src/frontend/item.rs b/src/frontend/item.rs index 88ab5b5..8378376 100644 --- a/src/frontend/item.rs +++ b/src/frontend/item.rs @@ -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" } } diff --git a/src/frontend/item_class.rs b/src/frontend/item_class.rs index ccebba1..2d73f43 100644 --- a/src/frontend/item_class.rs +++ b/src/frontend/item_class.rs @@ -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" } } diff --git a/src/frontend/templates/forms.rs b/src/frontend/templates/forms.rs index 62706c4..81f7328 100644 --- a/src/frontend/templates/forms.rs +++ b/src/frontend/templates/forms.rs @@ -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 - .form-control - #(self.name) - name={ (self.name) } - type={ (self.r#type) } - required[self.required || force_required] - disabled[self.disabled] - value=[self.value.clone()] - list=[self.datalist.map(|dl| format!("{}-datalist", dl.name()))]; + @match self.r#type { + InputType::Textarea => textarea + .form-control + #(self.name) + name=(self.name) + required[self.required || force_required] + disabled[self.disabled] + 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()))];, + } } } } diff --git a/src/manage/item.rs b/src/manage/item.rs index 76a42e6..4d8108a 100644 --- a/src/manage/item.rs +++ b/src/manage/item.rs @@ -12,11 +12,12 @@ use crate::models::{Item, NewItem}; pub async fn add(pool: &PgPool, new_item: NewItem) -> Result { 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, sqlx:: pub async fn update(pool: &PgPool, id: Uuid, modified_item: NewItem) -> Result { 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 diff --git a/src/manage/item_class.rs b/src/manage/item_class.rs index 2fc4bdf..c8505c9 100644 --- a/src/manage/item_class.rs +++ b/src/manage/item_class.rs @@ -12,9 +12,10 @@ use crate::models::{Item, ItemClass, NewItemClass}; pub async fn add(pool: &PgPool, new_item_class: NewItemClass) -> Result { 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 { 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 diff --git a/src/models.rs b/src/models.rs index 5d6738e..ae4a26c 100644 --- a/src/models.rs +++ b/src/models.rs @@ -22,6 +22,7 @@ pub struct Item { pub created_at: OffsetDateTime, pub short_id: i32, pub original_packaging: Option, + pub description: String, } #[derive(Debug, Deserialize)] @@ -32,6 +33,7 @@ pub struct NewItem { pub parent: Option, pub class: Uuid, pub original_packaging: Option, + pub description: String, } // Its structure is not how it could ideally be @@ -46,6 +48,7 @@ pub struct NewItemForm { pub parent: Option, pub class: Option, pub original_packaging: Option, + pub description: Option, } #[derive(Clone, Debug, Serialize)] @@ -56,6 +59,7 @@ pub struct ItemClass { pub parent: Option, #[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, + pub description: String, } // see NewItemForm @@ -71,4 +76,5 @@ pub struct NewItemClassForm { pub name: Option, #[serde(default)] pub parent: Option, + pub description: Option, }