Permalink
Browse files

Merge pull request #2 from alphagov/filter_by_section

Filter by section is here!
  • Loading branch information...
2 parents 78c4f2a + 612227d commit 9067fce6a3769ae1b9227026a02a2f1c48108275 @jystewart jystewart committed May 24, 2012
@@ -17,6 +17,10 @@ body {
padding-left: 2em;
}
+.sidebar-nav {
+ padding: 9px 0;
+}
+
td.icon {
text-align: center;
}
@@ -5,7 +5,13 @@ class ArtefactsController < ApplicationController
respond_to :html, :json
def index
- @artefacts = Artefact.order_by([[:name, :asc]]).all
+ @artefacts = Artefact.order_by([[:name, :asc]])
+
+ @section = params[:section] || "all"
+ unless params[:section].blank? || params[:section] != "all"
+ @artefacts = @artefacts.where(tag_ids: params[:section])
+ end
+
respond_with @artefacts
end
@@ -63,7 +69,7 @@ def extract_parameters(params)
# Strip out the empty submit option for sections
['sections'].each do |param|
param_value = parameters_to_use[param]
- param_value.reject! &:blank? if param_value
+ param_value.reject!(&:blank?) if param_value
end
parameters_to_use
end
@@ -20,4 +20,25 @@ def all_sections(options = {})
sections.reject { |s| s[1] == options[:except] }
end
+ def parent_sections
+ parent_sections = all_sections.reject do |title, tag_id|
+ tag_id =~ %r{/}
+ end
+ end
+
+ def parent_section_tab_list(options)
+ sections = [["All", "all"]] + parent_sections
+
+ output = sections.map do |title, tag_id|
+ css_class = ""
+ if tag_id == options[:current].downcase
+ css_class = "active"
+ end
+ content_tag(:li, :class => css_class) do
+ link_to(title, :section => tag_id)
+ end
+ end
+ safe_join(output)
+ end
+
end
@@ -1,40 +1,59 @@
<%= content_for :page_title, "List artefacts" %>
<div class="row-fluid">
- <div class="page-header">
- <h1>Artefacts</h1>
- </div>
+ <div class="span12">
- <table class="table table-striped table-bordered table-condensed" id="artefact-list" summary="List of everything">
- <thead>
- <tr>
- <th scope="col">Need</th>
- <th scope="col">Title</th>
- <th scope="col">Format</th>
- <th scope="col">Section</th>
- <th scope="col">Related Items</th>
- <th scope="col">Relatedness Done?</th>
- <th scope="col">App</th>
- <th scope="col">Slug</th>
- </tr>
- </thead>
- <tbody>
- <% @artefacts.each do |artefact| %>
- <tr>
- <td><%= artefact.need_id %></td>
- <td><%= link_to artefact.name, edit_artefact_path(artefact.id) %></td>
- <td class="icon">
- <%= image_tag "icon-#{artefact.kind.downcase}.png", :title => artefact.kind.humanize %>
- </td>
- <td><%=h artefact.primary_section %></td>
- <td><%=h artefact.related_artefact_ids.count %></td>
- <td><%=h artefact.relatedness_done %></td>
- <td><%= artefact.owning_app %></td>
- <td><%= link_to artefact.slug, "https://www.gov.uk/#{artefact.slug}" %></td>
- <% end %>
- </tbody>
- </table>
-</div>
+ <div class="page-header">
+ <h1>Artefacts</h1>
+ </div>
+ <div class="row-fluid">
+ <div class="span2">
+ <div class="well sidebar-nav">
+ <ul class="nav nav-list">
+ <li class="nav-header">Filter by Section</li>
+ <%= parent_section_tab_list(:current => @section) %>
+ </ul>
+
+ </div>
+
+ </div>
+
+ <div class="span10">
+ <table class="table table-striped table-bordered table-condensed" id="artefact-list" summary="List of everything">
+ <thead>
+ <tr>
+ <th scope="col">Need</th>
+ <th scope="col">Title</th>
+ <th scope="col">Format</th>
+ <th scope="col">Primary section</th>
+ <th scope="col">Other sections</th>
+ <th scope="col">Related items</th>
+ <th scope="col">Relatedness done?</th>
+ <th scope="col">App</th>
+ <th scope="col">Slug</th>
+ </tr>
+ </thead>
+ <tbody>
+ <% @artefacts.each do |artefact| %>
+ <tr>
+ <td><%= artefact.need_id %></td>
+ <td><%= link_to artefact.name, edit_artefact_path(artefact.id) %></td>
+ <td class="icon">
+ <%= image_tag "icon-#{artefact.kind.downcase}.png", :title => artefact.kind.humanize %>
+ </td>
+ <td><%=h artefact.primary_section %></td>
+ <td><%=h (artefact.sections - [artefact.primary_section]).join(", ") %></td>
+ <td><%=h artefact.related_artefact_ids.count %></td>
+ <td><%=h artefact.relatedness_done %></td>
+ <td><%= artefact.owning_app %></td>
+ <td><%= link_to artefact.slug, "https://www.gov.uk/#{artefact.slug}" %></td>
+ <% end %>
+ </tbody>
+ </table>
+ </div><!-- ./span10 -->
+ </div><!-- ./row fluid -->
+ </div><!-- ./span12 -->
+</div><!-- ./row-fluid-->
<%= content_for :extra_javascript do %>
<%= javascript_include_tag 'jquery.tablesorter.min.js' %>

0 comments on commit 9067fce

Please sign in to comment.