Add option to space to enable plural name usage

* Add option to space to enable usage of plural name
  for food and unit per space

* Respect option per space to use the plural name
This commit is contained in:
Niklas Schwarz
2022-09-11 22:45:18 +02:00
parent 9994b6f9c2
commit b1ad5ef205
40 changed files with 193 additions and 83 deletions

View File

@@ -12,7 +12,7 @@
<cookbook-edit-card :book="book" v-if="current_page === 1" v-on:editing="cookbook_editing = $event" v-on:refresh="$emit('refresh')" @reload="$emit('reload')"></cookbook-edit-card>
</transition>
<transition name="flip" mode="out-in">
<recipe-card :recipe="display_recipes[0].recipe_content" v-if="current_page > 1" :key="display_recipes[0].recipe"></recipe-card>
<recipe-card :recipe="display_recipes[0].recipe_content" v-if="current_page > 1" :key="display_recipes[0].recipe" :use_plural="use_plural"></recipe-card>
</transition>
</div>
<div class="col-md-5">
@@ -20,7 +20,7 @@
<cookbook-toc :recipes="recipes" v-if="current_page === 1" v-on:switchRecipe="switchRecipe($event)"></cookbook-toc>
</transition>
<transition name="flip" mode="out-in">
<recipe-card :recipe="display_recipes[1].recipe_content" v-if="current_page > 1 && display_recipes.length === 2" :key="display_recipes[1].recipe"></recipe-card>
<recipe-card :recipe="display_recipes[1].recipe_content" v-if="current_page > 1 && display_recipes.length === 2" :key="display_recipes[1].recipe" :use_plural="use_plural"></recipe-card>
</transition>
</div>
<div class="col-md-1" @click="swipeLeft" style="cursor: pointer"></div>
@@ -34,7 +34,7 @@ import CookbookEditCard from "./CookbookEditCard"
import CookbookToc from "./CookbookToc"
import Vue2TouchEvents from "vue2-touch-events"
import Vue from "vue"
import { ApiApiFactory } from "../utils/openapi/api"
import { ApiApiFactory } from "@/utils/openapi/api"
Vue.use(Vue2TouchEvents)
@@ -56,6 +56,12 @@ export default {
return this.recipes.slice((this.current_page - 1 - 1) * 2, (this.current_page - 1) * 2)
}
},
mounted(){
let apiClient = new ApiApiFactory()
apiClient.retrieveSpace(window.ACTIVE_SPACE_ID).then(r => {
this.use_plural = r.data.use_plural
})
},
data() {
return {
current_page: 1,
@@ -63,6 +69,7 @@ export default {
bounce_left: false,
bounce_right: false,
cookbook_editing: false,
use_plural: false,
}
},
methods: {

View File

@@ -23,7 +23,9 @@
<b-card-body class="m-0 py-0">
<b-card-text class="h-100 my-0 d-flex flex-column" style="text-overflow: ellipsis">
<h5 class="m-0 mt-1 text-truncate">{{ item[title] }}</h5>
<div v-if="item[plural] !== '' && item[plural] !== null" class="m-0 text-truncate">({{ $t("plural_short") }}: {{ item[plural] }})</div>
<template v-if="use_plural">
<div v-if="item[plural] !== '' && item[plural] !== null" class="m-0 text-truncate">({{ $t("plural_short") }}: {{ item[plural] }})</div>
</template>
<div class="m-0 text-truncate">{{ item[subtitle] }}</div>
<div class="m-0 text-truncate small text-muted" v-if="getFullname">{{ getFullname }}</div>
@@ -72,7 +74,11 @@
<!-- recursively add child cards -->
<div class="row" v-if="item.show_children">
<div class="col-md-10 offset-md-2">
<generic-horizontal-card v-for="child in item[children]" v-bind:key="child.id" :item="child" :model="model" @item-action="$emit('item-action', $event)"> </generic-horizontal-card>
<generic-horizontal-card v-for="child in item[children]"
v-bind:key="child.id"
:item="child" :model="model"
:use_plural="use_plural"
@item-action="$emit('item-action', $event)"></generic-horizontal-card>
</div>
</div>
<!-- conditionally view recipes -->
@@ -154,6 +160,7 @@ export default {
recipe_count: { type: String, default: "numrecipe" },
recipes: { type: String, default: "recipes" },
show_context_menu: { type: Boolean, default: true },
use_plural: { type: Boolean, default: false},
},
data() {
return {

View File

@@ -17,13 +17,18 @@
</td>
<td @click="done">
<template v-if="ingredient.unit !== null && !ingredient.no_amount">
<template v-if="ingredient.unit.plural_name === '' || ingredient.unit.plural_name === null">
<template v-if="!use_plural">
<span>{{ ingredient.unit.name }}
</template>
<template v-else>
<span v-if="ingredient.always_use_plural_unit">{{ ingredient.unit.plural_name}}</span>
<span v-else-if="(ingredient.amount * this.ingredient_factor) > 1">{{ ingredient.unit.plural_name }}</span>
<span v-else>{{ ingredient.unit.name }}</span>
<template v-if="ingredient.unit.plural_name === '' || ingredient.unit.plural_name === null">
<span>{{ ingredient.unit.name }}
</template>
<template v-else>
<span v-if="ingredient.always_use_plural_unit">{{ ingredient.unit.plural_name}}</span>
<span v-else-if="(ingredient.amount * this.ingredient_factor) > 1">{{ ingredient.unit.plural_name }}</span>
<span v-else>{{ ingredient.unit.name }}</span>
</template>
</template>
</template>
</td>
@@ -33,14 +38,19 @@
v-if="ingredient.food.recipe !== null" target="_blank"
rel="noopener noreferrer">{{ ingredient.food.name }}</a>
<template v-if="ingredient.food.recipe === null">
<template v-if="ingredient.food.plural_name === '' || ingredient.food.plural_name === null">
<template v-if="!use_plural">
<span>{{ ingredient.food.name }}</span>
</template>
<template v-else>
<span v-if="ingredient.always_use_plural_food">{{ ingredient.food.plural_name }}</span>
<span v-else-if="ingredient.no_amount">{{ ingredient.food.name }}</span>
<span v-else-if="(ingredient.amount * this.ingredient_factor) > 1">{{ ingredient.food.plural_name }}</span>
<span v-else>{{ ingredient.food.name }}</span>
<template v-if="ingredient.food.plural_name === '' || ingredient.food.plural_name === null">
<span>{{ ingredient.food.name }}</span>
</template>
<template v-else>
<span v-if="ingredient.always_use_plural_food">{{ ingredient.food.plural_name }}</span>
<span v-else-if="ingredient.no_amount">{{ ingredient.food.name }}</span>
<span v-else-if="(ingredient.amount * this.ingredient_factor) > 1">{{ ingredient.food.plural_name }}</span>
<span v-else>{{ ingredient.food.name }}</span>
</template>
</template>
</template>
</template>
@@ -74,6 +84,7 @@ export default {
props: {
ingredient: Object,
ingredient_factor: {type: Number, default: 1},
use_plural:{type: Boolean, default: false},
detailed: {type: Boolean, default: true},
},
mixins: [ResolveUrlMixin],

View File

@@ -24,6 +24,7 @@
<ingredient-component
:ingredient="i"
:ingredient_factor="ingredient_factor"
:use_plural="use_plural"
:key="i.id"
:detailed="detailed"
@checked-state-changed="$emit('checked-state-changed', $event)"
@@ -63,6 +64,7 @@ export default {
recipe: {type: Number},
ingredient_factor: {type: Number, default: 1},
servings: {type: Number, default: 1},
use_plural: {type: Boolean, default: false},
detailed: {type: Boolean, default: true},
header: {type: Boolean, default: false},
recipe_list: {type: Number, default: undefined},

View File

@@ -84,7 +84,7 @@
</b-input-group>
</div>
<div class="col-lg-6 d-none d-lg-block d-xl-block">
<recipe-card v-if="entryEditing.recipe" :recipe="entryEditing.recipe" :detailed="false"></recipe-card>
<recipe-card v-if="entryEditing.recipe" :recipe="entryEditing.recipe" :detailed="false" :use_plural="use_plural"></recipe-card>
</div>
</div>
<div class="row mt-3 mb-3">
@@ -144,6 +144,7 @@ export default {
addshopping: false,
reviewshopping: false,
},
use_plural: false,
}
},
watch: {
@@ -171,7 +172,12 @@ export default {
this.entryEditing.servings = newVal
},
},
mounted: function () {},
mounted: function () {
let apiClient = new ApiApiFactory()
apiClient.retrieveSpace(window.ACTIVE_SPACE_ID).then(r => {
this.use_plural = r.data.use_plural
})
},
computed: {
autoMealPlan: function () {
return getUserPreference("mealplan_autoadd_shopping")

View File

@@ -75,11 +75,15 @@
<h6 class="card-title"><i class="fas fa-pepper-hot"></i> {{ $t("Ingredients") }}
</h6>
<ingredients-card :steps="recipe.steps" :header="false" :detailed="false"
:servings="recipe.servings"/>
</div>
</div>
</transition>
<ingredients-card
:steps="recipe.steps"
:header="false"
:detailed="false"
:servings="recipe.servings"
:use_plural="use_plural" />
</div>
</div>
</transition>
<b-badge pill variant="info" v-if="!recipe.internal">{{ $t("External") }}</b-badge>
</template>
@@ -121,6 +125,7 @@ export default {
props: {
recipe: Object,
meal_plan: Object,
use_plural: { type: Boolean, default: false},
footer_text: String,
footer_icon: String,
detailed: {type: Boolean, default: true},