Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New publications page toggle #2240

Merged
merged 3 commits into from
Jul 12, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 70 additions & 0 deletions app/controllers/legacy_root_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
class LegacyRootController < ApplicationController
respond_to :html, :json

include ColumnSortable

ITEMS_PER_PAGE = 20

STATE_NAME_LISTS = { "draft" => "drafts", "fact_check" => "out_for_fact_check" }.freeze

def index
user_filter = params[:user_filter] || session[:user_filter]
session[:user_filter] = user_filter

@list = params[:list].presence || "drafts"
@presenter, @user_filter = build_presenter(user_filter, params[:page])

# Looking at another class, but the whole approach taken by this method and its
# associated presenter needs revisiting.
unless @presenter.acceptable_list?(@list)
render body: { "raw" => "Not Found" }, status: :not_found
return
end

if params[:string_filter].present?
clean_string_filter = params[:string_filter]
.strip
.gsub(/\s+/, " ")
@presenter.filter_by_substring(clean_string_filter)
end
end

private

def format_filter
Artefact::FORMATS_BY_DEFAULT_OWNING_APP["publisher"].include?(params[:format_filter]) ? params[:format_filter] : "edition"
end

def filtered_editions
return Edition if format_filter == "edition"

Edition.where(_type: "#{format_filter.camelcase}Edition")
end

def list_parameter_from_state(state)
STATE_NAME_LISTS[state] || state
end

def build_presenter(user_filter, current_page = nil)
user_filter, user = process_user_filter(user_filter)

editions = filtered_editions.order_by([sort_column, sort_direction])
editions = editions.page(current_page).per(ITEMS_PER_PAGE)
editions = editions.where.not(_type: "PopularLinksEdition")

[PrimaryListingPresenter.new(editions, user), user_filter]
end

def process_user_filter(user_filter = nil)
if user_filter.blank?
user_filter = current_user.uid
user = current_user
elsif %w[all nobody].include?(user_filter)
user = user_filter.to_sym
else
user = User.where(uid: user_filter).first
end

[user_filter, user]
end
end
2 changes: 2 additions & 0 deletions app/controllers/root_controller.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

class RootController < ApplicationController
respond_to :html, :json

Expand Down
13 changes: 13 additions & 0 deletions app/views/legacy_root/_amends_needed.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<table class="table table-striped table-bordered table-condensed" summary="List of &ldquo;Amends Needed&rdquo; content">
<thead>
<tr class="table-header">
<th scope="col"><%= sortable "_type", "Format" %></th>
<th scope="col"><%= sortable "title" %></th>
<th scope="col"><%= sortable "updated_at", "Updated" %></th>
<th scope="col"><%= sortable "assignee", "Assigned to" %></th>
</tr>
</thead>
<tbody>
<%= render :collection => @presenter.amends_needed, :partial => 'publication', :locals => {:tab => :amends_needed} %>
</tbody>
</table>
14 changes: 14 additions & 0 deletions app/views/legacy_root/_archived.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<table class="table table-striped table-bordered table-condensed" summary="List of &ldquo;Archived&rdquo; content">
<thead>
<tr class="table-header">
<th scope="col"><%= sortable "_type", "Format" %></th>
<th scope="col"><%= sortable "title" %></th>
<th scope="col"><%= sortable "updated_at", "Updated" %></th>
<th scope="col"><%= sortable "assignee", "Assigned to" %></th>
<th scope="col">Actions</th>
</tr>
</thead>
<tbody>
<%= render :collection => @presenter.archived, :partial => 'publication', :locals => {:tab => :archived} %>
</tbody>
</table>
13 changes: 13 additions & 0 deletions app/views/legacy_root/_drafts.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<table class="table table-striped table-bordered table-condensed" summary="List of &ldquo;Draft&rdquo; content">
<thead>
<tr class="table-header">
<th scope="col"><%= sortable "_type", "Format" %></th>
<th scope="col"><%= sortable "title" %></th>
<th scope="col"><%= sortable "updated_at", "Updated" %></th>
<th scope="col"><%= sortable "assignee", "Assigned to" %></th>
</tr>
</thead>
<tbody>
<%= render :collection => @presenter.draft, :partial => 'publication', :locals => {:tab => :draft} %>
</tbody>
</table>
13 changes: 13 additions & 0 deletions app/views/legacy_root/_fact_check_received.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<table class="table table-striped table-bordered table-condensed" summary="List of &ldquo;Fact-Check Received&rdquo; content">
<thead>
<tr class="table-header">
<th scope="col"><%= sortable "_type", "Format" %></th>
<th scope="col"><%= sortable "title" %></th>
<th scope="col"><%= sortable "updated_at", "Updated" %></th>
<th scope="col"><%= sortable "assignee", "Assigned to" %></th>
</tr>
</thead>
<tbody>
<%= render :collection => @presenter.fact_check_received, :partial => 'publication', :locals => {:tab => :fact_check_received} %>
</tbody>
</table>
15 changes: 15 additions & 0 deletions app/views/legacy_root/_in_review.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<table class="table table-striped table-bordered table-condensed" summary="List of &ldquo;In Review&rdquo; content">
<thead>
<tr class="table-header">
<th scope="col"><%= sortable "_type", "Format" %></th>
<th scope="col"><%= sortable "title" %></th>
<th scope="col"><%= sortable "updated_at", "Updated" %></th>
<th scope="col"><%= sortable "assignee", "Assigned to" %></th>
<th scope="col"><%= sortable "review_requested_at", "Awaiting review" %></th>
<th scope="col"><%= sortable "reviewer", "Reviewer" %></th>
</tr>
</thead>
<tbody>
<%= render :collection => @presenter.in_review, :partial => 'publication', :locals => {:tab => :in_review} %>
</tbody>
</table>
14 changes: 14 additions & 0 deletions app/views/legacy_root/_out_for_fact_check.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<table class="table table-striped table-bordered table-condensed" summary="List of &ldquo;Fact Check Requested&rdquo; content">
<thead>
<tr class="table-header">
<th scope="col"><%= sortable "format" %></th>
<th scope="col"><%= sortable "title" %></th>
<th scope="col"><%= sortable "updated_at", "Updated" %></th>
<th scope="col"><%= sortable "last_fact_checked_at", "Sent Out" %></th>
<th scope="col"><%= sortable "assignee", "Assigned to" %></th>
</tr>
</thead>
<tbody>
<%= render :collection => @presenter.fact_check, :partial => 'publication', :locals => {:tab => :fact_check} %>
</tbody>
</table>
78 changes: 78 additions & 0 deletions app/views/legacy_root/_publication.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
<tr>
<td>
<%= publication.format.underscore.humanize %>
</td>
<td class="title">
<h2 class="publication-table-title h4">
<%= link_to publication.admin_list_title, edition_path(publication) %>
<% if publication.in_beta? %>
<span class="badge badge-beta">beta</span>
<% end %>
</h2>

<% if publication.published? %>
<%= link_to "/#{publication.slug}", "#{Plek.website_root}/#{publication.slug}", class: 'link-muted' %>
<% elsif publication.safe_to_preview? %>
<%= link_to "/#{publication.slug}", preview_edition_path(publication), class: 'link-muted' %>
<% end %>

<span class="text-muted"> &middot; <span title="Edition <%= publication.version_number %>">#<%= publication.version_number %></span></span>
<% if tab && (tab == :published || tab == :archived) && publication.subsequent_siblings.first.present? %>
<span class="text-muted"> – <%= 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' %>
</span>
<% end %>

<% if publication.important_note.present? %>
<span class="text-muted">
&middot;
<i class="glyphicon glyphicon-comment" data-toggle="tooltip" title="<%= publication.important_note.comment %>"></i>
</span>
<% end %>
</td>
<td>
<time class="publication-table-date" data-toggle="tooltip" datetime="<%= publication.updated_at %>" title="<%= publication.updated_at.to_fs(:govuk_date) %>">
<%= publication.updated_at.to_date.to_fs(:govuk_date_short) %>
</time>
</td>
<% if tab && tab == :fact_check %>
<td>
<time class="publication-table-date" data-toggle="tooltip" datetime="<%= publication.last_fact_checked_at %>" title="<%= publication.last_fact_checked_at.to_fs(:govuk_date) %>">
<%= publication.last_fact_checked_at.to_date.to_fs(:govuk_date_short) %>
</time>
</td>
<% end %>
<% if tab && tab == :scheduled_for_publishing %>
<td>
<time class="publication-table-date" datetime="<%= publication.publish_at %>">
<%= publication.publish_at.to_fs(:govuk_date_short) %>
</time>
</td>
<% end %>
<td>
<%= publication.assignee %>
</td>
<% if tab && tab == :in_review %>
<td>
<%= time_ago_in_words(publication.review_requested_at) %>
</td>
<td>
<%= render partial: 'reviewer', locals: { publication: publication } %>
</td>
<% end %>
<% if tab && tab == :published %>
<td>
<%= publication.publisher %>
</td>
<% end %>
<% if tab && (tab == :archived || tab == :published) %>
<td>
<% if current_user.has_editor_permissions?(publication) %>
<% if publication.can_create_new_edition? %>
<%= link_to 'Create new edition', duplicate_edition_path(publication), class: 'btn btn-default', method: :post %>
<% elsif publication.in_progress_sibling %>
<%= link_to 'Edit newer edition', edition_path(publication.in_progress_sibling), html_options = { "class" => "btn btn-info"} %>
<% end %>
<% end %>
</td>
<% end %>
</tr>
15 changes: 15 additions & 0 deletions app/views/legacy_root/_published.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<table class="table table-striped table-bordered table-condensed" summary="List of &ldquo;Published&rdquo; content">
<thead>
<tr class="table-header">
<th scope="col"><%= sortable "_type", "Format" %></th>
<th scope="col"><%= sortable "title" %></th>
<th scope="col"><%= sortable "updated_at", "Updated" %></th>
<th scope="col"><%= sortable "assignee", "Assigned to" %></th>
<th scope="col"><%= sortable "publisher", "Published by" %></th>
<th scope="col">Actions</th>
</tr>
</thead>
<tbody>
<%= render :collection => @presenter.published, :partial => 'publication', :as => 'publication', :locals => {:tab => :published} %>
</tbody>
</table>
13 changes: 13 additions & 0 deletions app/views/legacy_root/_ready.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<table class="table table-striped table-bordered table-condensed" summary="List of &ldquo;Ready&rdquo; content">
<thead>
<tr class="table-header">
<th scope="col"><%= sortable "_type", "Format" %></th>
<th scope="col"><%= sortable "title" %></th>
<th scope="col"><%= sortable "updated_at", "Updated" %></th>
<th scope="col"><%= sortable "assignee", "Assigned to" %></th>
</tr>
</thead>
<tbody>
<%= render :collection => @presenter.ready, :partial => 'publication', :locals => {:tab => :ready} %>
</tbody>
</table>
8 changes: 8 additions & 0 deletions app/views/legacy_root/_reviewer.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<% if publication.reviewer and publication.reviewer.present? -%>
<%= publication.reviewer %>
<% elsif current_user != publication.assigned_to && current_user.has_editor_permissions?(publication) -%>
<%= form_for :edition, url: review_edition_path(publication._id), method: :put do |f| %>
<%= f.hidden_field :reviewer, value: current_user.name %>
<%= f.submit "Claim 2i", class: "btn btn-primary" %>
<% end -%>
<% end -%>
14 changes: 14 additions & 0 deletions app/views/legacy_root/_scheduled_for_publishing.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<table class="table table-striped table-bordered table-condensed" summary="List of &ldquo;Ready&rdquo; content">
<thead>
<tr class="table-header">
<th scope="col"><%= sortable "_type", "Format" %></th>
<th scope="col"><%= sortable "title" %></th>
<th scope="col"><%= sortable "updated_at", "Updated" %></th>
<th scope="col"><%= sortable "publish_at", "Scheduled" %></th>
<th scope="col"><%= sortable "assignee", "Assigned to" %></th>
</tr>
</thead>
<tbody>
<%= render :collection => @presenter.scheduled_for_publishing, :partial => 'publication', :locals => {:tab => :scheduled_for_publishing} %>
</tbody>
</table>
66 changes: 66 additions & 0 deletions app/views/legacy_root/index.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@

<div class="page-title">
<h1>
<% if !params[:string_filter].blank? %>
Searching for “<%= params[:string_filter] -%>” in “<%= @list.humanize %>”
<% else %>
<%= @list.humanize %>
<% end %>
</h1>
</div>

<% if flash[:notice] %>
<%= flash[:notice] %>
<% end %>

<div class="row">

<div class="col-md-2">

<div class="well sidebar-nav">
<ul class="nav nav-list">
<li class="nav-header">Filter by Status</li>
<%= publication_tab_list(@presenter, current: @list) %>
</ul>
</div>

<div class="well sidebar-nav">
<form method="GET" action="/" class="user-filter-form nav nav-list">
<%= hidden_field_tag :list, params[:list] %>
<%= hidden_field_tag :string_filter, params[:string_filter] %>
<label for="user_filter" class="nav-header">Assignee</label>
<%=
select_tag("user_filter", options_for_select(
[["All", "all"], ["Nobody", "nobody"]] +
User.enabled.alphabetized.map{ |u| [u.name, u.uid] }, @user_filter
), class: 'form-control js-user-filter', "data-module" => 'assignee-select')
%>
<label for="string_filter" class="add-top-margin nav-header">Keyword</label>
<%= text_field_tag "string_filter", params[:string_filter], class: 'form-control', type: "search" %>

<label for="format_filter" class="add-top-margin nav-header">Format</label>
<%= select_tag("format_filter", options_for_select(
format_filter_selection_options,
params[:format_filter]
), class: 'form-control') %>
<input class="add-top-margin btn btn-default" type="submit" value="Filter publications">
</form>
</div>
</div>

<% if params[:list] == "in_review" %>
<div class="col-md-10">
<p>
<%= link_to "Check Collections publisher", @presenter.step_by_step_review_url %> for step by steps that are waiting for review
</p>
</div>
<% end %>

<div id="publication-list-container" class="col-md-10">
<%= render @list %>
Dismissed Show dismissed Hide dismissed
<%= paginate @presenter.send(@list), theme: 'twitter-bootstrap-3' %>
Dismissed Show dismissed Hide dismissed
</div>

</div><!--./row -->

<% content_for :page_title, "Publications" %>
4 changes: 4 additions & 0 deletions config/features.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,8 @@
default: true,
description: "A feature only used by tests; not to be used for any actual features."
end

feature :design_system_publications_filter,
default: false,
description: "Update the publications page to use the GOV.UK Design System"
end
6 changes: 5 additions & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,11 @@
get "api/lookup-by-base-path", to: "publishing_api_proxy#lookup_by_base_path"

resources :publications
root to: "root#index"
constraints FeatureConstraint.new("design_system_publications_filter") do
root to: "root#index"
end
# The below "as: nil" is required to avoid a name clash with the constrained route, above, which causes an error
root to: "legacy_root#index", as: nil

# We used to nest all URLs under /admin so we now redirect that
# in case people had bookmarks set up. Using a proc as otherwise the
Expand Down
2 changes: 1 addition & 1 deletion test/functional/artefacts_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class ArtefactsControllerTest < ActionController::TestCase
get :new

assert_response :redirect
assert_redirected_to controller: "root", action: "index"
assert_redirected_to root_path
assert_includes flash[:danger], "do not have permission"
end
end
Expand Down
Loading
Loading