feat: bulk recipe settings update (#1557)

* extract switches from menu component

* implement bulk updater for settings

* fix browser cache api calls issue

* add frontend for bulk settings modifications
This commit is contained in:
Hayden
2022-08-14 10:37:44 -08:00
committed by GitHub
parent 5cfff75dbe
commit 7adcc86d03
10 changed files with 168 additions and 66 deletions

View File

@@ -1,3 +1,4 @@
import contextlib
import json
from collections.abc import Callable
from enum import Enum
@@ -31,16 +32,15 @@ class MealieCrudRoute(APIRoute):
original_route_handler = super().get_route_handler()
async def custom_route_handler(request: Request) -> Response:
try:
with contextlib.suppress(JSONDecodeError):
response = await original_route_handler(request)
response_body = json.loads(response.body)
if type(response_body) == dict:
if last_modified := response_body.get("updateAt"):
response.headers["last-modified"] = last_modified
except JSONDecodeError:
pass
# Force no-cache for all responses to prevent browser from caching API calls
response.headers["Cache-Control"] = "no-cache, no-store, must-revalidate"
return response
return custom_route_handler

View File

@@ -7,7 +7,13 @@ from mealie.core.dependencies.dependencies import temporary_zip_path
from mealie.core.security import create_file_token
from mealie.routes._base import BaseUserController, controller
from mealie.schema.group.group_exports import GroupDataExport
from mealie.schema.recipe.recipe_bulk_actions import AssignCategories, AssignTags, DeleteRecipes, ExportRecipes
from mealie.schema.recipe.recipe_bulk_actions import (
AssignCategories,
AssignSettings,
AssignTags,
DeleteRecipes,
ExportRecipes,
)
from mealie.schema.response.responses import SuccessResponse
from mealie.services.recipe.recipe_bulk_service import RecipeBulkActionsService
@@ -25,6 +31,10 @@ class RecipeBulkActionsController(BaseUserController):
def bulk_tag_recipes(self, tag_data: AssignTags):
self.service.assign_tags(tag_data.recipes, tag_data.tags)
@router.post("/settings")
def bulk_settings_recipes(self, settings_data: AssignSettings):
self.service.set_settings(settings_data.recipes, settings_data.settings)
@router.post("/categorize")
def bulk_categorize_recipes(self, assign_cats: AssignCategories):
self.service.assign_categories(assign_cats.recipes, assign_cats.categories)