Add notifications for forms smart annotations [SCI-11710]

This commit is contained in:
Anton 2025-03-24 18:25:37 +01:00
parent cc79bad19e
commit bdaa65b82a
4 changed files with 35 additions and 1 deletions

View file

@ -1,6 +1,7 @@
# frozen_string_literal: true
class FormFieldValuesController < ApplicationController
include ApplicationHelper
before_action :check_forms_enabled
before_action :load_form_response
before_action :load_form_field
@ -15,6 +16,7 @@ class FormFieldValuesController < ApplicationController
)
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
end
@ -45,6 +47,19 @@ class FormFieldValuesController < ApplicationController
render_404 unless Form.forms_enabled?
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
step = @form_response.step
protocol = step.protocol

View file

@ -1,6 +1,7 @@
# frozen_string_literal: true
class FormFieldsController < ApplicationController
include ApplicationHelper
before_action :check_forms_enabled
before_action :load_form
before_action :load_form_field, only: %i(update destroy duplicate)
@ -21,6 +22,7 @@ class FormFieldsController < ApplicationController
if @form_field.save
log_activity(:form_block_added, block_name: @form_field.name)
form_field_annotation
render json: @form_field, serializer: FormFieldSerializer, user: current_user
else
render json: { error: @form_field.errors.full_messages }, status: :unprocessable_entity
@ -31,6 +33,7 @@ class FormFieldsController < ApplicationController
def update
ActiveRecord::Base.transaction do
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)
render json: @form_field, serializer: FormFieldSerializer, user: current_user
else
@ -97,6 +100,18 @@ class FormFieldsController < ApplicationController
render_403 unless @form && can_manage_form_draft?(@form)
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
params.require(:form_field).permit(:name, :description, { data: [:type, :unit, :time, :range, validations: {}, options: []] }, :required, :allow_not_applicable, :uid)
end

View file

@ -77,10 +77,12 @@ module BreadcrumbsHelper
when Team
parent = nil
url = projects_path(team: subject.id)
when Form
parent = subject.team
url = form_path(subject, team: subject.team_id)
end
breadcrumbs << { name: subject.name, code: subject.try(:code), url:} if subject.name.present?
if parent
generate_breadcrumbs(parent, breadcrumbs)
else

View file

@ -4137,6 +4137,8 @@ en:
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_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}."
step_text_title: "%{user} mentioned you in a text on step %{step}."
step_table_title: "%{user} mentioned you in a table on step %{step}."