mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-10-06 11:57:16 +08:00
Add notifications for forms smart annotations [SCI-11710]
This commit is contained in:
parent
cc79bad19e
commit
bdaa65b82a
4 changed files with 35 additions and 1 deletions
|
@ -1,6 +1,7 @@
|
||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
class FormFieldValuesController < ApplicationController
|
class FormFieldValuesController < ApplicationController
|
||||||
|
include ApplicationHelper
|
||||||
before_action :check_forms_enabled
|
before_action :check_forms_enabled
|
||||||
before_action :load_form_response
|
before_action :load_form_response
|
||||||
before_action :load_form_field
|
before_action :load_form_field
|
||||||
|
@ -15,6 +16,7 @@ class FormFieldValuesController < ApplicationController
|
||||||
)
|
)
|
||||||
|
|
||||||
log_form_field_value_create_activity
|
log_form_field_value_create_activity
|
||||||
|
form_field_value_annotation if @form_field_value.is_a?(FormTextFieldValue)
|
||||||
|
|
||||||
render json: @form_field_value, serializer: FormFieldValueSerializer, user: current_user
|
render json: @form_field_value, serializer: FormFieldValueSerializer, user: current_user
|
||||||
end
|
end
|
||||||
|
@ -45,6 +47,19 @@ class FormFieldValuesController < ApplicationController
|
||||||
render_404 unless Form.forms_enabled?
|
render_404 unless Form.forms_enabled?
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def form_field_value_annotation
|
||||||
|
step = @form_response.step
|
||||||
|
smart_annotation_notification(
|
||||||
|
old_text: @form_field_value.text_previously_was,
|
||||||
|
new_text: @form_field_value.text,
|
||||||
|
subject: step.protocol,
|
||||||
|
title: t('notifications.form_field_value_title',
|
||||||
|
user: current_user.full_name,
|
||||||
|
field: @form_field_value.form_field.name,
|
||||||
|
step: step.name)
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
def log_form_field_value_create_activity
|
def log_form_field_value_create_activity
|
||||||
step = @form_response.step
|
step = @form_response.step
|
||||||
protocol = step.protocol
|
protocol = step.protocol
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
class FormFieldsController < ApplicationController
|
class FormFieldsController < ApplicationController
|
||||||
|
include ApplicationHelper
|
||||||
before_action :check_forms_enabled
|
before_action :check_forms_enabled
|
||||||
before_action :load_form
|
before_action :load_form
|
||||||
before_action :load_form_field, only: %i(update destroy duplicate)
|
before_action :load_form_field, only: %i(update destroy duplicate)
|
||||||
|
@ -21,6 +22,7 @@ class FormFieldsController < ApplicationController
|
||||||
|
|
||||||
if @form_field.save
|
if @form_field.save
|
||||||
log_activity(:form_block_added, block_name: @form_field.name)
|
log_activity(:form_block_added, block_name: @form_field.name)
|
||||||
|
form_field_annotation
|
||||||
render json: @form_field, serializer: FormFieldSerializer, user: current_user
|
render json: @form_field, serializer: FormFieldSerializer, user: current_user
|
||||||
else
|
else
|
||||||
render json: { error: @form_field.errors.full_messages }, status: :unprocessable_entity
|
render json: { error: @form_field.errors.full_messages }, status: :unprocessable_entity
|
||||||
|
@ -31,6 +33,7 @@ class FormFieldsController < ApplicationController
|
||||||
def update
|
def update
|
||||||
ActiveRecord::Base.transaction do
|
ActiveRecord::Base.transaction do
|
||||||
if @form_field.update(form_field_params.merge({ last_modified_by: current_user }))
|
if @form_field.update(form_field_params.merge({ last_modified_by: current_user }))
|
||||||
|
form_field_annotation
|
||||||
log_activity(:form_block_edited, block_name: @form_field.name)
|
log_activity(:form_block_edited, block_name: @form_field.name)
|
||||||
render json: @form_field, serializer: FormFieldSerializer, user: current_user
|
render json: @form_field, serializer: FormFieldSerializer, user: current_user
|
||||||
else
|
else
|
||||||
|
@ -97,6 +100,18 @@ class FormFieldsController < ApplicationController
|
||||||
render_403 unless @form && can_manage_form_draft?(@form)
|
render_403 unless @form && can_manage_form_draft?(@form)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def form_field_annotation
|
||||||
|
smart_annotation_notification(
|
||||||
|
old_text: @form_field.description_previously_was,
|
||||||
|
new_text: @form_field.description,
|
||||||
|
subject: @form,
|
||||||
|
title: t('notifications.form_field_title',
|
||||||
|
user: current_user.full_name,
|
||||||
|
field: @form_field.name,
|
||||||
|
form: @form.name)
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
def form_field_params
|
def form_field_params
|
||||||
params.require(:form_field).permit(:name, :description, { data: [:type, :unit, :time, :range, validations: {}, options: []] }, :required, :allow_not_applicable, :uid)
|
params.require(:form_field).permit(:name, :description, { data: [:type, :unit, :time, :range, validations: {}, options: []] }, :required, :allow_not_applicable, :uid)
|
||||||
end
|
end
|
||||||
|
|
|
@ -77,10 +77,12 @@ module BreadcrumbsHelper
|
||||||
when Team
|
when Team
|
||||||
parent = nil
|
parent = nil
|
||||||
url = projects_path(team: subject.id)
|
url = projects_path(team: subject.id)
|
||||||
|
when Form
|
||||||
|
parent = subject.team
|
||||||
|
url = form_path(subject, team: subject.team_id)
|
||||||
end
|
end
|
||||||
|
|
||||||
breadcrumbs << { name: subject.name, code: subject.try(:code), url:} if subject.name.present?
|
breadcrumbs << { name: subject.name, code: subject.try(:code), url:} if subject.name.present?
|
||||||
|
|
||||||
if parent
|
if parent
|
||||||
generate_breadcrumbs(parent, breadcrumbs)
|
generate_breadcrumbs(parent, breadcrumbs)
|
||||||
else
|
else
|
||||||
|
|
|
@ -4137,6 +4137,8 @@ en:
|
||||||
my_module_consumption_comment_annotation_message_html: "Project: %{project} | Experiment: %{experiment} | Task: %{my_module}"
|
my_module_consumption_comment_annotation_message_html: "Project: %{project} | Experiment: %{experiment} | Task: %{my_module}"
|
||||||
step_comment_annotation_title: "%{user} mentioned you in a comment on step %{step}."
|
step_comment_annotation_title: "%{user} mentioned you in a comment on step %{step}."
|
||||||
step_description_title: "%{user} mentioned you in a description on step %{step}."
|
step_description_title: "%{user} mentioned you in a description on step %{step}."
|
||||||
|
form_field_title: "%{user} mentioned you in a %{field} in form %{form}."
|
||||||
|
form_field_value_title: "%{user} mentioned you in a %{field} in step %{step}."
|
||||||
checklist_title: "%{user} mentioned you in a checklist on step %{step}."
|
checklist_title: "%{user} mentioned you in a checklist on step %{step}."
|
||||||
step_text_title: "%{user} mentioned you in a text on step %{step}."
|
step_text_title: "%{user} mentioned you in a text on step %{step}."
|
||||||
step_table_title: "%{user} mentioned you in a table on step %{step}."
|
step_table_title: "%{user} mentioned you in a table on step %{step}."
|
||||||
|
|
Loading…
Add table
Reference in a new issue