From d0ff8be0e3ac7eb9c023c276a92403091c82e5be Mon Sep 17 00:00:00 2001
From: Mark Taylor <138604938+mtaylorgds@users.noreply.github.com>
Date: Fri, 12 Jul 2024 15:55:05 +0100
Subject: [PATCH] Create a skeleton filtered editions view
Create a skeleton view for the root page that will display a filtered
list of editions, implemented using the GOV.UK Design System.
Sets up the basic page structure and makes available the entire list of
editions.
Implementing filtering will follow.
---
app/controllers/root_controller.rb | 67 +---------------
app/presenters/filtered_editions_presenter.rb | 7 ++
app/views/root/_amends_needed.html.erb | 13 ----
app/views/root/_archived.html.erb | 14 ----
app/views/root/_drafts.html.erb | 13 ----
app/views/root/_fact_check_received.html.erb | 13 ----
app/views/root/_in_review.html.erb | 15 ----
app/views/root/_out_for_fact_check.html.erb | 14 ----
app/views/root/_publication.html.erb | 78 -------------------
app/views/root/_published.html.erb | 15 ----
app/views/root/_ready.html.erb | 13 ----
app/views/root/_reviewer.html.erb | 8 --
.../root/_scheduled_for_publishing.html.erb | 14 ----
app/views/root/index.html.erb | 73 ++---------------
test/functional/root_controller_test.rb | 60 ++------------
15 files changed, 23 insertions(+), 394 deletions(-)
create mode 100644 app/presenters/filtered_editions_presenter.rb
delete mode 100644 app/views/root/_amends_needed.html.erb
delete mode 100644 app/views/root/_archived.html.erb
delete mode 100644 app/views/root/_drafts.html.erb
delete mode 100644 app/views/root/_fact_check_received.html.erb
delete mode 100644 app/views/root/_in_review.html.erb
delete mode 100644 app/views/root/_out_for_fact_check.html.erb
delete mode 100644 app/views/root/_publication.html.erb
delete mode 100644 app/views/root/_published.html.erb
delete mode 100644 app/views/root/_ready.html.erb
delete mode 100644 app/views/root/_reviewer.html.erb
delete mode 100644 app/views/root/_scheduled_for_publishing.html.erb
diff --git a/app/controllers/root_controller.rb b/app/controllers/root_controller.rb
index ed86bb232..ea449d955 100644
--- a/app/controllers/root_controller.rb
+++ b/app/controllers/root_controller.rb
@@ -1,72 +1,9 @@
# frozen_string_literal: true
class RootController < ApplicationController
- respond_to :html, :json
-
- include ColumnSortable
-
- ITEMS_PER_PAGE = 20
-
- STATE_NAME_LISTS = { "draft" => "drafts", "fact_check" => "out_for_fact_check" }.freeze
+ layout "design_system"
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]
+ @presenter = FilteredEditionsPresenter.new
end
end
diff --git a/app/presenters/filtered_editions_presenter.rb b/app/presenters/filtered_editions_presenter.rb
new file mode 100644
index 000000000..9f97a6b1d
--- /dev/null
+++ b/app/presenters/filtered_editions_presenter.rb
@@ -0,0 +1,7 @@
+# frozen_string_literal: true
+
+class FilteredEditionsPresenter
+ def editions
+ Edition.all
+ end
+end
diff --git a/app/views/root/_amends_needed.html.erb b/app/views/root/_amends_needed.html.erb
deleted file mode 100644
index 3b4c4dda1..000000000
--- a/app/views/root/_amends_needed.html.erb
+++ /dev/null
@@ -1,13 +0,0 @@
-
-
-
-
-
- <%= render :collection => @presenter.amends_needed, :partial => 'publication', :locals => {:tab => :amends_needed} %>
-
-
diff --git a/app/views/root/_archived.html.erb b/app/views/root/_archived.html.erb
deleted file mode 100644
index dcf9746cf..000000000
--- a/app/views/root/_archived.html.erb
+++ /dev/null
@@ -1,14 +0,0 @@
-
-
-
-
-
- <%= render :collection => @presenter.archived, :partial => 'publication', :locals => {:tab => :archived} %>
-
-
diff --git a/app/views/root/_drafts.html.erb b/app/views/root/_drafts.html.erb
deleted file mode 100644
index 8f172d9fb..000000000
--- a/app/views/root/_drafts.html.erb
+++ /dev/null
@@ -1,13 +0,0 @@
-
-
-
-
-
- <%= render :collection => @presenter.draft, :partial => 'publication', :locals => {:tab => :draft} %>
-
-
diff --git a/app/views/root/_fact_check_received.html.erb b/app/views/root/_fact_check_received.html.erb
deleted file mode 100644
index 7a74622c2..000000000
--- a/app/views/root/_fact_check_received.html.erb
+++ /dev/null
@@ -1,13 +0,0 @@
-
-
-
-
-
- <%= render :collection => @presenter.fact_check_received, :partial => 'publication', :locals => {:tab => :fact_check_received} %>
-
-
diff --git a/app/views/root/_in_review.html.erb b/app/views/root/_in_review.html.erb
deleted file mode 100644
index 8485ab8c9..000000000
--- a/app/views/root/_in_review.html.erb
+++ /dev/null
@@ -1,15 +0,0 @@
-
-
-
-
-
- <%= render :collection => @presenter.in_review, :partial => 'publication', :locals => {:tab => :in_review} %>
-
-
diff --git a/app/views/root/_out_for_fact_check.html.erb b/app/views/root/_out_for_fact_check.html.erb
deleted file mode 100644
index 7449498a8..000000000
--- a/app/views/root/_out_for_fact_check.html.erb
+++ /dev/null
@@ -1,14 +0,0 @@
-
-
-
-
-
- <%= render :collection => @presenter.fact_check, :partial => 'publication', :locals => {:tab => :fact_check} %>
-
-
diff --git a/app/views/root/_publication.html.erb b/app/views/root/_publication.html.erb
deleted file mode 100644
index 2fbe0ded2..000000000
--- a/app/views/root/_publication.html.erb
+++ /dev/null
@@ -1,78 +0,0 @@
-
-
- <%= publication.format.underscore.humanize %>
-
-
-
- <%= link_to publication.admin_list_title, edition_path(publication) %>
- <% if publication.in_beta? %>
- beta
- <% end %>
-
-
- <% 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 %>
-
- · #<%= publication.version_number %>
- <% if tab && (tab == :published || tab == :archived) && publication.subsequent_siblings.first.present? %>
- – <%= 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' %>
-
- <% end %>
-
- <% if publication.important_note.present? %>
-
- ·
-
-
- <% end %>
-
-
-
- <%= publication.updated_at.to_date.to_fs(:govuk_date_short) %>
-
-
- <% if tab && tab == :fact_check %>
-
-
- <%= publication.last_fact_checked_at.to_date.to_fs(:govuk_date_short) %>
-
-
- <% end %>
- <% if tab && tab == :scheduled_for_publishing %>
-
-
- <%= publication.publish_at.to_fs(:govuk_date_short) %>
-
-
- <% end %>
-
- <%= publication.assignee %>
-
- <% if tab && tab == :in_review %>
-
- <%= time_ago_in_words(publication.review_requested_at) %>
-
-
- <%= render partial: 'reviewer', locals: { publication: publication } %>
-
- <% end %>
- <% if tab && tab == :published %>
-
- <%= publication.publisher %>
-
- <% end %>
- <% if tab && (tab == :archived || tab == :published) %>
-
- <% 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 %>
-
- <% end %>
-
diff --git a/app/views/root/_published.html.erb b/app/views/root/_published.html.erb
deleted file mode 100644
index 9ba324bb5..000000000
--- a/app/views/root/_published.html.erb
+++ /dev/null
@@ -1,15 +0,0 @@
-
-
-
-
-
- <%= render :collection => @presenter.published, :partial => 'publication', :as => 'publication', :locals => {:tab => :published} %>
-
-
diff --git a/app/views/root/_ready.html.erb b/app/views/root/_ready.html.erb
deleted file mode 100644
index 87acd4f07..000000000
--- a/app/views/root/_ready.html.erb
+++ /dev/null
@@ -1,13 +0,0 @@
-
-
-
-
-
- <%= render :collection => @presenter.ready, :partial => 'publication', :locals => {:tab => :ready} %>
-
-
diff --git a/app/views/root/_reviewer.html.erb b/app/views/root/_reviewer.html.erb
deleted file mode 100644
index ae16cbc65..000000000
--- a/app/views/root/_reviewer.html.erb
+++ /dev/null
@@ -1,8 +0,0 @@
-<% 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 -%>
diff --git a/app/views/root/_scheduled_for_publishing.html.erb b/app/views/root/_scheduled_for_publishing.html.erb
deleted file mode 100644
index cd28b5178..000000000
--- a/app/views/root/_scheduled_for_publishing.html.erb
+++ /dev/null
@@ -1,14 +0,0 @@
-
-
-
-
-
- <%= render :collection => @presenter.scheduled_for_publishing, :partial => 'publication', :locals => {:tab => :scheduled_for_publishing} %>
-
-
diff --git a/app/views/root/index.html.erb b/app/views/root/index.html.erb
index 163a6b53d..e16679748 100644
--- a/app/views/root/index.html.erb
+++ b/app/views/root/index.html.erb
@@ -1,66 +1,9 @@
-
-
-
- <% if !params[:string_filter].blank? %>
- Searching for “<%= params[:string_filter] -%>” in “<%= @list.humanize %>”
- <% else %>
- <%= @list.humanize %>
- <% end %>
-
-
-
- <% if flash[:notice] %>
- <%= flash[:notice] %>
- <% end %>
-
-
-
-
-
-
-
-
-
-
- <% if params[:list] == "in_review" %>
-
-
- <%= link_to "Check Collections publisher", @presenter.step_by_step_review_url %> for step by steps that are waiting for review
-
-
- <% end %>
-
-
- <%= render @list %>
- <%= paginate @presenter.send(@list), theme: 'twitter-bootstrap-3' %>
-
-
-
-
<% content_for :page_title, "Publications" %>
+<% content_for :title, "Publications" %>
+
+
+
[replace with filter controls]
+
+
+
[replace with publications table]
+
diff --git a/test/functional/root_controller_test.rb b/test/functional/root_controller_test.rb
index 7742efc15..aab090f67 100644
--- a/test/functional/root_controller_test.rb
+++ b/test/functional/root_controller_test.rb
@@ -2,63 +2,15 @@
class RootControllerTest < ActionController::TestCase
setup do
- @users = FactoryBot.create_list(:user, 3)
login_as_stub_user
- session[:user_filter] = @users[0].uid
-
- @guide = FactoryBot.create(:guide_edition, state: "draft")
- end
-
- test "it returns a 404 for an unknown list" do
- get :index, params: { list: "draFts" }
- assert response.not_found?
- end
-
- # Most values of the list parameter match a scope on the Edition
- # model, but some don't and we want to test that we allow those
- # through correctly
- test "it supports lists that don't match a model scope" do
- get :index, params: { list: "drafts" }
- assert response.ok?
- end
-
- test "should strip leading/trailing whitespace from string_filter" do
- @guide.update!(title: "Stuff")
- get(
- :index,
- params: {
- list: "drafts",
- user_filter: "all",
- string_filter: " stuff",
- },
- )
- assert_select "td.title", /Stuff/i
end
- test "should strip excess interstitial whitespace from string_filter" do
- @guide.update!(title: "Stuff and things")
- get(
- :index,
- params: {
- list: "drafts",
- user_filter: "all",
- string_filter: "stuff and things",
- },
- )
- assert_select "td.title", /Stuff and things/i
- end
+ context "#index" do
+ should "render index template" do
+ get :index
- test "should search in slug with string_filter" do
- @guide.update!(title: "Stuff")
- @guide.update!(slug: "electric-banana")
- get(
- :index,
- params: {
- list: "drafts",
- user_filter: "all",
- string_filter: "electric-banana",
- },
- )
- assert_select "td.title", /Stuff/i
+ assert_response :ok
+ assert_template "root/index"
+ end
end
end