diff --git a/docs/docs/documentation/getting-started/api-usage.md b/docs/docs/documentation/getting-started/api-usage.md index a85eb2df6..cc7b1449e 100644 --- a/docs/docs/documentation/getting-started/api-usage.md +++ b/docs/docs/documentation/getting-started/api-usage.md @@ -9,6 +9,38 @@ Mealie supports long-live api tokens in the user frontend. These can be created ### Exploring Your Local API On your local installation you can access interactive API documentation that provides `curl` examples and expected results. This allows you to easily test and interact with your API to identify places to include your own functionality. You can visit the documentation at `http:///docs` or see the example at the [Demo Site](https://demo.mealie.io/docs). +### Meal Plan Ordering + +Meal plan entries have a `position` that determines their order within a day, starting at zero. By default, `GET /api/households/mealplans` returns entries ordered by date and then position. Without ordering parameters, both are sorted ascending. + +You can pass `orderDirection=desc` to reverse this order, or use `orderBy` and the other [advanced ordering](#advanced-ordering) parameters to choose your own sort. These parameters only change the order of the results, they do not change the saved positions. + +To reorder your household's entries or move them between days or weeks, use `PUT /api/households/mealplans/reorder`. Each request item identifies a bucket by its `date` and, for a week entry, its `endDate`. Omit `endDate` or set it to `null` for a day bucket. A week entry's `endDate` is six days after its `date`. The IDs in each item are meal plan entry IDs in the desired order. For example: + +```json +[ + {"date": "2026-10-20", "entryIds": [103, 101]}, + {"date": "2026-10-21", "entryIds": [102, 104]} +] +``` + +If October 20 contains entries `101`, `102`, and `103`, and October 21 contains `104`, this moves entry `102` to October 21 and places `103` before `101` on October 20. These are meal plan entry IDs, not recipe IDs. Dates outside the request are left unchanged. + +To move an entry between a day and a week bucket, include both buckets. For example, to move entry `105` from the day list to the week list starting October 20: + +```json +[ + {"date": "2026-10-20", "entryIds": []}, + {"date": "2026-10-20", "endDate": "2026-10-26", "entryIds": [105]} +] +``` + +Include every entry currently in each bucket you submit, including an empty ID list when clearing a bucket. Buckets are identified by date and whether they are day or week entries. + +Successful requests return `204 No Content`. An empty request, repeated buckets, or repeated IDs returns `422`. If the IDs do not match the entries currently in the submitted buckets, the API returns `409`. Fetch the affected buckets again before retrying. + +New meal entries are placed after the last entry of the same meal type. If there are none, Mealie uses the meal type order: breakfast, lunch, dinner, side, snack, drink, dessert. This also applies when changing an entry's date through the regular update endpoint. Existing entries keep their relative order. + ### Extras #### Recipe Extras Recipes extras are a key feature of the Mealie API. They allow you to create custom json key/value pairs within a recipe to reference from 3rd part applications. You can use these keys to contain information to trigger automation or custom messages to relay to your desired device. diff --git a/docs/docs/documentation/getting-started/features.md b/docs/docs/documentation/getting-started/features.md index 534e7afb6..6811c57a1 100644 --- a/docs/docs/documentation/getting-started/features.md +++ b/docs/docs/documentation/getting-started/features.md @@ -82,6 +82,10 @@ Mealie also has the concept of cookbooks. These can be created inside of a group Mealie uses a calendar like view to help you plan your meals. It shows you the previous day and the next 6 days by default. You can toggle through the calendar by clicking the arrows on the top of the page. In editor mode, you can use the random recipe buttons or manually add an entry. +In edit mode, drag entries to reorder them within a day or move them to another day. Your order is saved and also shown in the planner's view mode. Newly added entries are placed after the last entry of the same meal type, without rearranging existing entries. + +Integrations can also [reorder meal plan entries through the API](api-usage.md#meal-plan-ordering). + !!! tip You can also add a "Note" type entry to your meal plan when you want to include something that might not have a specific recipes. This is great for leftovers, or for ordering out. diff --git a/frontend/app/components/Domain/Mealplan/MealPlanLayout.test.ts b/frontend/app/components/Domain/Mealplan/MealPlanLayout.test.ts new file mode 100644 index 000000000..968a53449 --- /dev/null +++ b/frontend/app/components/Domain/Mealplan/MealPlanLayout.test.ts @@ -0,0 +1,33 @@ +import { mount } from "@vue/test-utils"; +import { describe, expect, it } from "vitest"; +import MealPlanLayout from "./MealPlanLayout.vue"; +import type { Days } from "~/composables/use-group-mealplan"; +import type { ReadPlanEntry } from "~/lib/api/types/meal-plan"; + +describe("MealPlanLayout", () => { + it.each([ + { types: [], sizes: [] }, + { types: ["breakfast", "breakfast", "lunch", "dinner"], sizes: [2, 1, 1] }, + { types: ["dinner", "breakfast", "dinner", "lunch"], sizes: [1, 1, 1, 1] }, + ])("preserves saved order and groups adjacent types: $types", ({ types, sizes }) => { + const meals = types.map((entryType, id) => ({ id, entryType }) as ReadPlanEntry); + let day: Days | undefined; + mount(MealPlanLayout, { + props: { mealplans: [{ date: new Date(2026, 9, 15), meals }] }, + global: { + stubs: { + "v-row": { template: "
" }, + "v-col": { template: "
" }, + }, + }, + slots: { + default: (props: { day: Days }) => { + day = props.day; + return ""; + }, + }, + }); + expect(day!.sections.flatMap(section => section.meals)).toEqual(meals); + expect(day!.sections.map(section => section.meals.length)).toEqual(sizes); + }); +}); diff --git a/frontend/app/components/Domain/Mealplan/MealPlanLayout.vue b/frontend/app/components/Domain/Mealplan/MealPlanLayout.vue index cbfc2eb23..246ad96cb 100644 --- a/frontend/app/components/Domain/Mealplan/MealPlanLayout.vue +++ b/frontend/app/components/Domain/Mealplan/MealPlanLayout.vue @@ -14,24 +14,34 @@