Skip to content

Commit

Permalink
first pass at CSV search output
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewcarpenter committed Jan 27, 2012
1 parent 492b0ee commit a273249
Show file tree
Hide file tree
Showing 9 changed files with 63 additions and 60 deletions.
6 changes: 6 additions & 0 deletions app/controllers/entries/search_controller.rb
Expand Up @@ -18,6 +18,12 @@ def show
@entries = @search.results
render :template => 'entries/index.rss.builder'
end
wants.csv do
@search.per_page = 100
@entries = @search.results
filename = @search.summary.gsub(/\W+/, '_').sub(/_$/,'').downcase
headers['Content-Disposition'] = "attachment; filename=\"#{filename}.csv\""
end
end
end

Expand Down
2 changes: 1 addition & 1 deletion app/searches/entry_search.rb
Expand Up @@ -95,7 +95,7 @@ def model

def find_options
{
:select => "id, title, publication_date, document_number, granule_class, document_file_path, abstract, length, start_page, end_page",
:select => "id, title, publication_date, document_number, granule_class, document_file_path, abstract, length, start_page, end_page, citation",
:include => :agencies,
}
end
Expand Down
11 changes: 1 addition & 10 deletions app/stylesheets/design/_buttons.scss
Expand Up @@ -81,8 +81,8 @@ BUTTONS / ICONS



.other_formats,
.rss,
.help_link,
.add_to_calendar,
a.subscription {
color: #6e6e6e;
Expand Down Expand Up @@ -112,15 +112,6 @@ a.subscription:hover {
background: sprite-image('icons/icon_subscribe_hover.png', 0, 0, 50px) no-repeat;
color: #B88659;
}
.help_link {
background: sprite-image('icons/icon_info.png', 0, 3px, 50px) no-repeat;
display: block;
height: image-height('icons/icon_info.png');
padding-bottom: 3px;
}
.help_link:hover {
background: sprite-image('icons/icon_info_hover.png', 0, 3px, 50px) no-repeat;
}
.add_to_calendar {
background: sprite-image('icons/add_to_calendar_half.png', 0, 0, 50px) no-repeat;
line-height: image-height('icons/add_to_calendar_half.png');
Expand Down
27 changes: 24 additions & 3 deletions app/stylesheets/design/_search.scss
Expand Up @@ -52,6 +52,19 @@ PAGE ELEMENTS
position: absolute;
right: 2em;
top: 1.2em;
text-align: right;
}
.search_bar .actions .other_formats, .search_bar .actions .subscription {
font-size: 15px;
}
.search_bar .actions .other_formats {
display: block;
}
.search_bar .actions .other_formats a {
color: #6E6E6E;
}
.search_bar .actions .other_formats a:hover {
color: #B88659;
}
.search_bar .button {
background-color: #fff;
Expand Down Expand Up @@ -701,16 +714,24 @@ ADVANCED SEARCH
margin-left: 16.75em;
margin-top: 2em;
}
#toggle_advanced {
.search_bar .options {
width: 410px;
clear: both;
cursor: pointer;
display: none;
float: left;
margin-left: 5em;
}
#toggle_advanced {
cursor: pointer;
float: left;
display: none;
}
.has_js #toggle_advanced {
display: block;
}
.search_bar .options .help_link {
float: right;
}

select.bsmSelect {
display: none !important; /* important needed for IE */
}
Expand Down
6 changes: 0 additions & 6 deletions app/stylesheets/ie6.scss
Expand Up @@ -251,12 +251,6 @@ SEARCH
.regulations .results { width: auto; }
.regulations .results li { border-bottom: 2px solid #eee; margin-bottom: 15px; padding-bottom: 15px; }

.help_link {
background: image-url('icons/ie6/icon_info.png') no-repeat left 3px;
float: left;
}
.help_link:hover { background: image-url('icons/ie6/icon_info_hover.png') no-repeat left 3px; }

.matching_citation_header { background: image-url('icons/ie6/icon_article.png') no-repeat left top; }

#main .formtastic .string label,
Expand Down
8 changes: 5 additions & 3 deletions app/views/entries/search/header.html.erb
Expand Up @@ -22,12 +22,14 @@
<div class="actions">
<%= link_to 'Subscribe', new_subscription_path(:subscription => {:search_conditions => conditions_for_subscription}), :class => 'subscription' %>
<%= add_template('subscription_modal', 'subscription-modal') %>
<span class="other_formats">Other Formats: <%= link_to 'CSV', entries_search_path(params.except(:controller, :action, :quiet).merge(:format => :csv)) %>,
<%= link_to 'JSON', api_v1_entries_url(params.except(:controller, :action, :quiet)) %></span>
</div>
<div class="options">
<%= link_to "Show Advanced Search", '#advanced', :id => :toggle_advanced %>
<%= link_to 'Learn More', entries_search_help_path, :class => 'help_link' %>
<%# link_to 'Widget', widget_instructions_path(params.except(:action, :controller)), :class => 'button widget spawn_modal notext', :id => 'widget' %>
</div>

<a title="Show Advanced Search" id="toggle_advanced" href="#advanced">Show Advanced Search</a>

</div>
<div class="advanced">
<%= render :partial => "advanced", :locals => {:f => f} %>
Expand Down
22 changes: 22 additions & 0 deletions app/views/entries/search/show.csv.erb
@@ -0,0 +1,22 @@
<%= FasterCSV.generate do |csv|
csv << [
'FR Citation',
'Document Number',
'Title',
'Publication Date',
'Document Type',
'Agencies',
'URL'
]
@entries.each do |entry|
csv << [
entry.citation,
entry.document_number,
entry.title,
entry.publication_date,
entry.entry_type,
entry.agencies.excluding_parents.map(&:name).join(', '),
short_entry_url(entry)
]
end
end %>
6 changes: 4 additions & 2 deletions app/views/public_inspection/search/header.html.erb
Expand Up @@ -21,11 +21,13 @@
<div class="actions">
<%= link_to 'Subscribe', new_subscription_path(:subscription => {:search_conditions => conditions_for_subscription}), :class => 'subscription' %>
<%= add_template('subscription_modal', 'subscription-modal') %>
<%= link_to 'Learn More', entries_search_help_path, :class => 'help_link' %>
<%# link_to 'Widget', widget_instructions_path(params.except(:action, :controller)), :class => 'button widget spawn_modal notext', :id => 'widget' %>
</div>

<a title="Show Advanced Search" id="toggle_advanced" href="#advanced">Show Advanced Search</a>
<div class="options">
<%= link_to 'Show Advanced Search', '#advanced', :id => "toggle_advanced" %>
<%= link_to 'Learn More', entries_search_help_path, :class => 'help_link' %>
</div>

</div>
<div class="advanced">
Expand Down
35 changes: 0 additions & 35 deletions public/javascripts/page_specific/search/search.js
Expand Up @@ -265,39 +265,4 @@ $(document).ready(function () {
$(window).bind('hashchange', function(){
toggleAdvanced(location.hash === "#advanced");
}).trigger('hashchange');

// $('.help_link').live('click',
// function () {
// load_help();
// $('#help_modal').centerScreen().jqmShow();
// return false;
// });
//
// function load_help() {
// if ($('#help_modal').size() == 0) {
//
// $.ajax({
// url: '/entries/search/help?no_layout=1',
// dataType: 'html',
// complete: function(xhr, textStatus) {
// //called when complete
// },
// success: function(data, textStatus, xhr) {
// $("#help_modal").append(data);
// },
// error: function(xhr, textStatus, errorThrown) {
// //called when there is an error
// }
// });
//
//
// $('#help_modal').jqm({
// modal: true,
// toTop: true
// });
// }
// }



});

0 comments on commit a273249

Please sign in to comment.