From a377624aee936f4e22500e7482ca622220617a3b Mon Sep 17 00:00:00 2001 From: Andrej Date: Mon, 24 Mar 2025 15:57:48 +0100 Subject: [PATCH] Add forms to print protocol [SCI-11648] --- .../layouts/print_protocol.sass.scss | 6 ++ app/views/layouts/protocols/print.html.erb | 1 + app/views/protocols/print.html.erb | 2 + .../print/_form_response_element.html.erb | 96 +++++++++++++++++++ .../print/element/_checkbox_button.html.erb | 6 ++ .../_form_choice_value_element.html.erb | 12 +++ ...form_datetime_field_value_element.html.erb | 28 ++++++ config/locales/en.yml | 3 + 8 files changed, 154 insertions(+) create mode 100644 app/views/protocols/print/_form_response_element.html.erb create mode 100644 app/views/protocols/print/element/_checkbox_button.html.erb create mode 100644 app/views/protocols/print/element/_form_choice_value_element.html.erb create mode 100644 app/views/protocols/print/element/_form_datetime_field_value_element.html.erb diff --git a/app/assets/stylesheets/layouts/print_protocol.sass.scss b/app/assets/stylesheets/layouts/print_protocol.sass.scss index 1c4ba9050..b064a8ce2 100644 --- a/app/assets/stylesheets/layouts/print_protocol.sass.scss +++ b/app/assets/stylesheets/layouts/print_protocol.sass.scss @@ -1,6 +1,8 @@ // scss-lint:disable SelectorDepth // scss-lint:disable NestingDepth +@import "sn-inter-font"; +@import "sn-icon-font"; @import "../shared_styles/constants"; @import "../constants"; @@ -294,3 +296,7 @@ hr { text-decoration: none; } } + +textarea { + resize: none; +} diff --git a/app/views/layouts/protocols/print.html.erb b/app/views/layouts/protocols/print.html.erb index fe823208a..96aed858e 100644 --- a/app/views/layouts/protocols/print.html.erb +++ b/app/views/layouts/protocols/print.html.erb @@ -10,6 +10,7 @@ <%= javascript_include_tag "handsontable.full" %> <%= render 'shared/formulas_libraries' %> <%= stylesheet_link_tag 'print_protocol', media: 'print, screen' %> + <%= stylesheet_link_tag 'tailwind', media: 'print, screen' %> <%= yield %>
<% end %>
+ <% when 'FormResponse' %> + <%= render partial: 'protocols/print/form_response_element', locals: { form_response: step_element.orderable }%> <% end %> <% end %> diff --git a/app/views/protocols/print/_form_response_element.html.erb b/app/views/protocols/print/_form_response_element.html.erb new file mode 100644 index 000000000..1372c8206 --- /dev/null +++ b/app/views/protocols/print/_form_response_element.html.erb @@ -0,0 +1,96 @@ +
+
+
+
+

<%= form_response.form.name %>

+ <% if form_response.status == 'submitted' %> +
+ <%= t('forms.response.submitted_on') %> <%= I18n.l(form_response.submitted_at, format: :full) %>
+ <%= t('forms.response.by') %> <%= form_response.submitted_by&.full_name %> +
+ <% else %> +
+ <%= t('forms.response.not_submitted') %> +
+ <% end %> +
+ <% form_response.form.form_fields.each do |field| %> +
+
+
+ <%= field.name %> + <% if field.data&.dig('unit') %> + (<%= field.data&.dig('unit') %>) + <% end %> + + <% case field.data.dig('type') %> + <% when 'SingleChoiceField' %> + <%= t("protocols.print.forms.single_choice_html") %> + <% when 'MultipleChoiceField' %> + <%= t("protocols.print.forms.multiple_choice_html") %> + <% end %> + + <% if field.required %> + * + <% end %> +
+ <% if field.description %> +
+ <%= field.description %> +
+ <% end %> + +
+ <% field_value = form_response.form_field_values.find_by(form_field_id: field.id, latest: true) %> + <% field_type = field.data.dig('type') %> + + <% case field_type %> + <% when 'TextField' %> +
+ +
+ + <% when 'NumberField' %> +
+ +
+ <% if field_value&.present? && !field_value&.value_in_range? %> +
+ <%= field&.data&.dig('validations', 'response_validation', 'message') %> +
+ <% end %> + + <% when 'DatetimeField' %> + <%= render partial: 'protocols/print/element/form_datetime_field_value_element', locals: { field: field, field_value: field_value } %> + + <% when 'SingleChoiceField' %> + <%= render partial: 'protocols/print/element/form_choice_value_element', locals: { field: field, selected_options: [field_value&.text] } %> + + <% when 'MultipleChoiceField' %> + <%= render partial: 'protocols/print/element/form_choice_value_element', locals: { field: field, selected_options: field_value&.selection } %> + + <% when 'ActionField' %> + <%= render partial: 'protocols/print/element/checkbox_button', locals: { value: field_value&.flag, description: I18n.t('forms.fields.mark_as_completed') } %> + <% end %> + +
+ <% if field_value&.submitted_at %> + + <%= I18n.t('forms.fields.submitted_by', date: I18n.l(field_value.submitted_at, format: :full), user: field_value.submitted_by&.full_name) %> + + <% end %> + + <% if field&.allow_not_applicable %> + <%= render partial: 'protocols/print/element/checkbox_button', locals: { value: field_value&.not_applicable, description: I18n.t('forms.fields.mark_as_na') } %> + <% end %> +
+
+
+
+ <% end%> +
+
diff --git a/app/views/protocols/print/element/_checkbox_button.html.erb b/app/views/protocols/print/element/_checkbox_button.html.erb new file mode 100644 index 000000000..157ca1863 --- /dev/null +++ b/app/views/protocols/print/element/_checkbox_button.html.erb @@ -0,0 +1,6 @@ + diff --git a/app/views/protocols/print/element/_form_choice_value_element.html.erb b/app/views/protocols/print/element/_form_choice_value_element.html.erb new file mode 100644 index 000000000..b4259f75f --- /dev/null +++ b/app/views/protocols/print/element/_form_choice_value_element.html.erb @@ -0,0 +1,12 @@ +<% field&.data&.dig('options')&.each do |option| %> + +<% end %> diff --git a/app/views/protocols/print/element/_form_datetime_field_value_element.html.erb b/app/views/protocols/print/element/_form_datetime_field_value_element.html.erb new file mode 100644 index 000000000..a3ea4faad --- /dev/null +++ b/app/views/protocols/print/element/_form_datetime_field_value_element.html.erb @@ -0,0 +1,28 @@ +<% if field&.data&.dig('range') %> +
+ <% [field_value&.datetime, field_value&.datetime_to].each_with_index do |date, index| %> +
+ + + + <% if date %> + <%= I18n.l(date, format: field&.data['time'] ? :full : :full_date) %> + <% end %> + + +
+ <%= '-' if index === 0 %> + <% end %> +
+<% else %> +
+ + + + <% if field_value&.datetime %> + <%= I18n.l(field_value.datetime, format: field.data['time'] ? :full : :full_date) %> + <% end %> + + +
+<% end %> diff --git a/config/locales/en.yml b/config/locales/en.yml index 53c666426..0d34bd110 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -3583,6 +3583,9 @@ en: header: printed_from: "Printed from" print_info: "on %{datetime} by %{full_name}" + forms: + single_choice_html: "(Select one)" + multiple_choice_html: "(Select multiple)" protocols_io_import: title_too_long: "... Text is too long so we had to cut it off." too_long: "... Text is too long so we had to cut it off."