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

View file

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

View file

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

View file

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

View file

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