Browse Source

Merge branch 'main' into CLDC-638-bulk_upload

pull/84/head
baarkerlounger 4 years ago
parent
commit
c08f32d18a
  1. 5
      README.md
  2. 2
      app/controllers/case_logs_controller.rb
  3. 2
      app/helpers/check_answers_helper.rb
  4. 2
      app/javascript/controllers/soft_validations_controller.js
  5. 5
      app/javascript/styles/_task-list.scss
  6. 9
      app/javascript/styles/application.scss
  7. 4
      app/models/case_log.rb
  8. 2
      app/views/case_logs/_log_list.html.erb
  9. 4
      app/views/case_logs/edit.html.erb
  10. 2
      app/views/form/check_answers.html.erb
  11. 41
      app/views/form/page.html.erb
  12. 48
      app/views/layouts/_footer.html.erb
  13. 29
      app/views/layouts/application.html.erb
  14. 23
      lib/tasks/form_definition.rake
  15. 2
      spec/features/case_log_spec.rb
  16. 5
      spec/lib/tasks/form_definition_validator_spec.rb

5
README.md

@ -163,7 +163,10 @@ Assumptions made by the format:
## JSON Form Validation against Schema
To validate the form JSON against the schema you can run:
`rake form_definition:validate["config/forms/2021_22.json"]`
`rake form_definition:validate["config/forms/2021_2022.json"]`
n.b. You may have to escape square brackets in zsh
`rake form_definition:validate\["config/forms/2021_2022.json"\]`
This will validate the given form definition against the schema in `config/forms/schema/generic.json`.

2
app/controllers/case_logs_controller.rb

@ -107,6 +107,8 @@ private
day = params["case_log"]["#{question_key}(3i)"]
month = params["case_log"]["#{question_key}(2i)"]
year = params["case_log"]["#{question_key}(1i)"]
next unless day.present? && month.present? && year.present?
result[question_key] = Date.new(year.to_i, month.to_i, day.to_i)
end
next unless question_params

2
app/helpers/check_answers_helper.rb

@ -60,6 +60,8 @@ module CheckAnswersHelper
case_log[question_key].blank? || !condition.include?(case_log[question_key])
when "radio"
case_log[question_key].blank? || !condition.include?(case_log[question_key])
when "select"
case_log[question_key].blank? || !condition.include?(case_log[question_key])
else
raise "Not implemented yet"
end

2
app/javascript/controllers/soft_validations_controller.js

@ -5,7 +5,7 @@ export default class extends Controller {
initialize() {
let url = window.location.href + "/soft_validations"
this.fetch_retry(url, { headers: { accept: "application/json" } }, 2)
this.fetch_retry(url, { headers: { accept: "application/json" } }, 5)
}
fetch_retry(url, options, n) {

5
app/javascript/styles/_task-list.scss

@ -81,11 +81,6 @@
}
}
// turbo-frame {
// display: block;
// border: 1px solid blue
// }
.app-task-list__item:target,
.tasklist_item_highlight{
background-color: $govuk-focus-colour;

9
app/javascript/styles/application.scss

@ -11,4 +11,11 @@ $govuk-image-url-function: frontend-image-url;
@import "~govuk-frontend/govuk/all";
@import '_task-list'
@import '_task-list';
$govuk-global-styles: true;
// turbo-frame {
// display: block;
// border: 1px solid blue
// }

4
app/models/case_log.rb

@ -10,7 +10,7 @@ class CaseLogValidator < ActiveModel::Validator
# If we've come from the form UI we only want to validate the specific fields
# that have just been submitted. If we're submitting a log via API or Bulk Upload
# we want to validate all data fields.
page_to_validate = options[:page]
page_to_validate = record.page
if page_to_validate
public_send("validate_#{page_to_validate}", record) if respond_to?("validate_#{page_to_validate}")
else
@ -41,7 +41,7 @@ class CaseLog < ApplicationRecord
default_scope -> { kept }
scope :not_completed, -> { where.not(status: "completed") }
validates_with CaseLogValidator, ({ page: @page } || {})
validates_with CaseLogValidator
before_save :update_status!
attr_accessor :page

2
app/views/case_logs/_log_list.html.erb

@ -12,7 +12,7 @@
<% case_logs.map do |log| %>
<tr class="govuk-table__row">
<th scope="row" class="govuk-table__header">
<%= link_to log.id, case_log_path(log) %>
<%= link_to log.id, case_log_path(log), class: "govuk-link" %>
</th>
<td class="govuk-table__cell govuk-table__cell">
<%= log.property_postcode %>

4
app/views/case_logs/edit.html.erb

@ -5,11 +5,11 @@
<%= @case_log.id %></h1>
<h2 class="govuk-heading-s govuk-!-margin-bottom-2">This submission is
<%= @case_log.status %></h2>
<%= @case_log.status.to_s.humanize %></h2>
<p class="govuk-body govuk-!-margin-bottom-7">You've completed <%= get_subsections_count(@form, @case_log, :completed) %> of <%= get_subsections_count(@form, @case_log, :all) %> sections.</p>
<p class="govuk-body govuk-!-margin-bottom-7">
<% next_incomplete_section=get_next_incomplete_section(@form, @case_log) %>
<a href="#<%= next_incomplete_section %>"
<a class="govuk-link" href="#<%= next_incomplete_section %>"
data-controller="tasklist"
data-action="tasklist#addHighlight"
data-info=<%= next_incomplete_section %>>

2
app/views/form/check_answers.html.erb

@ -10,7 +10,7 @@
<%end %>
<%end %>
<% end %>
<%= form_with action: '/case_logs', method: "next_page", builder: GOVUKDesignSystemFormBuilder::FormBuilder do |f| %>
<%= form_with model: @case_log, method: "get", builder: GOVUKDesignSystemFormBuilder::FormBuilder do |f| %>
<%= f.govuk_submit "Save and continue" %>
<% end %>
</div>

41
app/views/form/page.html.erb

@ -3,25 +3,28 @@
<% end %>
<%= turbo_frame_tag "case_log_form", target: "_top" do %>
<div class="govuk-grid-row">
<div class="govuk-grid-column-two-thirds">
<% if page_info["header"].present? %>
<h1 class="govuk-heading-xl">
<%= page_info["header"] %>
</h1>
<% end %>
<%= form_with model: @case_log, method: "submit_form", builder: GOVUKDesignSystemFormBuilder::FormBuilder do |f| %>
<%= f.govuk_error_summary %>
<% page_info["questions"].map do |question_key, question| %>
<div id=<%= question_key + "_div " %><%= display_question_key_div(page_info, question_key) %> >
<%= render partial: "form/#{question["type"]}_question", locals: { question_key: question_key.to_sym, question: question, f: f } %>
</div>
<% end %>
<% if page_info["header"].present? %>
<h1 class="govuk-heading-xl">
<%= page_info["header"] %>
</h1>
<% end %>
<%= form_with model: @case_log, url: form_case_log_path(@case_log), method: "post", builder: GOVUKDesignSystemFormBuilder::FormBuilder do |f| %>
<%= f.govuk_error_summary %>
<% page_info["questions"].map do |question_key, question| %>
<div id=<%= question_key + "_div " %><%= display_question_key_div(page_info, question_key) %> >
<%= render partial: "form/#{question["type"]}_question", locals: { question_key: question_key.to_sym, question: question, f: f } %>
</div>
<% end %>
<% if page_info["soft_validations"]&.keys&.first %>
<%= render partial: "form/validation_override_question", locals: { f: f, page_key: page_key, page_info: page_info } %>
<% end %>
<% if page_info["soft_validations"]&.keys&.first %>
<%= render partial: "form/validation_override_question", locals: { f: f, page_key: page_key, page_info: page_info } %>
<% end %>
<%= f.hidden_field :page, value: page_key %>
<%= f.govuk_submit "Save and continue" %>
<% end %>
<%= f.hidden_field :page, value: page_key %>
<%= f.govuk_submit "Save and continue" %>
<% end %>
</div>
</div>
<% end %>

48
app/views/layouts/_footer.html.erb

@ -0,0 +1,48 @@
<div class="govuk-width-container ">
<div class="govuk-footer__meta">
<div class="govuk-footer__meta-item govuk-footer__meta-item--grow">
<h2 class="govuk-visually-hidden">Support links</h2>
<div class="govuk-footer__meta-custom">
<h2 class="govuk-heading-m">Get help with this service</h2>
<h3 class="govuk-heading-s govuk-!-margin-bottom-1">Online helpdesk</h3>
<p class="govuk-body govuk-!-font-size-16">
<a class="govuk-link govuk-footer__link" href="https://digital.dclg.gov.uk/jira/servicedesk/customer/portal/4/group/21" target="_blank">CORE helpdesk</a>
(opens in a new tab)</p>
<h3 class="govuk-heading-s govuk-!-margin-bottom-1">Telephone</h3>
<ul class="govuk-list govuk-!-font-size-16">
<li>Telephone: 0333 202 5084</li>
<li>Monday to Friday, 9am to 5:30pm (except public holidays)</li>
</ul>
<h3 class="govuk-heading-s govuk-!-margin-bottom-1">Email</h3>
<ul class="govuk-list govuk-!-font-size-16">
<li>
<a class="govuk-link govuk-footer__link" href="mailto:mhclg.digital-services@communities.gov.uk?subject=CORE">mhclg.digital-services@communities.gov.uk</a>
</li>
<li>We aim to respond within 2 working days</li>
</ul>
<h2 class="govuk-visually-hidden">Footer links</h2>
</div>
<svg aria-hidden="true" focusable="false" class="govuk-footer__licence-logo" xmlns="http://www.w3.org/2000/svg" viewbox="0 0 483.2 195.7" height="17" width="41">
<path
fill="currentColor"
d="M421.5 142.8V.1l-50.7 32.3v161.1h112.4v-50.7zm-122.3-9.6A47.12 47.12 0 0 1 221 97.8c0-26 21.1-47.1 47.1-47.1 16.7 0 31.4 8.7 39.7 21.8l42.7-27.2A97.63 97.63 0 0 0 268.1 0c-36.5 0-68.3 20.1-85.1 49.7A98 98 0 0 0 97.8 0C43.9 0 0 43.9 0 97.8s43.9 97.8 97.8 97.8c36.5 0 68.3-20.1 85.1-49.7a97.76 97.76 0 0 0 149.6 25.4l19.4 22.2h3v-87.8h-80l24.3 27.5zM97.8 145c-26 0-47.1-21.1-47.1-47.1s21.1-47.1 47.1-47.1 47.2 21 47.2 47S123.8 145 97.8 145"/>
</svg>
<span class="govuk-footer__licence-description">
All content is available under the
<a class="govuk-footer__link" href="https://www.nationalarchives.gov.uk/doc/open-government-licence/version/3/" rel="license">Open Government Licence v3.0</a>, except where otherwise stated
</span>
</div>
<div class="govuk-footer__meta-item">
<a class="govuk-footer__link govuk-footer__copyright-logo" href="https://www.nationalarchives.gov.uk/information-management/re-using-public-sector-information/uk-government-licensing-framework/crown-copyright/">© Crown copyright</a>
</div>
</div>
</div>

29
app/views/layouts/application.html.erb

@ -72,34 +72,7 @@
</div>
<footer class="govuk-footer">
<div class="govuk-width-container ">
<div class="govuk-footer__meta">
<div class="govuk-footer__meta-item govuk-footer__meta-item--grow">
<h2 class="govuk-visually-hidden">Support links</h2>
<div class="govuk-footer__meta-custom">
<h2 class="govuk-heading-m">Support and guidance</h2>
<p class="govuk-body-s">
If you have a question, or you've had a problem using this service, please contact us at <%= mail_to "test@mhclg.gov.uk", "test@mhclg.gov.uk", class: "govuk-footer__link" %>
</p>
</div>
<svg aria-hidden="true" focusable="false" class="govuk-footer__licence-logo" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 483.2 195.7" height="17" width="41">
<path fill="currentColor" d="M421.5 142.8V.1l-50.7 32.3v161.1h112.4v-50.7zm-122.3-9.6A47.12 47.12 0 0 1 221 97.8c0-26 21.1-47.1 47.1-47.1 16.7 0 31.4 8.7 39.7 21.8l42.7-27.2A97.63 97.63 0 0 0 268.1 0c-36.5 0-68.3 20.1-85.1 49.7A98 98 0 0 0 97.8 0C43.9 0 0 43.9 0 97.8s43.9 97.8 97.8 97.8c36.5 0 68.3-20.1 85.1-49.7a97.76 97.76 0 0 0 149.6 25.4l19.4 22.2h3v-87.8h-80l24.3 27.5zM97.8 145c-26 0-47.1-21.1-47.1-47.1s21.1-47.1 47.1-47.1 47.2 21 47.2 47S123.8 145 97.8 145" />
</svg>
<span class="govuk-footer__licence-description">
All content is available under the
<a class="govuk-footer__link" href="https://www.nationalarchives.gov.uk/doc/open-government-licence/version/3/" rel="license">Open Government Licence v3.0</a>, except where otherwise stated
</span>
</div>
<div class="govuk-footer__meta-item">
<a class="govuk-footer__link govuk-footer__copyright-logo" href="https://www.nationalarchives.gov.uk/information-management/re-using-public-sector-information/uk-government-licensing-framework/crown-copyright/">© Crown copyright</a>
</div>
</div>
</div>
<%= render partial: "layouts/footer" %>
</footer>
</body>
</html>

23
lib/tasks/form_definition.rake

@ -12,13 +12,11 @@ def get_all_form_paths(directories)
end
namespace :form_definition do
desc "Validate JSON against Generic Form Schema"
desc "Validate all JSON against Generic Form Schema"
task validate_all: :environment do
puts Rails.root.to_s
directories = ["config/forms", "spec/fixtures/forms"]
paths = get_all_form_paths(directories) + ["config/forms/schema/generic.json"]
paths = get_all_form_paths(directories)
paths.each do |path|
Rake::Task["form_definition:validate"].reenable
@ -26,11 +24,26 @@ namespace :form_definition do
end
end
desc "Validate Single JSON against Generic Form Schema"
task :validate, %i[path] => :environment do |_task, args|
path = Rails.root.join("config/forms/schema/generic.json")
file = File.open(path)
schema = JSON.parse(file.read)
meta_schema = JSON::Validator.validator_for_name("draft4").metaschema
puts path
if JSON::Validator.validate(meta_schema, schema)
puts "Schema Definition is Valid"
else
puts "Schema Definition in #{path} is not valid against draft4 json schema."
next
end
path = Rails.root.join(args.path)
file = File.open(path)
form_definition = JSON.parse(file.read)
schema = JSON::Validator.validator_for_name("draft4").metaschema
puts path
puts JSON::Validator.fully_validate(schema, form_definition, strict: true)

2
spec/features/case_log_spec.rb

@ -43,7 +43,7 @@ RSpec.describe "Test Features" do
it "displays a tasklist header" do
visit("/case_logs/#{id}")
expect(page).to have_content("Tasklist for log #{id}")
expect(page).to have_content("This submission is #{status}")
expect(page).to have_content("This submission is #{status.humanize}")
end
it "displays a section status" do

5
spec/lib/tasks/form_definition_validator_spec.rb

@ -11,7 +11,7 @@ describe "rake form_definition:validate_all", type: :task do
end
it "runs the validate task for each form definition in the project" do
expect(Rake::Task["form_definition:validate"]).to receive(:invoke).exactly(5).times
expect(Rake::Task["form_definition:validate"]).to receive(:invoke).exactly(4).times
task.invoke
end
end
@ -22,11 +22,12 @@ describe "rake form_definition:validate", type: :task do
before do
Rake.application.rake_require("tasks/form_definition")
Rake::Task.define_task(:environment)
allow(JSON::Validator).to receive(:validate).and_return(true)
task.reenable
end
it "runs the validate task for the given form definition" do
expect(JSON::Validator).to receive(:validate!).at_least(1).time
expect(JSON::Validator).to receive(:validate!).at_least(2).times
task.invoke("config/forms/2021_2022.json")
end
end

Loading…
Cancel
Save