Skip to content
This repository has been archived by the owner on Apr 4, 2018. It is now read-only.

Commit

Permalink
Tidy up needs search list and facets
Browse files Browse the repository at this point in the history
  • Loading branch information
JordanHatch committed Apr 22, 2013
1 parent a216b09 commit 2e5fc22
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 30 deletions.
7 changes: 7 additions & 0 deletions app/assets/stylesheets/application.css.scss
Expand Up @@ -12,6 +12,13 @@
.search-filters {
h2 { font-size: 1.5em; line-height: 1.1em; }
h3 { font-size: 1em; line-height: 1.1em; }

ul.facet li {
&.active {
padding: 0px 1em;
a.remove { display: inline-block; padding: 0.3em 0.5em; margin-left: 0.5em; }
}
}
}

ul.filters {
Expand Down
10 changes: 10 additions & 0 deletions app/helpers/needs_helper.rb
Expand Up @@ -135,4 +135,14 @@ def accountabilities_for(need)
(0...Need::MAXIMUM_POLICY_DEPARTMENTS).map { |i| need.accountabilities.all[i] || need.accountabilities.build }
end

def label_for(status)
case status
when 'new' then 'label-inverse'
when 'done' then 'label-success'
when %w{bin icebox} then ''
when 'in-progress' then 'label-warning'
when 'format-assigned' then 'label-info'
end
end

end
1 change: 1 addition & 0 deletions app/locales/en.yml
Expand Up @@ -20,6 +20,7 @@ en:
status: Status
priority: Priority
kind: Format
priority_0: Priority 0
priority_1: Low
priority_2: Medium
priority_3: High
9 changes: 3 additions & 6 deletions app/views/needs/_needs_display.html.erb
Expand Up @@ -6,14 +6,12 @@
<%= sortable_heading('title') %>
<%= sortable_heading('kind') %>
<%= sortable_heading('priority') %>
<th><%= t('field.short.tags') %></th>
<%= sortable_heading('updated_at') %>
<% else %>
<th scope="col">ID</th>
<th scope="col">Title</th>
<th scope="col">Format</th>
<th scope="col">Priority</th>
<th scope="col">Tags</th>
<th scope="col">Last updated</th>
<% end %>
Expand All @@ -27,10 +25,9 @@
<% needs.each do |need| %>
<tr>
<td>#<%= need.id %></td>
<th scope="row"><%= link_to need.title, need %> <% if !params[:in_state] %><small class="status-label <%= need.status %>"><%= status_name need.status %></small><% end %></th>
<td class="need"><%= need.format_assigned? ? need.kind : "-" %></td>
<td><%= need.prioritised? ? need.named_priority : '-' %></td>
<td><%= need.tag_list %></td>
<th scope="row" style="width: 50%"><%= link_to need.title, need %> <% if !params[:in_state] %><span class="label <%= label_for need.status %>"><%= status_name need.status %></small><% end %></th>
<td class="need"><%= need.kind || "-" %></td>
<td><%= named_priority need.priority %></td>
<td><%= time_ago_in_words(need.updated_at, true) %></td>
<% if current_user.is_admin? %>
<td><%= link_to 'Edit', edit_need_path(need) %></td>
Expand Down
14 changes: 2 additions & 12 deletions app/views/search/index.html.erb
Expand Up @@ -11,16 +11,6 @@
end
} %>
<% if @search && (params[:query] || params[:filter]) %>
<div class="results">
<p>Your search
<% if params[:query].present? %>
for <strong><%= params[:query] %></strong>
<% end %>
returned <%= pluralize(@search.count, 'result') %>. You can filter those results below.</p>
</div>
<% end %>
<% if @filters.present? %>
<ul class="filters well">
<h3>Filter applied:</h3>
Expand Down Expand Up @@ -50,12 +40,12 @@
<h2>Search Filters</h2>
<% @facets.each do |facet| %>
<h3><span class="visuallyhidden">Filter by</span> <%= t("field.long.#{facet}") %></h3>
<ul class="nav nav-pills nav-stacked">
<ul class="facet nav nav-pills nav-stacked">
<% @search.facets[facet]['terms'].each do |details| %>
<% next if details['term'].blank? %>
<% label = facet == 'priority' ? t("priority_#{details['term']}") : details['term'] %>
<% if filtering_by?(facet, details['term']) %>
<li>
<li class="active">
<%= label %> (<%= details['count'] %>)
<%= link_to('x', search_link_with_removed_filter(params, @filters, facet => details['term']), class: 'remove') %>
</li>
Expand Down
24 changes: 12 additions & 12 deletions spec/acceptance/searching_for_a_need_spec.rb
Expand Up @@ -10,9 +10,9 @@ def create_need(name, options = {})
visit "/needs/new"
fill_in "Need", with: name
fill_in "Tags", with: options[:tags] if options.has_key?(:tags)
click_button "Create Need"
click_button "Create Need"
if options.has_key?(:edit_form_fields)
click_link 'Edit'
click_link 'Edit'
options[:edit_form_fields].each do |field, value|
(field == 'Writing team') ? select(value, from: field) : fill_in(field, with: value)
end
Expand All @@ -38,27 +38,27 @@ def survive_es_asynchonicity
create_need "Replace passport"
survive_es_asynchonicity

click_link "View all needs"
click_link "All needs"

search_for 'Replace passport'
page.should have_css "#needs-table", text: 'Replace passport'

search_for "Missing"
page.should have_content "Nothing found"
page.should have_content "No needs were found which match these criteria."
end

it 'works when searching for a word from the Writing department field' do
WritingDepartment.create name: "Ministry of Truth"
it 'works when searching for a word from the Writing department field' do
WritingDepartment.create name: "Ministry of Truth"
create_need "Get a new passport", edit_form_fields: { "Writing team" => "Ministry of Truth"}
create_need "Get a new driving licence"
survive_es_asynchonicity

click_link "View all needs"
click_link "All needs"
search_for 'Truth'
within '#needs-table' do
page.should have_content 'Get a new passport'
page.should have_no_content 'Get a new driving license'
end
end
end

it 'allows filtering by facets' do
Expand All @@ -67,15 +67,15 @@ def survive_es_asynchonicity

survive_es_asynchonicity

click_link "View all needs"
click_link "All needs"
click_link "red"

within '#needs-table' do
page.should have_content 'Get a new passport'
page.should have_no_content 'Learn to drive'
end

click_link "View all needs"
click_link "All needs"
click_link "blue"
within '#needs-table' do
page.should have_no_content 'Get a new passport'
Expand All @@ -90,7 +90,7 @@ def survive_es_asynchonicity

survive_es_asynchonicity

click_link "View all needs"
click_link "All needs"
click_link "blue"
click_link "red"
within '#needs-table' do
Expand Down Expand Up @@ -137,4 +137,4 @@ def survive_es_asynchonicity
page.text.should =~ /Carrots.*Bananas.*Apples/m
end
end
end
end

0 comments on commit 2e5fc22

Please sign in to comment.