Skip to content

Commit

Permalink
Merge pull request #2031 from alphagov/transition-downtime-index
Browse files Browse the repository at this point in the history
Transition Downtime Index to the Design System
  • Loading branch information
patrickpatrickpatrick authored Feb 1, 2024
2 parents 8a8b315 + a1a0058 commit 3eb02b8
Show file tree
Hide file tree
Showing 7 changed files with 97 additions and 75 deletions.
23 changes: 23 additions & 0 deletions app/helpers/downtimes_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,27 @@ def downtime_datetime(downtime)

strings.join(" ").gsub(":00", "").gsub("12pm", "midday").gsub("12am", "midnight")
end

def transactions_table_entries(transactions)
transactions.map do |transaction|
downtime = Downtime.for(transaction.artefact)

[
{ text: transaction.title },
{
text: downtime ? "Scheduled downtime #{downtime_datetime(downtime)}" : "Live",
},
{ text: action_link_for_transaction(transaction) },
{ text: link_to("View on website", "#{Plek.website_root}/#{transaction.slug}", class: "govuk-link") },
]
end
end

def action_link_for_transaction(transaction)
if transaction.artefact.downtime
link_to "Edit downtime", edit_edition_downtime_path(transaction), class: "govuk-link"
else
link_to "Add downtime", new_edition_downtime_path(transaction), class: "govuk-link"
end
end
end
80 changes: 27 additions & 53 deletions app/views/downtimes/index.html.erb
Original file line number Diff line number Diff line change
@@ -1,56 +1,30 @@
<% content_for :page_title, 'Downtime messages' %>
<% content_for :title, "Downtime messages" %>

<div class="page-title">
<h1>Downtime messages</h1>
<p class="lead">Show a message on a published transaction start page for a specific time.</p>
</div>
<div class="govuk-grid-column-full">

<%= render "govuk_publishing_components/components/lead_paragraph", {
text: "Show a message on a published transaction start page for a specific time.",
margin_bottom: 6
} %>

<table class="table table-bordered table-striped" data-module="filterable-table">
<caption class="h2 remove-top-margin">
<h2 class="remove-top-margin remove-bottom-margin">Services</h2>
</caption>
<thead>
<tr class="table-header">
<th>Service start page</th>
<th>Service status</th>
<th>Action</th>
</tr>
<tr class="if-no-js-hide table-header-secondary">
<td colspan="3">
<form>
<label class="remove-bottom-margin" for="table-filter">Filter services</label>
<p class="help-inline">For example ‘driving’ or ‘scheduled downtime’</p>
<input id="table-filter" type="text" class="form-control normal js-filter-table-input">
</form>
</td>
</tr>
</thead>
<tbody>
<% @transactions.each do |transaction| %>
<tr>
<td>
<h3 class="publication-table-title">
<%= link_to transaction.title, Downtime.for(transaction.artefact).present? ?
edit_edition_downtime_path(transaction) :
new_edition_downtime_path(transaction) %>
</h3>
<%= link_to "/#{transaction.slug}", "#{Plek.website_root}/#{transaction.slug}", class: 'link-muted' %>
</td>
<% if downtime = Downtime.for(transaction.artefact) %>
<td>
Scheduled downtime<br />
<span class="text-muted"><%= downtime_datetime(downtime) %></span>
</td>
<td>
<%= link_to 'Edit downtime', edit_edition_downtime_path(transaction), class: 'btn btn-info' %>
</td>
<% else %>
<td>Live</td>
<td>
<%= link_to 'Add downtime', new_edition_downtime_path(transaction), class: 'btn btn-default' %>
</td>
<% end %>
</tr>
<% end %>
</tbody>
</table>
<%= render "govuk_publishing_components/components/table", {
filterable: true,
label: "Filter by service or service status",
head: [
{
text: "Service Start page"
},
{
text: "Service Status",
},
{
text: tag.span("Action", class: "govuk-visually-hidden")
},
{
text: tag.span("Link to view live on GOV.UK", class: "govuk-visually-hidden")
}
],
rows: transactions_table_entries(@transactions.to_a)
} %>
</div>
22 changes: 3 additions & 19 deletions app/views/layouts/design_system.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -17,26 +17,10 @@
} %>

<div class="govuk-width-container">

<main class="govuk-main-wrapper govuk-main-wrapper--auto-spacing" id="main-content" role="main">
<% [:success, :info, :warning, :danger, :notice, :alert].select { |k| flash[k].present? }.each do |k| %>
<%
case k
when :notice
alert_class = "success"
when :alert
alert_class = "danger"
else
alert_class = k
end
%>
<div class="alert alert-<%= alert_class %>"
data-module="auto-track-event"
data-track-action="alert-<%= alert_class %>"
data-track-label="<%= strip_tags(flash[k]) %>">
<%= flash[k] %>
</div>
<% end %>

<%= render "shared/flash", flash: flash %>

<% if yield(:title).present? %>
<div class="govuk-grid-row">
<div class="govuk-grid-column-two-thirds">
Expand Down
15 changes: 15 additions & 0 deletions app/views/shared/_flash.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<% [:success, :info, :warning, :danger, :notice, :alert].select { |k| flash[k].present? }.each do |k| %>
<% if k == :warning || k == :danger || k == :alert %>
<%= render "govuk_publishing_components/components/error_alert", {
message: sanitize(flash[k])
} %>
<% elsif k == :notice || k == :info %>
<%= render "govuk_publishing_components/components/notice", {
description: sanitize(flash[k])
} %>
<% elsif k == :success %>
<%= render "govuk_publishing_components/components/success_alert", {
message: sanitize(flash[k])
} %>
<% end %>
<% end %>
4 changes: 2 additions & 2 deletions test/functional/downtimes_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,9 @@ class DowntimesControllerTest < ActionController::TestCase
get :index

assert_response :ok
assert_select "h3.publication-table-title", count: 0, text: unpublished_transaction_edition.title
assert_select ".govuk-table__cell", count: 0, text: unpublished_transaction_edition.title
transaction_editions.each do |edition|
assert_select "h3.publication-table-title", text: edition.title
assert_select ".govuk-table__cell", text: edition.title
end
end

Expand Down
2 changes: 1 addition & 1 deletion test/integration/downtime_integration_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class DowntimeIntegrationTest < JavascriptIntegrationTest

visit root_path
click_link "Downtime"
click_link "Apply to become a driving instructor"
click_link "Add downtime"

enter_start_time first_of_july_next_year_at_midday_bst
enter_end_time first_of_july_next_year_at_six_pm_bst
Expand Down
26 changes: 26 additions & 0 deletions test/unit/helpers/downtimes_helper_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@ class DowntimesHelperTest < ActionView::TestCase

def setup
@next_year = 1.year.from_now.year
@edition_live = FactoryBot.create(:transaction_edition)
@edition_downtime = FactoryBot.create(:transaction_edition)
@downtime = FactoryBot.create(
:downtime,
artefact: @edition_downtime.artefact,
start_time: Time.zone.local(@next_year, 10, 10, 15),
end_time: Time.zone.local(@next_year, 10, 11, 18),
)
end

test "#downtime_datetime should be a short string representation start and end time" do
Expand All @@ -21,4 +29,22 @@ def setup
downtime = FactoryBot.build(:downtime, start_time: Time.zone.local(@next_year, 10, 10, 21), end_time: Time.zone.local(@next_year, 10, 11, 0))
assert_equal "9pm to midnight on 10 October", downtime_datetime(downtime)
end

test "#transactions_table_entries should create valid entries for table" do
entries = transactions_table_entries([@edition_live, @edition_downtime])
assert_equal entries, [
[
{ text: @edition_live.title },
{ text: "Live" },
{ text: "<a class=\"govuk-link\" href=\"/editions/#{@edition_live.id}/downtime/new\">Add downtime</a>" },
{ text: "<a class=\"govuk-link\" href=\"#{Plek.website_root}/#{@edition_live.slug}\">View on website</a>" },
],
[
{ text: @edition_downtime.title },
{ text: "Scheduled downtime 3pm on 10 October to 6pm on 11 October" },
{ text: "<a class=\"govuk-link\" href=\"/editions/#{@edition_downtime.id}/downtime/edit\">Edit downtime</a>" },
{ text: "<a class=\"govuk-link\" href=\"#{Plek.website_root}/#{@edition_downtime.slug}\">View on website</a>" },
],
]
end
end

0 comments on commit 3eb02b8

Please sign in to comment.