-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add new table to render publications to publications view
- Loading branch information
1 parent
13fa5a7
commit a936f7f
Showing
13 changed files
with
699 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
window.GOVUK = window.GOVUK || {} | ||
window.GOVUK.Modules = window.GOVUK.Modules || {}; | ||
|
||
(function (Modules) { | ||
function PublicationsTable ($module) { | ||
this.$module = $module | ||
this.details = this.$module.querySelectorAll('.govuk-details') | ||
this.openDetailsCount = 0 | ||
this.numDetails = this.details.length | ||
} | ||
|
||
PublicationsTable.prototype.init = function () { | ||
// Add Expand/Contract link to DOM | ||
this.addExpandlink() | ||
|
||
// Add Event listener for Expand All button | ||
this.$module.querySelector('.publications-table__heading a').addEventListener('click', this.toggleDetails.bind(this)) | ||
} | ||
|
||
// Add Expand/Contract link to DOM | ||
PublicationsTable.prototype.addExpandlink = function () { | ||
var expandLink = document.createElement('a') | ||
expandLink.classList.add('govuk-link', 'publications-table--expand-link') | ||
expandLink.textContent = 'Expand all' | ||
this.$module.querySelector('.publications-table__heading').append(expandLink) | ||
} | ||
|
||
// Toggles the "More details" sections | ||
PublicationsTable.prototype.toggleDetails = function (e) { | ||
if (this.openDetailsCount < this.numDetails) { | ||
this.details.forEach(function (section) { | ||
section.setAttribute('open', true) | ||
}) | ||
|
||
this.openDetailsCount = this.numDetails | ||
e.target.textContent = 'Collapse all' | ||
} else if (this.openDetailsCount === this.numDetails) { | ||
this.details.forEach(function (section) { | ||
section.removeAttribute('open') | ||
}) | ||
|
||
this.openDetailsCount = 0 | ||
e.target.textContent = 'Expand all' | ||
} | ||
} | ||
|
||
Modules.PublicationsTable = PublicationsTable | ||
})(window.GOVUK.Modules) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
.publications-table { | ||
position: relative; | ||
|
||
&--expand-link { | ||
float: right; | ||
font-size: 1.1875rem; | ||
} | ||
|
||
.govuk-tag { | ||
&--amends_needed { | ||
@extend .govuk-tag--red; // stylelint-disable-line scss/at-extend-no-missing-placeholder | ||
} | ||
|
||
&--archived { | ||
@extend .govuk-tag--blue; // stylelint-disable-line scss/at-extend-no-missing-placeholder | ||
} | ||
|
||
&--draft { | ||
@extend .govuk-tag--yellow; // stylelint-disable-line scss/at-extend-no-missing-placeholder | ||
} | ||
|
||
&--fact_check { | ||
@extend .govuk-tag--purple; // stylelint-disable-line scss/at-extend-no-missing-placeholder | ||
} | ||
|
||
&--fact_check_received { | ||
@extend .govuk-tag--pink; // stylelint-disable-line scss/at-extend-no-missing-placeholder | ||
} | ||
|
||
&--ready { | ||
@extend .govuk-tag--green; // stylelint-disable-line scss/at-extend-no-missing-placeholder | ||
} | ||
|
||
&--scheduled_for_publishing { | ||
@extend .govuk-tag--turquoise; // stylelint-disable-line scss/at-extend-no-missing-placeholder | ||
} | ||
|
||
&--published { | ||
@extend .govuk-tag--orange; // stylelint-disable-line scss/at-extend-no-missing-placeholder | ||
} | ||
|
||
&--in_review { | ||
@extend .govuk-tag--grey; // stylelint-disable-line scss/at-extend-no-missing-placeholder | ||
} | ||
} | ||
|
||
.govuk-table { | ||
border-top: 2px solid $govuk-text-colour; | ||
|
||
.govuk-table__header { | ||
white-space: nowrap; | ||
} | ||
|
||
.govuk-table__cell__updated { | ||
white-space: nowrap; | ||
} | ||
} | ||
|
||
.govuk-details { | ||
margin-top: govuk-spacing(2); | ||
} | ||
|
||
.govuk-summary-list { | ||
width: auto; | ||
} | ||
|
||
.govuk-details__summary { | ||
&::before { | ||
color: $govuk-text-colour; | ||
} | ||
} | ||
|
||
.govuk-details__summary-text { | ||
color: $govuk-text-colour; | ||
} | ||
|
||
.govuk-details__text { | ||
dd { | ||
word-break: break-word; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
module PublicationsTableHelper | ||
def reviewer(publication, current_user) | ||
if publication.state == "in_review" | ||
if publication.reviewer.present? | ||
publication.reviewer | ||
elsif current_user != publication.assigned_to && current_user.has_editor_permissions?(publication) | ||
render partial: "root/claim_2i", locals: { publication:, current_user: } | ||
end | ||
end | ||
end | ||
|
||
def edition_number(publication) | ||
if (publication.state == "published" || publication.state == "archived") && publication.subsequent_siblings.first.present? | ||
sanitize("#{publication.version_number} - #{link_to("##{publication.subsequent_siblings.first.version_number} in #{publication.subsequent_siblings.first.state.humanize.downcase}", edition_path(publication.subsequent_siblings.first), class: 'link-inherit')}") | ||
else | ||
publication.version_number.to_s | ||
end | ||
end | ||
|
||
def format(publication) | ||
publication.format.underscore.humanize | ||
end | ||
|
||
def important_note(publication) | ||
publication.important_note.comment if publication.important_note.present? | ||
end | ||
|
||
def awaiting_review(publication) | ||
time_ago_in_words(publication.review_requested_at) if publication.state == "in_review" | ||
end | ||
|
||
def sent_out(publication) | ||
publication.last_fact_checked_at.to_date.to_fs(:govuk_date_short) if publication.state == "fact_check" | ||
end | ||
|
||
def scheduled(publication) | ||
publication.publish_at.to_fs(:govuk_date_short) if publication.publish_at.present? | ||
end | ||
|
||
def published_by(publication) | ||
publication.publisher.presence | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<%= form_for :edition, url: review_edition_path(publication._id), method: :put do |f| %> | ||
<%= f.hidden_field :reviewer, value: current_user.name %> | ||
<%= render "govuk_publishing_components/components/button", { | ||
text: "Claim 2i", | ||
} %> | ||
<% end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
<div class="publications-table" data-module="publications-table"> | ||
<p class="govuk-heading-m govuk-!-margin-bottom-3 publications-table__heading"><%= @presenter.editions.length %> document(s)</p> | ||
|
||
<%= render "govuk_publishing_components/components/table", { | ||
head: [ | ||
{ | ||
text: "Title", | ||
}, | ||
{ | ||
text: "Updated", | ||
}, | ||
{ | ||
text: "Assigned to", | ||
}, | ||
{ | ||
text: "Status", | ||
}, | ||
], | ||
rows: @presenter.editions.map do | publication | | ||
[ | ||
{ | ||
text: | ||
sanitize("<p class='title govuk-body'><a href='editions/#{publication._id}' class='govuk-link govuk-!-font-weight-bold'>#{publication.title}</a></p>") + | ||
(render "govuk_publishing_components/components/details", { | ||
title: "More details", | ||
} do | ||
render "govuk_publishing_components/components/summary_list", { | ||
items: [ | ||
{field: "Edition", value: edition_number(publication)}, | ||
{field: "Format", value: format(publication)}, | ||
*([{field: "Important Note", value: important_note(publication)}] if important_note(publication)), | ||
*([{field: "Awaiting review", value: awaiting_review(publication)}] if awaiting_review(publication)), | ||
*([{field: "2i reviewer", value: reviewer(publication, current_user)}] if reviewer(publication, current_user)), | ||
*([{field: "Sent Out", value: sent_out(publication)}] if sent_out(publication)), | ||
*([{field: "Scheduled", value: scheduled(publication)}] if scheduled(publication)), | ||
*([{field: "Published by", value: published_by(publication)}] if published_by(publication)), | ||
], | ||
borderless: true, | ||
} | ||
end | ||
), | ||
}, | ||
{ | ||
text: sanitize("<span class='govuk-table__cell__updated'>#{publication.updated_at.to_date.to_fs(:govuk_date_short)}</span>"), | ||
}, | ||
{ | ||
text: publication.assignee, | ||
}, | ||
{ | ||
text: sanitize("<span class='govuk-tag govuk-tag--#{publication.state}'>#{publication.state.humanize}</span>"), | ||
}, | ||
] | ||
end, | ||
} %> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.