From 629f4938bb8753a68780e2f65a11e37564e75845 Mon Sep 17 00:00:00 2001 From: Seamus Lowry Date: Sun, 22 Sep 2024 17:16:06 -0400 Subject: [PATCH 1/5] feat: default to sorting by name, asc for paged label requests --- mealie/routes/groups/controller_labels.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/mealie/routes/groups/controller_labels.py b/mealie/routes/groups/controller_labels.py index fb008ef030b..3b854ec2caf 100644 --- a/mealie/routes/groups/controller_labels.py +++ b/mealie/routes/groups/controller_labels.py @@ -14,12 +14,17 @@ MultiPurposeLabelUpdate, ) from mealie.schema.labels.multi_purpose_label import MultiPurposeLabelPagination -from mealie.schema.response.pagination import PaginationQuery +from mealie.schema.response.pagination import OrderDirection, PaginationQuery from mealie.services.group_services.labels_service import MultiPurposeLabelService router = APIRouter(prefix="/groups/labels", tags=["Groups: Multi Purpose Labels"], route_class=MealieCrudRoute) +class LabelPaginationQuery(PaginationQuery): + order_by: str | None = "name" + order_direction: OrderDirection = OrderDirection.asc + + @controller(router) class MultiPurposeLabelsController(BaseUserController): @cached_property @@ -41,7 +46,7 @@ def mixins(self) -> HttpRepo: return HttpRepo(self.repo, self.logger, self.registered_exceptions, self.t("generic.server-error")) @router.get("", response_model=MultiPurposeLabelPagination) - def get_all(self, q: PaginationQuery = Depends(PaginationQuery), search: str | None = None): + def get_all(self, q: PaginationQuery = Depends(LabelPaginationQuery), search: str | None = None): response = self.repo.page_all( pagination=q, override=MultiPurposeLabelSummary, From 30ac446bd793f7f816dd3da500a37a3a1c148736 Mon Sep 17 00:00:00 2001 From: Seamus Lowry Date: Mon, 23 Sep 2024 20:04:24 -0400 Subject: [PATCH 2/5] sort on frontend --- frontend/pages/shopping-lists/_id.vue | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontend/pages/shopping-lists/_id.vue b/frontend/pages/shopping-lists/_id.vue index 54c4a471b8f..3c5892041be 100644 --- a/frontend/pages/shopping-lists/_id.vue +++ b/frontend/pages/shopping-lists/_id.vue @@ -793,7 +793,7 @@ export default defineComponent({ } async function refreshLabels() { - const { data } = await userApi.multiPurposeLabels.getAll(); + const { data } = await userApi.multiPurposeLabels.getAll(1, -1, {orderBy: "name", orderDirection: "asc"}); if (data) { allLabels.value = data.items ?? []; From 72a9c22003e6961996d80785356390ffe6b05e79 Mon Sep 17 00:00:00 2001 From: Seamus Lowry Date: Mon, 23 Sep 2024 20:06:12 -0400 Subject: [PATCH 3/5] Revert "feat: default to sorting by name, asc for paged label requests" This reverts commit 629f4938bb8753a68780e2f65a11e37564e75845. --- mealie/routes/groups/controller_labels.py | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/mealie/routes/groups/controller_labels.py b/mealie/routes/groups/controller_labels.py index 3b854ec2caf..fb008ef030b 100644 --- a/mealie/routes/groups/controller_labels.py +++ b/mealie/routes/groups/controller_labels.py @@ -14,17 +14,12 @@ MultiPurposeLabelUpdate, ) from mealie.schema.labels.multi_purpose_label import MultiPurposeLabelPagination -from mealie.schema.response.pagination import OrderDirection, PaginationQuery +from mealie.schema.response.pagination import PaginationQuery from mealie.services.group_services.labels_service import MultiPurposeLabelService router = APIRouter(prefix="/groups/labels", tags=["Groups: Multi Purpose Labels"], route_class=MealieCrudRoute) -class LabelPaginationQuery(PaginationQuery): - order_by: str | None = "name" - order_direction: OrderDirection = OrderDirection.asc - - @controller(router) class MultiPurposeLabelsController(BaseUserController): @cached_property @@ -46,7 +41,7 @@ def mixins(self) -> HttpRepo: return HttpRepo(self.repo, self.logger, self.registered_exceptions, self.t("generic.server-error")) @router.get("", response_model=MultiPurposeLabelPagination) - def get_all(self, q: PaginationQuery = Depends(LabelPaginationQuery), search: str | None = None): + def get_all(self, q: PaginationQuery = Depends(PaginationQuery), search: str | None = None): response = self.repo.page_all( pagination=q, override=MultiPurposeLabelSummary, From 5d3c3c9b2e7d7e49734d5fb73adf386c2e00e7b7 Mon Sep 17 00:00:00 2001 From: Seamus Lowry Date: Tue, 24 Sep 2024 08:09:32 -0400 Subject: [PATCH 4/5] use label actions --- frontend/pages/shopping-lists/_id.vue | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/frontend/pages/shopping-lists/_id.vue b/frontend/pages/shopping-lists/_id.vue index 3c5892041be..fd744621592 100644 --- a/frontend/pages/shopping-lists/_id.vue +++ b/frontend/pages/shopping-lists/_id.vue @@ -602,7 +602,7 @@ export default defineComponent({ const localLabels = ref() - const { store: allLabels } = useLabelStore(); + const { store: allLabels, actions: labelActions } = useLabelStore(); const { store: allUnits } = useUnitStore(); const { store: allFoods } = useFoodStore(); @@ -792,15 +792,7 @@ export default defineComponent({ itemsByLabel.value = itemsSorted; } - async function refreshLabels() { - const { data } = await userApi.multiPurposeLabels.getAll(1, -1, {orderBy: "name", orderDirection: "asc"}); - - if (data) { - allLabels.value = data.items ?? []; - } - } - - refreshLabels(); + labelActions.getAll() // ===================================== // Add/Remove Recipe References From ec3e41c6edce65350fef5669e5ea99d35eee5d92 Mon Sep 17 00:00:00 2001 From: Seamus Lowry Date: Tue, 24 Sep 2024 16:30:11 -0400 Subject: [PATCH 5/5] actually don't need the call at all --- frontend/pages/shopping-lists/_id.vue | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/frontend/pages/shopping-lists/_id.vue b/frontend/pages/shopping-lists/_id.vue index fd744621592..512d95aba74 100644 --- a/frontend/pages/shopping-lists/_id.vue +++ b/frontend/pages/shopping-lists/_id.vue @@ -602,7 +602,7 @@ export default defineComponent({ const localLabels = ref() - const { store: allLabels, actions: labelActions } = useLabelStore(); + const { store: allLabels } = useLabelStore(); const { store: allUnits } = useUnitStore(); const { store: allFoods } = useFoodStore(); @@ -792,8 +792,6 @@ export default defineComponent({ itemsByLabel.value = itemsSorted; } - labelActions.getAll() - // ===================================== // Add/Remove Recipe References