mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-10-09 21:36:44 +08:00
Add Completion and Uncompletion consequences [SCI-5004]
This commit is contained in:
parent
51d69f9442
commit
73cf620960
6 changed files with 29 additions and 81 deletions
|
@ -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('<span class="fas fa-times"></span> ' +
|
|
||||||
data.task_button_title);
|
|
||||||
modal.modal('hide');
|
|
||||||
},
|
|
||||||
error: function() {
|
|
||||||
modal.modal('hide');
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
// Sets callback for completing/uncompleting step
|
// Sets callback for completing/uncompleting step
|
||||||
function applyStepCompletedCallBack() {
|
function applyStepCompletedCallBack() {
|
||||||
// First, remove old event handlers, as we use turbolinks
|
// First, remove old event handlers, as we use turbolinks
|
||||||
|
@ -79,11 +47,6 @@
|
||||||
button.attr("data-action", "uncomplete-step");
|
button.attr("data-action", "uncomplete-step");
|
||||||
button.find(".btn").removeClass("btn-toggle").addClass("btn-default");
|
button.find(".btn").removeClass("btn-toggle").addClass("btn-default");
|
||||||
button.find("button").html('<span class="fas fa-times"></span> ' + data.new_title);
|
button.find("button").html('<span class="fas fa-times"></span> ' + data.new_title);
|
||||||
|
|
||||||
if (data.task_ready_to_complete) {
|
|
||||||
$('#completed-task-modal').modal('show');
|
|
||||||
complete_my_module_actions();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
step.addClass("not-completed").removeClass("completed");
|
step.addClass("not-completed").removeClass("completed");
|
||||||
|
|
|
@ -321,10 +321,6 @@ class StepsController < ApplicationController
|
||||||
@step.completed = completed
|
@step.completed = completed
|
||||||
|
|
||||||
if @step.save
|
if @step.save
|
||||||
if @protocol.in_module?
|
|
||||||
ready_to_complete = @protocol.my_module.check_completness_status
|
|
||||||
end
|
|
||||||
|
|
||||||
# Create activity
|
# Create activity
|
||||||
if changed
|
if changed
|
||||||
completed_steps = @protocol.steps.where(completed: true).count
|
completed_steps = @protocol.steps.where(completed: true).count
|
||||||
|
@ -350,15 +346,8 @@ class StepsController < ApplicationController
|
||||||
t('protocols.steps.options.uncomplete_title')
|
t('protocols.steps.options.uncomplete_title')
|
||||||
end
|
end
|
||||||
format.json do
|
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
|
render json: { new_title: localized_title }, status: :ok
|
||||||
end
|
end
|
||||||
end
|
|
||||||
else
|
else
|
||||||
format.json { render json: {}, status: :unprocessable_entity }
|
format.json { render json: {}, status: :unprocessable_entity }
|
||||||
end
|
end
|
||||||
|
|
|
@ -9,8 +9,6 @@ class MyModule < ApplicationRecord
|
||||||
before_create :create_blank_protocol
|
before_create :create_blank_protocol
|
||||||
before_create :assign_default_status_flow
|
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?
|
before_save :exec_status_consequences, if: :my_module_status_id_changed?
|
||||||
|
|
||||||
auto_strip_attributes :name, :description, nullify: false
|
auto_strip_attributes :name, :description, nullify: false
|
||||||
|
@ -477,18 +475,6 @@ class MyModule < ApplicationRecord
|
||||||
{ x: 0, y: positions.last[1] + HEIGHT }
|
{ x: 0, y: positions.last[1] + HEIGHT }
|
||||||
end
|
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)
|
def assign_user(user, assigned_by = nil)
|
||||||
user_my_modules.create(
|
user_my_modules.create(
|
||||||
assigned_by: assigned_by || user,
|
assigned_by: assigned_by || user,
|
||||||
|
@ -506,22 +492,6 @@ class MyModule < ApplicationRecord
|
||||||
|
|
||||||
private
|
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
|
def create_blank_protocol
|
||||||
protocols << Protocol.new_blank_for_module(self)
|
protocols << Protocol.new_blank_for_module(self)
|
||||||
end
|
end
|
||||||
|
|
12
app/models/my_module_status_consequences/completion.rb
Normal file
12
app/models/my_module_status_consequences/completion.rb
Normal file
|
@ -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
|
14
app/models/my_module_status_consequences/uncompletion.rb
Normal file
14
app/models/my_module_status_consequences/uncompletion.rb
Normal file
|
@ -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
|
|
@ -327,7 +327,7 @@ class Extends
|
||||||
|
|
||||||
DEFAULT_FLOW_STATUSES = [
|
DEFAULT_FLOW_STATUSES = [
|
||||||
{ name: 'Not started', color: '#406d86' },
|
{ name: 'Not started', color: '#406d86' },
|
||||||
{ name: 'In progress', color: '#0065ff' },
|
{ name: 'In progress', color: '#0065ff', consequences: ['MyModuleStatusConsequences::Uncompletion'] },
|
||||||
{ name: 'Completed', color: '#00b900' }
|
{ name: 'Completed', color: '#00b900', consequences: ['MyModuleStatusConsequences::Completion'] }
|
||||||
]
|
]
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Reference in a new issue