From b93dae109e3dd850a23f6677313c3d9f294c4cd6 Mon Sep 17 00:00:00 2001 From: Hayden <64056131+hay-kot@users.noreply.github.com> Date: Sat, 9 Apr 2022 19:08:48 -0800 Subject: [PATCH] feat: merge food into another (#1143) * setup food repository * add merge route and payloads * remove type checking * generate types * implement merge dialog * food repo tests * split install from workflow * bum dependencies * revert changes * update copy * refactor URLs to avoid incorrect template being used * stick advanced items under developer mode * use utility component for advanced feature --- .github/workflows/backend-tests.yml | 2 +- .vscode/settings.json | 34 +---- .../getting-started/migrating-to-mealie-v1.md | 2 +- frontend/api/class-interfaces/recipe-foods.ts | 6 + frontend/components/global/ReportTable.vue | 5 +- frontend/layouts/admin.vue | 18 ++- frontend/pages/admin/backups.vue | 2 +- frontend/pages/group/data/foods.vue | 47 ++++++- .../pages/group/{data => }/migrations.vue | 0 .../pages/group/{data => }/reports/_id.vue | 0 frontend/pages/recipe/create.vue | 2 +- frontend/pages/user/profile/index.vue | 109 ++++++++------- frontend/types/api-types/recipe.ts | 4 + frontend/types/components.d.ts | 132 +++++++++--------- mealie/repos/repository_factory.py | 5 +- mealie/repos/repository_foods.py | 32 +++++ mealie/routes/unit_and_foods/foods.py | 19 ++- mealie/schema/recipe/recipe_ingredient.py | 5 + poetry.lock | 18 +-- pyproject.toml | 4 +- .../repository_tests/test_food_repository.py | 48 +++++++ 21 files changed, 319 insertions(+), 175 deletions(-) rename frontend/pages/group/{data => }/migrations.vue (100%) rename frontend/pages/group/{data => }/reports/_id.vue (100%) create mode 100644 mealie/repos/repository_foods.py create mode 100644 tests/unit_tests/repository_tests/test_food_repository.py diff --git a/.github/workflows/backend-tests.yml b/.github/workflows/backend-tests.yml index fdbde127087c..b3527fbdfd96 100644 --- a/.github/workflows/backend-tests.yml +++ b/.github/workflows/backend-tests.yml @@ -32,7 +32,6 @@ jobs: options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5 ports: - 5432:5432 - # Steps steps: #---------------------------------------------- @@ -70,6 +69,7 @@ jobs: poetry install poetry add "psycopg2-binary==2.8.6" if: steps.cached-poetry-dependencies.outputs.cache-hit != 'true' + #---------------------------------------------- # run test suite #---------------------------------------------- diff --git a/.vscode/settings.json b/.vscode/settings.json index dd7015aad437..a8937982d9fc 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -5,11 +5,7 @@ "backend", "code-generation" ], - "cSpell.enableFiletypes": [ - "!javascript", - "!python", - "!yaml" - ], + "cSpell.enableFiletypes": ["!javascript", "!python", "!yaml"], "cSpell.words": [ "chowdown", "compression", @@ -24,9 +20,7 @@ "source.organizeImports": false }, "editor.formatOnSave": true, - "eslint.workingDirectories": [ - "./frontend" - ], + "eslint.workingDirectories": ["./frontend"], "files.exclude": { "**/__pycache__": true, "**/.DS_Store": true, @@ -35,9 +29,7 @@ "**/.svn": true, "**/CVS": true }, - "i18n-ally.enabledFrameworks": [ - "vue" - ], + "i18n-ally.enabledFrameworks": ["vue"], "i18n-ally.keystyle": "nested", "i18n-ally.localesPaths": "frontend/lang/messages", "i18n-ally.sourceLanguage": "en-US", @@ -45,26 +37,14 @@ "python.linting.enabled": true, "python.linting.flake8Enabled": true, "python.linting.pylintEnabled": false, - "python.linting.pylintArgs": [ - "--rcfile=${workspaceFolder}/.pylintrc" - ], + "python.linting.pylintArgs": ["--rcfile=${workspaceFolder}/.pylintrc"], "python.testing.autoTestDiscoverOnSaveEnabled": false, - "python.testing.pytestArgs": [ - "tests" - ], + "python.testing.pytestArgs": ["tests"], "python.testing.pytestEnabled": true, "python.testing.unittestEnabled": false, - "python.analysis.typeCheckingMode": "basic", + "python.analysis.typeCheckingMode": "off", "python.linting.mypyEnabled": true, "python.sortImports.path": "${workspaceFolder}/.venv/bin/isort", "search.mode": "reuseEditor", - "vetur.validation.template": false, - "coverage-gutters.lcovname": "${workspaceFolder}/.coverage", - "python.testing.unittestArgs": [ - "-v", - "-s", - "./tests", - "-p", - "test_*.py" - ] + "python.testing.unittestArgs": ["-v", "-s", "./tests", "-p", "test_*.py"] } diff --git a/docs/docs/documentation/getting-started/migrating-to-mealie-v1.md b/docs/docs/documentation/getting-started/migrating-to-mealie-v1.md index 76186024a0ab..675b03a732e6 100644 --- a/docs/docs/documentation/getting-started/migrating-to-mealie-v1.md +++ b/docs/docs/documentation/getting-started/migrating-to-mealie-v1.md @@ -24,7 +24,7 @@ In your instance of Mealie prior to v1, perform an export of your data in the Ad ## Step 3: Using the Migration Tool -In your new v1 instance, navigate to `/group/data/migrations` and select "Mealie" from the dropdown selector. Upload the exported data from your pre-v1 instance. Optionally, you can tag all the recipes you've imported with the `mealie_alpha` tag to help you identify them. Once the upload has finished, submit the form and your migration will begin. This may take some time, but when it's complete you'll be provided a new entry in hte "Previous Migrations" table below. Be sure to review the migration report to make sure everything was successful. There may be instances where some of the recipes were not imported, but the migration will still import all the successful recipes. +In your new v1 instance, navigate to `/group/migrations` and select "Mealie" from the dropdown selector. Upload the exported data from your pre-v1 instance. Optionally, you can tag all the recipes you've imported with the `mealie_alpha` tag to help you identify them. Once the upload has finished, submit the form and your migration will begin. This may take some time, but when it's complete you'll be provided a new entry in hte "Previous Migrations" table below. Be sure to review the migration report to make sure everything was successful. There may be instances where some of the recipes were not imported, but the migration will still import all the successful recipes. In most cases, it's faster to manually migrate the recipes that didn't take instead of trying to identify why the recipes failed to import. If you're experiencing issues with the migration tool, please open an issue on GitHub. diff --git a/frontend/api/class-interfaces/recipe-foods.ts b/frontend/api/class-interfaces/recipe-foods.ts index 293815c5b55e..12b4b91169e4 100644 --- a/frontend/api/class-interfaces/recipe-foods.ts +++ b/frontend/api/class-interfaces/recipe-foods.ts @@ -6,9 +6,15 @@ const prefix = "/api"; const routes = { food: `${prefix}/foods`, foodsFood: (tag: string) => `${prefix}/foods/${tag}`, + merge: `${prefix}/foods/merge`, }; export class FoodAPI extends BaseCRUDAPI { baseRoute: string = routes.food; itemRoute = routes.foodsFood; + + merge(fromId: string, toId: string) { + // @ts-ignore TODO: fix this + return this.requests.put(routes.merge, { fromFood: fromId, toFood: toId }); + } } diff --git a/frontend/components/global/ReportTable.vue b/frontend/components/global/ReportTable.vue index 2a352ccd74ac..117f5de38dce 100644 --- a/frontend/components/global/ReportTable.vue +++ b/frontend/components/global/ReportTable.vue @@ -48,7 +48,7 @@ export default defineComponent({ ]; function handleRowClick(item: ReportSummary) { - router.push("/group/data/reports/" + item.id); + router.push("/group/reports/" + item.id); } function capitalize(str: string) { @@ -69,5 +69,4 @@ export default defineComponent({ }); - + diff --git a/frontend/layouts/admin.vue b/frontend/layouts/admin.vue index 11a7dce406bb..5831ae2bcdac 100644 --- a/frontend/layouts/admin.vue +++ b/frontend/layouts/admin.vue @@ -6,7 +6,8 @@ :top-link="topLinks" :bottom-links="bottomLinks" :user="{ data: true }" - :secondary-header="$t('user.admin')" + secondary-header="Developer" + :secondary-links="developerLinks" /> @@ -49,11 +50,7 @@ export default defineComponent({ to: "/admin/site-settings", title: i18n.t("sidebar.site-settings"), }, - { - icon: $globals.icons.wrench, - to: "/admin/maintenance", - title: "Maintenance", - }, + // { // icon: $globals.icons.chart, // to: "/admin/analytics", @@ -74,6 +71,14 @@ export default defineComponent({ to: "/admin/backups", title: i18n.t("sidebar.backups"), }, + ]; + + const developerLinks: SidebarLinks = [ + { + icon: $globals.icons.wrench, + to: "/admin/maintenance", + title: "Maintenance", + }, { icon: $globals.icons.check, to: "/admin/background-tasks", @@ -98,6 +103,7 @@ export default defineComponent({ sidebar, topLinks, bottomLinks, + developerLinks, }; }, }); diff --git a/frontend/pages/admin/backups.vue b/frontend/pages/admin/backups.vue index 00aca6fae508..77464b07461e 100644 --- a/frontend/pages/admin/backups.vue +++ b/frontend/pages/admin/backups.vue @@ -97,7 +97,7 @@ - Looking For Migrations? + Looking For Migrations? diff --git a/frontend/pages/group/data/foods.vue b/frontend/pages/group/data/foods.vue index 0c83f5dc1ae5..b7fb8588e1fc 100644 --- a/frontend/pages/group/data/foods.vue +++ b/frontend/pages/group/data/foods.vue @@ -1,5 +1,20 @@