From 56417b1f1f2b85e88e571fd71c0750057ec51086 Mon Sep 17 00:00:00 2001 From: Mark Taylor <138604938+mtaylorgds@users.noreply.github.com> Date: Wed, 6 Sep 2023 08:37:51 +0100 Subject: [PATCH 1/5] Rename link_check_reports to legacy_link_check_reports In preparation for migration to the design system, where we will migrate a page at a time to use a link checker that uses design system components. --- ...ller.rb => legacy_link_check_reports_controller.rb} | 6 +++--- .../_form.html.erb | 2 +- .../_link_check_report.html.erb | 8 ++++---- .../admin/legacy_link_check_reports/create.js.erb | 1 + app/views/admin/legacy_link_check_reports/show.js.erb | 3 +++ app/views/admin/link_check_reports/create.js.erb | 1 - app/views/admin/link_check_reports/show.js.erb | 3 --- app/views/manuals/show.html.erb | 2 +- app/views/sections/show.html.erb | 2 +- config/routes.rb | 2 +- ...rb => legacy_link_check_reports_controller_spec.rb} | 10 +++++----- 11 files changed, 20 insertions(+), 20 deletions(-) rename app/controllers/{link_check_reports_controller.rb => legacy_link_check_reports_controller.rb} (89%) rename app/views/admin/{link_check_reports => legacy_link_check_reports}/_form.html.erb (52%) rename app/views/admin/{link_check_reports => legacy_link_check_reports}/_link_check_report.html.erb (81%) create mode 100644 app/views/admin/legacy_link_check_reports/create.js.erb create mode 100644 app/views/admin/legacy_link_check_reports/show.js.erb delete mode 100644 app/views/admin/link_check_reports/create.js.erb delete mode 100644 app/views/admin/link_check_reports/show.js.erb rename spec/controllers/{link_check_reports_controller_spec.rb => legacy_link_check_reports_controller_spec.rb} (91%) diff --git a/app/controllers/link_check_reports_controller.rb b/app/controllers/legacy_link_check_reports_controller.rb similarity index 89% rename from app/controllers/link_check_reports_controller.rb rename to app/controllers/legacy_link_check_reports_controller.rb index 7ebfde520..03b41a900 100644 --- a/app/controllers/link_check_reports_controller.rb +++ b/app/controllers/legacy_link_check_reports_controller.rb @@ -1,4 +1,4 @@ -class LinkCheckReportsController < ApplicationController +class LegacyLinkCheckReportsController < ApplicationController def create service = LinkCheckReport::CreateService.new( user: current_user, @@ -13,7 +13,7 @@ def create @reportable = reportable_hash respond_to do |format| - format.js { render "admin/link_check_reports/create" } + format.js { render "admin/legacy_link_check_reports/create" } format.html { redirect_to_reportable_path } end end @@ -26,7 +26,7 @@ def show @reportable = reportable_hash respond_to do |format| - format.js { render "admin/link_check_reports/show" } + format.js { render "admin/legacy_link_check_reports/show" } format.html { redirect_to_reportable_path } end end diff --git a/app/views/admin/link_check_reports/_form.html.erb b/app/views/admin/legacy_link_check_reports/_form.html.erb similarity index 52% rename from app/views/admin/link_check_reports/_form.html.erb rename to app/views/admin/legacy_link_check_reports/_form.html.erb index 557c47571..969c5e987 100644 --- a/app/views/admin/link_check_reports/_form.html.erb +++ b/app/views/admin/legacy_link_check_reports/_form.html.erb @@ -1,3 +1,3 @@ -<%= form_tag link_check_reports_path(link_reportable: reportable), remote: true do %> +<%= form_tag legacy_link_check_reports_path(link_reportable: reportable), remote: true do %> <%= submit_tag button_text, class: "btn btn-default add-top-margin remove-bottom-margin" %> <% end %> diff --git a/app/views/admin/link_check_reports/_link_check_report.html.erb b/app/views/admin/legacy_link_check_reports/_link_check_report.html.erb similarity index 81% rename from app/views/admin/link_check_reports/_link_check_report.html.erb rename to app/views/admin/legacy_link_check_reports/_link_check_report.html.erb index 095a37cb6..11a8a491a 100644 --- a/app/views/admin/link_check_reports/_link_check_report.html.erb +++ b/app/views/admin/legacy_link_check_reports/_link_check_report.html.erb @@ -2,13 +2,13 @@ <% if !report.present? %>

Check this document for broken links. The report will take a few moments to complete.

- <%= render 'admin/link_check_reports/form', reportable: reportable, button_text: 'Check for broken links' %> + <%= render 'admin/legacy_link_check_reports/form', reportable: reportable, button_text: 'Check for broken links' %>
<% elsif report.in_progress? %>
Broken link report in progress.
Please wait. <%= link_to "Refresh", - link_check_report_path(report.id), + legacy_link_check_report_path(report.id), class: 'js-broken-links-refresh js-hidden', remote: true %>
@@ -33,12 +33,12 @@ <% end %> <% end %> - <%= render 'admin/link_check_reports/form', reportable: reportable, button_text: 'Check again' %> + <%= render 'admin/legacy_link_check_reports/form', reportable: reportable, button_text: 'Check again' %> <% else %>

This document contains no broken links.

- <%= render 'admin/link_check_reports/form', reportable: reportable, button_text: 'Check again' %> + <%= render 'admin/legacy_link_check_reports/form', reportable: reportable, button_text: 'Check again' %>
<% end %> diff --git a/app/views/admin/legacy_link_check_reports/create.js.erb b/app/views/admin/legacy_link_check_reports/create.js.erb new file mode 100644 index 000000000..6f8704888 --- /dev/null +++ b/app/views/admin/legacy_link_check_reports/create.js.erb @@ -0,0 +1 @@ +$('.broken-links-report').replaceWith('<%=escape_javascript render("admin/legacy_link_check_reports/link_check_report", report: @report, reportable: @reportable ) %>'); diff --git a/app/views/admin/legacy_link_check_reports/show.js.erb b/app/views/admin/legacy_link_check_reports/show.js.erb new file mode 100644 index 000000000..5f280dbfa --- /dev/null +++ b/app/views/admin/legacy_link_check_reports/show.js.erb @@ -0,0 +1,3 @@ +<% if @report.completed? %> + $('.broken-links-report').replaceWith('<%=escape_javascript render("admin/legacy_link_check_reports/link_check_report", report: @report, reportable: @reportable ) %>'); +<% end %> diff --git a/app/views/admin/link_check_reports/create.js.erb b/app/views/admin/link_check_reports/create.js.erb deleted file mode 100644 index 5daa6e9e9..000000000 --- a/app/views/admin/link_check_reports/create.js.erb +++ /dev/null @@ -1 +0,0 @@ -$('.broken-links-report').replaceWith('<%=escape_javascript render("admin/link_check_reports/link_check_report", report: @report, reportable: @reportable ) %>'); diff --git a/app/views/admin/link_check_reports/show.js.erb b/app/views/admin/link_check_reports/show.js.erb deleted file mode 100644 index e6afe2793..000000000 --- a/app/views/admin/link_check_reports/show.js.erb +++ /dev/null @@ -1,3 +0,0 @@ -<% if @report.completed? %> - $('.broken-links-report').replaceWith('<%=escape_javascript render("admin/link_check_reports/link_check_report", report: @report, reportable: @reportable ) %>'); -<% end %> diff --git a/app/views/manuals/show.html.erb b/app/views/manuals/show.html.erb index 385c374a1..848d5ff25 100644 --- a/app/views/manuals/show.html.erb +++ b/app/views/manuals/show.html.erb @@ -112,6 +112,6 @@
- <%= render "admin/link_check_reports/link_check_report", reportable: { manual_id: manual.to_param }, report: manual.link_check_report %> + <%= render "admin/legacy_link_check_reports/link_check_report", reportable: { manual_id: manual.to_param }, report: manual.link_check_report %>
diff --git a/app/views/sections/show.html.erb b/app/views/sections/show.html.erb index 1133f9f27..1c915e04c 100644 --- a/app/views/sections/show.html.erb +++ b/app/views/sections/show.html.erb @@ -27,6 +27,6 @@
- <%= render "admin/link_check_reports/link_check_report", reportable: { manual_id: manual.to_param, section_id: section.to_param }, report: section.link_check_report %> + <%= render "admin/legacy_link_check_reports/link_check_report", reportable: { manual_id: manual.to_param, section_id: section.to_param }, report: section.link_check_report %>
diff --git a/config/routes.rb b/config/routes.rb index f1e133100..04f1f2403 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -34,7 +34,7 @@ put :original_publication_date, on: :member, action: :update_original_publication_date end - resources :link_check_reports, only: %i[create show] + resources :legacy_link_check_reports, only: %i[create show] post "/link-checker-api-callback" => "link_checker_api_callback#callback", as: "link_checker_api_callback" diff --git a/spec/controllers/link_check_reports_controller_spec.rb b/spec/controllers/legacy_link_check_reports_controller_spec.rb similarity index 91% rename from spec/controllers/link_check_reports_controller_spec.rb rename to spec/controllers/legacy_link_check_reports_controller_spec.rb index c7250fcc9..5d73c0c06 100644 --- a/spec/controllers/link_check_reports_controller_spec.rb +++ b/spec/controllers/legacy_link_check_reports_controller_spec.rb @@ -1,7 +1,7 @@ require "spec_helper" require "gds_api/test_helpers/link_checker_api" -describe LinkCheckReportsController, type: :controller do +describe LegacyLinkCheckReportsController, type: :controller do include GdsApi::TestHelpers::LinkCheckerApi let(:user) { FactoryBot.create(:user) } @@ -47,7 +47,7 @@ it "AJAX POST renders the create template and creates a link check report" do post :create, xhr: true, params: { link_reportable: { manual_id: manual.id } } - expect(response).to render_template("admin/link_check_reports/create") + expect(response).to render_template("admin/legacy_link_check_reports/create") expect(LinkCheckReport.count).to eq(1) end end @@ -64,7 +64,7 @@ it "AJAX POST renders the create template and creates a link check report" do post :create, xhr: true, params: { link_reportable: { manual_id: manual.id, section_id: section_edition.id } } - expect(response).to render_template("admin/link_check_reports/create") + expect(response).to render_template("admin/legacy_link_check_reports/create") expect(LinkCheckReport.count).to eq(1) end end @@ -91,7 +91,7 @@ it "AJAX GET assigns the LinkCheckReport and renders the show template" do get :show, xhr: true, params: { id: link_check_report.id } - expect(response).to render_template("admin/link_check_reports/show") + expect(response).to render_template("admin/legacy_link_check_reports/show") expect(assigns(:report)).to eq(link_check_report) expect(assigns(:reportable)).to eq(manual_id: manual.id.to_s) end @@ -118,7 +118,7 @@ it "AJAX GET assigns the LinkCheckReport and renders the show template" do get :show, xhr: true, params: { id: link_check_report.id } - expect(response).to render_template("admin/link_check_reports/show") + expect(response).to render_template("admin/legacy_link_check_reports/show") expect(assigns(:report)).to eq(link_check_report) expect(assigns(:reportable)).to eq(manual_id: manual.id.to_s, section_id: section_edition.id.to_s) end From b14efd1fde0c8a35845281d1f3731fb4bc854d7e Mon Sep 17 00:00:00 2001 From: Mark Taylor <138604938+mtaylorgds@users.noreply.github.com> Date: Wed, 6 Sep 2023 08:50:45 +0100 Subject: [PATCH 2/5] Duplicate legacy_link_check_reports Create a duplicate, that will be migrated to use design system components and have pages switch over to this new version as those pages themselves are migrated. --- .../link_check_reports_controller.rb | 76 ++++++++++ .../admin/link_check_reports/_form.html.erb | 3 + .../_link_check_report.html.erb | 44 ++++++ .../admin/link_check_reports/create.js.erb | 1 + .../admin/link_check_reports/show.js.erb | 3 + config/routes.rb | 1 + .../link_check_reports_controller_spec.rb | 143 ++++++++++++++++++ 7 files changed, 271 insertions(+) create mode 100644 app/controllers/link_check_reports_controller.rb create mode 100644 app/views/admin/link_check_reports/_form.html.erb create mode 100644 app/views/admin/link_check_reports/_link_check_report.html.erb create mode 100644 app/views/admin/link_check_reports/create.js.erb create mode 100644 app/views/admin/link_check_reports/show.js.erb create mode 100644 spec/controllers/link_check_reports_controller_spec.rb diff --git a/app/controllers/link_check_reports_controller.rb b/app/controllers/link_check_reports_controller.rb new file mode 100644 index 000000000..7ebfde520 --- /dev/null +++ b/app/controllers/link_check_reports_controller.rb @@ -0,0 +1,76 @@ +class LinkCheckReportsController < ApplicationController + def create + service = LinkCheckReport::CreateService.new( + user: current_user, + manual_id: link_reportable_params[:manual_id], + section_id: link_reportable_params[:section_id], + ) + + @report = service.call + + return handle_nil_report unless @report + + @reportable = reportable_hash + + respond_to do |format| + format.js { render "admin/link_check_reports/create" } + format.html { redirect_to_reportable_path } + end + end + + def show + @report = LinkCheckReport::ShowService.new( + id: link_reportable_show_params[:id], + ).call + + @reportable = reportable_hash + + respond_to do |format| + format.js { render "admin/link_check_reports/show" } + format.html { redirect_to_reportable_path } + end + end + +private + + def handle_nil_report + respond_to do |format| + format.js { head :unprocessable_entity } + format.html { redirect_back(fallback_location: root_path) } + end + end + + def reportable_object + @reportable_object ||= find_reportable(section_id: @report.section_id, manual_id: @report.manual_id) + end + + def link_reportable_params + params.require(:link_reportable).permit(:manual_id, :section_id) + end + + def link_reportable_show_params + params.permit(:id) + end + + def find_reportable(reportable_params) + LinkCheckReport::FindReportableService.new( + user: current_user, + manual_id: reportable_params[:manual_id], + section_id: reportable_params[:section_id], + ).call + end + + def redirect_to_reportable_path + case reportable_object + when Section + redirect_to manual_section_path(@report.manual_id, reportable_object.to_param) + when Manual + redirect_to manual_path(reportable_object.to_param) + end + end + + def reportable_hash + { section_id: @report.section_id, + manual_id: @report.manual_id }.delete_if { |_, v| v.blank? } + end +end diff --git a/app/views/admin/link_check_reports/_form.html.erb b/app/views/admin/link_check_reports/_form.html.erb new file mode 100644 index 000000000..557c47571 --- /dev/null +++ b/app/views/admin/link_check_reports/_form.html.erb @@ -0,0 +1,3 @@ +<%= form_tag link_check_reports_path(link_reportable: reportable), remote: true do %> + <%= submit_tag button_text, class: "btn btn-default add-top-margin remove-bottom-margin" %> +<% end %> diff --git a/app/views/admin/link_check_reports/_link_check_report.html.erb b/app/views/admin/link_check_reports/_link_check_report.html.erb new file mode 100644 index 000000000..095a37cb6 --- /dev/null +++ b/app/views/admin/link_check_reports/_link_check_report.html.erb @@ -0,0 +1,44 @@ + diff --git a/app/views/admin/link_check_reports/create.js.erb b/app/views/admin/link_check_reports/create.js.erb new file mode 100644 index 000000000..5daa6e9e9 --- /dev/null +++ b/app/views/admin/link_check_reports/create.js.erb @@ -0,0 +1 @@ +$('.broken-links-report').replaceWith('<%=escape_javascript render("admin/link_check_reports/link_check_report", report: @report, reportable: @reportable ) %>'); diff --git a/app/views/admin/link_check_reports/show.js.erb b/app/views/admin/link_check_reports/show.js.erb new file mode 100644 index 000000000..e6afe2793 --- /dev/null +++ b/app/views/admin/link_check_reports/show.js.erb @@ -0,0 +1,3 @@ +<% if @report.completed? %> + $('.broken-links-report').replaceWith('<%=escape_javascript render("admin/link_check_reports/link_check_report", report: @report, reportable: @reportable ) %>'); +<% end %> diff --git a/config/routes.rb b/config/routes.rb index 04f1f2403..8604a62c8 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -35,6 +35,7 @@ end resources :legacy_link_check_reports, only: %i[create show] + resources :link_check_reports, only: %i[create show] post "/link-checker-api-callback" => "link_checker_api_callback#callback", as: "link_checker_api_callback" diff --git a/spec/controllers/link_check_reports_controller_spec.rb b/spec/controllers/link_check_reports_controller_spec.rb new file mode 100644 index 000000000..c7250fcc9 --- /dev/null +++ b/spec/controllers/link_check_reports_controller_spec.rb @@ -0,0 +1,143 @@ +require "spec_helper" +require "gds_api/test_helpers/link_checker_api" + +describe LinkCheckReportsController, type: :controller do + include GdsApi::TestHelpers::LinkCheckerApi + + let(:user) { FactoryBot.create(:user) } + let(:manual) { FactoryBot.build(:manual, id: 538, body: "[link](http://[www.example.com)") } + let(:section_edition) { FactoryBot.create(:section_edition, id: 53_880, body: "[link](http://[www.example.com/section)") } + let(:section) { Section.new(manual:, uuid: "section-uuid", latest_edition: section_edition) } + + before do + login_as_stub_user + allow(Manual).to receive(:find).and_return(manual) + allow(Section).to receive(:find).and_return(section) + end + + describe "#create" do + before do + stub_link_checker_api + end + + context "when there are no links" do + let(:manual) { FactoryBot.build(:manual, id: 538, body: "hello") } + + it "returns 422 for AJAX requests" do + post :create, xhr: true, params: { link_reportable: { manual_id: manual.id } } + expect(response.status).to eq(422) + end + + it "redirects POST page" do + post :create, params: { link_reportable: { manual_id: manual.id } } + + expect(response).to redirect_to(root_path) + end + end + + context "manual" do + it "POST returns a redirects to the manual show page" do + post :create, params: { link_reportable: { manual_id: manual.id } } + + expected_path = manual_path(manual.to_param) + expect(response).to redirect_to(expected_path) + expect(LinkCheckReport.count).to eq(1) + end + + it "AJAX POST renders the create template and creates a link check report" do + post :create, xhr: true, params: { link_reportable: { manual_id: manual.id } } + + expect(response).to render_template("admin/link_check_reports/create") + expect(LinkCheckReport.count).to eq(1) + end + end + + context "section" do + it "POST returns redirects to the section show page" do + post :create, params: { link_reportable: { manual_id: manual.id, section_id: section_edition.id } } + + expected_path = manual_section_path(manual.to_param, section.to_param) + expect(response).to redirect_to(expected_path) + expect(LinkCheckReport.count).to eq(1) + end + + it "AJAX POST renders the create template and creates a link check report" do + post :create, xhr: true, params: { link_reportable: { manual_id: manual.id, section_id: section_edition.id } } + + expect(response).to render_template("admin/link_check_reports/create") + expect(LinkCheckReport.count).to eq(1) + end + end + end + + describe "#show" do + context "manual" do + let(:link_check_report) do + FactoryBot.create( + :link_check_report, + :with_broken_links, + manual_id: manual.id, + batch_id: 1, + ) + end + + it "GET redirects back to the manual page" do + get :show, params: { id: link_check_report.id } + + expected_path = manual_path(manual.to_param) + expect(response).to redirect_to(expected_path) + end + + it "AJAX GET assigns the LinkCheckReport and renders the show template" do + get :show, xhr: true, params: { id: link_check_report.id } + + expect(response).to render_template("admin/link_check_reports/show") + expect(assigns(:report)).to eq(link_check_report) + expect(assigns(:reportable)).to eq(manual_id: manual.id.to_s) + end + end + + context "section" do + let(:link_check_report) do + FactoryBot.create( + :link_check_report, + :with_broken_links, + manual_id: manual.id, + section_id: section_edition.id, + batch_id: 1, + ) + end + + it "GET redirects back to the section page" do + get :show, params: { id: link_check_report.id } + + expected_path = manual_section_path(manual.to_param, section.to_param) + expect(response).to redirect_to(expected_path) + end + + it "AJAX GET assigns the LinkCheckReport and renders the show template" do + get :show, xhr: true, params: { id: link_check_report.id } + + expect(response).to render_template("admin/link_check_reports/show") + expect(assigns(:report)).to eq(link_check_report) + expect(assigns(:reportable)).to eq(manual_id: manual.id.to_s, section_id: section_edition.id.to_s) + end + end + end + +private + + def stub_link_checker_api + body = link_checker_api_batch_report_hash( + id: 5, + links: [{ uri: "http://www.example.com" }], + ) + + stub_request(:post, %r{\A#{Plek.find('link-checker-api')}/batch}) + .to_return( + body: body.to_json, + status: 202, + headers: { "Content-Type": "application/json" }, + ) + end +end From 32023f67720e75986b7c90f2651cb7bb293afb73 Mon Sep 17 00:00:00 2001 From: Mark Taylor <138604938+mtaylorgds@users.noreply.github.com> Date: Wed, 6 Sep 2023 11:12:17 +0100 Subject: [PATCH 3/5] Migrate the manuals show view to the design system Update the layout of the "show" view from using the legacy layout to use the design system one. This change significantly alters the layout of the page, but without changing any of the underlying functionality. --- app/assets/javascripts/application.js | 1 + .../stylesheets/_broken-links-report.scss | 48 +--- app/assets/stylesheets/_header.scss | 18 -- .../stylesheets/application-legacy.scss | 1 - app/assets/stylesheets/application.scss | 17 ++ app/assets/stylesheets/views/manuals.scss | 40 +++ app/controllers/manuals_controller.rb | 1 + app/helpers/application_helper.rb | 116 ++++++++ .../admin/link_check_reports/_form.html.erb | 5 +- .../_link_check_report.html.erb | 38 +-- app/views/layouts/design_system.html.erb | 26 ++ app/views/manuals/_title.html.erb | 13 - app/views/manuals/show.html.erb | 214 +++++++------- .../shared/_summary_card_component.html.erb | 41 +++ features/step_definitions/manual_steps.rb | 10 +- features/support/manual_helpers.rb | 10 +- spec/features/manual_urls_spec.rb | 2 +- spec/helpers/application_helper_spec.rb | 267 ++++++++++++++++++ .../link_check_reports/_form.html.erb_spec.rb | 12 + spec/views/manuals/show.html.erb_spec.rb | 21 ++ 20 files changed, 708 insertions(+), 193 deletions(-) create mode 100644 app/assets/stylesheets/views/manuals.scss delete mode 100644 app/views/manuals/_title.html.erb create mode 100644 app/views/shared/_summary_card_component.html.erb create mode 100644 spec/views/admin/link_check_reports/_form.html.erb_spec.rb diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js index 760ea533f..1275150d2 100644 --- a/app/assets/javascripts/application.js +++ b/app/assets/javascripts/application.js @@ -1,6 +1,7 @@ //= require govuk_publishing_components/dependencies //= require govuk_publishing_components/lib //= require govuk_publishing_components/components/button +//= require govuk_publishing_components/components/details //= require govuk_publishing_components/components/layout-header //= require govuk_publishing_components/components/skip-link //= require govuk_publishing_components/components/table diff --git a/app/assets/stylesheets/_broken-links-report.scss b/app/assets/stylesheets/_broken-links-report.scss index 5f9d89127..ed709c006 100644 --- a/app/assets/stylesheets/_broken-links-report.scss +++ b/app/assets/stylesheets/_broken-links-report.scss @@ -1,41 +1,21 @@ -.broken-links-report { - .issue-summary { - font-weight: normal; - } - - .issue-list { - list-style: none; - padding-left: 0; - - li { - margin-top: 5px; - } - } +.app-inset-prompt { + @include govuk-text-colour; + @include govuk-responsive-padding(4); + @include govuk-responsive-margin(6, "bottom"); - .issue-status-description { - margin-top: 10px; - } + border-left: $govuk-border-width-narrow solid govuk-colour("dark-grey"); + background-color: govuk-colour("light-grey"); - .issue-list + .issue-status-description { - margin: 15px 0; + @include govuk-media-query($from: tablet) { + border-left: $govuk-border-width solid govuk-colour("dark-grey"); } - .display-issue-details { - display: block; - font-weight: bold; - padding-top: 5px; - } - - .display-issue-details::-webkit-details-marker { - display: none; - } - - .display-issue-details:before { - content: "\25B6"; - padding-right: 3px; + &:focus { + outline: $govuk-focus-width solid $govuk-focus-colour; } +} - details[open] > .display-issue-details:before { - content: "\25BC"; - } +.app-inset-prompt--error { + border-color: $govuk-error-colour; + background-color: govuk-tint($govuk-error-colour, 90%); } diff --git a/app/assets/stylesheets/_header.scss b/app/assets/stylesheets/_header.scss index b432fdd15..96f5a71b3 100644 --- a/app/assets/stylesheets/_header.scss +++ b/app/assets/stylesheets/_header.scss @@ -1,21 +1,3 @@ .page-header { border-bottom: none; - - .document-slug { - color: $text-muted; - font-size: $font-size-large; - display: block; - margin-top: 5px; - font-weight: normal; - padding: 0; - } - - .document-slug li { - display: inline; - list-style: none; - } - - .document-slug li + li:before { - content: "– "; - } } diff --git a/app/assets/stylesheets/application-legacy.scss b/app/assets/stylesheets/application-legacy.scss index 2bfd9fae3..d40cd81e5 100644 --- a/app/assets/stylesheets/application-legacy.scss +++ b/app/assets/stylesheets/application-legacy.scss @@ -14,7 +14,6 @@ @import "navbar"; @import "header"; @import "ordered_lists"; -@import "broken-links-report"; p.no-content-message { // stylelint-disable-line selector-no-qualifying-type @include core-19; diff --git a/app/assets/stylesheets/application.scss b/app/assets/stylesheets/application.scss index 30d221521..d7ec13d2c 100644 --- a/app/assets/stylesheets/application.scss +++ b/app/assets/stylesheets/application.scss @@ -1,12 +1,29 @@ +$govuk-page-width: 1140px; + @import "govuk_publishing_components/govuk_frontend_support"; @import "govuk_publishing_components/component_support"; @import "govuk_publishing_components/components/breadcrumbs"; @import "govuk_publishing_components/components/button"; +@import "govuk_publishing_components/components/details"; +@import "govuk_publishing_components/components/error-alert"; +@import "govuk_publishing_components/components/error-message"; +@import "govuk_publishing_components/components/hint"; +@import "govuk_publishing_components/components/input"; +@import "govuk_publishing_components/components/label"; @import "govuk_publishing_components/components/layout-footer"; +@import "govuk_publishing_components/components/layout-for-admin"; @import "govuk_publishing_components/components/layout-header"; +@import "govuk_publishing_components/components/notice"; +@import "govuk_publishing_components/components/search"; @import "govuk_publishing_components/components/skip-link"; +@import "govuk_publishing_components/components/success-alert"; +@import "govuk_publishing_components/components/summary-list"; @import "govuk_publishing_components/components/table"; @import "govuk_publishing_components/components/title"; +@import "govuk_publishing_components/components/warning-text"; +@import "views/manuals"; @import "views/whats_new"; + +@import "broken-links-report"; diff --git a/app/assets/stylesheets/views/manuals.scss b/app/assets/stylesheets/views/manuals.scss new file mode 100644 index 000000000..5a078f0b5 --- /dev/null +++ b/app/assets/stylesheets/views/manuals.scss @@ -0,0 +1,40 @@ +.app-view-manuals__section { + padding: govuk-spacing(3) 0; +} + +.app-view-manuals__section:first-child { + padding-top: 0; +} + +.app-view-manuals__sidebar-actions { + padding: govuk-spacing(3); + margin-bottom: govuk-spacing(6); + background-color: govuk-colour("light-grey"); + + .gem-c-button { + width: 100%; + } + + .govuk-list { + margin-bottom: 0; + + li:last-child { + margin-bottom: 0; + } + } +} + +.app-view-summary__sidebar-actions .govuk-list--spaced li:last-child div + .broken-links-report { + margin-top: govuk-spacing(6); +} + +.app-flash-container { + .govuk-notification-banner { + margin-top: govuk-spacing(4); + } + + .gem-c-error-alert { + margin-bottom: 0; + margin-top: govuk-spacing(4); + } +} diff --git a/app/controllers/manuals_controller.rb b/app/controllers/manuals_controller.rb index b5ecefec4..022a536ab 100644 --- a/app/controllers/manuals_controller.rb +++ b/app/controllers/manuals_controller.rb @@ -27,6 +27,7 @@ def show render( :show, + layout: "design_system", locals: { manual:, slug_unique:, diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 52f4a5316..b43b1719a 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -15,6 +15,122 @@ def state(manual) tag.span(state, class: classes).html_safe end + def state_label(manual) + state_text = manual.publication_state + + if state_text == "published" && manual.draft? + state_text << " with new draft" + end + + classes = "govuk-tag govuk-tag--s" + classes << if manual.draft? + " govuk-tag--blue" + elsif manual.published? + " govuk-tag--green" + else + " govuk-tag--grey" + end + + tag.span(state_text, class: classes).html_safe + end + + def manual_metadata_rows(manual) + rows = [ + { + key: "Status", + value: state_label(manual), + }, + ] + + if current_user_is_gds_editor? + rows << { + key: "From", + value: link_to(manual.organisation_slug, url_for_public_org(manual.organisation_slug)), + } + end + + if manual.originally_published_at.present? + rows << { + key: "Originally published", + value: nice_time_format(manual.originally_published_at), + } + end + + if manual.publish_tasks.any? + rows << { + key: "Last published", + value: publication_task_state(manual.publish_tasks.first), + } + end + rows + end + + def manual_front_page_rows(manual) + rows = [ + { + key: "Slug", + value: manual.slug, + }, + { + key: "Title", + value: sanitize(manual.title), + }, + { + key: "Summary", + value: sanitize(manual.summary), + }, + ] + + if manual.body.present? + rows << { + key: "Body", + value: simple_format(truncate(manual.body, length: 500, class: "govuk-!-margin-top-0")), + } + end + + rows + end + + def manual_sidebar_action_items(manual, slug_unique) + items = [] + + if allow_publish?(manual, slug_unique) + items << render("govuk_publishing_components/components/button", { + text: "Publish", + href: confirm_publish_manual_path(manual), + }) + end + + unless manual.has_ever_been_published? + items << render("govuk_publishing_components/components/button", { + text: "Discard", + destructive: true, + }) + end + + items + end + + def manual_section_rows(manual) + manual.sections.map do |section| + row = {} + + row[:key] = if section.draft? + draft_tag = tag.span("DRAFT", class: "govuk-tag govuk-tag--s govuk-tag--blue") + title_span = tag.span(section.title, class: "govuk-!-static-margin-2") + draft_tag << title_span + else + tag.span(section.title) + end + row[:value] = last_updated_text(section) + row[:actions] = [{ + label: "View", + href: manual_section_path(manual, section), + }] + row + end + end + def show_preview?(item) if item.respond_to?(:sections) item.draft? || item.sections.any?(&:draft?) diff --git a/app/views/admin/link_check_reports/_form.html.erb b/app/views/admin/link_check_reports/_form.html.erb index 557c47571..3f2a41f78 100644 --- a/app/views/admin/link_check_reports/_form.html.erb +++ b/app/views/admin/link_check_reports/_form.html.erb @@ -1,3 +1,6 @@ <%= form_tag link_check_reports_path(link_reportable: reportable), remote: true do %> - <%= submit_tag button_text, class: "btn btn-default add-top-margin remove-bottom-margin" %> + <%= render "govuk_publishing_components/components/button", { + text: button_text, + secondary_quiet: true + } %> <% end %> diff --git a/app/views/admin/link_check_reports/_link_check_report.html.erb b/app/views/admin/link_check_reports/_link_check_report.html.erb index 095a37cb6..c287ee7e1 100644 --- a/app/views/admin/link_check_reports/_link_check_report.html.erb +++ b/app/views/admin/link_check_reports/_link_check_report.html.erb @@ -1,34 +1,36 @@