Skip to content
Browse files

sort moving into columns

  • Loading branch information...
1 parent 782fc00 commit 9e95dbbb557f9020d3c3ecb54bdfd92b5925bd8b stu committed
View
4 lib/page_options.rb
@@ -28,6 +28,10 @@ def sort_order
@sort_order || 'ASC'
end
+ def sort_column?(column)
+ column.human_name == sort_column
+ end
+
def active_record_order_option
if self.sort_column && self.sort_order
{:order => [self.sort_column, self.sort_order].map{|x| x.tr(" ", "_")}.join(" ")}
View
7 lib/streamlined/column/association.rb
@@ -87,5 +87,12 @@ def relationship_div_id(item, in_window = false)
"#{fragment}::#{name}::#{item.id}::#{class_name}#{'::win' if in_window}"
end
+ def render_th(context,view)
+ x = Builder::XmlMarkup.new
+ x.th(:scope=>"col") {
+ x << human_name
+ }
+ end
+
end
View
16 lib/streamlined/column/base.rb
@@ -19,4 +19,20 @@ def render_td(view, item, model_ui, controller)
end
content
end
+ # TODO: make a streamlined_context that delegates to pageoptions, etc.
+ def sort_image(context, view)
+ if context.sort_column?(self)
+ direction = context.ascending? ? 'up' : 'down'
+ view.image_tag("streamlined/arrow-#{direction}_16.png", {:height => '10px', :border => 0})
+ else
+ ''
+ end
+ end
+ def render_th(context,view)
+ x = Builder::XmlMarkup.new
+ x.th(:scope=>"col", :class=>"sortSelector") {
+ x << human_name
+ x << sort_image(context,view)
+ }
+ end
end
View
2 lib/streamlined/controller/crud_methods.rb
@@ -66,7 +66,7 @@ def list
# flash[:info] = @controller.list_notice_info if @controller.respond_to?( "list_notice_info" )
# end
render :partial => 'list' if request.xhr?
- render :template => generic_view('atom'), :controler => @model_name, :layout => false if params[:syndicated]
+ render :template => generic_view('atom'), :controller => @model_name, :layout => false if params[:syndicated]
end
# Renders the Show view for a given instance.
def show
View
11 lib/streamlined/helper.rb
@@ -37,17 +37,6 @@ def image_tag_if_exists(image, options = {})
image_tag(image, options) if(File.exist?File.join(RAILS_ROOT, 'public', 'images', image))
end
- # TODO: move this onto mixin that mixes into AR Column and into Streamlined Column
- # column_sort_image(page_options.sort_column, column.human_name, page_options.sort_order)
- def column_sort_image(page_options, column)
- if page_options.sort_column == column.human_name
- direction = page_options.ascending? ? 'up' : 'down'
- image_tag("streamlined/arrow-#{direction}_16.png", {:height => '10px', :border => 0})
- else
- ''
- end
- end
-
# invisible links are plucked out by unobtrusive JavaScript to add functionality
def invisible_link_to(options = {}, html_options={}, *parms)
link_to('', options, html_options.merge(:style=>"display:none;"), *parms)
View
7 script/console
@@ -0,0 +1,7 @@
+#!/usr/bin/env ruby
+irb = RUBY_PLATFORM =~ /mswin32/ ? 'irb.bat' : 'irb'
+
+libs = " -r irb/completion"
+libs = " -r test/test_helper"
+
+exec "#{irb} #{libs} --simple-prompt"
View
2 templates/generic_views/_list.rhtml
@@ -2,7 +2,7 @@
<thead>
<tr>
<% list_columns_for_model(@model, @model_ui, params[:controller]).each do |column| %>
- <th scope="col" class="sortSelector"><%= column.human_name %><%= column_sort_image(@page_options, column)%></th>
+ <%= column.render_th(@page_options, self )%>
<% end %>
<%= streamlined_table_row_button_header %>
</tr>
View
17 test/functional/streamlined/column/base_test.rb
@@ -24,4 +24,21 @@ def test_render_popup_td
assert_equal '<span class="sl-popup"><a href="/people/foo/1" style="display:none;"></a>Justin</span>', @ui.column(:first_name).render_td(@view,people(:justin),@ui,@controller)
end
+ def test_sort_image_up
+ options = PageOptions.new(:sort_column=>"First name")
+ assert_equal "<img alt=\"Arrow-up_16\" border=\"0\" height=\"10px\" src=\"/images/streamlined/arrow-up_16.png\" />",
+ @ui.column(:first_name).sort_image(options,@view)
+ end
+
+ def test_sort_image_down
+ options = PageOptions.new(:sort_column=>"First name", :sort_order=>"DESC")
+ assert_equal "<img alt=\"Arrow-down_16\" border=\"0\" height=\"10px\" src=\"/images/streamlined/arrow-down_16.png\" />",
+ @ui.column(:first_name).sort_image(options,@view)
+ end
+
+ def test_sort_image_none
+ options = PageOptions.new
+ assert_equal '', @ui.column(:first_name).sort_image(options,nil)
+ end
+
end
View
7 test/unit/page_options_test.rb
@@ -24,4 +24,11 @@ def test_empty_order_option
assert_equal({}, o.active_record_order_option)
end
+ def test_sort_column
+ o = PageOptions.new
+ column = Struct.new(:human_name).new("foo")
+ assert_equal false, o.sort_column?(column)
+ o.sort_column = "foo"
+ assert_equal true, o.sort_column?(column)
+ end
end
View
38 test/unit/streamlined_helper_test.rb
@@ -3,42 +3,6 @@
module Streamlined; end
class Streamlined::HelperTest < Test::Unit::TestCase
- include FlexMock::TestCase
- include Streamlined::Helper
-
- def column_named_name
- column = flexmock("column")
- column.should_expect do |o|
- o.human_name.returns("name")
- end
- column
- end
-
- def test_column_sort_image_up
- options = flexmock("options")
- options.should_expect do |o|
- o.sort_column.returns("name")
- o.ascending?.returns(true)
- end
- flexstub(self).should_receive(:image_tag).with("streamlined/arrow-up_16.png", Hash).and_return("testing up")
- assert_equal("testing up", column_sort_image(options,column_named_name))
- end
-
- def test_column_sort_image_down
- options = flexmock("options")
- options.should_expect do |o|
- o.sort_column.returns("name")
- o.ascending?.returns(false)
- end
- flexstub(self).should_receive(:image_tag).with("streamlined/arrow-down_16.png", Hash).and_return("testing down")
- assert_equal("testing down", column_sort_image(options,column_named_name))
- end
-
- def test_column_sort_image_none
- options = flexmock("options")
- options.should_expect do |o|
- o.sort_column.returns("foo")
- end
- assert_equal("", column_sort_image(options,column_named_name))
+ def test_truth
end
end

0 comments on commit 9e95dbb

Please sign in to comment.
Something went wrong with that request. Please try again.