2021-04-28 21:31:39 -08:00
|
|
|
<template>
|
2021-06-12 22:23:23 -08:00
|
|
|
<div v-if="value && value.length > 0">
|
2021-04-28 21:31:39 -08:00
|
|
|
<h2 class="mb-4">{{ $t("recipe.ingredients") }}</h2>
|
|
|
|
<div v-if="edit">
|
2021-05-01 20:46:02 -08:00
|
|
|
<draggable :value="value" @input="updateIndex" @start="drag = true" @end="drag = false" handle=".handle">
|
2021-04-28 21:31:39 -08:00
|
|
|
<transition-group type="transition" :name="!drag ? 'flip-list' : null">
|
2021-05-01 20:46:02 -08:00
|
|
|
<div v-for="(ingredient, index) in value" :key="generateKey('ingredient', index)">
|
2021-04-28 21:31:39 -08:00
|
|
|
<v-row align="center">
|
|
|
|
<v-textarea
|
|
|
|
class="mr-2"
|
|
|
|
:label="$t('recipe.ingredient')"
|
2021-06-12 22:23:23 -08:00
|
|
|
v-model="value[index].note"
|
2021-04-28 21:31:39 -08:00
|
|
|
auto-grow
|
|
|
|
solo
|
|
|
|
dense
|
|
|
|
rows="1"
|
|
|
|
>
|
|
|
|
<template slot="append-outer">
|
2021-06-16 18:55:32 -08:00
|
|
|
<v-icon class="handle">{{ $globals.icons.arrowUpDown }}</v-icon>
|
2021-04-28 21:31:39 -08:00
|
|
|
</template>
|
2021-05-01 20:46:02 -08:00
|
|
|
<v-icon class="mr-n1" slot="prepend" color="error" @click="removeByIndex(value, index)">
|
2021-05-23 12:38:55 -08:00
|
|
|
{{ $globals.icons.delete }}
|
2021-04-28 21:31:39 -08:00
|
|
|
</v-icon>
|
|
|
|
</v-textarea>
|
|
|
|
</v-row>
|
|
|
|
</div>
|
|
|
|
</transition-group>
|
|
|
|
</draggable>
|
|
|
|
|
|
|
|
<div class="d-flex row justify-end">
|
|
|
|
<BulkAdd @bulk-data="addIngredient" class="mr-2" />
|
|
|
|
<v-btn color="secondary" dark @click="addIngredient" class="mr-4">
|
2021-05-23 12:38:55 -08:00
|
|
|
<v-icon>{{ $globals.icons.create }}</v-icon>
|
2021-04-28 21:31:39 -08:00
|
|
|
</v-btn>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div v-else>
|
|
|
|
<v-list-item
|
|
|
|
dense
|
|
|
|
v-for="(ingredient, index) in value"
|
|
|
|
:key="generateKey('ingredient', index)"
|
|
|
|
@click="toggleChecked(index)"
|
|
|
|
>
|
2021-05-01 20:46:02 -08:00
|
|
|
<v-checkbox hide-details :value="checked[index]" class="pt-0 my-auto py-auto" color="secondary"> </v-checkbox>
|
2021-04-28 21:31:39 -08:00
|
|
|
|
|
|
|
<v-list-item-content>
|
2021-06-12 22:23:23 -08:00
|
|
|
<vue-markdown class="ma-0 pa-0 text-subtitle-1 dense-markdown" :source="ingredient.note"> </vue-markdown>
|
2021-04-28 21:31:39 -08:00
|
|
|
</v-list-item-content>
|
|
|
|
</v-list-item>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
|
|
|
import BulkAdd from "@/components/Recipe/Parts/Helpers/BulkAdd";
|
|
|
|
import VueMarkdown from "@adapttive/vue-markdown";
|
|
|
|
import draggable from "vuedraggable";
|
2021-05-05 14:08:13 -08:00
|
|
|
import { utils } from "@/utils";
|
2021-04-28 21:31:39 -08:00
|
|
|
export default {
|
|
|
|
components: {
|
|
|
|
BulkAdd,
|
|
|
|
draggable,
|
|
|
|
VueMarkdown,
|
|
|
|
},
|
|
|
|
props: {
|
|
|
|
value: {
|
|
|
|
type: Array,
|
|
|
|
},
|
|
|
|
|
|
|
|
edit: {
|
|
|
|
type: Boolean,
|
|
|
|
default: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
drag: false,
|
|
|
|
checked: [],
|
|
|
|
};
|
|
|
|
},
|
|
|
|
mounted() {
|
|
|
|
this.checked = this.value.map(() => false);
|
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
addIngredient(ingredients = null) {
|
|
|
|
if (ingredients.length) {
|
2021-06-12 22:23:23 -08:00
|
|
|
const newIngredients = ingredients.map(x => {
|
|
|
|
return {
|
|
|
|
title: null,
|
|
|
|
note: x,
|
|
|
|
unit: null,
|
|
|
|
food: null,
|
|
|
|
disableAmount: true,
|
|
|
|
quantity: 1,
|
|
|
|
};
|
|
|
|
});
|
|
|
|
this.value.push(...newIngredients);
|
2021-04-28 21:31:39 -08:00
|
|
|
} else {
|
2021-06-12 22:23:23 -08:00
|
|
|
this.value.push({
|
|
|
|
title: null,
|
|
|
|
note: "",
|
|
|
|
unit: null,
|
|
|
|
food: null,
|
|
|
|
disableAmount: true,
|
|
|
|
quantity: 1,
|
|
|
|
});
|
2021-04-28 21:31:39 -08:00
|
|
|
}
|
|
|
|
},
|
|
|
|
generateKey(item, index) {
|
|
|
|
return utils.generateUniqueKey(item, index);
|
|
|
|
},
|
|
|
|
updateIndex(data) {
|
|
|
|
this.$emit("input", data);
|
|
|
|
},
|
|
|
|
toggleChecked(index) {
|
|
|
|
this.$set(this.checked, index, !this.checked[index]);
|
|
|
|
},
|
|
|
|
removeByIndex(list, index) {
|
|
|
|
list.splice(index, 1);
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
</script>
|
|
|
|
|
2021-05-01 20:46:02 -08:00
|
|
|
<style>
|
2021-04-28 21:31:39 -08:00
|
|
|
.dense-markdown p {
|
|
|
|
margin: auto !important;
|
|
|
|
}
|
2021-05-01 20:46:02 -08:00
|
|
|
</style>
|