Skip to content

Commit 3984bc2

Browse files
author
matthew
committed
fixed enumeration editing bugs
1 parent 3f750c5 commit 3984bc2

File tree

5 files changed

+20
-3
lines changed

5 files changed

+20
-3
lines changed

Diff for: CHANGELOG

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
- public API change: streamlined_model now called streamlined_ui
33
- added CSS IDs to each item table row on the list view (MJB)
44
- now outputting flash notices on the list view (MJB)
5+
- fixed enumeration editing bugs (MJB)
56

67
1.0RC02 -- 02/22/08
78
- fixed show stopper bug on editing relationships (SDH)

Diff for: lib/streamlined/column/active_record.rb

+10-2
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,15 @@ def edit_view
3434
Streamlined::View::EditViews.create_relationship(:enumerable_select)
3535
end
3636

37+
def show_view
38+
Streamlined::View::ShowViews.create_summary(:enumeration)
39+
end
40+
3741
def render_td_show(view, item)
3842
if enumeration
3943
content = item.send(self.name)
4044
if enumeration.first.is_a?(Array)
41-
key_value_pair = enumeration.detect { |e| e.last == content }
45+
key_value_pair = enumeration_key_for(content)
4246
content = key_value_pair.first if key_value_pair
4347
end
4448
content = content && !content.blank? ? content : self.unassigned_value
@@ -53,12 +57,16 @@ def enumeration
5357
@enumeration.is_a?(Hash) ? @enumeration.to_a : @enumeration
5458
end
5559

60+
def enumeration_key_for(value)
61+
enumeration.detect { |e| e.last == value }
62+
end
63+
5664
def render_td_list(view, item)
5765
id = relationship_div_id(name, item)
5866
div = render_td_show(view, item)
5967
div = div_wrapper(id) { div } if enumeration
6068
div += view.link_to_function("Edit", "Streamlined.Enumerations." <<
61-
"open_enumeration('#{id}', this, '/#{view.controller_name}')") if enumeration && editable
69+
"open_enumeration('#{id}', this, '/#{view.controller_path}')") if enumeration && editable
6270
div
6371
end
6472

Diff for: lib/streamlined/view/show_views.rb

+5
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,11 @@ class Name < Streamlined::View::Base
3737

3838
end
3939

40+
# Renders the enumeration value.
41+
class Enumeration < Streamlined::View::Base
42+
43+
end
44+
4045
class Graph < Streamlined::View::Base
4146
def must_have_sparklines!
4247
raise "STREAMLINED ERROR: Cannot use the Sparklines Graph relationship summary: need to install Sparklines plugin first (requires RMagick, which is not the easiest thing to install, we're just warning you)" unless 'Sparklines'.to_const
+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<% value = item.send(relationship.name).to_i -%>
2+
<% key_value_pair = relationship.enumeration_key_for(value) -%>
3+
<%= key_value_pair ? key_value_pair.first : relationship.unassigned_value %>

Diff for: test/unit/streamlined/column/active_record_test.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ def ar_column(name, human_name)
256256
end
257257

258258
def setup_mocks(item_attrs={})
259-
@view = flexmock(:controller_name => 'controller_name', :link_to_function => 'link')
259+
@view = flexmock(:controller_path => 'controller_path', :link_to_function => 'link')
260260
@item = flexmock(item_attrs.reverse_merge(:id => 123, :column => 'render'))
261261
end
262262
end

0 commit comments

Comments
 (0)