Skip to content

Commit

Permalink
Merge pull request #2244 from alphagov/design-system/filtered-edition…
Browse files Browse the repository at this point in the history
…s-skeleton

Create a skeleton filtered editions view
  • Loading branch information
mtaylorgds authored Jul 12, 2024
2 parents f67d862 + d0ff8be commit ec8472c
Show file tree
Hide file tree
Showing 15 changed files with 23 additions and 394 deletions.
67 changes: 2 additions & 65 deletions app/controllers/root_controller.rb
Original file line number Diff line number Diff line change
@@ -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
7 changes: 7 additions & 0 deletions app/presenters/filtered_editions_presenter.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# frozen_string_literal: true

class FilteredEditionsPresenter
def editions
Edition.all
end
end
13 changes: 0 additions & 13 deletions app/views/root/_amends_needed.html.erb

This file was deleted.

14 changes: 0 additions & 14 deletions app/views/root/_archived.html.erb

This file was deleted.

13 changes: 0 additions & 13 deletions app/views/root/_drafts.html.erb

This file was deleted.

13 changes: 0 additions & 13 deletions app/views/root/_fact_check_received.html.erb

This file was deleted.

15 changes: 0 additions & 15 deletions app/views/root/_in_review.html.erb

This file was deleted.

14 changes: 0 additions & 14 deletions app/views/root/_out_for_fact_check.html.erb

This file was deleted.

78 changes: 0 additions & 78 deletions app/views/root/_publication.html.erb

This file was deleted.

15 changes: 0 additions & 15 deletions app/views/root/_published.html.erb

This file was deleted.

13 changes: 0 additions & 13 deletions app/views/root/_ready.html.erb

This file was deleted.

8 changes: 0 additions & 8 deletions app/views/root/_reviewer.html.erb

This file was deleted.

14 changes: 0 additions & 14 deletions app/views/root/_scheduled_for_publishing.html.erb

This file was deleted.

73 changes: 8 additions & 65 deletions app/views/root/index.html.erb
Original file line number Diff line number Diff line change
@@ -1,66 +1,9 @@

<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 %>
<%= paginate @presenter.send(@list), theme: 'twitter-bootstrap-3' %>
</div>

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

<% content_for :page_title, "Publications" %>
<% content_for :title, "Publications" %>

<div class="govuk-grid-column-one-third">
<p>[replace with filter controls]</p>
</div>
<div class="govuk-grid-column-two-thirds">
<p>[replace with publications table]</p>
</div>
Loading

0 comments on commit ec8472c

Please sign in to comment.