From cb0cb9359e7d3cddf8b631e9217a69253da8e659 Mon Sep 17 00:00:00 2001 From: Erik Hatcher Date: Wed, 7 Feb 2007 20:57:32 +0000 Subject: [PATCH] handy rake addition to list routes git-svn-id: https://svn.apache.org/repos/asf/lucene/solr/trunk@504689 13f79535-47bb-0310-9956-ffa450edef68 --- .../app/controllers/browse_controller.rb | 2 +- .../app/controllers/sparklines_controller.rb | 40 +++++++++++++++++++ .../ruby/flare/app/views/browse/facet.rhtml | 4 +- .../ruby/flare/app/views/browse/index.rhtml | 12 ++++-- client/ruby/flare/lib/tasks/routes.rake | 22 ++++++++++ 5 files changed, 73 insertions(+), 7 deletions(-) create mode 100644 client/ruby/flare/app/controllers/sparklines_controller.rb create mode 100755 client/ruby/flare/lib/tasks/routes.rake diff --git a/client/ruby/flare/app/controllers/browse_controller.rb b/client/ruby/flare/app/controllers/browse_controller.rb index c8779aae217..ab8c14d17c0 100644 --- a/client/ruby/flare/app/controllers/browse_controller.rb +++ b/client/ruby/flare/app/controllers/browse_controller.rb @@ -78,7 +78,7 @@ class BrowseController < ApplicationController req = Solr::Request::Standard.new(:query => query, :filter_queries => filters, :facets => {:fields => [field], - :mincount => 1, :limit => limit, :prefix => prefix + :mincount => 1, :limit => limit, :prefix => prefix, :missing => true, :sort => :count }, :rows => 0 ) diff --git a/client/ruby/flare/app/controllers/sparklines_controller.rb b/client/ruby/flare/app/controllers/sparklines_controller.rb new file mode 100644 index 00000000000..1c69f290525 --- /dev/null +++ b/client/ruby/flare/app/controllers/sparklines_controller.rb @@ -0,0 +1,40 @@ +class SparklinesController < ApplicationController + + # Handles requests for sparkline graphs from views. + # + # Params are generated by the sparkline_tag helper method. + # + def index + # Make array from comma-delimited list of data values + ary = [] + if params.has_key?('results') && !params['results'].nil? + params['results'].split(',').each do |s| + ary << s.to_i + end + end + + send_data( Sparklines.plot( ary, params ), + :disposition => 'inline', + :type => 'image/png', + :filename => "spark_#{params[:type]}.png" ) + end + + + # Use this type of method for sparklines that can be cached. (Doesn't work with the helper.) + # + # To make caching easier, add a line like this to config/routes.rb: + # map.sparklines "sparklines/:action/:id/image.png", :controller => "sparklines" + # + # Then reference it with the named route: + # image_tag sparklines_url(:action => 'show', :id => 42) + def show + send_data(Sparklines.plot( + [42, 37, 89, 74, 70, 50, 40, 30, 40, 50], + :type => 'bar', :above_color => 'orange' + ), + :disposition => 'inline', + :type => 'image/png', + :filename => "sparkline.png") + end + +end diff --git a/client/ruby/flare/app/views/browse/facet.rhtml b/client/ruby/flare/app/views/browse/facet.rhtml index 782981c9d95..16b53579aee 100755 --- a/client/ruby/flare/app/views/browse/facet.rhtml +++ b/client/ruby/flare/app/views/browse/facet.rhtml @@ -1,3 +1,3 @@ -<% @facets.each do |value,count| %> - <%= link_to value, :action => 'add_filter', :field_name => params[:field_name], :value => value %> (<%=count%>) +<% @facets.each do |f| %> + <%= link_to (f.name ? f.name : '#### NO VALUE ###'), :action => 'add_filter', :field_name => params[:field_name], :value => f.name %> (<%=f.value%>) <% end%> \ No newline at end of file diff --git a/client/ruby/flare/app/views/browse/index.rhtml b/client/ruby/flare/app/views/browse/index.rhtml index 0b0f104b608..ac7a76f0bed 100644 --- a/client/ruby/flare/app/views/browse/index.rhtml +++ b/client/ruby/flare/app/views/browse/index.rhtml @@ -8,13 +8,16 @@ <% @facet_fields.each do |field|%>

<%=link_to field, :action => 'facet', :field_name => field%>

<% end %> - - +<%=link_to image_tag("simile-exhibit.png"), :controller => :simile, :action => :exhibit %> +
Queries: @@ -52,6 +55,7 @@ Filters: + diff --git a/client/ruby/flare/lib/tasks/routes.rake b/client/ruby/flare/lib/tasks/routes.rake new file mode 100755 index 00000000000..3fecf372f25 --- /dev/null +++ b/client/ruby/flare/lib/tasks/routes.rake @@ -0,0 +1,22 @@ +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# Borrowed from , by Josh Susser +desc "Print out all the currently defined routes, with names." +task :routes => :environment do + name_col_width = ActionController::Routing::Routes.named_routes.routes.keys.sort {|a,b| a.to_s.size <=> b.to_s.size}.last.to_s.size + ActionController::Routing::Routes.routes.each do |route| + name = ActionController::Routing::Routes.named_routes.routes.index(route).to_s + name = name.ljust(name_col_width + 1) + puts "#{name}#{route}" + end +end \ No newline at end of file