g_already_grid 1.0.6 → 1.0.7

Sign up to get free protection for your applications and to get access to all the features.
data/History.txt CHANGED
@@ -1,9 +1,16 @@
1
- 1.0.5 2009-10-27
1
+ == 1.0.7 2009-10-27
2
+
3
+ * Added a use_polymorphic_path option to the grid view helper to enable the polymorphic path helper to determine the path of
4
+ each object in the collection to use as the link for each grid record. Used when the AR object is STI'ed and one would like
5
+ to generate show links that are correctly pathed to the specific type (not the base class).
6
+
7
+
8
+ == 1.0.5 2009-10-27
2
9
 
3
10
  * Added :clickable option to avoid creating link to show from table rows.
4
11
 
5
12
 
6
- 1.0.4 2009-03-26
13
+ == 1.0.4 2009-03-26
7
14
 
8
15
  * Refactored to utilize the REST path helper resolution available in Guilded 0.1.9
9
16
  * Added multi level scoped by option
data/README.rdoc CHANGED
@@ -56,6 +56,11 @@ Add namespace option for namespacing:
56
56
  <%= g_already_grid @items, :id => "items-grid", :cols => [:name, :is_active], :sort => [:name],
57
57
  :namespace => :admin %>
58
58
 
59
+ Add use polymorphic path option for STI'ed models:
60
+
61
+ <%= g_already_grid @items, :id => "items-grid", :cols => [:name, :is_active], :sort => [:name],
62
+ :namespace => :admin, :use_polymorphic_path => true %>
63
+
59
64
 
60
65
  == OPTIONS:
61
66
 
@@ -68,6 +73,7 @@ actions:: Action links to include in the action column of grid. A boolean or Ar
68
73
  paginate:: A boolean indicating whether to output pagination controls. Defaults to true. Utilizes will_paginate plugin features.
69
74
  polymorphic_type:: The type of this polymorphic record. Should be a string representing the class name.
70
75
  polymorphic_as:: The as used for the polymorphic type. Can be a symbol or string.
76
+ use_polymorphic_path:: When true, uses hte polymorphic path helper to determine the AR objects path from it's type (STI), otherwise, does not. Defaults to false.
71
77
  namespace:: A string or symbol that is the namespace this collection is under.
72
78
  scoped_by:: The active record object that the objects in the ar_col is scoped by.
73
79
  shallow:: True if this collection is nested shallow, otherwise, false.
@@ -78,7 +84,7 @@ adaptable_url:: True in order to make the index url automagically adapt to :get
78
84
  == REQUIREMENTS:
79
85
 
80
86
  * Rails >= 2.2.0
81
- * Guilded >= 0.1.4 (http://github.com/midas/guilded/tree/master)
87
+ * Guilded >= 1.0.0 (http://github.com/midas/guilded/tree/master)
82
88
  * will_paginate
83
89
 
84
90
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.0.6
1
+ 1.0.7
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{g_already_grid}
8
- s.version = "1.0.6"
8
+ s.version = "1.0.7"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["C. Jason Harrelson (midas)"]
12
- s.date = %q{2009-12-09}
12
+ s.date = %q{2010-01-28}
13
13
  s.description = %q{A Guilded Rails component that generates a rich grid control from an ActiveRecord.}
14
14
  s.email = %q{jason@lookforwardenterprises.com}
15
15
  s.extra_rdoc_files = [
@@ -4,7 +4,7 @@ $:.unshift(File.dirname(__FILE__)) unless
4
4
  require 'g_already_grid/view_helpers'
5
5
 
6
6
  module GAlreadyGrid
7
- VERSION = '1.0.6'
7
+ VERSION = '1.0.7'
8
8
  end
9
9
 
10
10
  if defined?( ActionView::Base )
@@ -47,7 +47,12 @@
47
47
  <td>
48
48
  <% cell_args = path_helpers[:show_rest_args] + record_array %>
49
49
  <% if options[:actions].empty? && options[:clickable] == true %>
50
- <%= link_to( record_val, @controller.send( path_helpers[:show_rest_helper], *cell_args ) ) %>
50
+ <% if options[:use_polymorphic_path] == true
51
+ cell_args.insert( 0, options[:namespace] ) -%>
52
+ <%= link_to record_val, @controller.polymorphic_path( cell_args ) %>
53
+ <% else -%>
54
+ <%= link_to( record_val, @controller.send( path_helpers[:show_rest_helper], *cell_args ) ) %>
55
+ <% end -%>
51
56
  <% else %>
52
57
  <%= link_to( record_val, "javascript:void(0)" ) %>
53
58
  <% end %>
@@ -1,57 +1,68 @@
1
1
  module GAlreadyGrid
2
2
  module ViewHelpers
3
-
3
+
4
4
  # GUIlded element. This is a grid that is utilizing the already grid jQuery plugin. It is
5
5
  # a progressively enhanced table.
6
- #
6
+ #
7
7
  # *parameters*
8
- # ar_col:: (required) An ActiveRecord collection.
9
- # options:: As follows.
10
- #
8
+ # +ar_col+ (required) An ActiveRecord collection.
9
+ # +options+ As follows.
10
+ #
11
11
  # *options*
12
- # id:: (required) The id of the element. Must be unique on the page.
13
- # cols:: (required) An array of column names to include in the table. Each position of
12
+ # +id+ (required) The id of the element. Must be unique on the page.
13
+ # +cols+ (required) An array of column names to include in the table. Each position of
14
14
  # the array can be a symbol, string, or hash with 1 entry. The hash entry is the
15
15
  # database field name as a key and the name to use in the gird as the value. Each
16
16
  # key and value in the hash can be a symbol or string.
17
- # skin:: The name of the skin to use for this Guilded element. Defaults to default => which is default.css.
18
- # exclude_css:: A boolean indicating if Guilded should create a stylesheet inlcude tag for
17
+ # +skin+ The name of the skin to use for this Guilded element. Defaults to default => which is default.css.
18
+ # +exclude_css+ A boolean indicating if Guilded should create a stylesheet inlcude tag for
19
19
  # this element. Defaults to false.
20
- # empty_msg:: a message to display when the ar_col is empty or nil. Defaults to 'No matching records'.
21
- # actions:: Action links to include in the action column of grid. A boolean or Array of symbols. When
22
- # boolean, if true, add show, edit and delete actions. When boolean, if false, hide actions column.
20
+ # +empty_msg+ a message to display when the ar_col is empty or nil. Defaults to 'No matching records'.
21
+ # +actions+ Action links to include in the action column of grid. A boolean or Array of symbols. When
22
+ # boolean, if true, add show, edit and delete actions. When boolean, if false, hide actions column.
23
23
  # When Array of symbols, add only actions present in array.
24
- # paginate:: A boolean indicating whether to output pagination controls. Defaults to
24
+ # +paginate+ A boolean indicating whether to output pagination controls. Defaults to
25
25
  # true. Utilizes will_paginate plugin features.
26
- # polymorphic_type:: The type of this polymorphic record. Should be a string representing the class name.
27
- # polymorphic_as:: The as used for the polymorphic type. Can be a symbol or string.
28
- # namespace:: A string or symbol that is the namespace this collection is under.
29
- # scoped_by:: The active record object that the objects in the ar_col is scoped by.
30
- # shallow:: True if this collection is nested shallow, otherwise, false.
31
- # clickable:: Set to false in order to avoid rows linking to show action. Defaults to true.
32
- # adaptable_url:: True in order to make the index url automagically adapt to :get collection routes, otherwise false.
26
+ # +polymorphic_type+ The type of this polymorphic record. Should be a string representing the class name.
27
+ # +polymorphic_as+ The as used for the polymorphic type. Can be a symbol or string.
28
+ # +use_polymorphic_path+ When true, uses hte polymorphic path helper to determine the AR objects path from it's type (STI),
29
+ # otherwise, does not. Defaults to false.
30
+ # +namespace+ A string or symbol that is the namespace this collection is under.
31
+ # +scoped_by+ The active record object that the objects in the ar_col is scoped by.
32
+ # +shallow+ True if this collection is nested shallow, otherwise, false.
33
+ # +clickable+ Set to false in order to avoid rows linking to show action. Defaults to true.
34
+ # +adaptable_url+ True in order to make the index url automagically adapt to :get collection routes, otherwise false.
33
35
  #
34
36
  def g_already_grid( ar_col, *args )
35
37
  options = args.extract_options!
36
38
  raise ArgumentError, "'cols' option required" unless options.include?( :cols )
37
39
  raise ArgumentError, "'cols' option must be an array of columns" unless options[:cols].is_a? Array
38
-
40
+
39
41
  Guilded::Guilder.instance.add( :already_grid, options, [ 'jquery/jquery-already_grid-0.1.min.js' ] )
40
42
 
41
43
  return "<span class=\"list-empty-msg\">#{options[:empty_msg] || 'No matching records'}</span>" if ar_col.nil? || ar_col.empty?
42
-
44
+
43
45
  options[:grid_class] ||= 'already-grid'
44
46
  options[:checkbox_class] ||= "chk"
45
47
  options[:check_all_class] ||= "checkAll"
46
48
  options[:date_format] ||= :default
47
49
  options[:del_confirmation] ||= 'Are you sure you would like to delete this record?'
48
50
  options[:clickable] = true if options[:clickable].nil?
49
-
51
+
50
52
  options[:cols], options[:col_titles] = Guilded::Rails::Helpers.resolve_field_methods_and_titles( options[:cols], ar_col[0] )
51
53
  path_helpers = Guilded::Rails::Helpers.resolve_rest_path_helpers( ar_col, options )
54
+
55
+ if options[:use_sti_base_index] == true
56
+ specific_name = ar_col.first.class.name.tableize
57
+ unless ar_col.first.class.superclass.is_a?( ActiveRecord::Base )
58
+ base_class = ar_col.first.class.superclass
59
+ base_name = base_class.name.tableize
60
+ path_helpers[:index_rest_helper] = path_helpers[:index_rest_helper].gsub( /#{specific_name}/, base_name ) unless base_name.nil?
61
+ end
62
+ end
52
63
 
53
64
  scoped_by = options.delete( :scoped_by )
54
-
65
+
55
66
  # Resolve sorting
56
67
  if options[:sort]
57
68
  if options[:sort].is_a?( Array )
@@ -63,7 +74,7 @@ module GAlreadyGrid
63
74
  end
64
75
  end
65
76
  sort_by = Array.new unless sort_by
66
-
77
+
67
78
  if options[:actions].is_a?( TrueClass )
68
79
  options[:actions] = [ :show, :edit, :delete ]
69
80
  elsif options[:actions].nil?
@@ -85,13 +96,13 @@ module GAlreadyGrid
85
96
  end
86
97
 
87
98
  options[:checkboxes] = true if options[:checkboxes].nil?
88
-
99
+
89
100
  total_columns = options[:cols].size
90
101
  total_columns = total_columns + 1 if options[:checkboxes]
91
102
  total_columns = total_columns + 1 unless options[:actions].empty?
92
103
  options[:total_columns] = total_columns
93
-
94
- vars = {
104
+
105
+ vars = {
95
106
  :options => options, :ar_col => ar_col, :do_paginate => do_paginate, :sort_by => sort_by, :path_helpers => path_helpers
96
107
  }
97
108
 
@@ -100,19 +111,19 @@ module GAlreadyGrid
100
111
  full_path = "#{path}/templates/guilded.already_grid.html.erb"
101
112
  self.render( :file => full_path, :use_full_path => false, :locals => vars )
102
113
  end
103
-
114
+
104
115
  private
105
-
106
- # Creates a link to sort this column of a table. Utilizes the link_to helper,
107
- # but resolves sort by, direction and adds correct CSS classes for UI elements to
116
+
117
+ # Creates a link to sort this column of a table. Utilizes the link_to helper,
118
+ # but resolves sort by, direction and adds correct CSS classes for UI elements to
108
119
  # be displayed.
109
- #
120
+ #
110
121
  # *parameters*
111
- # name:: The text to use for the link
112
- # method:: The actual name of this column's field.
113
- # path:: (Symbol) The name of the path method to call from routing.
114
- # already_grid_options:: The options hash from the already grid view helper.
115
- # options:: see link_to helper.
122
+ # +name+ The text to use for the link
123
+ # +method+ The actual name of this column's field.
124
+ # +path+ (Symbol) The name of the path method to call from routing.
125
+ # +already_grid_options+ The options hash from the already grid view helper.
126
+ # +options+ see link_to helper.
116
127
  #
117
128
  def sortable_header( name, method, path, scoping_args, already_grid_options, options={} )
118
129
  is_sorted_link = ( method.to_s == params[:order].to_s )
@@ -132,21 +143,21 @@ module GAlreadyGrid
132
143
  sort_options.merge!( :filter => params[:filter] ) if params[:filter]
133
144
  unsorted_options = { :order => method, :direction => 'ASC' } # always sort ascending on first sort
134
145
  unsorted_options.merge!( :filter => params[:filter] ) if params[:filter]
135
-
146
+
136
147
  path = path.to_sym unless path.is_a?( Symbol )
137
148
  path_args = [] + scoping_args
138
-
149
+
139
150
  if is_sorted_link
140
151
  # Handle the currently sorted by link
141
152
  path_args << sort_options
142
153
  path = @controller.send( path, *path_args )
143
154
  else
144
- # Handle the the other currently unsorted by links (we will always sort in
155
+ # Handle the the other currently unsorted by links (we will always sort in
145
156
  # an ASC direction the first time)
146
157
  path_args << unsorted_options
147
158
  path = @controller.send( path, *path_args )
148
159
  end
149
-
160
+
150
161
  # Try to adapt to get collection rest methods
151
162
  if already_grid_options[:adaptable_url]
152
163
  path_parts = path.split( '?' )
@@ -156,13 +167,13 @@ module GAlreadyGrid
156
167
  path = "#{request.path_info}?#{path_parts[1]}" # path.gsub( /#path_parts[0]/, request.request_uri )
157
168
  end
158
169
  end
159
-
170
+
160
171
  # Load the params to an args array to send to the link_to helper
161
172
  args = []
162
173
  args << name << path << options
163
174
 
164
175
  link_to( *args )
165
176
  end
166
-
177
+
167
178
  end
168
179
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: g_already_grid
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.6
4
+ version: 1.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - C. Jason Harrelson (midas)
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-12-09 00:00:00 -06:00
12
+ date: 2010-01-28 00:00:00 -06:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency