From c81fa9d8a96c45669c5ab3c04ec3825639bdd4a4 Mon Sep 17 00:00:00 2001 From: hay-kot Date: Mon, 8 Feb 2021 20:22:13 -0900 Subject: [PATCH] unified notifications --- frontend/src/App.vue | 35 ++++++++++++++++--- frontend/src/api/api-utils.js | 12 ++----- frontend/src/api/themes.js | 11 +++--- .../src/components/Recipe/RecipeViewer.vue | 6 ---- frontend/src/plugins/vuetify.js | 2 ++ frontend/src/utils.js | 33 +++++++++++++++++ mealie/routes/backup_routes.py | 2 +- mealie/routes/meal_routes.py | 4 +-- mealie/routes/migration_routes.py | 2 +- mealie/routes/recipe/category_routes.py | 4 +++ mealie/routes/recipe/recipe_crud_routes.py | 2 +- mealie/routes/recipe/tag_routes.py | 4 +++ mealie/routes/theme_routes.py | 22 ++---------- mealie/utils/snackbar.py | 12 ------- 14 files changed, 89 insertions(+), 62 deletions(-) diff --git a/frontend/src/App.vue b/frontend/src/App.vue index 2b32f1787..ffd80d668 100644 --- a/frontend/src/App.vue +++ b/frontend/src/App.vue @@ -63,11 +63,6 @@ export default { this.$store.dispatch("initLang"); this.darkModeSystemCheck(); this.darkModeAddEventListener(); - - this.flashMessage.success({ - title: "Success Message Title", - message: "Hoorah, it is my fist npm package and it works!", - }); }, data: () => ({ @@ -100,4 +95,34 @@ export default { diff --git a/frontend/src/api/api-utils.js b/frontend/src/api/api-utils.js index 20c23f9d2..852a0d521 100644 --- a/frontend/src/api/api-utils.js +++ b/frontend/src/api/api-utils.js @@ -1,20 +1,14 @@ const baseURL = "/api/"; import axios from "axios"; -import { vueApp } from "../main"; - +import utils from "../utils"; // look for data.snackbar in response function processResponse(response) { try { - vueApp.flashMessage.show({ - status: response.data.snackbar.type, - title: 'Error Message Title', - message: response.data.snackbar.text - }); + utils.notify.show(response.data.snackbar.text, response.data.snackbar.type); } catch (err) { return; } - return; } @@ -37,7 +31,7 @@ const apiReq = { return response; } else return; }); - // processResponse(response); + processResponse(response); return response; }, diff --git a/frontend/src/api/themes.js b/frontend/src/api/themes.js index 01c3b38a3..6ff7a85ee 100644 --- a/frontend/src/api/themes.js +++ b/frontend/src/api/themes.js @@ -1,14 +1,14 @@ import { baseURL } from "./api-utils"; import { apiReq } from "./api-utils"; -const prefix = baseURL + "themes/"; +const prefix = baseURL + "themes"; const settingsURLs = { allThemes: `${baseURL}themes`, - specificTheme: themeName => `${prefix}${themeName}`, - createTheme: `${prefix}create`, - updateTheme: themeName => `${prefix}${themeName}`, - deleteTheme: themeName => `${prefix}${themeName}`, + specificTheme: themeName => `${prefix}/${themeName}`, + createTheme: `${prefix}/create`, + updateTheme: themeName => `${prefix}/${themeName}`, + deleteTheme: themeName => `${prefix}/${themeName}`, }; export default { @@ -33,6 +33,7 @@ export default { colors: colors, }; let response = await apiReq.put(settingsURLs.updateTheme(themeName), body); + console.log(response.data); return response.data; }, diff --git a/frontend/src/components/Recipe/RecipeViewer.vue b/frontend/src/components/Recipe/RecipeViewer.vue index e7a0094fd..3fbc04646 100644 --- a/frontend/src/components/Recipe/RecipeViewer.vue +++ b/frontend/src/components/Recipe/RecipeViewer.vue @@ -158,12 +158,6 @@ export default { disabledSteps: [], }; }, - mounted() { - this.flashMessage.success({ - title: "Success Message Recipe", - message: "Hoorah, it is my fist npm package and it works!", - }); - }, methods: { toggleDisabled(stepIndex) { if (this.disabledSteps.includes(stepIndex)) { diff --git a/frontend/src/plugins/vuetify.js b/frontend/src/plugins/vuetify.js index 58c516363..e86b91143 100644 --- a/frontend/src/plugins/vuetify.js +++ b/frontend/src/plugins/vuetify.js @@ -6,6 +6,8 @@ Vue.use(Vuetify); const vuetify = new Vuetify({ theme: { dark: false, + options: { customProperties: true }, + themes: { light: { primary: "#E58325", diff --git a/frontend/src/utils.js b/frontend/src/utils.js index f2038b6c6..fba99dc50 100644 --- a/frontend/src/utils.js +++ b/frontend/src/utils.js @@ -1,6 +1,15 @@ // import utils from "../../utils"; // import Vue from "vue"; // import Vuetify from "./plugins/vuetify"; +import { vueApp } from "./main"; + +const notifyHelpers = { + baseCSS: "notify-base", + error: "notify-error-color", + warning: "notify-warning-color", + success: "notify-success-color", + info: "notify-info-color", +}; const days = [ "Sunday", @@ -72,4 +81,28 @@ export default { return `${year}-${month}-${day}`; }, + notify: { + show: function(text, type = "info", title = null) { + vueApp.flashMessage.show({ + status: type, + title: title, + message: text, + time: 3000, + blockClass: `${notifyHelpers.baseCSS} ${notifyHelpers[type]}`, + contentClass: `${notifyHelpers.baseCSS} ${notifyHelpers[type]}`, + }); + }, + info: function(text, title = null) { + this.show(text, "info", title); + }, + success: function(text, title = null) { + this.show(text, "success", title); + }, + error: function(text, title = null) { + this.show(text, "error", title); + }, + warning: function(text, title = null) { + this.show(text, "warning", title); + }, + }, }; diff --git a/mealie/routes/backup_routes.py b/mealie/routes/backup_routes.py index 229d4c60a..24edf1103 100644 --- a/mealie/routes/backup_routes.py +++ b/mealie/routes/backup_routes.py @@ -110,4 +110,4 @@ def delete_backup(file_name: str): detail=SnackResponse.error("Unable to Delete Backup. See Log File"), ) - return SnackResponse.success(f"{file_name} Deleted") + return SnackResponse.error(f"{file_name} Deleted") diff --git a/mealie/routes/meal_routes.py b/mealie/routes/meal_routes.py index 6145676fd..8f523b736 100644 --- a/mealie/routes/meal_routes.py +++ b/mealie/routes/meal_routes.py @@ -53,7 +53,7 @@ def update_meal_plan( # detail=SnackResponse.error("Unable to Update Mealplan"), # ) - return SnackResponse.success("Mealplan Updated") + return SnackResponse.info("Mealplan Updated") @router.delete("/{plan_id}") @@ -62,7 +62,7 @@ def delete_meal_plan(plan_id, db: Session = Depends(generate_session)): MealPlan.delete(db, plan_id) - return SnackResponse.success("Mealplan Deleted") + return SnackResponse.error("Mealplan Deleted") @router.get("/today", tags=["Meal Plan"]) diff --git a/mealie/routes/migration_routes.py b/mealie/routes/migration_routes.py index 26845607b..8fc2f0b76 100644 --- a/mealie/routes/migration_routes.py +++ b/mealie/routes/migration_routes.py @@ -62,7 +62,7 @@ def delete_migration_data(type: str, file_name: str): else: SnackResponse.error("File/Folder not found.") - return SnackResponse.info(f"Migration Data Remove: {remove_path.absolute()}") + return SnackResponse.error(f"Migration Data Remove: {remove_path.absolute()}") @router.post("/{type}/upload") diff --git a/mealie/routes/recipe/category_routes.py b/mealie/routes/recipe/category_routes.py index 67a4c213e..57873afef 100644 --- a/mealie/routes/recipe/category_routes.py +++ b/mealie/routes/recipe/category_routes.py @@ -4,6 +4,8 @@ from fastapi import APIRouter, Depends from models.category_models import RecipeCategoryResponse from sqlalchemy.orm.session import Session +from utils.snackbar import SnackResponse + router = APIRouter( prefix="/api/categories", tags=["Recipe Categories"], @@ -33,3 +35,5 @@ async def delete_recipe_category( from any recipes that contain it """ db.categories.delete(session, category) + + return SnackResponse(f"Category Deleted: {category}") diff --git a/mealie/routes/recipe/recipe_crud_routes.py b/mealie/routes/recipe/recipe_crud_routes.py index af2e89253..80681e71e 100644 --- a/mealie/routes/recipe/recipe_crud_routes.py +++ b/mealie/routes/recipe/recipe_crud_routes.py @@ -62,7 +62,7 @@ def delete_recipe(recipe_slug: str, db: Session = Depends(generate_session)): status_code=404, detail=SnackResponse.error("Unable to Delete Recipe") ) - return SnackResponse.success("Recipe Deleted") + return SnackResponse.error(f"Recipe {recipe_slug} Deleted") @router.get("/{recipe_slug}/image") diff --git a/mealie/routes/recipe/tag_routes.py b/mealie/routes/recipe/tag_routes.py index ce527f01c..c18846407 100644 --- a/mealie/routes/recipe/tag_routes.py +++ b/mealie/routes/recipe/tag_routes.py @@ -3,6 +3,8 @@ from db.db_setup import generate_session from fastapi import APIRouter, Depends from sqlalchemy.orm.session import Session +from utils.snackbar import SnackResponse + router = APIRouter(tags=["Recipes"]) router = APIRouter( @@ -30,3 +32,5 @@ async def delete_recipe_tag(tag: str, session: Session = Depends(generate_sessio from any recipes that contain it""" db.tags.delete(session, tag) + + return SnackResponse.error(f"Tag Deleted: {tag}") diff --git a/mealie/routes/theme_routes.py b/mealie/routes/theme_routes.py index d2c5da7f1..3c244931c 100644 --- a/mealie/routes/theme_routes.py +++ b/mealie/routes/theme_routes.py @@ -18,12 +18,6 @@ def get_all_themes(db: Session = Depends(generate_session)): def create_theme(data: SiteTheme, db: Session = Depends(generate_session)): """ Creates a site color theme database entry """ data.save_to_db(db) - # try: - # data.save_to_db() - # except: - # raise HTTPException( - # status_code=400, detail=SnackResponse.error("Unable to Save Theme") - # ) return SnackResponse.success("Theme Saved") @@ -41,24 +35,12 @@ def update_theme( """ Update a theme database entry """ data.update_document(db) - # try: - # except: - # raise HTTPException( - # status_code=400, detail=SnackResponse.error("Unable to Update Theme") - # ) - - return SnackResponse.success("Theme Updated") + return SnackResponse.info(f"Theme Updated: {theme_name}") @router.delete("/themes/{theme_name}") def delete_theme(theme_name: str, db: Session = Depends(generate_session)): """ Deletes theme from the database """ SiteTheme.delete_theme(db, theme_name) - # try: - # SiteTheme.delete_theme(theme_name) - # except: - # raise HTTPException( - # status_code=400, detail=SnackResponse.error("Unable to Delete Theme") - # ) - return SnackResponse.success("Theme Deleted") + return SnackResponse.error(f"Theme Deleted: {theme_name}") diff --git a/mealie/utils/snackbar.py b/mealie/utils/snackbar.py index 766bb5fd7..dd4ee9de2 100644 --- a/mealie/utils/snackbar.py +++ b/mealie/utils/snackbar.py @@ -9,18 +9,6 @@ class SnackResponse: return snackbar - @staticmethod - def primary(message: str, additional_data: dict = None) -> dict: - return SnackResponse._create_response(message, "primary", additional_data) - - @staticmethod - def accent(message: str, additional_data: dict = None) -> dict: - return SnackResponse._create_response(message, "accent", additional_data) - - @staticmethod - def secondary(message: str, additional_data: dict = None) -> dict: - return SnackResponse._create_response(message, "secondary", additional_data) - @staticmethod def success(message: str, additional_data: dict = None) -> dict: return SnackResponse._create_response(message, "success", additional_data)