From 38e4afcc3c9899a915b5015d0cb3d0cfd6fa7e11 Mon Sep 17 00:00:00 2001 From: hayden Date: Wed, 3 Feb 2021 19:07:19 -0900 Subject: [PATCH] api refactoring + random cleanup --- frontend/src/api/category.js | 4 +-- frontend/src/api/migration.js | 6 ++-- frontend/src/api/settings.js | 4 +-- .../components/Recipe/RecipeEditor/index.vue | 4 +-- .../Settings/Backup/ImportDialog.vue | 2 +- .../components/Settings/Migration/index.vue | 4 +-- frontend/src/locales/en.json | 4 +-- frontend/src/pages/CategoryPage.vue | 2 +- frontend/src/pages/RecipePage.vue | 31 +++++++++++++------ frontend/src/pages/SearchPage.vue | 2 +- frontend/src/utils.js | 2 +- 11 files changed, 38 insertions(+), 27 deletions(-) diff --git a/frontend/src/api/category.js b/frontend/src/api/category.js index 5132795b3..20b72d458 100644 --- a/frontend/src/api/category.js +++ b/frontend/src/api/category.js @@ -1,10 +1,10 @@ import { baseURL } from "./api-utils"; import { apiReq } from "./api-utils"; -const prefix = baseURL + "/recipes/categories"; +const prefix = baseURL + "categories"; const categoryURLs = { - get_all: `${prefix}/all`, + get_all: `${prefix}`, get_category: (category) => `${prefix}/${category}`, delete_category: (category) => `${prefix}/${category}`, }; diff --git a/frontend/src/api/migration.js b/frontend/src/api/migration.js index 728a4151e..5a4b40dc4 100644 --- a/frontend/src/api/migration.js +++ b/frontend/src/api/migration.js @@ -2,13 +2,13 @@ import { baseURL } from "./api-utils"; import { apiReq } from "./api-utils"; import { store } from "../store/store"; -const migrationBase = baseURL + "migrations/"; +const migrationBase = baseURL + "migrations"; const migrationURLs = { // New all: migrationBase, - delete: (folder, file) => `${migrationBase}/${folder}/${file}/delete/`, - import: (folder, file) => `${migrationBase}/${folder}/${file}/import/`, + delete: (folder, file) => `${migrationBase}/${folder}/${file}/delete`, + import: (folder, file) => `${migrationBase}/${folder}/${file}/import`, }; export default { diff --git a/frontend/src/api/settings.js b/frontend/src/api/settings.js index a81aac174..650f5bb1d 100644 --- a/frontend/src/api/settings.js +++ b/frontend/src/api/settings.js @@ -1,12 +1,12 @@ import { baseURL } from "./api-utils"; import { apiReq } from "./api-utils"; -const settingsBase = baseURL + "site-settings/"; +const settingsBase = baseURL + "site-settings"; const settingsURLs = { siteSettings: `${settingsBase}`, updateSiteSettings: `${settingsBase}`, - testWebhooks: `${settingsBase}webhooks/test`, + testWebhooks: `${settingsBase}/webhooks/test`, }; export default { diff --git a/frontend/src/components/Recipe/RecipeEditor/index.vue b/frontend/src/components/Recipe/RecipeEditor/index.vue index 9fe95fc19..dea51653b 100644 --- a/frontend/src/components/Recipe/RecipeEditor/index.vue +++ b/frontend/src/components/Recipe/RecipeEditor/index.vue @@ -37,7 +37,7 @@ class="my-3" :label="$t('recipe.recipe-name')" v-model="value.name" - :rules="[rules.required, rules.whiteSpace]" + :rules="[rules.required]" > - + {{ $t("general.download") }} diff --git a/frontend/src/components/Settings/Migration/index.vue b/frontend/src/components/Settings/Migration/index.vue index 26694ea43..f8cde97f8 100644 --- a/frontend/src/components/Settings/Migration/index.vue +++ b/frontend/src/components/Settings/Migration/index.vue @@ -17,7 +17,7 @@ { + response.forEach((element) => { if (element.type === "nextcloud") { this.migrations.nextcloud.availableImports = element.files; } else if (element.type === "chowdown") { diff --git a/frontend/src/locales/en.json b/frontend/src/locales/en.json index c6cb8764b..20c9a1140 100644 --- a/frontend/src/locales/en.json +++ b/frontend/src/locales/en.json @@ -70,7 +70,7 @@ "title": "Title", "total-time": "Total Time", "prep-time": "Prep Time", - "perform-time": "Cook Time / Perform Time", + "perform-time": "Cook Time", "api-extras": "API Extras", "object-key": "Object Key", "object-value": "Object Value", @@ -155,4 +155,4 @@ "description": "Migrate data from Chowdown" } } -} +} \ No newline at end of file diff --git a/frontend/src/pages/CategoryPage.vue b/frontend/src/pages/CategoryPage.vue index 89735233c..812cc06b4 100644 --- a/frontend/src/pages/CategoryPage.vue +++ b/frontend/src/pages/CategoryPage.vue @@ -23,7 +23,7 @@ export default { }, data() { return { - title: null, + title: "", recipes: [], }; }, diff --git a/frontend/src/pages/RecipePage.vue b/frontend/src/pages/RecipePage.vue index 26016fcc2..05b8f96b1 100644 --- a/frontend/src/pages/RecipePage.vue +++ b/frontend/src/pages/RecipePage.vue @@ -143,19 +143,30 @@ export default { deleteRecipe() { api.recipes.delete(this.recipeDetails.slug); }, + validateRecipe() { + if (this.jsonEditor) { + return true; + } else { + return this.$refs.recipeEditor.validateRecipe(); + } + }, async saveRecipe() { - if (this.$refs.recipeEditor.validateRecipe()) { - console.log("Thank you"); - } - let slug = await api.recipes.update(this.recipeDetails); + if (this.validateRecipe()) { + let slug = await api.recipes.update(this.recipeDetails); - if (this.fileObject) { - await api.recipes.updateImage(this.recipeDetails.slug, this.fileObject); - } + if (this.fileObject) { + await api.recipes.updateImage( + this.recipeDetails.slug, + this.fileObject + ); + } - this.form = false; - this.imageKey += 1; - this.$router.push(`/recipe/${slug}`); + this.form = false; + this.imageKey += 1; + if (slug != this.recipeDetails.slug) { + this.$router.push(`/recipe/${slug}`); + } + } }, showForm() { this.form = true; diff --git a/frontend/src/pages/SearchPage.vue b/frontend/src/pages/SearchPage.vue index 022610b02..7c3b3d7ff 100644 --- a/frontend/src/pages/SearchPage.vue +++ b/frontend/src/pages/SearchPage.vue @@ -43,7 +43,7 @@ export default { }, data() { return { - searchResults: null, + searchResults: [], }; }, methods: { diff --git a/frontend/src/utils.js b/frontend/src/utils.js index 63018b86d..f2038b6c6 100644 --- a/frontend/src/utils.js +++ b/frontend/src/utils.js @@ -43,7 +43,7 @@ const monthsShort = [ export default { getImageURL(image) { - return `/api/recipe/image/${image}/`; + return `/api/recipes/${image}/image`; }, generateUniqueKey(item, index) { const uniqueKey = `${item}-${index}`;