recipe steps tagging support
This commit is contained in:
@ -64,15 +64,29 @@ class KeywordSerializer(UniqueFieldsMixin, serializers.ModelSerializer):
|
|||||||
|
|
||||||
|
|
||||||
class UnitSerializer(UniqueFieldsMixin, serializers.ModelSerializer):
|
class UnitSerializer(UniqueFieldsMixin, serializers.ModelSerializer):
|
||||||
|
|
||||||
|
def create(self, validated_data):
|
||||||
|
# since multi select tags dont have id's duplicate names might be routed to create
|
||||||
|
obj, created = Unit.objects.get_or_create(**validated_data)
|
||||||
|
return obj
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = Unit
|
model = Unit
|
||||||
fields = '__all__'
|
fields = ('id', 'name', 'description')
|
||||||
|
read_only_fields = ('id',)
|
||||||
|
|
||||||
|
|
||||||
class FoodSerializer(UniqueFieldsMixin, serializers.ModelSerializer):
|
class FoodSerializer(UniqueFieldsMixin, serializers.ModelSerializer):
|
||||||
|
|
||||||
|
def create(self, validated_data):
|
||||||
|
# since multi select tags dont have id's duplicate names might be routed to create
|
||||||
|
obj, created = Food.objects.get_or_create(**validated_data)
|
||||||
|
return obj
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = Food
|
model = Food
|
||||||
fields = '__all__'
|
fields = ('id', 'name', 'recipe')
|
||||||
|
read_only_fields = ('id',)
|
||||||
|
|
||||||
|
|
||||||
class IngredientSerializer(WritableNestedModelSerializer):
|
class IngredientSerializer(WritableNestedModelSerializer):
|
||||||
|
@ -76,12 +76,14 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div v-for="step in recipe.steps">
|
<div v-for="step, step_index in recipe.steps" style="margin-top: 1vh">
|
||||||
|
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-md-12">
|
<div class="col-md-12">
|
||||||
<h3>Step</h3>
|
<h3>{% trans 'Step' %} [[step_index+1]]</h3>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-md-12">
|
<div class="col-md-12">
|
||||||
<label :for="'id_step_' + step.id + 'name'">{% trans 'Step Name' %}</label>
|
<label :for="'id_step_' + step.id + 'name'">{% trans 'Step Name' %}</label>
|
||||||
@ -121,13 +123,15 @@
|
|||||||
:preserve-search="true"
|
:preserve-search="true"
|
||||||
placeholder="{% trans 'Select Unit' %}"
|
placeholder="{% trans 'Select Unit' %}"
|
||||||
tag-placeholder="{% trans 'Select' %}"
|
tag-placeholder="{% trans 'Select' %}"
|
||||||
|
:taggable="true"
|
||||||
|
@tag="addUnitType"
|
||||||
|
:id="`unit_${step_index}_${index}`"
|
||||||
label="name"
|
label="name"
|
||||||
track-by="id"
|
track-by="name"
|
||||||
:multiple="false"
|
:multiple="false"
|
||||||
:loading="units_loading"
|
:loading="units_loading"
|
||||||
@search-change="searchUnits">
|
@search-change="searchUnits">
|
||||||
</multiselect>
|
</multiselect>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
<div class="col-lg-4 col-md-6 small-padding">
|
<div class="col-lg-4 col-md-6 small-padding">
|
||||||
<multiselect
|
<multiselect
|
||||||
@ -141,8 +145,11 @@
|
|||||||
:preserve-search="true"
|
:preserve-search="true"
|
||||||
placeholder="{% trans 'Select Food' %}"
|
placeholder="{% trans 'Select Food' %}"
|
||||||
tag-placeholder="{% trans 'Select' %}"
|
tag-placeholder="{% trans 'Select' %}"
|
||||||
|
:taggable="true"
|
||||||
|
@tag="addFoodType"
|
||||||
|
:id="`ingredient_${step_index}_${index}`"
|
||||||
label="name"
|
label="name"
|
||||||
track-by="id"
|
track-by="name"
|
||||||
:multiple="false"
|
:multiple="false"
|
||||||
:loading="foods_loading"
|
:loading="foods_loading"
|
||||||
@search-change="searchFoods">
|
@search-change="searchFoods">
|
||||||
@ -180,8 +187,10 @@
|
|||||||
<br/>
|
<br/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<button type="button" @click="updateRecipe(true)" class="btn btn-success shadow-none">{% trans 'Save & View' %}</button>
|
<button type="button" @click="updateRecipe(true)"
|
||||||
<button type="button" @click="updateRecipe(false)" class="btn btn-info shadow-none">{% trans 'Save' %}</button>
|
class="btn btn-success shadow-none">{% trans 'Save & View' %}</button>
|
||||||
|
<button type="button" @click="updateRecipe(false)"
|
||||||
|
class="btn btn-info shadow-none">{% trans 'Save' %}</button>
|
||||||
<button type="button" @click="addStep()" class="btn btn-primary shadow-none">{% trans 'Add Step' %}</button>
|
<button type="button" @click="addStep()" class="btn btn-primary shadow-none">{% trans 'Add Step' %}</button>
|
||||||
<a href="{% url 'view_recipe' recipe.pk %}" @click="addStep()"
|
<a href="{% url 'view_recipe' recipe.pk %}" @click="addStep()"
|
||||||
class="btn btn-secondary shadow-none">{% trans 'View Recipe' %}</a>
|
class="btn btn-secondary shadow-none">{% trans 'View Recipe' %}</a>
|
||||||
@ -308,6 +317,7 @@
|
|||||||
'unit': undefined,
|
'unit': undefined,
|
||||||
'amount': 0,
|
'amount': 0,
|
||||||
'note': '',
|
'note': '',
|
||||||
|
'order': 0,
|
||||||
})
|
})
|
||||||
this.sortStep(step)
|
this.sortStep(step)
|
||||||
},
|
},
|
||||||
@ -316,6 +326,22 @@
|
|||||||
step.ingredients = step.ingredients.filter(item => item !== ingredient)
|
step.ingredients = step.ingredients.filter(item => item !== ingredient)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
addFoodType: function (tag, index) {
|
||||||
|
let [tmp, step, id] = index.split('_')
|
||||||
|
|
||||||
|
let new_food = this.recipe.steps[step].ingredients[id]
|
||||||
|
new_food.food = {'name': tag}
|
||||||
|
this.foods.push(new_food.food)
|
||||||
|
this.recipe.steps[step].ingredients[id] = new_food
|
||||||
|
},
|
||||||
|
addUnitType: function (tag, index) {
|
||||||
|
let [tmp, step, id] = index.split('_')
|
||||||
|
|
||||||
|
let new_unit = this.recipe.steps[step].ingredients[id]
|
||||||
|
new_unit.unit = {'name': tag}
|
||||||
|
this.foods.push(new_unit.unit)
|
||||||
|
this.recipe.steps[step].ingredients[id] = new_unit
|
||||||
|
},
|
||||||
searchKeywords: function (query) {
|
searchKeywords: function (query) {
|
||||||
this.keywords_loading = true
|
this.keywords_loading = true
|
||||||
this.$http.get("{% url 'api:keyword-list' %}" + '?query=' + query + '&limit=10').then((response) => {
|
this.$http.get("{% url 'api:keyword-list' %}" + '?query=' + query + '&limit=10').then((response) => {
|
||||||
@ -329,7 +355,13 @@
|
|||||||
this.units_loading = true
|
this.units_loading = true
|
||||||
this.$http.get("{% url 'api:unit-list' %}" + '?query=' + query + '&limit=10').then((response) => {
|
this.$http.get("{% url 'api:unit-list' %}" + '?query=' + query + '&limit=10').then((response) => {
|
||||||
this.units = response.data;
|
this.units = response.data;
|
||||||
//TODO add back code to include custom created ingredients
|
for (let s of this.recipe.steps){
|
||||||
|
for (let i of s.ingredients) {
|
||||||
|
if (i.unit.id === undefined) {
|
||||||
|
this.units.push(i.unit)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
this.units_loading = false
|
this.units_loading = false
|
||||||
}).catch((err) => {
|
}).catch((err) => {
|
||||||
console.log(err)
|
console.log(err)
|
||||||
@ -339,7 +371,14 @@
|
|||||||
this.foods_loading = true
|
this.foods_loading = true
|
||||||
this.$http.get("{% url 'api:food-list' %}" + '?query=' + query + '&limit=10').then((response) => {
|
this.$http.get("{% url 'api:food-list' %}" + '?query=' + query + '&limit=10').then((response) => {
|
||||||
this.foods = response.data
|
this.foods = response.data
|
||||||
//TODO add back code to include custom created ingredients
|
|
||||||
|
for (let s of this.recipe.steps){
|
||||||
|
for (let i of s.ingredients) {
|
||||||
|
if (i.food.id === undefined) {
|
||||||
|
this.foods.push(i.food)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
this.foods_loading = false
|
this.foods_loading = false
|
||||||
}).catch((err) => {
|
}).catch((err) => {
|
||||||
|
@ -101,8 +101,8 @@
|
|||||||
label="text"
|
label="text"
|
||||||
:taggable="true"
|
:taggable="true"
|
||||||
@tag="addUnitType"
|
@tag="addUnitType"
|
||||||
@open="openUnitSelect"
|
|
||||||
:id="'unit_' + index"
|
:id="'unit_' + index"
|
||||||
|
@open="openUnitSelect"
|
||||||
track-by="id"
|
track-by="id"
|
||||||
:multiple="false"
|
:multiple="false"
|
||||||
:loading="units_loading"
|
:loading="units_loading"
|
||||||
@ -127,6 +127,7 @@
|
|||||||
:options="ingredients"
|
:options="ingredients"
|
||||||
:taggable="true"
|
:taggable="true"
|
||||||
@tag="addIngredientType"
|
@tag="addIngredientType"
|
||||||
|
:id="'ingredient_' + index"
|
||||||
placeholder="{% trans 'Select one' %}"
|
placeholder="{% trans 'Select one' %}"
|
||||||
tag-placeholder="{% trans 'Select' %}"
|
tag-placeholder="{% trans 'Select' %}"
|
||||||
:close-on-select="true"
|
:close-on-select="true"
|
||||||
@ -134,7 +135,6 @@
|
|||||||
:allow-empty="false"
|
:allow-empty="false"
|
||||||
:preserve-search="true"
|
:preserve-search="true"
|
||||||
label="text"
|
label="text"
|
||||||
:id="'ingredient_' + index"
|
|
||||||
track-by="id"
|
track-by="id"
|
||||||
:multiple="false"
|
:multiple="false"
|
||||||
:loading="ingredients_loading"
|
:loading="ingredients_loading"
|
||||||
|
Reference in New Issue
Block a user