From f3b10bcb0eb61f0db8197366768cb02d492f488a Mon Sep 17 00:00:00 2001 From: Dan Garland Date: Tue, 22 Dec 2020 15:29:01 +0000 Subject: [PATCH 1/5] using form styleguide --- Gemfile | 2 +- Gemfile.lock | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Gemfile b/Gemfile index 9880d2a2..c07f4cae 100644 --- a/Gemfile +++ b/Gemfile @@ -26,7 +26,7 @@ gem 'validates_timeliness' gem 'paranoia', '~> 2.2' gem 'browser', require: 'browser/browser' gem 'activerecord-import' -gem 'camden_style_guide', '0.2.1', git: 'https://github.com/wearefuturegov/camden-style-guide.git' +gem 'camden_style_guide', '0.3.0', git: 'https://github.com/wearefuturegov/camden-style-guide.git' group :development, :test do gem 'byebug', platforms: [:mri, :mingw, :x64_mingw] diff --git a/Gemfile.lock b/Gemfile.lock index 6f39dc7b..d148d6e8 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,8 +1,8 @@ GIT remote: https://github.com/wearefuturegov/camden-style-guide.git - revision: 7225feda3203575e1847e8aa49dd83207ce94844 + revision: 0ac45ca25e2d1e8c2bd9a924ef32ff62526a7592 specs: - camden_style_guide (0.2.1) + camden_style_guide (0.3.0) rails (~> 6.0.2, >= 6.0.2.2) webpacker (~> 4) @@ -383,7 +383,7 @@ DEPENDENCIES bootsnap (>= 1.4.2) browser byebug - camden_style_guide (= 0.2.1)! + camden_style_guide (= 0.3.0)! capybara (>= 2.15) csv cucumber-rails From 36b899db1ca0b7fde4c9535aacaeab219880c641 Mon Sep 17 00:00:00 2001 From: Dan Garland Date: Wed, 23 Dec 2020 11:37:49 +0000 Subject: [PATCH 2/5] Using a default class called 'form' on form helpers The legacy css was using generic selectors for form elements, e.g. input[type="text"] which was adding unwanted styles to new form layouts. This commit monkey patches the form helpers to set a default css class of 'form' on form helper elements, and the form scss is now scoped with that class, so existing forms ought to work as before and new forms start with clean css. Once all the forms have been migrated to the style guide then these files can be deleted. --- app/assets/stylesheets/forms.scss | 538 ++++++++++++----------- app/helpers/application_helper.rb | 1 + config/initializers/form_monkey_patch.rb | 1 + lib/form_helper.rb | 27 ++ lib/monkey_patches/form_helper.rb | 27 ++ 5 files changed, 326 insertions(+), 268 deletions(-) create mode 100644 config/initializers/form_monkey_patch.rb create mode 100644 lib/form_helper.rb create mode 100644 lib/monkey_patches/form_helper.rb diff --git a/app/assets/stylesheets/forms.scss b/app/assets/stylesheets/forms.scss index 1f81b477..bc430263 100644 --- a/app/assets/stylesheets/forms.scss +++ b/app/assets/stylesheets/forms.scss @@ -1,307 +1,309 @@ @import "variables"; -.field-section{ - border: none; - margin: 0; - padding: 0; - margin-bottom: 45px; - .field-section__title{ - font-size: 1.1rem; - margin-bottom: 25px; - } - .field-section__hint{ - grid-column: 1 / 3; - margin-top: 15px; - } - - .field:last-child{ - margin-bottom: 0px; - } +.legacy-form { + .field-section{ + border: none; + margin: 0; + padding: 0; + margin-bottom: 45px; + .field-section__title{ + font-size: 1.1rem; + margin-bottom: 25px; + } + .field-section__hint{ + grid-column: 1 / 3; + margin-top: 15px; + } - .checkbox { - margin-bottom: 20px; - } -} + .field:last-child{ + margin-bottom: 0px; + } -.field-section--two-cols{ - display: grid; - grid-template-columns: 1fr 1fr; - grid-column-gap: 35px; -} -.field-section--four-cols{ - display: grid; - grid-template-columns: 1fr 1fr 1fr 1fr; - grid-column-gap: 35px; - legend { - margin-bottom: 20px; + .checkbox { + margin-bottom: 20px; + } } -} -.field-section-small{ - @extend .field-section; - margin-bottom: 0; - &.field-section--two-cols{ - display: grid; - grid-template-columns: 1fr 1fr; - grid-column-gap: 15px; - } -} - -.field{ - margin-bottom: 35px; - .field__label{ - display: inline-block; - font-weight: 500; - font-size: 0.9rem; - margin-bottom: 7px; - } - .field__label-top{ - @extend .field__label; - display: block !important; + .field-section--two-cols{ + display: grid; + grid-template-columns: 1fr 1fr; + grid-column-gap: 35px; } - &.field--span-two-cols{ - grid-column: 1 / 3; + .field-section--four-cols{ + display: grid; + grid-template-columns: 1fr 1fr 1fr 1fr; + grid-column-gap: 35px; + legend { + margin-bottom: 20px; + } } -} + .field-section-small{ + @extend .field-section; + margin-bottom: 0; + &.field-section--two-cols{ + display: grid; + grid-template-columns: 1fr 1fr; + grid-column-gap: 15px; + } + } -.field-small{ - @extend .field; - margin-bottom: 10px; -} - -:disabled+label { - color: darkgray; -} + .field{ + margin-bottom: 35px; + .field__label{ + display: inline-block; + font-weight: 500; + font-size: 0.9rem; + margin-bottom: 7px; + } + .field__label-top{ + @extend .field__label; + display: block !important; + } + &.field--span-two-cols{ + grid-column: 1 / 3; + } + } -select{ - font-size: 1rem; - padding: 10px; - display: block; - background: $pale; - border: none; -} -input[type=text], -input[type=email], -input[type=number], -input[type=date], -textarea{ - font-size: 1.2rem; - padding: 10px; - display: block; - background: transparentize($pale, 0.5); - border: none; - border-bottom: 1px solid $text; - width: 100%; - &:focus{ - border-color: $yellow; - background: transparentize($yellow, 0.9) - } - &:invalid{ - outline: none; - border-color: $red; - background: transparentize($red, 0.9) + .field-small{ + @extend .field; + margin-bottom: 10px; } -} -.radio{ - position: relative; - padding: 10px 0 10px 50px; - &:focus-within label:before{ - box-shadow: 0 0 0 2px $yellow; + :disabled+label { + color: darkgray; } - input{ - font-size: 2rem; - -webkit-appearance:none; - width:35px; - height:35px; - position: absolute; - left: 0; - top: 0; - &:checked + label:after{ - position: absolute; - content: ""; + + select{ + font-size: 1rem; + padding: 10px; display: block; - height: 27px; - width: 27px; - left: 6px; - top: 6px; - background-color: $text; - border-radius: 100%; - } + background: $pale; + border: none; } - .radio__label{ - cursor: pointer; - color: $text; - &:before{ - content: ""; - display: inline-block; - background: $white; - border: 2px solid $text; - width: 35px; - border-radius: 100%; - height: 35px; - position: absolute; - left: 0; - top: 0; - } - } - &.radio-spacing-small { - padding-top: 2px; - padding-bottom: 20px; - padding-left: 35px; - input { - width: 0; - height: 0; - &:checked + label:after { - width: 12px; - height: 12px; + + input[type=text], + input[type=email], + input[type=number], + input[type=date], + textarea{ + font-size: 1.2rem; + padding: 10px; + display: block; + background: transparentize($pale, 0.5); + border: none; + border-bottom: 1px solid $text; + width: 100%; + &:focus{ + border-color: $yellow; + background: transparentize($yellow, 0.9) } - } - .radio__label { - &:before { - width: 20px; - height: 20px; + &:invalid{ + outline: none; + border-color: $red; + background: transparentize($red, 0.9) } - } } -} -.checkbox{ - position: relative; - padding: 10px 0px 10px 50px; - &:focus-within label:before{ - outline: 2px solid $yellow; - } - input{ - font-size: 2rem; - -webkit-appearance:none; - width:35px; - height:35px; - position: absolute; - left: 0px; - top: 0px; - &:checked + label{ - &:before{ - background-color: $blue; - border-color: $blue; + .radio{ + position: relative; + padding: 10px 0 10px 50px; + &:focus-within label:before{ + box-shadow: 0 0 0 2px $yellow; } - &:after{ + input{ + font-size: 2rem; + -webkit-appearance:none; + width:35px; + height:35px; position: absolute; - content: ""; - display: block; - height: 24px; - width: 24px; - left: 8px; - top: 8px; - background-size: contain; - background-repeat: no-repeat; - background-position: center; - background-image: url(asset_path('white-tick.svg')); - } - } + left: 0; + top: 0; + &:checked + label:after{ + position: absolute; + content: ""; + display: block; + height: 27px; + width: 27px; + left: 6px; + top: 6px; + background-color: $text; + border-radius: 100%; + } + } + .radio__label{ + cursor: pointer; + color: $text; + &:before{ + content: ""; + display: inline-block; + background: $white; + border: 2px solid $text; + width: 35px; + border-radius: 100%; + height: 35px; + position: absolute; + left: 0; + top: 0; + } + } + &.radio-spacing-small { + padding-top: 2px; + padding-bottom: 20px; + padding-left: 35px; + input { + width: 0; + height: 0; + &:checked + label:after { + width: 12px; + height: 12px; + } + } + .radio__label { + &:before { + width: 20px; + height: 20px; + } + } + } } - .checkbox__label{ - cursor: pointer; - color: $text; - &:before{ - content: ""; - display: inline-block; - background: $white; - border: 2px solid $text; - width: 35px; - height: 35px; - position: absolute; - left: 0px; - top: 0px; - } + + .checkbox{ + position: relative; + padding: 10px 0px 10px 50px; + &:focus-within label:before{ + outline: 2px solid $yellow; + } + input{ + font-size: 2rem; + -webkit-appearance:none; + width:35px; + height:35px; + position: absolute; + left: 0px; + top: 0px; + &:checked + label{ + &:before{ + background-color: $blue; + border-color: $blue; + } + &:after{ + position: absolute; + content: ""; + display: block; + height: 24px; + width: 24px; + left: 8px; + top: 8px; + background-size: contain; + background-repeat: no-repeat; + background-position: center; + background-image: url(asset_path('white-tick.svg')); + } + } + } + .checkbox__label{ + cursor: pointer; + color: $text; + &:before{ + content: ""; + display: inline-block; + background: $white; + border: 2px solid $text; + width: 35px; + height: 35px; + position: absolute; + left: 0px; + top: 0px; + } + } } -} -.checkbox-black{ - @extend .checkbox; - input{ - &:checked + label{ - &:before{ - background-color: $white; - border-color: black; - } - &:after{ - background-image: url(asset_path('black-tick.svg')); + .checkbox-black{ + @extend .checkbox; + input{ + &:checked + label{ + &:before{ + background-color: $white; + border-color: black; + } + &:after{ + background-image: url(asset_path('black-tick.svg')); + } + } } } - } -} -.radios, .checkboxes{ - border: none; - margin: 0; - padding: 0; - margin-bottom: 45px; - display: grid; - grid-template-columns: 1fr 1fr; - grid-column-gap: 35px; - legend{ - font-size: 0.9rem; - font-weight: 500; - margin-bottom: 10px; - } - *:last-child{ - margin-bottom: 0px; - } -} + .radios, .checkboxes{ + border: none; + margin: 0; + padding: 0; + margin-bottom: 45px; + display: grid; + grid-template-columns: 1fr 1fr; + grid-column-gap: 35px; + legend{ + font-size: 0.9rem; + font-weight: 500; + margin-bottom: 10px; + } + *:last-child{ + margin-bottom: 0px; + } + } -.error{ - padding: 25px; - border-left: 5px solid $red; - background: transparentize($red, 0.9); - margin-bottom: 25px; - grid-column: 1 / 3; - li{ - padding-left: 10px; - margin-bottom: 7px; - &:last-of-type{ - margin-bottom: 0px; + .error{ + padding: 25px; + border-left: 5px solid $red; + background: transparentize($red, 0.9); + margin-bottom: 25px; + grid-column: 1 / 3; + li{ + padding-left: 10px; + margin-bottom: 7px; + &:last-of-type{ + margin-bottom: 0px; + } + } + } + .assessment-buttons-right{ + margin-top: 20px; + margin-bottom: 60px; } - } -} -.assessment-buttons-right{ - margin-top: 20px; - margin-bottom: 60px; -} -.panel-buttons-right{ - position: relative; - float: right; - font-size: 0.9rem; - margin: -10px -10px 10px 20px; -} -.contact-edit-link{ - margin-left: auto; - margin-bottom: 0px; - margin-right: 0px !important; -} + .panel-buttons-right{ + position: relative; + float: right; + font-size: 0.9rem; + margin: -10px -10px 10px 20px; + } + .contact-edit-link{ + margin-left: auto; + margin-bottom: 0px; + margin-right: 0px !important; + } -.accordion-buttons-right{ - position: relative; - float: right; - font-size: 0.9rem; - margin: 20px 20px 20px 20px; -} + .accordion-buttons-right{ + position: relative; + float: right; + font-size: 0.9rem; + margin: 20px 20px 20px 20px; + } -.contact-back-top-link{ - position: relative; - float: right; - font-size: 0.9rem; - margin: 0px 0px 30px 0px; -} + .contact-back-top-link{ + position: relative; + float: right; + font-size: 0.9rem; + margin: 0px 0px 30px 0px; + } -.btn-right{ - margin-left: auto; - margin-bottom: 0px; - margin-right: 0px !important; + .btn-right{ + margin-left: auto; + margin-bottom: 0px; + margin-right: 0px !important; + } } diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index a640c366..6bb74823 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -1,3 +1,4 @@ +# coding: utf-8 # frozen_string_literal: true module ApplicationHelper diff --git a/config/initializers/form_monkey_patch.rb b/config/initializers/form_monkey_patch.rb new file mode 100644 index 00000000..351c6527 --- /dev/null +++ b/config/initializers/form_monkey_patch.rb @@ -0,0 +1 @@ +require './lib/monkey_patches/form_helper' diff --git a/lib/form_helper.rb b/lib/form_helper.rb new file mode 100644 index 00000000..65fce534 --- /dev/null +++ b/lib/form_helper.rb @@ -0,0 +1,27 @@ +module ActionView + module Helpers + module FormHelper + LEGACY_CLASS_NAME = 'legacy-form'.freeze + alias_method :rails_form_with, :form_with + alias_method :rails_form_for, :form_for + + def form_with(**options, &block) + rails_form_with(**options_with_default(options), &block) + end + + + def form_for(record, **options, &block) + rails_form_for(record, **options_with_default(options), &block) + end + + private + def options_with_default(options) + unless options[:html] && options[:html][:class].present? + options.merge(html: { class: LEGACY_CLASS_NAME }) + else + options + end + end + end + end +end diff --git a/lib/monkey_patches/form_helper.rb b/lib/monkey_patches/form_helper.rb new file mode 100644 index 00000000..811e6120 --- /dev/null +++ b/lib/monkey_patches/form_helper.rb @@ -0,0 +1,27 @@ +module ActionView + module Helpers + module FormHelper + LEGACY_CLASS_NAME = 'legacy-form'.freeze + alias rails_form_with form_with + alias rails_form_for form_for + + def form_with(**options, &block) + rails_form_with(**options_with_default(options), &block) + end + + def form_for(record, **options, &block) + rails_form_for(record, **options_with_default(options), &block) + end + + private + + def options_with_default(options) + if options[:html] && options[:html][:class].present? + options + else + options.merge(html: { class: LEGACY_CLASS_NAME }) + end + end + end + end +end From 0efcc69747fe0fec718cde564aafc2f46c6622b9 Mon Sep 17 00:00:00 2001 From: Dan Garland Date: Wed, 23 Dec 2020 11:53:20 +0000 Subject: [PATCH 3/5] Styling new schedule page --- app/controllers/assessments_controller.rb | 8 +- app/javascript/packs/need-actions.js | 12 +- app/views/assessments/new.html.erb | 158 ++++++++++++---------- app/views/needs/_need-actions.html.erb | 58 ++++---- 4 files changed, 129 insertions(+), 107 deletions(-) diff --git a/app/controllers/assessments_controller.rb b/app/controllers/assessments_controller.rb index c8a6c39b..88e40463 100644 --- a/app/controllers/assessments_controller.rb +++ b/app/controllers/assessments_controller.rb @@ -173,14 +173,12 @@ def log_assessment def schedule_assessment @need = Need.new(assessment_params.merge(contact_id: @contact.id)) @note = Note.new - unless @need.valid? + unless @need.save @assigned_to_options = construct_assigned_to_options render :new - return + else + redirect_to contact_path(@contact) end - - @need.save - redirect_to contact_path(@contact) end def type_param diff --git a/app/javascript/packs/need-actions.js b/app/javascript/packs/need-actions.js index 3af8ab48..6a92aec0 100644 --- a/app/javascript/packs/need-actions.js +++ b/app/javascript/packs/need-actions.js @@ -4,5 +4,13 @@ const form = $("form.need-actions-form"); const formDropdowns = form.find(".dropdown"); formDropdowns.select2(); formDropdowns.on("select2:select", () => { - form.submit(); -}); \ No newline at end of file + form.submit(); +}); + +$(document).on("turbolinks:load", () => { + $(".submit-on-change").change(e => { + $(e.currentTarget) + .closest("form") + .submit(); + }); +}); diff --git a/app/views/assessments/new.html.erb b/app/views/assessments/new.html.erb index 8db7f10e..91cf1863 100644 --- a/app/views/assessments/new.html.erb +++ b/app/views/assessments/new.html.erb @@ -2,90 +2,100 @@
-<%= render 'shared/side-contact-profile' %> + <%= render 'shared/side-contact-profile' %> - +
+ <%= f.radio_button :category, 'triage'%> + <%= f.label :category_triage, "Triage" %> +
+
+ <%= f.radio_button :category, 'check in'%> + <%= f.label :category_check_in, "Check in" %> +
+
+ <%= f.radio_button :category, 'mdt review'%> + <%= f.label :category_mdt_review, "MDT review" %> +
+ + +
+ <%= f.label :name, "Description" %> +
+ <%= f.text_field :name, placeholder: 'Describe how we can help' %> +
+
+ <% if @type == 'log' %> + <%= f.fields_for :note, @note do |notes_fields| %> +
+ <%= notes_fields.text_area :body, placeholder: 'Call notes' %> +
+ <% end %> + <% elsif @type == 'schedule' %> +
+ <%= f.label :start_on, "When should the call be scheduled for?" %> +
+ <%= f.text_field :start_on, autocomplete: 'off', placeholder: 'Date (e.g. 25/04/2020)' %> +
+
+ <% end %> + <%= f.button class: "c-btn c-btn--primary u-mt" do %> + Save to profile + + <% end %> + <% end %> +
+ + <%= javascript_pack_tag 'assessments' %> <%= javascript_pack_tag 'assessment_datepicker' %> -<%= javascript_pack_tag 'users_viewing_page.js' %> \ No newline at end of file +<%= javascript_pack_tag 'users_viewing_page.js' %> diff --git a/app/views/needs/_need-actions.html.erb b/app/views/needs/_need-actions.html.erb index 5f5d4e44..34132621 100644 --- a/app/views/needs/_need-actions.html.erb +++ b/app/views/needs/_need-actions.html.erb @@ -1,33 +1,39 @@ -<%= form_with(model: @need, local: true, class: "need-actions-form") do |f| %> -
- <%= f.hidden_field :lock_version, :value => @need.lock_version %> +<%= form_with(model: @need, local: true, class: "camden-form") do |f| %> + <%= f.hidden_field :lock_version, :value => @need.lock_version %> -
- <%= f.label :assigned_to, 'Assigned to', class: 'need-actions__label dropdown-label' %> - <%= f.select :assigned_to, - options_for_select([['Assigned to me','assigned-to-me'], ['Unassigned', '']], (@need.assigned_to.nil?) ? '' : nil) + - grouped_options_for_select(@assigned_to_options, @need.assigned_to, prompt: nil), - {}, { class: "need-actions__select dropdown dropdown-autocomplete" } %> -
+
+
+ <%= f.label :assigned_to, 'Assigned to'%> +
+ <%= f.select :assigned_to, options_for_select([['Assigned to me','assigned-to-me'], ['Unassigned', '']], (@need.assigned_to.nil?) ? '' : nil) + grouped_options_for_select(@assigned_to_options, @need.assigned_to, prompt: nil), { class: 'submit-on-change' } %> +
+
-
- <%= f.label :is_urgent, 'Priority', class: 'need-actions__label dropdown-label' %> - <%= f.select :is_urgent, { - "Urgent" => true, - "Normal" => false - }, {}, { class: @need.is_urgent ? "need-actions__select need-actions__select--red dropdown" : "need-actions__select dropdown", "data-minimum-results-for-search" => "Infinity" } %> -
+
+ <%= f.label :is_urgent, 'Priority'%> +
+ <%= f.select :is_urgent, { + "Urgent" => true, + "Normal" => false + }, {}, { class: "submit-on-change", "data-minimum-results-for-search" => "Infinity" } %> +
+
-
- <%= f.label :status, 'Status', class: 'need-actions__label dropdown-label' %> - <%= f.select :status, need_statuses, {}, { class: "need-actions__select dropdown", "data-minimum-results-for-search" => "Infinity" } %> -
-
+
+ <%= f.label :status, 'Status'%> +
+ <%= f.select :status, need_statuses, {}, { class: "submit-on-change", "data-minimum-results-for-search" => "Infinity" } %> +
+
+
-
- <%= f.check_box :send_email, {class: 'bulk-action-checkbox', checked: false, id: "send-email"}, 'true', 'false' %> - <%= label_tag :send_email, 'Send notification email?', id: "send-email-label" %> -
+
+ <%= f.check_box :send_email, {}, 'true', 'false' %> + <%= f.label :send_email, 'Send notification email?' %> +
<% end %> + + <%= javascript_pack_tag 'need-actions', 'data-turbolinks-track': 'reload' %> From 80067cfb0af67e07fc94424f5a7b271d7a6b278e Mon Sep 17 00:00:00 2001 From: Dan Garland Date: Wed, 23 Dec 2020 16:01:28 +0000 Subject: [PATCH 4/5] Rubocop --- app/controllers/assessments_controller.rb | 6 +++--- app/helpers/application_helper.rb | 1 - lib/form_helper.rb | 12 ++++++------ 3 files changed, 9 insertions(+), 10 deletions(-) diff --git a/app/controllers/assessments_controller.rb b/app/controllers/assessments_controller.rb index 88e40463..5cd23567 100644 --- a/app/controllers/assessments_controller.rb +++ b/app/controllers/assessments_controller.rb @@ -173,11 +173,11 @@ def log_assessment def schedule_assessment @need = Need.new(assessment_params.merge(contact_id: @contact.id)) @note = Note.new - unless @need.save + if @need.save + redirect_to contact_path(@contact) + else @assigned_to_options = construct_assigned_to_options render :new - else - redirect_to contact_path(@contact) end end diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 6bb74823..a640c366 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -1,4 +1,3 @@ -# coding: utf-8 # frozen_string_literal: true module ApplicationHelper diff --git a/lib/form_helper.rb b/lib/form_helper.rb index 65fce534..811e6120 100644 --- a/lib/form_helper.rb +++ b/lib/form_helper.rb @@ -2,24 +2,24 @@ module ActionView module Helpers module FormHelper LEGACY_CLASS_NAME = 'legacy-form'.freeze - alias_method :rails_form_with, :form_with - alias_method :rails_form_for, :form_for + alias rails_form_with form_with + alias rails_form_for form_for def form_with(**options, &block) rails_form_with(**options_with_default(options), &block) end - def form_for(record, **options, &block) rails_form_for(record, **options_with_default(options), &block) end private + def options_with_default(options) - unless options[:html] && options[:html][:class].present? - options.merge(html: { class: LEGACY_CLASS_NAME }) - else + if options[:html] && options[:html][:class].present? options + else + options.merge(html: { class: LEGACY_CLASS_NAME }) end end end From 696822f75efcd92fd1c22dc8d85e0ec2d0b01806 Mon Sep 17 00:00:00 2001 From: Dan Garland Date: Wed, 23 Dec 2020 19:08:13 +0000 Subject: [PATCH 5/5] Fixing cukes --- app/controllers/assessments_controller.rb | 27 ++++++++----------- app/models/need.rb | 1 + app/views/assessments/assign.html.erb | 4 +-- app/views/assessments/new.html.erb | 7 +++-- app/views/shared/_create-need-errors.erb | 7 ++--- features/step_definitions/assessment_steps.rb | 11 +++----- .../assessments/complete_assessment_steps.rb | 3 +-- .../assessments/fail_assessment_steps.rb | 3 +-- .../assignment_emails_steps.rb | 11 +++++--- .../edit_support_actions_steps.rb | 10 +++---- .../support_actions_list_steps.rb | 2 +- 11 files changed, 39 insertions(+), 47 deletions(-) diff --git a/app/controllers/assessments_controller.rb b/app/controllers/assessments_controller.rb index 5cd23567..874a3522 100644 --- a/app/controllers/assessments_controller.rb +++ b/app/controllers/assessments_controller.rb @@ -41,7 +41,7 @@ def new @type = %w[log schedule].include?(type_param) ? type_param : 'log' @need = Need.new - @note = Note.new + @need.notes.build(category: 'phone_success', user_id: current_user.id) @need.status = 'complete' if @type == 'log' @need.user = current_user if @type == 'log' @@ -50,6 +50,7 @@ def new def create authorize Need @type = %w[log schedule].include?(type_param) ? type_param : 'log' + if @type == 'log' log_assessment else @@ -68,11 +69,11 @@ def fail def update_failure Rails.logger.unknown("User updated failed assignment for assessment ID: #{params[:id]}") @failure_form = AssessmentFailureForm.new(assessment_failure_params.merge(id: params[:id])) - if @failure_form.valid? && @failure_form.save(current_user) + if @failure_form.save(current_user) redirect_to need_path(@assessment), notice: 'Record successfully updated.' - return + else + render :fail end - render :fail end def assign @@ -159,15 +160,13 @@ def find_contact_id; end def log_assessment @need = Need.new(assessment_params.merge(contact_id: @contact.id, start_on: Date.today)) - notes_permit_params = notes_params.merge(need: @need, category: 'phone_success', user_id: current_user.id) - @note = Note.new(notes_permit_params) - if @need.valid? && @need.save && (notes_permit_params[:body].empty? || @note.valid? && @need.save && @note.save) + if @need.save redirect_to contact_path(@contact) - return - end + else + @assigned_to_options = construct_assigned_to_options - @assigned_to_options = construct_assigned_to_options - render :new + render :new + end end def schedule_assessment @@ -186,7 +185,7 @@ def type_param end def assessment_params - params.require(:need).permit(:assigned_to, :name, :is_urgent, :status, :category, :status, :start_on, :assessment_id, :send_email) + params.require(:need).permit(:assigned_to, :name, :is_urgent, :status, :category, :status, :start_on, :assessment_id, :send_email, { :note => [:body, :category, :user_id] }) end def assessment_failure_params @@ -205,10 +204,6 @@ def assessment_completion_params params.require(:assessment_completion_form).permit(:completion_method, :completion_note, :next_check_in_date, :next_check_in_description, :mdt_review_is_urgent, :mdt_review_note) end - def notes_params - params.require(:note).permit(:body) - end - def contact_params params.require(:contact).permit(:first_name, :middle_names, :surname, :date_of_birth, :nhs_number, :address, :postcode, :email, :telephone, :mobile, :additional_info, :is_vulnerable, :count_people_in_house, :any_children_under_age, diff --git a/app/models/need.rb b/app/models/need.rb index 0f67ab94..5ecbdbb3 100644 --- a/app/models/need.rb +++ b/app/models/need.rb @@ -16,6 +16,7 @@ class Need < ApplicationRecord belongs_to :user, optional: true belongs_to :role, optional: true has_many :notes, dependent: :destroy + accepts_nested_attributes_for :notes has_paper_trail diff --git a/app/views/assessments/assign.html.erb b/app/views/assessments/assign.html.erb index 49599095..9893ad8f 100644 --- a/app/views/assessments/assign.html.erb +++ b/app/views/assessments/assign.html.erb @@ -43,7 +43,7 @@ Priority Assigned Status - Send notification email + Send notification email? @@ -87,4 +87,4 @@ -<%= javascript_pack_tag 'assessment_assignment' %> \ No newline at end of file +<%= javascript_pack_tag 'assessment_assignment' %> diff --git a/app/views/assessments/new.html.erb b/app/views/assessments/new.html.erb index 91cf1863..3522d128 100644 --- a/app/views/assessments/new.html.erb +++ b/app/views/assessments/new.html.erb @@ -19,8 +19,9 @@
<%= render "shared/create-need-errors" %> - <%= form_with(model: @need, url: contact_assessments_path, local: true, class: "camden-form") do |f| %> + <%= form_with(model: @need, url: contact_assessments_path, local: true, html: { class: "camden-form" }) do |f| %> <%= f.hidden_field :lock_version, :value => @need.lock_version %> + <%= hidden_field_tag :type, params[:type] %>
@@ -72,9 +73,11 @@
<% if @type == 'log' %> - <%= f.fields_for :note, @note do |notes_fields| %> + <%= f.fields_for :notes do |notes_fields| %>
<%= notes_fields.text_area :body, placeholder: 'Call notes' %> + <%= notes_fields.hidden_field :category %> + <%= notes_fields.hidden_field :user_id %>
<% end %> <% elsif @type == 'schedule' %> diff --git a/app/views/shared/_create-need-errors.erb b/app/views/shared/_create-need-errors.erb index 077bee8f..9ed127ad 100644 --- a/app/views/shared/_create-need-errors.erb +++ b/app/views/shared/_create-need-errors.erb @@ -1,4 +1,4 @@ -<% if @need.errors.any? || @note&.errors.any? %> +<% if @need.errors.any? %>

<%= pluralize(@need.errors.count + (@note&.errors&.count || 0), "error") %> prohibited from being saved:

@@ -6,9 +6,6 @@ <% @need.errors.full_messages.each do |message| %>
  • <%= message.downcase %>
  • <% end %> - <% @note && @note.errors.full_messages.each do |message| %> -
  • Note <%= message.downcase %>
  • - <% end %>
    -<% end %> \ No newline at end of file +<% end %> diff --git a/features/step_definitions/assessment_steps.rb b/features/step_definitions/assessment_steps.rb index 57c010bf..83b82d2d 100644 --- a/features/step_definitions/assessment_steps.rb +++ b/features/step_definitions/assessment_steps.rb @@ -15,22 +15,20 @@ end Then('I see the schedule assessment form') do - expect(page).to have_css('.panel__header-with-arrow', text: 'Schedule') expect(page).to have_field('need[start_on]') expect(page).not_to have_field('note[body]') end Then('I see the log assessment form') do - expect(page).to have_css('.panel__header-with-arrow', text: 'Log') expect(page).not_to have_field('need[start_on]') - expect(page).to have_field('note[body]') + expect(page).to have_field('need_notes_attributes_0_body') end And('I enter valid details') do page.find('label', text: 'Triage').click page.find('#need_name').fill_in(with: 'A task description') if @assessment_type == 'log' - page.find('#note_body').fill_in(with: 'Some call notes') + page.find('#need_notes_attributes_0_body').fill_in(with: 'Some call notes') elsif @assessment_type == 'schedule' @scheduled_date = (Date.today + 1.day) page.find('#need_start_on').fill_in(with: @scheduled_date.strftime('%-d/%-m/%Y')) @@ -46,9 +44,6 @@ completed_link = find('#toggle-visibility-completed-assessment') expect(completed_link).to have_content('1 x completed') elsif @assessment_type == 'schedule' - assessments_table = find('.assessments-table') - assessment_row = assessments_table.find('tbody tr') - expect(assessment_row).to have_content('Triage') - expect(assessment_row).to have_content("#{@scheduled_date.strftime('%-d %B %Y')} (Future)") + expect(page).to have_content("#{@scheduled_date.strftime('%-d %B %Y')} (Future)") end end diff --git a/features/step_definitions/assessments/complete_assessment_steps.rb b/features/step_definitions/assessments/complete_assessment_steps.rb index 9042b9b1..78b7c57a 100644 --- a/features/step_definitions/assessments/complete_assessment_steps.rb +++ b/features/step_definitions/assessments/complete_assessment_steps.rb @@ -94,8 +94,7 @@ end Then('I can see the assessment has a completed status') do - status = page.find('#status-actions__field select').value - expect(status).to have_content 'complete' + expect(page).to have_select('Status', selected: 'Complete') end Then('I cannot see the option to start the assessment') do diff --git a/features/step_definitions/assessments/fail_assessment_steps.rb b/features/step_definitions/assessments/fail_assessment_steps.rb index 3fc88f55..c71d25c5 100644 --- a/features/step_definitions/assessments/fail_assessment_steps.rb +++ b/features/step_definitions/assessments/fail_assessment_steps.rb @@ -20,8 +20,7 @@ end Then('the assessment is set to blocked') do - status_container = find('#select2-need_status-container') - expect(status_container.text).to eq 'Blocked' + expect(page).to have_select('Status', selected: 'Blocked') end And('my note is stored against the assessment') do diff --git a/features/step_definitions/assignment_emails_steps.rb b/features/step_definitions/assignment_emails_steps.rb index 71c5a48f..e681bc51 100644 --- a/features/step_definitions/assignment_emails_steps.rb +++ b/features/step_definitions/assignment_emails_steps.rb @@ -5,7 +5,7 @@ visit "/needs/#{@need.id}" check_email_send @user_email = @user_email.present? ? @user_email : @user.email - select2 'need_assigned_to', role + select role, from: 'need_assigned_to' @expected_assignee = role page.find('.notice', text: 'Record successfully updated.') end @@ -36,7 +36,10 @@ def check_email_send return unless @send_email == true - - find('#send-email').click - expect(find('#send-email').checked?).to eq(true) + begin + find('label', text: 'Send notification email?').click + rescue Capybara::ElementNotFound => e + puts e + find('#send-email').click + end end diff --git a/features/step_definitions/edit_support_actions_steps.rb b/features/step_definitions/edit_support_actions_steps.rb index 42e543bb..874ba235 100644 --- a/features/step_definitions/edit_support_actions_steps.rb +++ b/features/step_definitions/edit_support_actions_steps.rb @@ -7,7 +7,7 @@ visit "/needs/#{@need.id}" check_email_send @user_email = @user_email.present? ? @user_email : @user.email - select2 'need_assigned_to', @user_email + select @user_email, from: 'need_assigned_to' @expected_assignee = @user_email page.find('.notice', text: 'Record successfully updated.') end @@ -20,14 +20,14 @@ When('I assign the support action to another user') do @another_user = User.create!(email: 'other_user@email.com', invited: Date.today) visit "/needs/#{@need.id}" - select2 'need_assigned_to', 'other_user@email.com' + select 'other_user@email.com', from: 'need_assigned_to' @expected_assignee = 'other_user@email.com' page.find('.notice', text: 'Record successfully updated.') end When("I change the support action status to 'complete'") do visit "/needs/#{@need.id}" - select2 'need_status', 'Complete' + select 'Complete', from: 'need_status' page.find('.notice', text: 'Record successfully updated.') end @@ -66,11 +66,11 @@ Capybara.using_session('Second_users_session') do visit "/needs/#{@need.id}" - select2 'need_assigned_to', 'manager@test.com' + select 'manager@test.com', from: 'need_assigned_to' @expected_assignee = 'manager@test.com' page.find('.notice', text: 'Record successfully updated.') end - select2 'need_status', 'Complete' + select 'Complete', from: 'need_status' end Then('I see my support action change was unsuccessful') do diff --git a/features/step_definitions/support_actions_list_steps.rb b/features/step_definitions/support_actions_list_steps.rb index c5a40c27..e87d427f 100644 --- a/features/step_definitions/support_actions_list_steps.rb +++ b/features/step_definitions/support_actions_list_steps.rb @@ -16,7 +16,7 @@ end When('I filter needs by category {string}') do |category| - select2 'category', category + select category, from: 'category' end Then('I see the support action for category {string} in the results') do |category|