Skip to content

Commit

Permalink
WIP commit
Browse files Browse the repository at this point in the history
  • Loading branch information
PeterHattyar committed Jul 21, 2024
1 parent 2e8b09d commit a261071
Show file tree
Hide file tree
Showing 14 changed files with 234 additions and 51 deletions.
2 changes: 1 addition & 1 deletion app/controllers/content_advice_requests_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def content_advice_request_params
:urls,
:contact_number,
requester_attributes: %i[email name collaborator_emails],
time_constraint_attributes: %i[needed_by_date time_constraint_reason],
time_constraint_attributes: %i[needed_by_date needed_by_day needed_by_month needed_by_year time_constraint_reason],
).to_h
end
end
2 changes: 1 addition & 1 deletion app/controllers/content_change_requests_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def content_change_request_params
:url,
:related_urls,
requester_attributes: %i[email name collaborator_emails],
time_constraint_attributes: %i[not_before_date needed_by_date time_constraint_reason needed_by_time not_before_time],
time_constraint_attributes: %i[not_before_day not_before_month not_before_year needed_by_date needed_by_day needed_by_month needed_by_year time_constraint_reason needed_by_time not_before_time],
).to_h
end
end
2 changes: 1 addition & 1 deletion app/controllers/remove_user_requests_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def remove_user_request_params
:user_email,
:reason_for_removal,
requester_attributes: %i[email name collaborator_emails],
time_constraint_attributes: %i[not_before_date needed_by_date time_constraint_reason],
time_constraint_attributes: %i[needed_by_date time_constraint_reason not_before_day not_before_month not_before_year],
).to_h
end
end
20 changes: 19 additions & 1 deletion app/models/support/requests/time_constraint.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module Support
module Requests
class TimeConstraint
include ActiveModel::Model
attr_accessor :not_before_date, :not_before_time, :needed_by_date, :needed_by_time, :time_constraint_reason
attr_accessor :not_before_day, :not_before_month, :not_before_year, :not_before_time, :needed_by_day, :needed_by_month, :needed_by_year, :needed_by_time, :time_constraint_reason

validates_date :needed_by_date, allow_blank: true, on_or_after: :today
validates_date :not_before_date, allow_blank: true, on_or_after: :today
Expand All @@ -24,6 +24,24 @@ class TimeConstraint
validates_time :not_before_time, on_or_before: :needed_by_time, unless: proc { |c|
[c.needed_by_date, c.needed_by_time, c.not_before_date, c.not_before_time].any?(&:blank?) || c.needed_by_date != c.not_before_date
}

def not_before_date
return "" unless not_before_year.present? && not_before_month.present? && not_before_day.present?

date_args = [not_before_year, not_before_month, not_before_day].map(&:to_i)
date = Date.new(*date_args)

"#{date.strftime('%d')}-#{date.strftime('%m')}-#{date.strftime('%Y')}"
end

def needed_by_date
return "" unless needed_by_year.present? && needed_by_month.present? && needed_by_day.present?

date_args = [needed_by_year, needed_by_month, needed_by_day].map(&:to_i)
date = Date.new(*date_args)

"#{date.strftime('%d')}-#{date.strftime('%m')}-#{date.strftime('%Y')}"
end
end
end
end
25 changes: 21 additions & 4 deletions app/views/content_advice_requests/_request_details.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,29 @@
</legend>

<div class="form-group">
<span class="form-label">
<%= r.label :needed_by_date, "Is there a date you need to have a response by?" %>
<h4>
<%= "Is there a date you need to have a response by?" %>
</h4>

<%# <span class="form-wrapper">
<%= r.text_field :needed_by_date, placeholder: "dd-mm-yyyy", value: r.object.needed_by_date, class: "input-md-2 form-control", data: { module: "calendar", format: "dd-mm-yy", min_date: 0 }
</span> %>

<span class="govuk-date-input__item">
<%= r.label :needed_by_day, "Day", class: "govuk-label govuk-date-input__label" %>
<%= r.text_field :needed_by_day, required: false, value: r.object.needed_by_day, class: "govuk-input govuk-date-input__input govuk-input--width-2", id: "needed-by-day" %>
</span>
<span class="form-wrapper">
<%= r.text_field :needed_by_date, placeholder: "dd-mm-yyyy", value: r.object.needed_by_date, class: "input-md-2 form-control", data: { module: "calendar", format: "dd-mm-yy", min_date: 0 } %>

<span class="govuk-date-input__item">
<%= r.label :needed_by_month, "Month", class: "govuk-label govuk-date-input__label" %>
<%= r.text_field :needed_by_month, required: false, value: r.object.needed_by_month, class: "govuk-input govuk-date-input__input govuk-input--width-2", id: "needed-by-month" %>
</span>

<span class="govuk-date-input__item">
<%= r.label :needed_by_year, "Year", class: "govuk-label govuk-date-input__label" %>
<%= r.text_field :needed_by_year, required: false, value: r.object.needed_by_year, class: "govuk-input govuk-date-input__input govuk-input--width-4", id: "needed-by-year" %>
</span>

</div>

<div class="form-group">
Expand Down
1 change: 1 addition & 0 deletions app/views/layouts/application.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
<%= csp_meta_tag %>
<%= stylesheet_link_tag "legacy/application", :media => "all" %>
<%= javascript_include_tag "legacy/application" %>
<%= stylesheet_link_tag "application", :media => "all" %>
<% end %>

<% content_for :favicon do %>
Expand Down
42 changes: 36 additions & 6 deletions app/views/remove_user_requests/_request_details.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,44 @@
</div>

<%= f.fields_for :time_constraint do |r| %>

<h4>
<%= "MUST NOT be removed BEFORE" %>
</h4>

<div id="date-hint" class="govuk-hint">
For example, 27 3 2007
</div>

<div class="form-group">
<span class="form-label">
<%= r.label :not_before_date, "MUST NOT be removed BEFORE" %>
</span>
<span class="form-wrapper">
<%= r.text_field :not_before_date, required: false, placeholder: "dd-mm-yyyy", value: r.object.not_before_date, class: "input-md-2 form-control", data: { module: "calendar", format: "dd-mm-yy", min_date: 0 } %>
</span>

<div class="govuk-date-input" id="not-before-date-input">

<div class="govuk-date-input__item">
<div class="govuk-form-group">
<%= r.label :not_before_day, "Day", class: "govuk-label govuk-date-input__label" %>
<%= r.text_field :not_before_day, required: false, value: r.object.not_before_day, class: "govuk-input govuk-date-input__input govuk-input--width-2", id: "not-before-day" %>
</div>
</div>

<div class="govuk-date-input__item">
<div class="govuk-form-group">
<%= r.label :not_before_month, "Month", class: "govuk-label govuk-date-input__label" %>
<%= r.text_field :not_before_month, required: false, value: r.object.not_before_month, class: "govuk-input govuk-date-input__input govuk-input--width-2", id: "not-before-month" %>
</div>
</div>

<div class="govuk-date-input__item">
<div class="govuk-form-group">
<%= r.label :not_before_year, "Year", class: "govuk-label govuk-date-input__label" %>
<%= r.text_field :not_before_year, required: false, value: r.object.not_before_year, class: "govuk-input govuk-date-input__input govuk-input--width-4", id: "not-before-year" %>
</div>
</div>

</div>

</div>

<% end %>

<div class="form-group">
Expand Down
43 changes: 39 additions & 4 deletions app/views/support/_time_constraint.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,26 @@
<span class="form-label">
<%= r.label :needed_by_date, "Deadline" %>
</span>
<span class="form-wrapper">
<%= r.text_field :needed_by_date, required: false, placeholder: "dd-mm-yyyy", value: r.object.needed_by_date, class: "input-md-2 form-control", data: { module: "calendar", format: "dd-mm-yy", min_date: 0 } %>
<br>

<%# <span class="form-wrapper">
<%= r.text_field :needed_by_date, required: false, placeholder: "dd-mm-yyyy", value: r.object.needed_by_date, class: "input-md-2 form-control", data: { module: "calendar", format: "dd-mm-yy", min_date: 0 }
</span> %>

<span class="govuk-date-input__item">
<%= r.label :needed_by_day, "Day", class: "govuk-label govuk-date-input__label" %>
<%= r.text_field :needed_by_day, required: false, value: r.object.needed_by_day, class: "govuk-input govuk-date-input__input govuk-input--width-2", id: "needed-by-day" %>
</span>

<span class="govuk-date-input__item">
<%= r.label :needed_by_month, "Month", class: "govuk-label govuk-date-input__label" %>
<%= r.text_field :needed_by_month, required: false, value: r.object.needed_by_month, class: "govuk-input govuk-date-input__input govuk-input--width-2", id: "needed-by-month" %>
</span>

<span class="govuk-date-input__item">
<%= r.label :needed_by_year, "Year", class: "govuk-label govuk-date-input__label" %>
<%= r.text_field :needed_by_year, required: false, value: r.object.needed_by_year, class: "govuk-input govuk-date-input__input govuk-input--width-4", id: "needed-by-year" %>
</span>
</div>

<div class="form-group">
Expand All @@ -26,9 +43,27 @@
<span class="form-label">
<%= r.label :not_before_date, "Must not be published before" %>
</span>
<span class="form-wrapper">
<%= r.text_field :not_before_date, required: false, placeholder: "dd-mm-yyyy", value: r.object.not_before_date, class: "input-md-2 form-control", data: { module: "calendar", format: "dd-mm-yy", min_date: 0 } %>
<br>

<%# <span class="form-wrapper">
<%= r.text_field :not_before_date, required: false, placeholder: "dd-mm-yyyy", value: r.object.not_before_date, class: "input-md-2 form-control", data: { module: "calendar", format: "dd-mm-yy", min_date: 0 }
</span> %>

<span class="govuk-date-input__item">
<%= r.label :not_before_day, "Day", class: "govuk-label govuk-date-input__label" %>
<%= r.text_field :not_before_day, required: false, value: r.object.not_before_day, class: "govuk-input govuk-date-input__input govuk-input--width-2", id: "not-before-day" %>
</span>

<span class="govuk-date-input__item">
<%= r.label :not_before_month, "Month", class: "govuk-label govuk-date-input__label" %>
<%= r.text_field :not_before_month, required: false, value: r.object.not_before_month, class: "govuk-input govuk-date-input__input govuk-input--width-2", id: "not-before-month" %>
</span>

<span class="govuk-date-input__item">
<%= r.label :not_before_year, "Year", class: "govuk-label govuk-date-input__label" %>
<%= r.text_field :not_before_year, required: false, value: r.object.not_before_year, class: "govuk-input govuk-date-input__input govuk-input--width-4", id: "not-before-year" %>
</span>

</div>

<div class="form-group">
Expand Down
10 changes: 8 additions & 2 deletions spec/features/content_advice_requests_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,10 @@
title: "Which format",
details: "I need help to choose a format, here's my content...",
urls: "https://www.gov.uk/x, https://www.gov.uk/y",
needed_by: "12-01-#{next_year}",
# needed_by: "12-01-#{next_year}",
needed_by_day: "12",
needed_by_month: "01",
needed_by_year: next_year.to_s,
reason_for_deadline: "Ministerial announcement Z",
contact_number: "0121 111111",
)
Expand Down Expand Up @@ -87,7 +90,10 @@ def user_requests_content_advice(details)
fill_in "Please explain what you would like help with", with: details[:details]
fill_in "Relevant URLs (if applicable)", with: details[:urls]

fill_in "Is there a date you need to have a response by?", with: details[:needed_by]
# fill_in "Is there a date you need to have a response by?", with: details[:needed_by]
find("#needed-by-day").set(details[:needed_by_day])
find("#needed-by-month").set(details[:needed_by_month])
find("#needed-by-year").set(details[:needed_by_year])
fill_in "Reason for deadline", with: details[:reason_for_deadline]
fill_in "Contact telephone number (in case we need to call you to discuss the content)",
with: details[:contact_number]
Expand Down
8 changes: 6 additions & 2 deletions spec/features/content_change_requests_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,13 @@
details_of_change: "Out of date XX YY",
url: "http://gov.uk/X",
related_urls: "http://gov.uk/welsh",
needed_by_date: "31-12-#{next_year}",
needed_by_day: "31",
needed_by_month: "12",
needed_by_year: next_year.to_s,
needed_by_time: "13:00",
not_before_date: "01-12-#{next_year}",
not_before_day: "01",
not_before_month: "12",
not_before_year: next_year.to_s,
not_before_time: "18:00",
reason: "New law",
)
Expand Down
8 changes: 6 additions & 2 deletions spec/features/remove_user_requests_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@
user_name: "Bob",
user_email: "[email protected]",
reason_for_removal: "User has left the organisation",
not_before_date: "31-12-#{next_year}",
not_before_day: "31",
not_before_month: "12",
not_before_year: next_year.to_s,
)

expect(request).to have_been_made
Expand All @@ -59,7 +61,9 @@ def user_requests_removal_of_another_user(details)
fill_in "Reason for removal", with: details[:reason_for_removal]
end

fill_in "MUST NOT be removed BEFORE", with: details[:not_before_date]
find("#not-before-day").set(details[:not_before_day])
find("#not-before-month").set(details[:not_before_month])
find("#not-before-year").set(details[:not_before_year])

user_submits_the_request_successfully
end
Expand Down
Loading

0 comments on commit a261071

Please sign in to comment.