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 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/controllers/assessments_controller.rb b/app/controllers/assessments_controller.rb index c8a6c39b..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,28 +160,24 @@ 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 @need = Need.new(assessment_params.merge(contact_id: @contact.id)) @note = Note.new - unless @need.valid? + if @need.save + redirect_to contact_path(@contact) + else @assigned_to_options = construct_assigned_to_options render :new - return end - - @need.save - redirect_to contact_path(@contact) end def type_param @@ -188,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 @@ -207,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/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/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 @@