diff --git a/cookbook/admin.py b/cookbook/admin.py index 625b2a6bc..5c32c168e 100644 --- a/cookbook/admin.py +++ b/cookbook/admin.py @@ -177,8 +177,8 @@ admin.site.register(Keyword, KeywordAdmin) class StepAdmin(admin.ModelAdmin): - list_display = ('name', 'type', 'order') - search_fields = ('name', 'type') + list_display = ('name', 'order',) + search_fields = ('name',) admin.site.register(Step, StepAdmin) diff --git a/cookbook/migrations/0165_remove_step_type.py b/cookbook/migrations/0165_remove_step_type.py new file mode 100644 index 000000000..3eca515fc --- /dev/null +++ b/cookbook/migrations/0165_remove_step_type.py @@ -0,0 +1,17 @@ +# Generated by Django 3.2.11 on 2022-01-18 19:19 + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('cookbook', '0164_space_show_facet_count'), + ] + + operations = [ + migrations.RemoveField( + model_name='step', + name='type', + ), + ] diff --git a/cookbook/models.py b/cookbook/models.py index 6fc3fb30b..df6ec226f 100644 --- a/cookbook/models.py +++ b/cookbook/models.py @@ -576,17 +576,7 @@ class Ingredient(ExportModelOperationsMixin('ingredient'), models.Model, Permiss class Step(ExportModelOperationsMixin('step'), models.Model, PermissionModelMixin): - TEXT = 'TEXT' - TIME = 'TIME' - FILE = 'FILE' - RECIPE = 'RECIPE' - name = models.CharField(max_length=128, default='', blank=True) - type = models.CharField( - choices=((TEXT, _('Text')), (TIME, _('Time')), (FILE, _('File')), (RECIPE, _('Recipe')),), - default=TEXT, - max_length=16 - ) instruction = models.TextField(blank=True) ingredients = models.ManyToManyField(Ingredient, blank=True) time = models.IntegerField(default=0, blank=True) diff --git a/cookbook/serializer.py b/cookbook/serializer.py index 3584138c2..ad6015e70 100644 --- a/cookbook/serializer.py +++ b/cookbook/serializer.py @@ -481,7 +481,7 @@ class StepSerializer(WritableNestedModelSerializer, ExtendedRecipeMixin): class Meta: model = Step fields = ( - 'id', 'name', 'type', 'instruction', 'ingredients', 'ingredients_markdown', + 'id', 'name', 'instruction', 'ingredients', 'ingredients_markdown', 'ingredients_vue', 'time', 'order', 'show_as_header', 'file', 'step_recipe', 'step_recipe_data', 'numrecipe' ) diff --git a/vue/src/apps/RecipeEditView/RecipeEditView.vue b/vue/src/apps/RecipeEditView/RecipeEditView.vue index d8bf65a6c..f2fe4b21b 100644 --- a/vue/src/apps/RecipeEditView/RecipeEditView.vue +++ b/vue/src/apps/RecipeEditView/RecipeEditView.vue @@ -1,10 +1,12 @@ @@ -646,19 +682,26 @@ export default { loadRecipe: function () { let apiFactory = new ApiApiFactory() - apiFactory - .retrieveRecipe(this.recipe_id) - .then((response) => { - this.recipe = response.data - this.loading = false + apiFactory.retrieveRecipe(this.recipe_id).then((response) => { + this.recipe = response.data + this.loading = false - //TODO workaround function until view is properly refactored, loads name of selected sub recipe so the input can find its label - this.recipe.steps.forEach((s) => { - if (s.step_recipe != null) { - this.recipes.push(s.step_recipe_data) - } - }) + // set default visibility style for each component of the step + this.recipe.steps.forEach((s) => { + this.$set(s, 'time_visible', (s.time !== 0)) + this.$set(s, 'ingredients_visible', (s.ingredients.length > 0)) + this.$set(s, 'instruction_visible', (s.instruction !== '')) + this.$set(s, 'step_recipe_visible', (s.step_recipe !== null)) + this.$set(s, 'file_visible', (s.file !== null)) }) + + //TODO workaround function until view is properly refactored, loads name of selected sub recipe so the input can find its label + this.recipe.steps.forEach((s) => { + if (s.step_recipe != null) { + this.recipes.push(s.step_recipe_data) + } + }) + }) .catch((err) => { this.loading = false console.log(err) @@ -735,7 +778,16 @@ export default { }, addStep: function (step_index) { //TODO see if default can be generated from options request - let empty_step = {instruction: "", ingredients: [], type: "TEXT", show_as_header: true} + let empty_step = { + instruction: "", + ingredients: [], + show_as_header: true, + time_visible: false, + ingredients_visible: true, + instruction_visible: true, + step_recipe_visible: false, + file_visible: false + } if (step_index !== undefined) { console.log('adding at index', step_index) this.recipe.steps.splice(step_index + 1, 0, empty_step) diff --git a/vue/src/components/StepComponent.vue b/vue/src/components/StepComponent.vue index d02873de3..adc1d9300 100644 --- a/vue/src/components/StepComponent.vue +++ b/vue/src/components/StepComponent.vue @@ -1,126 +1,119 @@