mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-03-03 19:24:48 +08:00
refactor steps annotation
This commit is contained in:
parent
bb437bd8c5
commit
f16607579f
5 changed files with 33 additions and 289 deletions
|
@ -524,6 +524,7 @@ function onClickSave() {
|
|||
|
||||
// First fetch all the data in input fields
|
||||
data = {
|
||||
request_url: $('#samples').data('current-uri'),
|
||||
sample_id: $(selectedSample).attr("id"),
|
||||
sample: {},
|
||||
custom_fields: {}, // These fields are not currently bound to this sample
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
class SamplesController < ApplicationController
|
||||
include InputSanitizeHelper
|
||||
include ActionView::Helpers::TextHelper
|
||||
include ApplicationHelper
|
||||
|
||||
before_action :load_vars, only: [:edit, :update, :destroy, :show]
|
||||
before_action :load_vars_nested, only: [:new, :create]
|
||||
|
@ -82,6 +84,8 @@ class SamplesController < ApplicationController
|
|||
errors[:custom_fields] << {
|
||||
"#{id}": scf.errors.messages
|
||||
}
|
||||
else
|
||||
sample_annotation_notification(sample, scf)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -198,6 +202,7 @@ class SamplesController < ApplicationController
|
|||
scf = SampleCustomField.where("custom_field_id = ? AND sample_id = ?", id, sample.id).take
|
||||
|
||||
if scf
|
||||
old_text = scv.value
|
||||
# Well, client was naughty, no XMAS for him this year, update
|
||||
# existing SCF instead of creating new one
|
||||
scf.value = val
|
||||
|
@ -207,6 +212,8 @@ class SamplesController < ApplicationController
|
|||
errors[:custom_fields] << {
|
||||
"#{id}": scf.errors.messages
|
||||
}
|
||||
else
|
||||
sample_annotation_notification(sample, scf, old_text)
|
||||
end
|
||||
else
|
||||
# SCF doesn't exist, create it
|
||||
|
@ -220,6 +227,8 @@ class SamplesController < ApplicationController
|
|||
errors[:custom_fields] << {
|
||||
"#{id}": scf.errors.messages
|
||||
}
|
||||
else
|
||||
sample_annotation_notification(sample, scf)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -235,6 +244,7 @@ class SamplesController < ApplicationController
|
|||
if val.empty?
|
||||
scf_to_delete << scf
|
||||
else
|
||||
old_text = scf.value
|
||||
# SCF exists, update away
|
||||
scf.value = val
|
||||
|
||||
|
@ -242,6 +252,8 @@ class SamplesController < ApplicationController
|
|||
errors[:sample_custom_fields] << {
|
||||
"#{id}": scf.errors.messages
|
||||
}
|
||||
else
|
||||
sample_annotation_notification(sample, scf, old_text)
|
||||
end
|
||||
end
|
||||
else
|
||||
|
@ -331,4 +343,19 @@ class SamplesController < ApplicationController
|
|||
:sample_group_id
|
||||
)
|
||||
end
|
||||
|
||||
def sample_annotation_notification(sample, scf, old_text = nil)
|
||||
table_url = params.fetch(:request_url) { :request_url_must_be_present }
|
||||
smart_annotation_notification(
|
||||
old_text: (old_text if old_text),
|
||||
new_text: scf.value,
|
||||
title: t('notifications.sample_annotation_title',
|
||||
user: current_user.full_name,
|
||||
column: scf.custom_field.name,
|
||||
sample: sample.name),
|
||||
message: t('notifications.sample_annotation_message_html',
|
||||
sample: link_to(sample.name, table_url),
|
||||
column: link_to(scf.custom_field.name, table_url))
|
||||
)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
class StepsController < ApplicationController
|
||||
include ActionView::Helpers::TextHelper
|
||||
include ApplicationHelper
|
||||
include StepsActions
|
||||
|
||||
before_action :load_vars, only: [:edit, :update, :destroy, :show]
|
||||
before_action :load_vars_nested, only: [:new, :create]
|
||||
|
@ -686,293 +687,4 @@ class StepsController < ApplicationController
|
|||
]
|
||||
)
|
||||
end
|
||||
|
||||
# generates notification for smart annotations
|
||||
def create_annotation_notification(step)
|
||||
# step description
|
||||
smart_annotation_notification(
|
||||
new_text: step.description,
|
||||
title: t('notifications.step_description_title',
|
||||
user: current_user.full_name,
|
||||
step: step.name),
|
||||
message: t('notifications.step_annotation_message_html',
|
||||
project: link_to(
|
||||
step.my_module.experiment.project.name,
|
||||
project_url(step.my_module.experiment.project)
|
||||
),
|
||||
my_module: link_to(
|
||||
step.my_module.name,
|
||||
protocols_my_module_url(step.my_module)
|
||||
),
|
||||
step: link_to(
|
||||
step.name,
|
||||
protocols_my_module_url(step.my_module)
|
||||
))
|
||||
)
|
||||
# checklists
|
||||
step.checklists.each do |checklist|
|
||||
smart_annotation_notification(
|
||||
new_text: checklist.name,
|
||||
title: t('notifications.checklist_title',
|
||||
user: current_user.full_name,
|
||||
step: step.name),
|
||||
message: t('notifications.step_annotation_message_html',
|
||||
project: link_to(
|
||||
step.my_module.experiment.project.name,
|
||||
project_url(step.my_module.experiment.project)
|
||||
),
|
||||
my_module: link_to(
|
||||
step.my_module.name,
|
||||
protocols_my_module_url(step.my_module)
|
||||
),
|
||||
step: link_to(
|
||||
step.name,
|
||||
protocols_my_module_url(step.my_module)
|
||||
))
|
||||
)
|
||||
checklist.checklist_items.each do |checklist_item|
|
||||
smart_annotation_notification(
|
||||
new_text: checklist_item.text,
|
||||
title: t('notifications.checklist_title',
|
||||
user: current_user.full_name,
|
||||
step: step.name),
|
||||
message: t('notifications.step_annotation_message_html',
|
||||
project: link_to(
|
||||
step.my_module.experiment.project.name,
|
||||
project_url(step.my_module.experiment.project)
|
||||
),
|
||||
my_module: link_to(
|
||||
step.my_module.name,
|
||||
protocols_my_module_url(step.my_module)
|
||||
),
|
||||
step: link_to(
|
||||
step.name,
|
||||
protocols_my_module_url(step.my_module)
|
||||
))
|
||||
)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def fetch_new_checklists_data
|
||||
checklists = []
|
||||
new_checklists = step_params[:checklists_attributes]
|
||||
|
||||
if new_checklists
|
||||
new_checklists.each do |e|
|
||||
list = PreviouseChecklist.new(
|
||||
e.second[:id].to_i,
|
||||
e.second[:name]
|
||||
)
|
||||
if e.second[:checklist_items_attributes]
|
||||
e.second[:checklist_items_attributes].each do |el|
|
||||
list.add_checklist(
|
||||
PreviouseChecklistItem.new(el.second[:id].to_i, el.second[:text])
|
||||
)
|
||||
end
|
||||
end
|
||||
checklists << list
|
||||
end
|
||||
end
|
||||
checklists
|
||||
end
|
||||
|
||||
def fetch_old_checklists_data(step)
|
||||
checklists = []
|
||||
if step.checklists
|
||||
step.checklists.each do |e|
|
||||
list = PreviouseChecklist.new(
|
||||
e.id,
|
||||
e.name
|
||||
)
|
||||
e.checklist_items.each do |el|
|
||||
list.add_checklist(
|
||||
PreviouseChecklistItem.new(el.id, el.text)
|
||||
)
|
||||
end
|
||||
checklists << list
|
||||
end
|
||||
end
|
||||
checklists
|
||||
end
|
||||
|
||||
def update_annotation_notification(step,
|
||||
old_description,
|
||||
new_checklists,
|
||||
old_checklists)
|
||||
smart_annotation_notification(
|
||||
old_text: old_description,
|
||||
new_text: step.description,
|
||||
title: t('notifications.step_description_title',
|
||||
user: current_user.full_name,
|
||||
step: step.name),
|
||||
message: t('notifications.step_annotation_message_html',
|
||||
project: link_to(
|
||||
step.my_module.experiment.project.name,
|
||||
project_url(step.my_module.experiment.project)
|
||||
),
|
||||
my_module: link_to(
|
||||
step.my_module.name,
|
||||
protocols_my_module_url(step.my_module)
|
||||
),
|
||||
step: link_to(
|
||||
step.name,
|
||||
protocols_my_module_url(step.my_module)
|
||||
))
|
||||
)
|
||||
|
||||
new_checklists.each do |e|
|
||||
# generates smart annotaion if the checklist is new
|
||||
add_new_checklist(step, e) if e.id.zero?
|
||||
smart_annotation_notification(
|
||||
new_text: e.name,
|
||||
title: t('notifications.checklist_title',
|
||||
user: current_user.full_name,
|
||||
step: step.name),
|
||||
message: t('notifications.step_annotation_message_html',
|
||||
project: link_to(
|
||||
step.my_module.experiment.project.name,
|
||||
project_url(step.my_module.experiment.project)
|
||||
),
|
||||
my_module: link_to(
|
||||
step.my_module.name,
|
||||
protocols_my_module_url(step.my_module)
|
||||
),
|
||||
step: link_to(
|
||||
step.name,
|
||||
protocols_my_module_url(step.my_module)
|
||||
))
|
||||
) unless e.id
|
||||
# else check if checklist is not deleted and generates
|
||||
# new notifications
|
||||
next unless old_checklists.map(&:id).include?(e.id)
|
||||
old_checklist = old_checklists.select { |i| i.id == e.id }.first
|
||||
smart_annotation_notification(
|
||||
old_text: (old_checklist.name if old_checklist),
|
||||
new_text: e.name,
|
||||
title: t('notifications.checklist_title',
|
||||
user: current_user.full_name,
|
||||
step: step.name),
|
||||
message: t('notifications.step_annotation_message_html',
|
||||
project: link_to(
|
||||
step.my_module.experiment.project.name,
|
||||
project_url(step.my_module.experiment.project)
|
||||
),
|
||||
my_module: link_to(
|
||||
step.my_module.name,
|
||||
protocols_my_module_url(step.my_module)
|
||||
),
|
||||
step: link_to(
|
||||
step.name,
|
||||
protocols_my_module_url(step.my_module)
|
||||
))
|
||||
)
|
||||
e.items.each do |ci|
|
||||
old_list = old_checklists.select { |i| i.id == e.id }.first
|
||||
old_item = old_list.items.select { |i| i.id == ci.id }.first if old_list
|
||||
|
||||
smart_annotation_notification(
|
||||
old_text: (old_item.text if old_item),
|
||||
new_text: ci.text,
|
||||
title: t('notifications.checklist_title',
|
||||
user: current_user.full_name,
|
||||
step: step.name),
|
||||
message: t('notifications.step_annotation_message_html',
|
||||
project: link_to(
|
||||
step.my_module.experiment.project.name,
|
||||
project_url(step.my_module.experiment.project)
|
||||
),
|
||||
my_module: link_to(
|
||||
step.my_module.name,
|
||||
protocols_my_module_url(step.my_module)
|
||||
),
|
||||
step: link_to(
|
||||
step.name,
|
||||
protocols_my_module_url(step.my_module)
|
||||
))
|
||||
)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def add_new_checklist(step, checklist)
|
||||
smart_annotation_notification(
|
||||
new_text: checklist.name,
|
||||
title: t('notifications.checklist_title',
|
||||
user: current_user.full_name,
|
||||
step: step.name),
|
||||
message: t('notifications.step_annotation_message_html',
|
||||
project: link_to(
|
||||
step.my_module.experiment.project.name,
|
||||
project_url(step.my_module.experiment.project)
|
||||
),
|
||||
my_module: link_to(
|
||||
step.my_module.name,
|
||||
protocols_my_module_url(step.my_module)
|
||||
),
|
||||
step: link_to(
|
||||
step.name,
|
||||
protocols_my_module_url(step.my_module)
|
||||
))
|
||||
)
|
||||
|
||||
checklist.items.each do |ci|
|
||||
smart_annotation_notification(
|
||||
new_text: ci.text,
|
||||
title: t('notifications.checklist_title',
|
||||
user: current_user.full_name,
|
||||
step: step.name),
|
||||
message: t('notifications.step_annotation_message_html',
|
||||
project: link_to(
|
||||
step.my_module.experiment.project.name,
|
||||
project_url(step.my_module.experiment.project)
|
||||
),
|
||||
my_module: link_to(
|
||||
step.my_module.name,
|
||||
protocols_my_module_url(step.my_module)
|
||||
),
|
||||
step: link_to(
|
||||
step.name,
|
||||
protocols_my_module_url(step.my_module)
|
||||
))
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
PreviouseChecklistItem = Struct.new(:id, :text)
|
||||
PreviouseChecklist = Struct.new(:id, :name, :items) do
|
||||
def initialize(id, name, items = [])
|
||||
super(id, name, items)
|
||||
end
|
||||
|
||||
def add_checklist(item)
|
||||
items << item
|
||||
end
|
||||
end
|
||||
|
||||
# def update_annotation_notification(step, updated_step)
|
||||
# # step description
|
||||
# smart_annotation_notification(
|
||||
# old_text:
|
||||
# new_text: updated_step.description,
|
||||
# title: t('notifications.step_description_title'),
|
||||
# message: t('notifications.step_description_message')
|
||||
# )
|
||||
# # checklists
|
||||
# updated_step.checklists.each do |checklist|
|
||||
# smart_annotation_notification(
|
||||
#
|
||||
# new_text: checklist.name,
|
||||
# title: t('notifications.checklist_title'),
|
||||
# message: t('notifications.checklist_message')
|
||||
# )
|
||||
# checklist.checklist_items.each do |checklist_item|
|
||||
# smart_annotation_notification(
|
||||
# new_text: checklist_item.text,
|
||||
# title: t('notifications.checklist_item_title'),
|
||||
# message: t('notifications.checklist_item_message')
|
||||
# )
|
||||
# end
|
||||
# end
|
||||
# end
|
||||
end
|
||||
|
|
|
@ -125,6 +125,7 @@
|
|||
|
||||
<div class="samples-table">
|
||||
<table id="samples" class="table"
|
||||
data-current-uri="<%= request.original_url %>"
|
||||
data-team-id="<%= @project.team.id %>"
|
||||
data-user-id="<%= @current_user.id %>"
|
||||
data-source="<%= @samples_index_link %>"
|
||||
|
|
|
@ -1523,6 +1523,9 @@ en:
|
|||
result_annotation_title: "%{user} mentioned you in result %{result}."
|
||||
result_comment_annotation_title: "%{user} mentioned you in result %{result} comment."
|
||||
result_annotation_message_html: "Project: %{project} | Task: %{my_module}"
|
||||
sample_annotation_title: "%{user} mentioned you in Column: %{column} of Sample %{sample}"
|
||||
sample_annotation_message_html: "Sample: %{sample} | Column: %{column}"
|
||||
protocol_step_annotation_message_html: "Protocol: %{protocol}"
|
||||
email_title: "You've received a sciNote notification!"
|
||||
assign_user_to_team: "<i>%{assigned_user}</i> was added as %{role} to team <strong>%{team}</strong> by <i>%{assigned_by_user}</i>."
|
||||
unassign_user_from_team: "<i>%{unassigned_user}</i> was removed from team <strong>%{team}</strong> by <i>%{unassigned_by_user}</i>."
|
||||
|
|
Loading…
Reference in a new issue