Refactor API texts handling #2

This commit is contained in:
Florian Dupret 2021-04-28 19:44:54 +02:00
commit f192dd0c73
6 changed files with 14 additions and 56 deletions

View file

@ -150,7 +150,6 @@ import { api } from "@/api";
import LanguageSelector from "@/components/FormHelpers/LanguageSelector"; import LanguageSelector from "@/components/FormHelpers/LanguageSelector";
import draggable from "vuedraggable"; import draggable from "vuedraggable";
import NewCategoryTagDialog from "@/components/UI/Dialogs/NewCategoryTagDialog.vue"; import NewCategoryTagDialog from "@/components/UI/Dialogs/NewCategoryTagDialog.vue";
import utils from "@/utils";
export default { export default {
components: { components: {
@ -214,13 +213,8 @@ export default {
writeLang(val) { writeLang(val) {
this.settings.language = val; this.settings.language = val;
}, },
async deleteCategoryfromDatabase(category) { deleteCategoryfromDatabase(category) {
const response = await api.categories.delete(category); api.categories.delete(category);
if (response.status != 200) {
utils.notify.error(this.$t('settings.category-deletion-failed'));
} else {
utils.notify.success(this.$t('settings.category-deleted'));
}
}, },
async getOptions() { async getOptions() {
this.settings = await api.siteSettings.get(); this.settings = await api.siteSettings.get();
@ -229,13 +223,9 @@ export default {
this.settings.categories.splice(index, 1); this.settings.categories.splice(index, 1);
}, },
async saveSettings() { async saveSettings() {
const response = await api.siteSettings.update(this.settings); if (await api.siteSettings.update(this.settings)) {
if (response.status != 200) { this.getOptions();
utils.notify.error(this.$t('settings.settings-update-failed'));
} else {
utils.notify.success(this.$t('settings.settings-updated'));
} }
this.getOptions();
}, },
}, },
}; };

View file

@ -46,7 +46,6 @@
<script> <script>
import ConfirmationDialog from "@/components/UI/Dialogs/ConfirmationDialog"; import ConfirmationDialog from "@/components/UI/Dialogs/ConfirmationDialog";
import { api } from "@/api"; import { api } from "@/api";
import utils from "@/utils";
const DELETE_EVENT = "delete"; const DELETE_EVENT = "delete";
const APPLY_EVENT = "apply"; const APPLY_EVENT = "apply";
@ -71,11 +70,7 @@ export default {
}, },
async deleteSelectedTheme() { async deleteSelectedTheme() {
//Delete Theme from DB //Delete Theme from DB
const response = await api.themes.delete(this.theme.name); if (await api.themes.delete(this.theme.name)) {
if (response.status != 200) {
utils.notify.error(this.$t('settings.theme.error-deleting-theme'));
} else {
utils.notify.success(this.$t('settings.theme.theme-deleted'));
//Get the new list of available from DB //Get the new list of available from DB
this.availableThemes = await api.themes.requestAll(); this.availableThemes = await api.themes.requestAll();
this.$emit(DELETE_EVENT); this.$emit(DELETE_EVENT);

View file

@ -138,7 +138,6 @@ import { api } from "@/api";
import ColorPickerDialog from "@/components/FormHelpers/ColorPickerDialog"; import ColorPickerDialog from "@/components/FormHelpers/ColorPickerDialog";
import NewThemeDialog from "./NewThemeDialog"; import NewThemeDialog from "./NewThemeDialog";
import ThemeCard from "./ThemeCard"; import ThemeCard from "./ThemeCard";
import utils from "@/utils";
export default { export default {
components: { components: {
@ -173,10 +172,7 @@ export default {
*/ */
async appendTheme(NewThemeDialog) { async appendTheme(NewThemeDialog) {
const response = await api.themes.create(NewThemeDialog); const response = await api.themes.create(NewThemeDialog);
if (response.status != 201) { if (response) {
utils.notify.error(this.$t('settings.theme.error-creating-theme-see-log-file'));
} else {
utils.notify.success(this.$t('settings.theme.theme-saved'));
this.availableThemes.push(NewThemeDialog); this.availableThemes.push(NewThemeDialog);
this.$store.commit("setTheme", NewThemeDialog); this.$store.commit("setTheme", NewThemeDialog);
} }
@ -187,16 +183,11 @@ export default {
/** /**
* This will save the current colors and make the selected theme live. * This will save the current colors and make the selected theme live.
*/ */
async saveThemes() { saveThemes() {
const response = await api.themes.update( api.themes.update(
this.selectedTheme.name, this.selectedTheme.name,
this.selectedTheme.colors this.selectedTheme.colors
); );
if (response.status != 200) {
utils.notify.error(this.$t('settings.theme.error-updating-theme'));
} else {
utils.notify.success(this.$t('settings.theme.theme-updated'));
}
}, },
}, },
}; };

View file

@ -128,11 +128,7 @@ export default {
this.requestMeals(); this.requestMeals();
}, },
async deletePlan(id) { async deletePlan(id) {
const response = await api.mealPlans.delete(id); if (await api.mealPlans.delete(id)) {
if (response.status != 200) {
utils.notify.error(this.$t('meal-plan.mealplan-deletion-failed'));
} else {
utils.notify.success(this.$t('meal-plan.mealplan-deleted'));
this.requestMeals(); this.requestMeals();
} }
}, },

View file

@ -42,7 +42,6 @@
<script> <script>
import { api } from "@/api"; import { api } from "@/api";
import utils from "@/utils";
import RecipeEditor from "@/components/Recipe/RecipeEditor"; import RecipeEditor from "@/components/Recipe/RecipeEditor";
import VJsoneditor from "v-jsoneditor"; import VJsoneditor from "v-jsoneditor";
@ -102,12 +101,7 @@ export default {
let slug = await api.recipes.create(this.recipeDetails); let slug = await api.recipes.create(this.recipeDetails);
if (this.fileObject) { if (this.fileObject) {
const response = await api.recipes.updateImage(slug, this.fileObject); api.recipes.updateImage(slug, this.fileObject, true);
if (response.status != 200) {
utils.notify.error(this.$t('general.image-upload-failed'));
} else {
utils.notify.success(this.$t('recipe.recipe-image-updated'));
}
} }
this.isLoading = false; this.isLoading = false;

View file

@ -78,7 +78,6 @@ import RecipeEditor from "@/components/Recipe/RecipeEditor";
import RecipeTimeCard from "@/components/Recipe/RecipeTimeCard.vue"; import RecipeTimeCard from "@/components/Recipe/RecipeTimeCard.vue";
import EditorButtonRow from "@/components/Recipe/EditorButtonRow"; import EditorButtonRow from "@/components/Recipe/EditorButtonRow";
import { user } from "@/mixins/user"; import { user } from "@/mixins/user";
import utils from "@/utils";
import store from "@/store"; import store from "@/store";
import { router } from "@/routes"; import { router } from "@/routes";
@ -169,10 +168,7 @@ export default {
}, },
async deleteRecipe() { async deleteRecipe() {
let response = await api.recipes.delete(this.recipeDetails.slug); let response = await api.recipes.delete(this.recipeDetails.slug);
if (response.status != 200) { if (response) {
utils.notify.error(this.$t('recipe.unable-to-delete-recipe'));
} else {
utils.notify.success(this.$t('recipe.recipe-deleted'));
store.dispatch("requestRecentRecipes"); store.dispatch("requestRecentRecipes");
router.push(`/`); router.push(`/`);
} }
@ -186,14 +182,10 @@ export default {
}, },
async saveImage() { async saveImage() {
if (this.fileObject) { if (this.fileObject) {
const response = await api.recipes.updateImage(this.recipeDetails.slug, this.fileObject); if (api.recipes.updateImage(this.recipeDetails.slug, this.fileObject)) {
if (response.status != 200) { this.imageKey += 1;
utils.notify.error(this.$t('general.image-upload-failed'));
} else {
utils.notify.success(this.$t('recipe.recipe-image-updated'));
} }
} }
this.imageKey += 1;
}, },
async saveRecipe() { async saveRecipe() {
if (this.validateRecipe()) { if (this.validateRecipe()) {