Browse Source

Add status tag helper

pull/619/head
Paul Robert Lloyd 3 years ago committed by baarkerlounger
parent
commit
8a79603457
  1. 25
      app/helpers/tag_helper.rb
  2. 14
      app/helpers/tasklist_helper.rb
  3. 5
      app/views/case_logs/_log_list.html.erb
  4. 4
      app/views/case_logs/_tasklist.html.erb
  5. 2
      app/views/case_logs/edit.html.erb
  6. 16
      spec/helpers/tag_helper_spec.rb

25
app/helpers/tag_helper.rb

@ -0,0 +1,25 @@
module TagHelper
include GovukComponentsHelper
TEXT = {
not_started: "Not started",
cannot_start_yet: "Cannot start yet",
in_progress: "In progress",
completed: "Completed",
}.freeze
COLOUR = {
not_started: "grey",
cannot_start_yet: "grey",
in_progress: "blue",
completed: "green",
}.freeze
def status_tag(status, classes = [])
govuk_tag(
classes:,
colour: COLOUR[status.to_sym],
text: TEXT[status.to_sym],
)
end
end

14
app/helpers/tasklist_helper.rb

@ -1,20 +1,6 @@
module TasklistHelper module TasklistHelper
include GovukLinkHelper include GovukLinkHelper
STATUSES = {
not_started: "Not started",
cannot_start_yet: "Cannot start yet",
completed: "Completed",
in_progress: "In progress",
}.freeze
STYLES = {
not_started: "govuk-tag--grey",
cannot_start_yet: "govuk-tag--grey",
completed: "",
in_progress: "govuk-tag--blue",
}.freeze
def get_next_incomplete_section(case_log) def get_next_incomplete_section(case_log)
case_log.form.subsections.find { |subsection| subsection.is_incomplete?(case_log) } case_log.form.subsections.find { |subsection| subsection.is_incomplete?(case_log) }
end end

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

@ -41,10 +41,7 @@
<%= log.created_at.to_formatted_s(:govuk_date) %> <%= log.created_at.to_formatted_s(:govuk_date) %>
</td> </td>
<td class="govuk-table__cell"> <td class="govuk-table__cell">
<%= govuk_tag( <%= status_tag(log.status) %>
colour: log.status == "completed" ? "blue" : "grey",
text: log.status.humanize,
) %>
</td> </td>
<% if current_user.support? %> <% if current_user.support? %>
<td class="govuk-table__cell"> <td class="govuk-table__cell">

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

@ -14,9 +14,7 @@
<span class="app-task-list__task-name" id="<%= subsection.id.dasherize %>"> <span class="app-task-list__task-name" id="<%= subsection.id.dasherize %>">
<%= subsection_link(subsection, @case_log) %> <%= subsection_link(subsection, @case_log) %>
</span> </span>
<strong class="govuk-tag app-task-list__tag <%= TasklistHelper::STYLES[subsection_status] %>"> <%= status_tag(subsection_status, "app-task-list__tag") %>
<%= TasklistHelper::STATUSES[subsection_status] %>
</strong>
</li> </li>
<% end %> <% end %>
</ul> </ul>

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

@ -26,7 +26,7 @@
<p class="govuk-body">This log has not been started.</p> <p class="govuk-body">This log has not been started.</p>
<% elsif @case_log.status == "completed" %> <% elsif @case_log.status == "completed" %>
<p class="govuk-body"> <p class="govuk-body">
<%= govuk_tag(text: "Completed") %> <%= status_tag(@case_log.status) %>
</p> </p>
<p class="govuk-body"> <p class="govuk-body">
You can <%= govuk_link_to "review and make changes to this log", "/logs/#{@case_log.id}/review" %> up to 3 months after the end of the current collection year, which closes on 31 March <%= @case_log.collection_start_year.present? ? @case_log.collection_start_year + 1 : "" %>. You can <%= govuk_link_to "review and make changes to this log", "/logs/#{@case_log.id}/review" %> up to 3 months after the end of the current collection year, which closes on 31 March <%= @case_log.collection_start_year.present? ? @case_log.collection_start_year + 1 : "" %>.

16
spec/helpers/tag_helper_spec.rb

@ -0,0 +1,16 @@
require "rails_helper"
RSpec.describe TagHelper do
let(:empty_case_log) { FactoryBot.create(:case_log) }
let(:case_log) { FactoryBot.create(:case_log, :in_progress) }
describe "get the status tag" do
it "returns tag with correct status text and colour" do
expect(status_tag(case_log.status)).to eq("<strong class=\"govuk-tag govuk-tag--blue\">In progress</strong>")
end
it "returns tag with correct status text and colour and custom class" do
expect(status_tag("not_started", "app-tag--small")).to eq("<strong class=\"govuk-tag app-tag--small govuk-tag--grey\">Not started</strong>")
end
end
end
Loading…
Cancel
Save