diff --git a/app/assets/javascripts/protocols/steps.js.erb b/app/assets/javascripts/protocols/steps.js.erb index d259cb8f1..ae4cbd0fb 100644 --- a/app/assets/javascripts/protocols/steps.js.erb +++ b/app/assets/javascripts/protocols/steps.js.erb @@ -24,38 +24,6 @@ }); } - // Complete mymodule - function complete_my_module_actions() { - var modal = $('#completed-task-modal'); - - modal.find('[data-action="complete"]') - .off().on().click(function(event) { - event.stopPropagation(); - event.preventDefault(); - event.stopImmediatePropagation(); - $.ajax({ - url: modal.data('url'), - type: 'GET', - success: function(data) { - var task_button = $("[data-action='complete-task']"); - task_button.attr('data-action', 'uncomplete-task'); - task_button.find('.btn') - .removeClass('btn-toggle').addClass('btn-default'); - $('.task-due-date').html(data.module_header_due_date); - $('.task-state-label').html(data.module_state_label); - task_button - .find('button') - .html(' ' + - data.task_button_title); - modal.modal('hide'); - }, - error: function() { - modal.modal('hide'); - } - }); - }); - } - // Sets callback for completing/uncompleting step function applyStepCompletedCallBack() { // First, remove old event handlers, as we use turbolinks @@ -79,11 +47,6 @@ button.attr("data-action", "uncomplete-step"); button.find(".btn").removeClass("btn-toggle").addClass("btn-default"); button.find("button").html(' ' + data.new_title); - - if (data.task_ready_to_complete) { - $('#completed-task-modal').modal('show'); - complete_my_module_actions(); - } } else { step.addClass("not-completed").removeClass("completed"); diff --git a/app/assets/stylesheets/my_modules/status_flow.scss b/app/assets/stylesheets/my_modules/status_flow.scss index 0d26ea384..c82bfd9bb 100644 --- a/app/assets/stylesheets/my_modules/status_flow.scss +++ b/app/assets/stylesheets/my_modules/status_flow.scss @@ -22,7 +22,7 @@ align-items: center; display: grid; grid-template-columns: minmax(0, auto) 12px minmax(0, auto); - padding: .5em 0; + padding: .5em 0 0; li { display: contents; @@ -74,13 +74,23 @@ grid-column: span 3; line-height: 1em; padding: 0em 1em .5em; + + &:empty { + display: none; + } + + &.permission-error { + padding: .5em 1em; + } } #viewTaskFlow { + border-top: $border-default; cursor: pointer; display: list-item; grid-column: span 3; line-height: 2em; + margin-top: .5em; padding: .5em 1em; } } diff --git a/app/controllers/api/v1/tasks_controller.rb b/app/controllers/api/v1/tasks_controller.rb index b3b28bb85..635082f88 100644 --- a/app/controllers/api/v1/tasks_controller.rb +++ b/app/controllers/api/v1/tasks_controller.rb @@ -60,13 +60,13 @@ module Api def task_params_create raise TypeError unless params.require(:data).require(:type) == 'tasks' - params.require(:data).require(:attributes).permit(%i(name x y description state)) + params.require(:data).require(:attributes).permit(%i(name x y description)) end def task_params_update raise TypeError unless params.require(:data).require(:type) == 'tasks' - params.require(:data).require(:attributes).permit(%i(name x y description state my_module_status_id)) + params.require(:data).require(:attributes).permit(%i(name x y description my_module_status_id)) end def load_task_for_managing diff --git a/app/controllers/steps_controller.rb b/app/controllers/steps_controller.rb index fcd52c50e..c2075b2e5 100644 --- a/app/controllers/steps_controller.rb +++ b/app/controllers/steps_controller.rb @@ -321,10 +321,6 @@ class StepsController < ApplicationController @step.completed = completed if @step.save - if @protocol.in_module? - ready_to_complete = @protocol.my_module.check_completness_status - end - # Create activity if changed completed_steps = @protocol.steps.where(completed: true).count @@ -350,14 +346,7 @@ class StepsController < ApplicationController t('protocols.steps.options.uncomplete_title') end format.json do - if ready_to_complete && @protocol.my_module.uncompleted? - render json: { - task_ready_to_complete: true, - new_title: localized_title - }, status: :ok - else - render json: { new_title: localized_title }, status: :ok - end + render json: { new_title: localized_title }, status: :ok end else format.json { render json: {}, status: :unprocessable_entity } diff --git a/app/models/my_module.rb b/app/models/my_module.rb index 4b135931b..915695817 100644 --- a/app/models/my_module.rb +++ b/app/models/my_module.rb @@ -9,8 +9,6 @@ class MyModule < ApplicationRecord before_create :create_blank_protocol before_create :assign_default_status_flow - before_validation :set_completed, if: :my_module_status_id_changed? - before_validation :set_completed_on, if: :state_changed? before_save :exec_status_consequences, if: :my_module_status_id_changed? auto_strip_attributes :name, :description, nullify: false @@ -477,18 +475,6 @@ class MyModule < ApplicationRecord { x: 0, y: positions.last[1] + HEIGHT } end - # Check if my_module is ready to become completed - def check_completness_status - if protocol && protocol.steps.count > 0 - completed = true - protocol.steps.find_each do |step| - completed = false unless step.completed - end - return true if completed - end - false - end - def assign_user(user, assigned_by = nil) user_my_modules.create( assigned_by: assigned_by || user, @@ -506,22 +492,6 @@ class MyModule < ApplicationRecord private - def set_completed - return if my_module_status.blank? - - if my_module_status.final_status? - self.state = 'completed' - else - self.state = 'uncompleted' - end - end - - def set_completed_on - return if completed? && completed_on.present? - - self.completed_on = completed? ? DateTime.now : nil - end - def create_blank_protocol protocols << Protocol.new_blank_for_module(self) end diff --git a/app/models/my_module_status_consequences/completion.rb b/app/models/my_module_status_consequences/completion.rb new file mode 100644 index 000000000..4111f045c --- /dev/null +++ b/app/models/my_module_status_consequences/completion.rb @@ -0,0 +1,12 @@ +# frozen_string_literal: true + +# Just an example, to be replaced with an actual implementation +module MyModuleStatusConsequences + class Completion < MyModuleStatusConsequence + def call(my_module) + my_module.state = 'completed' + my_module.completed_on = DateTime.now + my_module.save! + end + end +end diff --git a/app/models/my_module_status_consequences/uncompletion.rb b/app/models/my_module_status_consequences/uncompletion.rb new file mode 100644 index 000000000..4d3a5e184 --- /dev/null +++ b/app/models/my_module_status_consequences/uncompletion.rb @@ -0,0 +1,14 @@ +# frozen_string_literal: true + +# Just an example, to be replaced with an actual implementation +module MyModuleStatusConsequences + class Uncompletion < MyModuleStatusConsequence + def call(my_module) + return unless my_module.state == 'completed' + + my_module.state = 'uncompleted' + my_module.completed_on = nil + my_module.save! + end + end +end diff --git a/app/views/my_modules/protocols.html.erb b/app/views/my_modules/protocols.html.erb index 6a89c4c32..882f6c144 100644 --- a/app/views/my_modules/protocols.html.erb +++ b/app/views/my_modules/protocols.html.erb @@ -26,7 +26,7 @@ <%= render partial: 'my_module_details' %>
- <%= render partial: 'my_modules/status_flow/task_flow_button', locals: { my_module: @my_module } if @my_module.my_module_status_flow && can_change_my_module_flow_status?(@my_module) %> + <%= render partial: 'my_modules/status_flow/task_flow_button', locals: { my_module: @my_module } if @my_module.my_module_status_flow %>
diff --git a/app/views/my_modules/status_flow/_task_flow_button.html.erb b/app/views/my_modules/status_flow/_task_flow_button.html.erb index 6cd25ddbd..2a5c80804 100644 --- a/app/views/my_modules/status_flow/_task_flow_button.html.erb +++ b/app/views/my_modules/status_flow/_task_flow_button.html.erb @@ -21,38 +21,38 @@