Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Move "on hand" and "last made" to household #4616

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
64 commits
Select commit Hold shift + click to select a range
3d7c776
add household to recipe relationship for last_made
michael-genson Nov 20, 2024
272f531
add household food/tool relationships
michael-genson Nov 20, 2024
d09e8b5
add migration
michael-genson Nov 20, 2024
2933484
rename relationship columns
michael-genson Nov 20, 2024
cfd1a78
updated food/tool models
michael-genson Nov 20, 2024
6417378
convert slugs back to relationships
michael-genson Nov 20, 2024
0dd1de1
added household recipe routes
michael-genson Nov 20, 2024
f51401e
updated recipe service set last made
michael-genson Nov 20, 2024
eab57b4
handle ordering by last made using household ordering
michael-genson Nov 20, 2024
fbd2dea
fix some import issues
michael-genson Nov 21, 2024
ce7180e
fix sqlalchemy warnings
michael-genson Nov 21, 2024
ea08778
more import issues
michael-genson Nov 21, 2024
a1b2ccf
dev:generate
michael-genson Nov 21, 2024
7d80243
fix return schema
michael-genson Nov 21, 2024
38ad4eb
remove unused onHand in recipe actions
michael-genson Nov 21, 2024
f0ad138
misc backend/schema fixes
michael-genson Nov 21, 2024
3e5b2f6
updated onHand logic in app
michael-genson Nov 21, 2024
eba94d4
use user-household last made timestamp
michael-genson Nov 22, 2024
468ab54
added migration scripts
michael-genson Nov 22, 2024
9e5dce0
fix list item sorting
michael-genson Nov 22, 2024
a483a9b
refactor and add migration to backup test
michael-genson Nov 22, 2024
9720c5d
Merge remote-tracking branch 'upstream/mealie-next' into feat/expand-…
michael-genson Nov 26, 2024
d6e1876
dev:generate (I'm so happy this works again)
michael-genson Nov 26, 2024
1628908
docs:gen
michael-genson Nov 26, 2024
155338d
better edge-case handling
michael-genson Nov 26, 2024
8129f45
added self service tests
michael-genson Nov 26, 2024
b056de8
update tests for last_made
michael-genson Nov 26, 2024
6911048
fix updating last made via task
michael-genson Nov 26, 2024
a5532f3
updated test
michael-genson Nov 26, 2024
25c3712
fix camelCase orderBy
michael-genson Nov 26, 2024
a688ec4
added order by lastMade test
michael-genson Nov 26, 2024
5318e8a
support custom columns on query
michael-genson Nov 26, 2024
1d7574c
refactor to use custom columns for rating and last made
michael-genson Nov 26, 2024
2154730
fix literal_column type and clean up namespace
michael-genson Nov 27, 2024
d08c4c5
simplify queries and move cast to repo
michael-genson Nov 27, 2024
d91a089
added tests
michael-genson Nov 27, 2024
49f71d4
made defaults less hardcoded
michael-genson Nov 27, 2024
69cfca5
lint
michael-genson Nov 27, 2024
8ffd644
added missing correlate statement for order_by
michael-genson Nov 27, 2024
fdc5d94
removed unused onHand attr
michael-genson Nov 27, 2024
598419b
removed unused onHand
michael-genson Nov 27, 2024
3855f7a
lint
michael-genson Nov 27, 2024
7aa4f11
update tests for mealplan timeline events
michael-genson Nov 27, 2024
4ad12b2
use column expressions instead of labels
michael-genson Nov 27, 2024
484573d
simplify implementation
michael-genson Nov 27, 2024
3e395fd
Merge branch 'mealie-next' into feat/expand-relationships-to-households
michael-genson Nov 27, 2024
43d5766
Merge branch 'mealie-next' into feat/expand-relationships-to-households
michael-genson Dec 2, 2024
2c60d37
Merge remote-tracking branch 'upstream/mealie-next' into feat/expand-…
michael-genson Dec 3, 2024
7848b84
modify recipe finder on_hand queries
michael-genson Dec 3, 2024
59c46d2
add/update tests
michael-genson Dec 3, 2024
5cfa638
Merge branch 'mealie-next' into feat/expand-relationships-to-households
michael-genson Dec 5, 2024
7e57759
move migration to new alembic folder
michael-genson Dec 5, 2024
95bd5c9
fix ruff lint rule
michael-genson Dec 5, 2024
ea2cff6
fix lint
michael-genson Dec 5, 2024
9390b6c
fix lint
michael-genson Dec 5, 2024
7772074
fix ruff thinking alembic is local package
michael-genson Dec 5, 2024
430c0d6
Merge remote-tracking branch 'upstream/mealie-next' into feat/expand-…
michael-genson Jan 8, 2025
a24f074
weird merge issue?
michael-genson Jan 8, 2025
673a472
Merge branch 'mealie-next' into feat/expand-relationships-to-households
Kuchenpirat Jan 13, 2025
5e419f0
Merge branch 'mealie-next' into feat/expand-relationships-to-households
michael-genson Jan 13, 2025
b67c193
Merge branch 'mealie-next' into feat/expand-relationships-to-households
michael-genson Jan 13, 2025
fa81e96
Merge remote-tracking branch 'upstream/mealie-next' into feat/expand-…
michael-genson Jan 13, 2025
dad8f7e
oops
michael-genson Jan 13, 2025
4f1b45d
Merge branch 'mealie-next' into feat/expand-relationships-to-households
Kuchenpirat Jan 13, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/docs/overrides/api.html

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,10 @@ export default defineComponent({
shoppingListShowAllToggled: false,
});

const userHousehold = computed(() => {
return $auth.user?.householdSlug || "";
});

const shoppingListChoices = computed(() => {
return props.shoppingLists.filter((list) => preferences.value.viewAllLists || list.userId === $auth.user?.id);
});
Expand Down Expand Up @@ -248,8 +252,9 @@ export default defineComponent({
}

const shoppingListIngredients: ShoppingListIngredient[] = recipe.recipeIngredient.map((ing) => {
const householdsWithFood = (ing.food?.householdsWithIngredientFood || []);
return {
checked: !ing.food?.onHand,
checked: !householdsWithFood.includes(userHousehold.value),
ingredient: ing,
disableAmount: recipe.settings?.disableAmount || false,
}
Expand All @@ -276,7 +281,8 @@ export default defineComponent({
}

// Store the on-hand ingredients for later
if (ing.ingredient.food?.onHand) {
const householdsWithFood = (ing.ingredient.food?.householdsWithIngredientFood || []);
if (householdsWithFood.includes(userHousehold.value)) {
onHandIngs.push(ing);
return sections;
}
Expand Down
35 changes: 25 additions & 10 deletions frontend/components/Domain/Recipe/RecipeLastMade.vue
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,12 @@
<v-icon left>
{{ $globals.icons.calendar }}
</v-icon>
{{ $t('recipe.last-made-date', { date: value ? new Date(value).toLocaleDateString($i18n.locale) : $t("general.never") } ) }}
<div v-if="lastMadeReady">
{{ $t('recipe.last-made-date', { date: lastMade ? new Date(lastMade).toLocaleDateString($i18n.locale) : $t("general.never") } ) }}
</div>
<div v-else>
<AppLoader tiny />
</div>
</v-chip>
</div>
<div class="d-flex justify-center flex-wrap mt-1">
Expand All @@ -110,7 +115,7 @@
</template>

<script lang="ts">
import { computed, defineComponent, reactive, ref, toRefs, useContext } from "@nuxtjs/composition-api";
import { computed, defineComponent, onMounted, reactive, ref, toRefs, useContext } from "@nuxtjs/composition-api";
import { whenever } from "@vueuse/core";
import { VForm } from "~/types/vuetify";
import { useUserApi } from "~/composables/api";
Expand All @@ -119,10 +124,6 @@ import { Recipe, RecipeTimelineEventIn } from "~/lib/api/types/recipe";

export default defineComponent({
props: {
value: {
type: String,
default: null,
},
recipe: {
type: Object as () => Recipe,
required: true,
Expand All @@ -146,6 +147,20 @@ export default defineComponent({
const newTimelineEventImagePreviewUrl = ref<string>();
const newTimelineEventTimestamp = ref<string>();

const lastMade = ref(props.recipe.lastMade);
const lastMadeReady = ref(false);
onMounted(async () => {
if (!$auth.user?.householdSlug) {
lastMade.value = props.recipe.lastMade;
} else {
const { data } = await userApi.households.getCurrentUserHouseholdRecipe(props.recipe.slug || "");
lastMade.value = data?.lastMade;
}

lastMadeReady.value = true;
});


whenever(
() => madeThisDialog.value,
() => {
Expand Down Expand Up @@ -195,11 +210,9 @@ export default defineComponent({
const newEvent = eventResponse.data;

// we also update the recipe's last made value
if (!props.value || newTimelineEvent.value.timestamp > props.value) {
if (!lastMade.value || newTimelineEvent.value.timestamp > lastMade.value) {
lastMade.value = newTimelineEvent.value.timestamp;
await userApi.recipes.updateLastMade(props.recipe.slug, newTimelineEvent.value.timestamp);

// update recipe in parent so the user can see it
context.emit("input", newTimelineEvent.value.timestamp);
}

// update the image, if provided
Expand Down Expand Up @@ -234,6 +247,8 @@ export default defineComponent({
newTimelineEventImage,
newTimelineEventImagePreviewUrl,
newTimelineEventTimestamp,
lastMade,
lastMadeReady,
createTimelineEvent,
clearImage,
uploadImage,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
<v-col cols="12" class="d-flex flex-wrap justify-center">
<RecipeLastMade
v-if="isOwnGroup"
:value="recipe.lastMade"
:recipe="recipe"
:class="true ? undefined : 'force-bottom'"
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<h2 class="mb-2 mt-4">{{ $t('tool.required-tools') }}</h2>
<v-list-item v-for="(tool, index) in recipe.tools" :key="index" dense>
<v-checkbox
v-model="recipe.tools[index].onHand"
v-model="recipeTools[index].onHand"
hide-details
class="pt-0 my-auto py-auto"
color="secondary"
Expand All @@ -26,14 +26,18 @@
</template>

<script lang="ts">
import { defineComponent } from "@nuxtjs/composition-api";
import { computed, defineComponent } from "@nuxtjs/composition-api";
import { useLoggedInState } from "~/composables/use-logged-in-state";
import { usePageState, usePageUser } from "~/composables/recipe-page/shared-state";
import { useToolStore } from "~/composables/store";
import { NoUndefinedField } from "~/lib/api/types/non-generated";
import { Recipe } from "~/lib/api/types/recipe";
import { Recipe, RecipeTool } from "~/lib/api/types/recipe";
import RecipeIngredients from "~/components/Domain/Recipe/RecipeIngredients.vue";

interface RecipeToolWithOnHand extends RecipeTool {
onHand: boolean;
}

export default defineComponent({
components: {
RecipeIngredients,
Expand All @@ -59,16 +63,39 @@ export default defineComponent({
const { user } = usePageUser();
const { isEditMode } = usePageState(props.recipe.slug);

const recipeTools = computed(() => {
if (!(user.householdSlug && toolStore)) {
return props.recipe.tools.map((tool) => ({ ...tool, onHand: false }) as RecipeToolWithOnHand);
} else {
return props.recipe.tools.map((tool) => {
const onHand = tool.householdsWithTool?.includes(user.householdSlug) || false;
return { ...tool, onHand } as RecipeToolWithOnHand;
});
}
})

function updateTool(index: number) {
if (user.id && toolStore) {
toolStore.actions.updateOne(props.recipe.tools[index]);
if (user.id && user.householdSlug && toolStore) {
const tool = recipeTools.value[index];
if (tool.onHand && !tool.householdsWithTool?.includes(user.householdSlug)) {
if (!tool.householdsWithTool) {
tool.householdsWithTool = [user.householdSlug];
} else {
tool.householdsWithTool.push(user.householdSlug);
}
} else if (!tool.onHand && tool.householdsWithTool?.includes(user.householdSlug)) {
tool.householdsWithTool = tool.householdsWithTool.filter((household) => household !== user.householdSlug);
}

toolStore.actions.updateOne(tool);
} else {
console.log("no user, skipping server update");
}
}

return {
toolStore,
recipeTools,
isEditMode,
updateTool,
};
Expand Down
15 changes: 13 additions & 2 deletions frontend/components/global/AppLoader.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@
</v-icon>
<div v-if="large" class="text-small">
<slot>
{{ small ? "" : waitingText }}
{{ (small || tiny) ? "" : waitingText }}
</slot>
</div>
</div>
</v-progress-circular>
<div v-if="!large" class="text-small">
<slot>
{{ small ? "" : waitingTextCalculated }}
{{ (small || tiny) ? "" : waitingTextCalculated }}
</slot>
</div>
</div>
Expand All @@ -31,6 +31,10 @@ export default defineComponent({
type: Boolean,
default: true,
},
tiny: {
type: Boolean,
default: false,
},
small: {
type: Boolean,
default: false,
Expand All @@ -50,6 +54,13 @@ export default defineComponent({
},
setup(props) {
const size = computed(() => {
if (props.tiny) {
return {
width: 2,
icon: 0,
size: 25,
};
}
if (props.small) {
return {
width: 2,
Expand Down
1 change: 0 additions & 1 deletion frontend/composables/recipes/use-recipe-tools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ export const useTools = function (eager = true) {
id: "",
name: "",
slug: "",
onHand: false,
});

const api = useUserApi();
Expand Down
1 change: 0 additions & 1 deletion frontend/composables/store/use-food-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ export const useFoodData = function () {
name: "",
description: "",
labelId: undefined,
onHand: false,
});
}

Expand Down
7 changes: 6 additions & 1 deletion frontend/composables/store/use-tool-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,21 @@ import { useData, useReadOnlyStore, useStore } from "../partials/use-store-facto
import { RecipeTool } from "~/lib/api/types/recipe";
import { usePublicExploreApi, useUserApi } from "~/composables/api";

interface RecipeToolWithOnHand extends RecipeTool {
onHand: boolean;
}

const store: Ref<RecipeTool[]> = ref([]);
const loading = ref(false);
const publicLoading = ref(false);

export const useToolData = function () {
return useData<RecipeTool>({
return useData<RecipeToolWithOnHand>({
id: "",
name: "",
slug: "",
onHand: false,
householdsWithTool: [],
});
}

Expand Down
2 changes: 1 addition & 1 deletion frontend/lib/api/types/admin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ export interface RecipeTool {
id: string;
name: string;
slug: string;
onHand?: boolean;
householdsWithTool?: string[];
[k: string]: unknown;
}
export interface CustomPageImport {
Expand Down
2 changes: 1 addition & 1 deletion frontend/lib/api/types/cookbook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ export interface RecipeTool {
id: string;
name: string;
slug: string;
onHand?: boolean;
householdsWithTool?: string[];
[k: string]: unknown;
}
export interface SaveCookBook {
Expand Down
29 changes: 24 additions & 5 deletions frontend/lib/api/types/household.ts
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,27 @@ export interface ReadWebhook {
householdId: string;
id: string;
}
export interface HouseholdRecipeBase {
lastMade?: string | null;
}
export interface HouseholdRecipeCreate {
lastMade?: string | null;
householdId: string;
recipeId: string;
}
export interface HouseholdRecipeOut {
lastMade?: string | null;
householdId: string;
recipeId: string;
id: string;
}
export interface HouseholdRecipeSummary {
lastMade?: string | null;
recipeId: string;
}
export interface HouseholdRecipeUpdate {
lastMade?: string | null;
}
export interface HouseholdSave {
groupId: string;
name: string;
Expand Down Expand Up @@ -297,7 +318,6 @@ export interface IngredientUnit {
extras?: {
[k: string]: unknown;
} | null;
onHand?: boolean;
fraction?: boolean;
abbreviation?: string;
pluralAbbreviation?: string | null;
Expand All @@ -318,7 +338,6 @@ export interface CreateIngredientUnit {
extras?: {
[k: string]: unknown;
} | null;
onHand?: boolean;
fraction?: boolean;
abbreviation?: string;
pluralAbbreviation?: string | null;
Expand All @@ -338,9 +357,9 @@ export interface IngredientFood {
extras?: {
[k: string]: unknown;
} | null;
onHand?: boolean;
labelId?: string | null;
aliases?: IngredientFoodAlias[];
householdsWithIngredientFood?: string[];
label?: MultiPurposeLabelSummary | null;
createdAt?: string | null;
updatedAt?: string | null;
Expand All @@ -363,9 +382,9 @@ export interface CreateIngredientFood {
extras?: {
[k: string]: unknown;
} | null;
onHand?: boolean;
labelId?: string | null;
aliases?: CreateIngredientFoodAlias[];
householdsWithIngredientFood?: string[];
[k: string]: unknown;
}
export interface CreateIngredientFoodAlias {
Expand Down Expand Up @@ -592,7 +611,7 @@ export interface RecipeTool {
id: string;
name: string;
slug: string;
onHand?: boolean;
householdsWithTool?: string[];
[k: string]: unknown;
}
export interface ShoppingListRemoveRecipeParams {
Expand Down
2 changes: 1 addition & 1 deletion frontend/lib/api/types/meal-plan.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ export interface RecipeTool {
id: string;
name: string;
slug: string;
onHand?: boolean;
householdsWithTool?: string[];
[k: string]: unknown;
}
export interface SavePlanEntry {
Expand Down
Loading
Loading