diff --git a/backend/handlers/views.go b/backend/handlers/views.go index d88c50d..ab75386 100644 --- a/backend/handlers/views.go +++ b/backend/handlers/views.go @@ -68,7 +68,10 @@ func UpdateView(c *fiber.Ctx) error { view := types.View{ID: id} if err := c.BodyParser(&view); err != nil { - return c.Status(fiber.StatusBadRequest).JSON(fiber.Map{"error": "Cannot parse request"}) + return c.Status(fiber.StatusBadRequest).JSON(fiber.Map{ + "error": "Cannot parse request", + "trace": fmt.Sprint(err), + }) } count, err := db.UpdateView(view) diff --git a/backend/types/view.go b/backend/types/view.go index 851d6cd..cf8b1a4 100644 --- a/backend/types/view.go +++ b/backend/types/view.go @@ -1,11 +1,11 @@ package types type View struct { - ID int `json:"id"` - ProjectID int `json:"project_id"` - Title string `json:"title"` - PrimaryTagID *int `json:"primary_tag_id"` - SecondaryTagID *int `json:"secondary_tag_id"` - SortTagID *int `json:"sort_tag_id"` - SortDirection *string `json:"sort_direction"` + ID int `json:"id"` + ProjectID int `json:"project_id"` + Title string `json:"title"` + PrimaryTagID *int `json:"primary_tag_id"` + SecondaryTagID *int `json:"secondary_tag_id"` + SortTagID *int `json:"sort_tag_id"` + SortDirection *int `json:"sort_direction"` } diff --git a/frontend/src/components/project/groupMenu.svelte b/frontend/src/components/project/card/header/menus/group_menu.svelte similarity index 92% rename from frontend/src/components/project/groupMenu.svelte rename to frontend/src/components/project/card/header/menus/group_menu.svelte index 7eb7805..9779b2b 100644 --- a/frontend/src/components/project/groupMenu.svelte +++ b/frontend/src/components/project/card/header/menus/group_menu.svelte @@ -1,5 +1,5 @@ - + {#each choices as choice} - +
+ + tag.id !== view?.primary_tag_id) + .map((tag) => ({ id: tag.id, value: tag.title }))} + onChoice={async (id) => { + if (!(await setSort(id))) return; + sortMenuOpen = false; + }} + currentChoice={view?.sort_tag_id} + currentDirection={view?.sort_direction} + /> +
diff --git a/frontend/src/components/project/project.svelte b/frontend/src/components/project/project.svelte index d833738..9c2d2d7 100644 --- a/frontend/src/components/project/project.svelte +++ b/frontend/src/components/project/project.svelte @@ -35,9 +35,23 @@ optionId={option.id} primary_tag_id={view.primary_tag_id} title={option.value} - columnCards={$cards.filter((c) => - c.tags.map((t) => t.option_id).includes(option.id) - )} + columnCards={$cards + .filter((c) => c.tags.map((t) => t.option_id).includes(option.id)) + .sort((a, b) => { + if (!view?.sort_tag_id) return 0; + const aTag = a.tags.find((t) => t.tag_id === view?.sort_tag_id); + const bTag = b.tags.find((t) => t.tag_id === view?.sort_tag_id); + + if (!aTag) return -(view?.sort_direction || 1); + if (!bTag) return view?.sort_direction || 1; + + const aValue = aTag.value || aTag.option_id || 0; + const bValue = bTag.value || bTag.option_id || 0; + + return aValue < bValue + ? view?.sort_direction || 1 + : -(view?.sort_direction || 1); + })} projectId={project.id} /> {/each} diff --git a/frontend/src/components/tuils/menu.svelte b/frontend/src/components/utils/menu.svelte similarity index 100% rename from frontend/src/components/tuils/menu.svelte rename to frontend/src/components/utils/menu.svelte