-
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.
Merge pull request #2244 from alphagov/design-system/filtered-edition…
…s-skeleton Create a skeleton filtered editions view
- Loading branch information
Showing
15 changed files
with
23 additions
and
394 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 |
---|---|---|
@@ -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 |
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 @@ | ||
# frozen_string_literal: true | ||
|
||
class FilteredEditionsPresenter | ||
def editions | ||
Edition.all | ||
end | ||
end |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -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> |
Oops, something went wrong.