\ No newline at end of file
diff --git a/app/javascript/vue/protocol/step_components/table.vue b/app/javascript/vue/protocol/step_components/table.vue
new file mode 100644
index 000000000..9c744d468
--- /dev/null
+++ b/app/javascript/vue/protocol/step_components/table.vue
@@ -0,0 +1,11 @@
+
+
+ Table
+
+
+
+
\ No newline at end of file
diff --git a/app/javascript/vue/protocol/step_components/text.vue b/app/javascript/vue/protocol/step_components/text.vue
new file mode 100644
index 000000000..10825cc0c
--- /dev/null
+++ b/app/javascript/vue/protocol/step_components/text.vue
@@ -0,0 +1,11 @@
+
+
+ Text
+
+
+
+
\ No newline at end of file
diff --git a/app/models/step_orderable_element.rb b/app/models/step_orderable_element.rb
index 01e282ebc..1f8081142 100644
--- a/app/models/step_orderable_element.rb
+++ b/app/models/step_orderable_element.rb
@@ -6,7 +6,7 @@ class StepOrderableElement < ApplicationRecord
around_destroy :decrement_following_elements_positions
- belongs_to :step, inverse_of: :step_oerderable_elements, touch: true
+ belongs_to :step, inverse_of: :step_orderable_elements, touch: true
belongs_to :orderable, polymorphic: true, inverse_of: :step_orderable_elements
private
diff --git a/app/models/step_text.rb b/app/models/step_text.rb
index e19805d9d..dff232a91 100644
--- a/app/models/step_text.rb
+++ b/app/models/step_text.rb
@@ -4,7 +4,6 @@ class StepText < ApplicationRecord
include TinyMceImages
auto_strip_attributes :text, nullify: false
- validates :text, presence: true
validates :text, length: { maximum: Constants::RICH_TEXT_MAX_LENGTH }
belongs_to :step, inverse_of: :step_texts, touch: true
diff --git a/app/serializers/checklist_serializer.rb b/app/serializers/checklist_serializer.rb
new file mode 100644
index 000000000..e087236fd
--- /dev/null
+++ b/app/serializers/checklist_serializer.rb
@@ -0,0 +1,5 @@
+# frozen_string_literal: true
+
+class ChecklistSerializer < ActiveModel::Serializer
+ attributes :name
+end
diff --git a/app/serializers/step_orderable_element_serializer.rb b/app/serializers/step_orderable_element_serializer.rb
new file mode 100644
index 000000000..b36b44b2f
--- /dev/null
+++ b/app/serializers/step_orderable_element_serializer.rb
@@ -0,0 +1,16 @@
+# frozen_string_literal: true
+
+class StepOrderableElementSerializer < ActiveModel::Serializer
+ attributes :position, :element, :orderable_type
+
+ def element
+ case object.orderable_type
+ when 'Checklist'
+ ChecklistSerializer
+ when 'StepTable'
+ StepTableSerializer
+ when 'StepText'
+ StepTextSerializer
+ end
+ end
+end
diff --git a/app/serializers/step_serializer.rb b/app/serializers/step_serializer.rb
index 3fa75c0cf..3636dff1a 100644
--- a/app/serializers/step_serializer.rb
+++ b/app/serializers/step_serializer.rb
@@ -7,7 +7,11 @@ class StepSerializer < ActiveModel::Serializer
{
delete_url: step_path(object),
state_url: toggle_step_state_step_path(object),
- update_url: step_path(object)
+ update_url: step_path(object),
+ elements_url: elements_step_path(object),
+ create_table_url: step_tables_path(object),
+ create_text_url: step_texts_path(object),
+ create_checklist_url: step_checklists_path(object)
}
end
end
diff --git a/app/serializers/step_table_serializer.rb b/app/serializers/step_table_serializer.rb
new file mode 100644
index 000000000..5aa4d8d70
--- /dev/null
+++ b/app/serializers/step_table_serializer.rb
@@ -0,0 +1,5 @@
+# frozen_string_literal: true
+
+class StepTableSerializer < ActiveModel::Serializer
+ attributes :name
+end
diff --git a/app/serializers/step_text_serializer.rb b/app/serializers/step_text_serializer.rb
new file mode 100644
index 000000000..d916477eb
--- /dev/null
+++ b/app/serializers/step_text_serializer.rb
@@ -0,0 +1,5 @@
+# frozen_string_literal: true
+
+class StepTextSerializer < ActiveModel::Serializer
+ attributes :text
+end
diff --git a/config/locales/en.yml b/config/locales/en.yml
index ebf198065..10dd0f723 100644
--- a/config/locales/en.yml
+++ b/config/locales/en.yml
@@ -2512,6 +2512,17 @@ en:
comments: "Comments"
empty_checklist: "No items"
comment_title: "%{user} at %{time}:"
+ insert:
+ button: 'Insert'
+ title: 'insert content'
+ table: 'Add table'
+ text: 'Add text'
+ checklist: 'Add checklist'
+ table:
+ default_name: 'Table %{position}'
+ checklist:
+ default_name: 'Checklist %{position}'
+
options:
up_arrow_title: "Move step up"
down_arrow_title: "Move step down"
diff --git a/config/routes.rb b/config/routes.rb
index 274e479f3..0a0e2e642 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -448,7 +448,12 @@ Rails.application.routes.draw do
resources :step_comments,
path: '/comments',
only: %i(create index update destroy)
+
+ resources :tables, controller: 'step_components/tables', only: :create
+ resources :texts, controller: 'step_components/texts', only: :create
+ resources :checklists, controller: 'step_components/checklists', only: :create
member do
+ get 'elements'
post 'checklistitem_state'
post 'toggle_step_state'
put 'move_down'
diff --git a/db/migrate/20220429083335_generate_step_orderable_relation.rb b/db/migrate/20220429083335_generate_step_orderable_relation.rb
new file mode 100644
index 000000000..0c75d887b
--- /dev/null
+++ b/db/migrate/20220429083335_generate_step_orderable_relation.rb
@@ -0,0 +1,33 @@
+# frozen_string_literal: true
+
+require File.expand_path('app/helpers/database_helper')
+class GenerateStepOrderableRelation < ActiveRecord::Migration[6.1]
+ include DatabaseHelper
+
+ def up
+ Step.find_in_batches(batch_size: 100) do |steps|
+ steps.each do |step|
+ position = 0
+ orderable_elements = []
+ step.step_texts.each do |text|
+ orderable_elements << step.step_orderable_elements.new(orderable: text, position: position)
+ position += 1
+ end
+ step.step_tables.each do |table|
+ orderable_elements << step.step_orderable_elements.new(orderable: table, position: position)
+ position += 1
+ end
+ step.checklists.each do |checklist|
+ orderable_elements << step.step_orderable_elements.new(orderable: checklist, position: position)
+ position += 1
+ end
+
+ StepOrderableElement.import(orderable_elements)
+ end
+ end
+ end
+
+ def down
+ StepOrderableElement.destroy_all
+ end
+end