From 82ba28adebe457a55516acc6696c87425f0dbefe Mon Sep 17 00:00:00 2001 From: Bhasher Date: Fri, 29 Dec 2023 17:02:46 +0100 Subject: [PATCH] Modal card --- backend/db/cards.go | 4 +- backend/db/cardtags.go | 24 ++++-- backend/handlers/cards.go | 4 +- backend/handlers/cardtags.go | 4 +- backend/main.go | 2 +- frontend/src/components/card.svelte | 55 +++++++----- frontend/src/components/modal_card.svelte | 75 ++++++++++++++++ frontend/src/components/modal_tag.svelte | 65 ++++++++++++++ frontend/src/components/modal_tags.svelte | 74 ++++++++++++++++ frontend/src/components/project.svelte | 28 ++---- frontend/src/stores/config.ts | 1 + frontend/src/stores/interfaces.ts | 19 ++++ frontend/static/css/modalCard.css | 100 ++++++++++++++++++++++ 13 files changed, 396 insertions(+), 59 deletions(-) create mode 100644 frontend/src/components/modal_card.svelte create mode 100644 frontend/src/components/modal_tag.svelte create mode 100644 frontend/src/components/modal_tags.svelte create mode 100644 frontend/src/stores/config.ts create mode 100644 frontend/src/stores/interfaces.ts create mode 100644 frontend/static/css/modalCard.css diff --git a/backend/db/cards.go b/backend/db/cards.go index 8f4bc76..84347cc 100644 --- a/backend/db/cards.go +++ b/backend/db/cards.go @@ -30,7 +30,7 @@ func GetAllCardsOf(projectID int) ([]types.FullCard, error) { return nil, err } - tags, err := GetAllTagsOfCard(c.ID) + tags, err := GetAllTagsOfCard(c.ID, projectID) if err != nil { return nil, err } @@ -54,7 +54,7 @@ func GetCard(id int) (*types.FullCard, error) { return nil, err } - tags, err := GetAllTagsOfCard(id) + tags, err := GetAllTagsOfCard(id, c.ProjectID) if err != nil { return nil, err } diff --git a/backend/db/cardtags.go b/backend/db/cardtags.go index 4bfc347..650c56f 100644 --- a/backend/db/cardtags.go +++ b/backend/db/cardtags.go @@ -9,12 +9,20 @@ func AddTagToCard(ct types.CardTag) error { return err } -func GetAllTagsOfCard(cardID int) ([]types.FullCardTag, error) { - rows, err := db.Query(`SELECT ct.card_id, ct.tag_id, t.title, ct.value - FROM cardtags ct - JOIN tags t ON ct.tag_id = t.id - WHERE ct.card_id = ?; - `, cardID) +func GetAllTagsOfCard(cardID int, projectID int) ([]types.FullCardTag, error) { + if projectID < 0 { + card, err := GetCard(cardID) + if err != nil { + return nil, err + } + projectID = card.ProjectID + } + + rows, err := db.Query(`SELECT t.id, t.title, COALESCE(ct.value, '') + FROM tags t + LEFT JOIN cardtags ct ON ct.tag_id = t.id AND ct.card_id = ? + WHERE t.project_id = ? + `, cardID, projectID) if err != nil { return nil, err } @@ -22,8 +30,8 @@ func GetAllTagsOfCard(cardID int) ([]types.FullCardTag, error) { var cardtags []types.FullCardTag for rows.Next() { - var ct types.FullCardTag - if err := rows.Scan(&ct.CardID, &ct.TagID, &ct.TagTitle, &ct.Value); err != nil { + ct := types.FullCardTag{CardID: cardID} + if err := rows.Scan(&ct.TagID, &ct.TagTitle, &ct.Value); err != nil { return nil, err } cardtags = append(cardtags, ct) diff --git a/backend/handlers/cards.go b/backend/handlers/cards.go index e1e4090..4479a6e 100644 --- a/backend/handlers/cards.go +++ b/backend/handlers/cards.go @@ -26,12 +26,12 @@ func CreateCard(c *fiber.Ctx) error { func GetAllCardsOf(c *fiber.Ctx) error { projectID, err := strconv.Atoi(c.Params("project_id")) if err != nil { - return c.Status(fiber.StatusBadRequest).JSON(fiber.Map{"status": "error", "error": "Invalid project_id"}) + return c.Status(fiber.StatusBadRequest).JSON(fiber.Map{"status": "error", "error": "Invalid project_id", "trace": fmt.Sprint(err)}) } projects, err := db.GetAllCardsOf(projectID) if err != nil { - return c.Status(fiber.StatusInternalServerError).JSON(fiber.Map{"error": "Cannot retrieve cards"}) + return c.Status(fiber.StatusInternalServerError).JSON(fiber.Map{"status": "error", "error": "Cannot retrieve cards", "trace": fmt.Sprint(err)}) } return c.JSON(fiber.Map{"status": "ok", "data": projects}) diff --git a/backend/handlers/cardtags.go b/backend/handlers/cardtags.go index 91772b6..c775bc2 100644 --- a/backend/handlers/cardtags.go +++ b/backend/handlers/cardtags.go @@ -29,7 +29,7 @@ func GetAllTagsOfCard(c *fiber.Ctx) error { return c.Status(fiber.StatusBadRequest).JSON(fiber.Map{"status": "error", "error": "Invalid card_id"}) } - cardtags, err := db.GetAllTagsOfCard(cardID) + cardtags, err := db.GetAllTagsOfCard(cardID, -1) if err != nil { return c.Status(fiber.StatusInternalServerError).JSON(fiber.Map{"status": "error", "error": "Cannot retrieve tags of card", "stack": fmt.Sprint(err)}) } @@ -78,7 +78,7 @@ func UpdateTagOfCard(c *fiber.Ctx) error { tag_id, err := strconv.Atoi(c.Params("tag_id")) if err != nil { - return c.Status(fiber.StatusBadRequest).JSON(fiber.Map{"error": "Invalid tag ID"}) + return c.Status(fiber.StatusBadRequest).JSON(fiber.Map{"status": "error", "error": "Invalid tag ID", "stack": fmt.Sprint(err)}) } cardtag := types.CardTag{CardID: card_id, TagID: tag_id} diff --git a/backend/main.go b/backend/main.go index 7d07b94..9d8505f 100644 --- a/backend/main.go +++ b/backend/main.go @@ -58,7 +58,7 @@ func main() { app.Get("/api/cardtags/:card_id", handlers.GetAllTagsOfCard) app.Delete("/api/cardtag/:card_id/:tag_id", handlers.DeleteTagOfCard) app.Delete("/api/cardtags/:card_id", handlers.DeleteTagsOfCard) - app.Put("/api/cardtag/:card_id/:tag_id", handlers.UpdateTag) + app.Put("/api/cardtag/:card_id/:tag_id", handlers.UpdateTagOfCard) log.Fatal(app.Listen(fmt.Sprintf(":%v", port))) } diff --git a/frontend/src/components/card.svelte b/frontend/src/components/card.svelte index 62f8fc0..618a4eb 100644 --- a/frontend/src/components/card.svelte +++ b/frontend/src/components/card.svelte @@ -1,41 +1,52 @@ - - - - -
+
{card.title}
{#if card.tags}
{#each card.tags as tag} - {tag.value} + {#if tag.value} + {tag.value} + {/if} {/each}
{/if}
+ + diff --git a/frontend/src/components/modal_card.svelte b/frontend/src/components/modal_card.svelte new file mode 100644 index 0000000..0f6fffa --- /dev/null +++ b/frontend/src/components/modal_card.svelte @@ -0,0 +1,75 @@ + + +{#if show} + + +