Skip to content

Commit

Permalink
Merge pull request #2067 from alphagov/transition-add-downtime-page/r…
Browse files Browse the repository at this point in the history
…ename-datetime-fields

Transition add downtime page/rename datetime fields
  • Loading branch information
mtaylorgds authored Feb 16, 2024
2 parents cd4f167 + 5c28af1 commit 653fb8e
Show file tree
Hide file tree
Showing 9 changed files with 163 additions and 117 deletions.
14 changes: 7 additions & 7 deletions app/assets/javascripts/modules/downtime_message.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ window.GOVUK.Modules = window.GOVUK.Modules || {};
form.addEventListener('change', updateMessage)

function updateMessage () {
const fromDate = getDate('from')
const toDate = getDate('to')
const fromDate = getDate('start')
const toDate = getDate('end')

let message = ''
if (isValidSchedule(fromDate, toDate)) {
Expand All @@ -25,11 +25,11 @@ window.GOVUK.Modules = window.GOVUK.Modules || {};
}

function getDate (selector) {
const day = form.elements[`${selector}-date[day]`].value
const month = form.elements[`${selector}-date[month]`].value
const year = form.elements[`${selector}-date[year]`].value
const hours = form.elements[`${selector}-time[hour]`].value
const minutes = form.elements[`${selector}-time[minute]`].value
const day = form.elements[`downtime[${selector}_time(3i)]`].value
const month = form.elements[`downtime[${selector}_time(2i)]`].value
const year = form.elements[`downtime[${selector}_time(1i)]`].value
const hours = form.elements[`downtime[${selector}_time(4i)]`].value
const minutes = form.elements[`downtime[${selector}_time(5i)]`].value

// The Date class treats 1 as February, but in the UI we expect 1 to be January
const zeroIndexedMonth = parseInt(month) - 1
Expand Down
2 changes: 1 addition & 1 deletion app/views/artefacts/new.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<h1><%= yield :page_title %></h1>
</legend>

<%= render :partial => 'shared/error_summary', locals: { object: @artefact} %>
<%= render :partial => 'shared/legacy_error_summary', locals: { object: @artefact} %>

<div class="row">
<div class="col-md-12">
Expand Down
48 changes: 48 additions & 0 deletions app/views/downtimes/_datetime_fields.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<%
date_legend_text ||= nil
time_legend_text ||= nil

year ||= nil
month ||= nil
day ||= nil
date_input_items = []
date_input_items << day if day
date_input_items << month if month
date_input_items << year if year
date_input_items = nil unless date_input_items.any?

hour ||= nil
minute ||= nil
time_input_items = []
time_input_items << hour if hour
time_input_items << minute if minute
time_input_items = nil unless time_input_items.any?
%>
<div class="govuk-grid-row">
<div class="govuk-grid-column-full">
<div class="govuk-grid-row">
<div class="govuk-grid-column-one-half">
<%= render "govuk_publishing_components/components/fieldset", {
legend_text: date_legend_text,
heading_size: "m"
} do %>
<%= render "govuk_publishing_components/components/date_input", {
hint: "For example, 01 08 2022",
items: date_input_items,
} %>
<% end %>
</div>
<div class="govuk-grid-column-one-half">
<%= render "govuk_publishing_components/components/fieldset", {
legend_text: time_legend_text,
heading_size: "m"
} do %>
<%= render "time_input", {
hint: "For example, 9:30 or 19:30",
items: time_input_items,
} %>
<% end %>
</div>
</div>
</div>
</div>
116 changes: 59 additions & 57 deletions app/views/downtimes/_form.html.erb
Original file line number Diff line number Diff line change
@@ -1,64 +1,66 @@
<%= f.hidden_field :artefact_id %>

<%= render :partial => 'shared/error_summary', locals: { object: @downtime} %>
<%= render :partial => 'shared/legacy_error_summary', locals: { object: @downtime} %>

<div class="govuk-grid-row">
<div class="govuk-grid-column-full">
<div class="govuk-grid-row">
<div class="govuk-grid-column-one-half">
<%= render "govuk_publishing_components/components/fieldset", {
legend_text: "From date",
heading_size: "m"
} do %>
<%= render "govuk_publishing_components/components/date_input", {
hint: "For example, 01 08 2022",
name: "from-date"
} %>
<% end %>
</div>
<div class="govuk-grid-column-one-half">
<%= render "govuk_publishing_components/components/fieldset", {
legend_text: "From time",
heading_size: "m"
} do %>
<%= render "time_input", {
hint: "For example, 9:30 or 19:30",
name: "from-time"
} %>
<% end %>
</div>
</div>
</div>
</div>
<%= render partial: "downtimes/datetime_fields", locals: {
date_legend_text: "From date",
time_legend_text: "From time",
year: {
name: "downtime[start_time(1i)]",
label: "Year",
width: 4,
},
month: {
name: "downtime[start_time(2i)]",
label: "Month",
width: 2,
},
day: {
name: "downtime[start_time(3i)]",
label: "Day",
width: 2,
},
hour: {
name: "downtime[start_time(4i)]",
label: "Hour",
width: 2,
},
minute: {
name: "downtime[start_time(5i)]",
label: "Minute",
width: 2,
},
} %>

<div class="govuk-grid-row">
<div class="govuk-grid-column-full">
<div class="govuk-grid-row">
<div class="govuk-grid-column-one-half">
<%= render "govuk_publishing_components/components/fieldset", {
legend_text: "To date",
heading_size: "m"
} do %>
<%= render "govuk_publishing_components/components/date_input", {
hint: "For example, 01 08 2022",
name: "to-date"
} %>
<% end %>
</div>
<div class="govuk-grid-column-one-half">
<%= render "govuk_publishing_components/components/fieldset", {
legend_text: "To time",
heading_size: "m"
} do %>
<%= render "time_input", {
hint: "For example, 9:30 or 19:30",
name: "to-time"
} %>
<% end %>
</div>
</div>
</div>
</div>
<%= render partial: "downtimes/datetime_fields", locals: {
date_legend_text: "To date",
time_legend_text: "To time",
year: {
name: "downtime[end_time(1i)]",
label: "Year",
width: 4,
},
month: {
name: "downtime[end_time(2i)]",
label: "Month",
width: 2,
},
day: {
name: "downtime[end_time(3i)]",
label: "Day",
width: 2,
},
hour: {
name: "downtime[end_time(4i)]",
label: "Hour",
width: 2,
},
minute: {
name: "downtime[end_time(5i)]",
label: "Minute",
width: 2,
},
} %>

<div class="govuk-grid-row">
<div class="govuk-grid-column-full">
Expand Down
2 changes: 1 addition & 1 deletion app/views/legacy_downtimes/_form.html.erb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<%= f.hidden_field :artefact_id %>

<%= render :partial => 'shared/error_summary', locals: { object: @downtime} %>
<%= render :partial => 'shared/legacy_error_summary', locals: { object: @downtime} %>

<div class="downtime-dates">
<div class="form-group">
Expand Down
2 changes: 1 addition & 1 deletion app/views/licences/new.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
We need a bit more information to create your licence.
</p>

<%= render :partial => 'shared/error_summary', locals: { object: @publication } %>
<%= render :partial => 'shared/legacy_error_summary', locals: { object: @publication } %>

<%= form_for(@publication, :url => editions_path, :as => :edition, :html => { :id => 'edition-form' } ) do |f| %>
<%= form_group(f, :licence_identifier) do %>
Expand Down
2 changes: 1 addition & 1 deletion app/views/local_transactions/new.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
We need a bit more information to create your local transaction.
</p>

<%= render :partial => 'shared/error_summary', locals: { object: @publication} %>
<%= render :partial => 'shared/legacy_error_summary', locals: { object: @publication} %>

<%= form_for(@publication, as: :edition, url: editions_path, html: { id: 'edition-form', novalidate: 'novalidate' } ) do |f| %>
<fieldset class="inputs">
Expand Down
File renamed without changes.
Loading

0 comments on commit 653fb8e

Please sign in to comment.