Skip to content

Commit

Permalink
Merge pull request #2151 from alphagov/consolidation-move-manual-show…
Browse files Browse the repository at this point in the history
…-page-to-design-system

Consolidation move manual show page to design system
  • Loading branch information
ryanb-gds authored Sep 8, 2023
2 parents adbbbbb + a86634d commit 073f2ce
Show file tree
Hide file tree
Showing 28 changed files with 995 additions and 198 deletions.
1 change: 1 addition & 0 deletions app/assets/javascripts/application.js
Original file line number Diff line number Diff line change
@@ -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
48 changes: 14 additions & 34 deletions app/assets/stylesheets/_broken-links-report.scss
Original file line number Diff line number Diff line change
@@ -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%);
}
18 changes: 0 additions & 18 deletions app/assets/stylesheets/_header.scss
Original file line number Diff line number Diff line change
@@ -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: "";
}
}
1 change: 0 additions & 1 deletion app/assets/stylesheets/application-legacy.scss
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
18 changes: 18 additions & 0 deletions app/assets/stylesheets/application.scss
Original file line number Diff line number Diff line change
@@ -1,12 +1,30 @@
$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/heading";
@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";
40 changes: 40 additions & 0 deletions app/assets/stylesheets/views/manuals.scss
Original file line number Diff line number Diff line change
@@ -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);
}
}
76 changes: 76 additions & 0 deletions app/controllers/legacy_link_check_reports_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
class LegacyLinkCheckReportsController < 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/legacy_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/legacy_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
1 change: 1 addition & 0 deletions app/controllers/manuals_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ def show

render(
:show,
layout: "design_system",
locals: {
manual:,
slug_unique:,
Expand Down
116 changes: 116 additions & 0 deletions app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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?)
Expand Down
3 changes: 3 additions & 0 deletions app/views/admin/legacy_link_check_reports/_form.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<%= 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 %>
Loading

0 comments on commit 073f2ce

Please sign in to comment.