Provide feedback for tags CRUD

This commit is contained in:
Florian Dupret 2021-04-29 09:18:45 +02:00
commit d6f0291a27
7 changed files with 47 additions and 19 deletions

View file

@ -84,28 +84,48 @@ export const tagAPI = {
return response.data; return response.data;
}, },
async create(name) { async create(name) {
let response = await apiReq.post(tagURLs.getAll, { name: name }); const response = await apiReq.post(
store.dispatch("requestTags"); tagURLs.getAll,
return response.data; { name: name },
function() { return i18n.t('tag.tag-creation-failed'); },
function() { return i18n.t('tag.tag-created'); }
);
if(response) {
store.dispatch("requestTags");
return response.data;
}
}, },
async getRecipesInTag(tag) { async getRecipesInTag(tag) {
let response = await apiReq.get(tagURLs.getTag(tag)); let response = await apiReq.get(tagURLs.getTag(tag));
return response.data; return response.data;
}, },
async update(name, newName, overrideRequest = false) { async update(name, newName, overrideRequest = false) {
let response = await apiReq.put(tagURLs.updateTag(name), { name: newName }); const response = await apiReq.put(
tagURLs.updateTag(name),
{ name: newName },
function() { return i18n.t('tag.tag-update-failed'); },
function() { return i18n.t('tag.tag-updated'); }
);
if (!overrideRequest) { if(response) {
store.dispatch("requestTags"); if (!overrideRequest) {
store.dispatch("requestTags");
}
return response.data;
} }
return response.data;
}, },
async delete(tag, overrideRequest = false) { async delete(tag, overrideRequest = false) {
let response = await apiReq.delete(tagURLs.deleteTag(tag)); const response = await apiReq.delete(
if (!overrideRequest) { tagURLs.deleteTag(tag),
store.dispatch("requestTags"); null,
function() { return i18n.t('tag.tag-deletion-failed'); },
function() { return i18n.t('tag.tag-deleted'); }
);
if(response) {
if (!overrideRequest) {
store.dispatch("requestTags");
}
return response.data;
} }
return response.data;
}, },
}; };

View file

@ -90,7 +90,7 @@ export default {
computed: { computed: {
inputLabel() { inputLabel() {
if (!this.showLabel) return null; if (!this.showLabel) return null;
return this.tagSelector ? this.$t('recipe.tags') : this.$t('recipe.categories'); return this.tagSelector ? this.$t('tag.tags') : this.$t('recipe.categories');
}, },
activeItems() { activeItems() {
let ItemObjects = []; let ItemObjects = [];

View file

@ -74,7 +74,7 @@
:show-label="false" :show-label="false"
/> />
<h2 class="mt-4">{{ $t("recipe.tags") }}</h2> <h2 class="mt-4">{{ $t("tag.tags") }}</h2>
<CategoryTagSelector <CategoryTagSelector
:return-object="false" :return-object="false"
v-model="value.tags" v-model="value.tags"

View file

@ -44,7 +44,7 @@
</v-card> </v-card>
<v-card class="mt-2" v-if="tags.length > 0"> <v-card class="mt-2" v-if="tags.length > 0">
<v-card-title class="py-2"> <v-card-title class="py-2">
{{ $t("recipe.tags") }} {{ $t("tag.tags") }}
</v-card-title> </v-card-title>
<v-divider class="mx-2"></v-divider> <v-divider class="mx-2"></v-divider>
<v-card-text> <v-card-text>
@ -69,7 +69,7 @@
</v-row> </v-row>
<div v-if="!medium"> <div v-if="!medium">
<RecipeChips :title="$t('recipe.categories')" :items="categories" /> <RecipeChips :title="$t('recipe.categories')" :items="categories" />
<RecipeChips :title="$t('recipe.tags')" :items="tags" /> <RecipeChips :title="$t('tag.tags')" :items="tags" />
<Nutrition :value="nutrition" :edit="false" /> <Nutrition :value="nutrition" :edit="false" />
<Assets :value="assets" :edit="false" :slug="slug" /> <Assets :value="assets" :edit="false" :slug="slug" />
</div> </div>

View file

@ -204,7 +204,6 @@
"sodium-content": "Sodium", "sodium-content": "Sodium",
"step-index": "Step: {step}", "step-index": "Step: {step}",
"sugar-content": "Sugar", "sugar-content": "Sugar",
"tags": "Tags",
"title": "Title", "title": "Title",
"total-time": "Total Time", "total-time": "Total Time",
"unable-to-delete-recipe": "Unable to Delete Recipe", "unable-to-delete-recipe": "Unable to Delete Recipe",
@ -310,6 +309,15 @@
"webhook-url": "Webhook URL" "webhook-url": "Webhook URL"
} }
}, },
"tag": {
"tag-created": "Tag created",
"tag-creation-failed": "Tag creation failed",
"tag-deleted": "Tag deleted",
"tag-deletion-failed": "Tag deletion failed",
"tag-update-failed": "Tag update failed",
"tag-updated": "Tag updated",
"tags": "Tags"
},
"user": { "user": {
"admin": "Admin", "admin": "Admin",
"are-you-sure-you-want-to-delete-the-link": "Are you sure you want to delete the link <b>{link}<b/>?", "are-you-sure-you-want-to-delete-the-link": "Are you sure you want to delete the link <b>{link}<b/>?",

View file

@ -7,7 +7,7 @@
:title=" :title="
$t('general.delete') + $t('general.delete') +
' ' + ' ' +
(isTags ? $t('recipe.tags') : $t('recipe.categories')) (isTags ? $t('tag.tags') : $t('recipe.categories'))
" "
:loading="loading" :loading="loading"
modal-width="400" modal-width="400"

View file

@ -16,7 +16,7 @@
</v-tab> </v-tab>
<v-tab> <v-tab>
{{ $t("recipe.tags") }} {{ $t("tag.tags") }}
<v-icon>mdi-tag-multiple-outline</v-icon> <v-icon>mdi-tag-multiple-outline</v-icon>
</v-tab> </v-tab>
</v-tabs> </v-tabs>