forked from mealie-recipes/mealie
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add Household Filter to Meal Plan Rules (mealie-recipes#4231)
- Loading branch information
1 parent
6fce4a6
commit b74ef08
Showing
13 changed files
with
533 additions
and
87 deletions.
There are no files selected for viewing
53 changes: 53 additions & 0 deletions
53
alembic/versions/2024-09-18-14.52.55_1fe4bd37ccc8_add_households_filter_to_meal_plans.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
"""add households filter to meal plans | ||
Revision ID: 1fe4bd37ccc8 | ||
Revises: be568e39ffdf | ||
Create Date: 2024-09-18 14:52:55.831540 | ||
""" | ||
|
||
import sqlalchemy as sa | ||
|
||
import mealie.db.migration_types | ||
from alembic import op | ||
|
||
# revision identifiers, used by Alembic. | ||
revision = "1fe4bd37ccc8" | ||
down_revision: str | None = "be568e39ffdf" | ||
branch_labels: str | tuple[str, ...] | None = None | ||
depends_on: str | tuple[str, ...] | None = None | ||
|
||
|
||
def upgrade(): | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
op.create_table( | ||
"plan_rules_to_households", | ||
sa.Column("group_plan_rule_id", mealie.db.migration_types.GUID(), nullable=True), | ||
sa.Column("household_id", mealie.db.migration_types.GUID(), nullable=True), | ||
sa.ForeignKeyConstraint( | ||
["group_plan_rule_id"], | ||
["group_meal_plan_rules.id"], | ||
), | ||
sa.ForeignKeyConstraint( | ||
["household_id"], | ||
["households.id"], | ||
), | ||
sa.UniqueConstraint("group_plan_rule_id", "household_id", name="group_plan_rule_id_household_id_key"), | ||
) | ||
with op.batch_alter_table("plan_rules_to_households", schema=None) as batch_op: | ||
batch_op.create_index( | ||
batch_op.f("ix_plan_rules_to_households_group_plan_rule_id"), ["group_plan_rule_id"], unique=False | ||
) | ||
batch_op.create_index(batch_op.f("ix_plan_rules_to_households_household_id"), ["household_id"], unique=False) | ||
|
||
# ### end Alembic commands ### | ||
|
||
|
||
def downgrade(): | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
with op.batch_alter_table("plan_rules_to_households", schema=None) as batch_op: | ||
batch_op.drop_index(batch_op.f("ix_plan_rules_to_households_household_id")) | ||
batch_op.drop_index(batch_op.f("ix_plan_rules_to_households_group_plan_rule_id")) | ||
|
||
op.drop_table("plan_rules_to_households") | ||
# ### end Alembic commands ### |
91 changes: 91 additions & 0 deletions
91
frontend/components/Domain/Household/GroupHouseholdSelector.vue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
<template> | ||
<v-select | ||
v-model="selected" | ||
:items="households" | ||
:label="label" | ||
:hint="description" | ||
:persistent-hint="!!description" | ||
item-text="name" | ||
:multiple="multiselect" | ||
:prepend-inner-icon="$globals.icons.household" | ||
return-object | ||
> | ||
<template #selection="data"> | ||
<v-chip | ||
:key="data.index" | ||
class="ma-1" | ||
:input-value="data.selected" | ||
small | ||
close | ||
label | ||
color="accent" | ||
dark | ||
@click:close="removeByIndex(data.index)" | ||
> | ||
{{ data.item.name || data.item }} | ||
</v-chip> | ||
</template> | ||
</v-select> | ||
</template> | ||
|
||
<script lang="ts"> | ||
import { computed, defineComponent, onMounted, useContext } from "@nuxtjs/composition-api"; | ||
import { useHouseholdStore } from "~/composables/store/use-household-store"; | ||
interface HouseholdLike { | ||
id: string; | ||
name: string; | ||
} | ||
export default defineComponent({ | ||
props: { | ||
value: { | ||
type: Array as () => HouseholdLike[], | ||
required: true, | ||
}, | ||
multiselect: { | ||
type: Boolean, | ||
default: false, | ||
}, | ||
description: { | ||
type: String, | ||
default: "", | ||
}, | ||
}, | ||
setup(props, context) { | ||
const selected = computed({ | ||
get: () => props.value, | ||
set: (val) => { | ||
context.emit("input", val); | ||
}, | ||
}); | ||
onMounted(() => { | ||
if (selected.value === undefined) { | ||
selected.value = []; | ||
} | ||
}); | ||
const { i18n } = useContext(); | ||
const label = computed( | ||
() => props.multiselect ? i18n.tc("household.households") : i18n.tc("household.household") | ||
); | ||
const { store: households } = useHouseholdStore(); | ||
function removeByIndex(index: number) { | ||
if (selected.value === undefined) { | ||
return; | ||
} | ||
const newSelected = selected.value.filter((_, i) => i !== index); | ||
selected.value = [...newSelected]; | ||
} | ||
return { | ||
selected, | ||
label, | ||
households, | ||
removeByIndex, | ||
}; | ||
}, | ||
}); | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.