admin_data 1.1.10 → 1.1.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README.md CHANGED
@@ -5,7 +5,7 @@
5
5
  # [Installing in a Rails3 application](https://github.com/neerajdotname/admin_data/wiki/Installation-and-Usage-information-for-a-Rails-3-application) #
6
6
  # [Installing in a Rails 2.3.x application](https://github.com/neerajdotname/admin_data/wiki/Installation-and-Usage-information-for-a-Rails-2.3.x-application) #
7
7
 
8
- # [Live Demo](http://admin-data-test.heroku.com/admin_data) #
8
+ # [Live Demo](http://admin-data-demo.heroku.com/admin_data) #
9
9
 
10
10
 
11
11
  #Test#
@@ -1,8 +1,32 @@
1
1
  require File.join(AdminData::LIBPATH, 'admin_data', 'search')
2
2
 
3
+ class SearchAction
4
+ attr_accessor :relation, :success_message
5
+
6
+ def initialize(relation)
7
+ @relation = relation
8
+ end
9
+
10
+ def delete
11
+ count = relation.count
12
+ relation.delete_all
13
+ self.success_message = "#{count} #{AdminData::Util.pluralize(count, 'record')} deleted"
14
+ end
15
+
16
+ def destroy
17
+ count = relation.count
18
+ relation.find_in_batches do |group|
19
+ group.each {|record| record.destroy }
20
+ end
21
+ self.success_message = "#{count} #{AdminData::Util.pluralize(count, 'record')} destroyed"
22
+ end
23
+ end
24
+
3
25
  module AdminData
4
26
  class SearchController < ApplicationController
5
27
 
28
+ layout 'search'
29
+
6
30
  include Search
7
31
 
8
32
  before_filter :get_class_from_params
@@ -10,21 +34,22 @@ module AdminData
10
34
  before_filter :ensure_is_authorized_for_update_opration, :only => [:advance_search]
11
35
  before_filter :set_column_type_info, :only => [:advance_search]
12
36
 
37
+
13
38
  def quick_search
14
39
  @page_title = "Search #{@klass.name.underscore}"
15
- @order = default_order
40
+ order = default_order
16
41
 
17
42
  if params[:base]
18
43
  klass = Util.camelize_constantize(params[:base])
19
44
  model = klass.find(params[:model_id])
20
45
  has_many_proxy = model.send(params[:children].intern)
21
46
  @total_num_of_children = has_many_proxy.send(:count)
22
- h = { :page => params[:page], :per_page => per_page, :order => @order }
47
+ h = { :page => params[:page], :per_page => per_page, :order => order }
23
48
  @records = has_many_proxy.send(:paginate, h)
24
49
  else
25
50
  params[:query] = params[:query].strip unless params[:query].blank?
26
51
  cond = build_quick_search_conditions(@klass, params[:query])
27
- h = { :page => params[:page], :per_page => per_page, :order => @order, :conditions => cond }
52
+ h = { :page => params[:page], :per_page => per_page, :order => order, :conditions => cond }
28
53
  @records = @klass.unscoped.paginate(h)
29
54
  end
30
55
  respond_to {|format| format.html}
@@ -34,9 +59,9 @@ module AdminData
34
59
  def advance_search
35
60
  @page_title = "Advance search #{@klass.name.underscore}"
36
61
  hash = build_advance_search_conditions(@klass, params[:adv_search])
37
- @relation = hash[:cond]
62
+ relation = hash[:cond]
38
63
  errors = hash[:errors]
39
- @order = default_order
64
+ order = default_order
40
65
 
41
66
  respond_to do |format|
42
67
  format.html { render }
@@ -47,16 +72,20 @@ module AdminData
47
72
  render :file => file, :locals => {:errors => errors}
48
73
  return
49
74
  end
50
- if params[:admin_data_advance_search_action_type] == 'destroy'
51
- handle_advance_search_action_type_destroy
52
- elsif params[:admin_data_advance_search_action_type] == 'delete'
53
- handle_advance_search_action_type_delete
75
+
76
+ search_action = SearchAction.new(relation)
77
+
78
+ case params[:admin_data_advance_search_action_type]
79
+ when 'destroy'
80
+ search_action.destroy
81
+ when 'delete'
82
+ search_action.delete
54
83
  else
55
- @records = @relation.order(@order).paginate(:page => params[:page], :per_page => per_page)
84
+ @records = relation.order(order).paginate(:page => params[:page], :per_page => per_page)
56
85
  end
57
86
 
58
- if @success_message
59
- render :json => {:success => @success_message }
87
+ if search_action.success_message
88
+ render :json => {:success => search_action.success_message }
60
89
  else
61
90
  file = "/admin_data/search/search/listing.html.erb"
62
91
  render :partial => file, :locals => {:klass => @klass}, :layout => false
@@ -92,20 +121,6 @@ module AdminData
92
121
  end
93
122
  end
94
123
 
95
- def handle_advance_search_action_type_delete
96
- count = @relation.count
97
- @relation.delete_all
98
- @success_message = "#{count} #{Util.pluralize(count, 'record')} deleted"
99
- end
100
-
101
- def handle_advance_search_action_type_destroy
102
- count = @relation.count
103
- @relation.find_in_batches do |group|
104
- group.each {|record| record.destroy }
105
- end
106
- @success_message = "#{count} #{Util.pluralize(count, 'record')} destroyed"
107
- end
108
-
109
124
  def default_order
110
125
  params[:sortby] || "#{@klass.send(:table_name)}.#{@klass.send(:primary_key)} desc"
111
126
  end
@@ -1,6 +1,11 @@
1
1
  module AdminData
2
2
  module ApplicationHelper
3
3
 
4
+ def parent_layout(layout)
5
+ @_content_for[:layout] = self.output_buffer
6
+ self.output_buffer = render(:file => "layouts/#{layout}")
7
+ end
8
+
4
9
  def column_title(klass, column)
5
10
  AdminData.config.column_headers[klass.name].try(:fetch,column.intern, nil) || column
6
11
  end
@@ -62,7 +67,7 @@ module AdminData
62
67
  end
63
68
 
64
69
  def has_one(model, klass)
65
- tmp = AdminData::ActiveRecordUtil.new(klass).declared_has_one_association_names
70
+ tmp = ActiveRecordUtil.new(klass).declared_has_one_association_names
66
71
  tmp.inject('') do |output, ho|
67
72
  begin
68
73
  label = ho
@@ -72,27 +77,27 @@ module AdminData
72
77
  output << label
73
78
  end
74
79
  rescue => e
75
- Rails.logger.debug AdminData::Util.exception_info(e)
80
+ Rails.logger.debug Util.exception_info(e)
76
81
  end
77
82
  output
78
83
  end
79
84
  end
80
85
 
81
86
  def has_many_data(model, klass)
82
- array = AdminData::ActiveRecordUtil.new(klass).declared_has_many_association_names.map do |m|
87
+ array = ActiveRecordUtil.new(klass).declared_has_many_association_names.map do |m|
83
88
  begin
84
89
  count = model.send(m.intern).count
85
90
  label = m.to_s + '(' + count.to_s + ')'
86
91
  output = label
87
92
  if count > 0
88
- has_many_klass_name = AdminData::ActiveRecordUtil.new(model.class).klass_for_association_type_and_name(:has_many, m).name.underscore
93
+ has_many_klass_name = ActiveRecordUtil.new(model.class).klass_for_association_type_and_name(:has_many, m).name.underscore
89
94
  output = link_to(label, admin_data_search_path( :klass => has_many_klass_name,
90
95
  :children => m,
91
96
  :base => klass.name.underscore,
92
97
  :model_id => model.id))
93
98
  end
94
99
  rescue => e
95
- Rails.logger.debug AdminData::Util.exception_info(e)
100
+ Rails.logger.debug Util.exception_info(e)
96
101
  end
97
102
  output
98
103
  end
@@ -100,35 +105,35 @@ module AdminData
100
105
  end
101
106
 
102
107
  def belongs_to_data(model, klass)
103
- AdminData::ActiveRecordUtil.new(klass).declared_belongs_to_association_names.map do |assoc_name|
108
+ ActiveRecordUtil.new(klass).declared_belongs_to_association_names.map do |assoc_name|
104
109
  begin
105
110
  output = assoc_name
106
111
  if belongs_to_record = model.send(assoc_name)
107
112
  output = link_to(assoc_name, admin_data_path(:klass => belongs_to_record.class.name.underscore, :id => belongs_to_record.id))
108
113
  end
109
114
  rescue => e
110
- Rails.logger.info AdminData::Util.exception_info(e)
115
+ Rails.logger.info Util.exception_info(e)
111
116
  end
112
117
  output
113
118
  end.join(', ')
114
119
  end
115
120
 
116
121
  def habtm_data(model, klass)
117
- AdminData::ActiveRecordUtil.new(klass).declared_habtm_association_names.map do |assoc_name|
122
+ ActiveRecordUtil.new(klass).declared_habtm_association_names.map do |assoc_name|
118
123
  begin
119
124
  count = model.send(assoc_name.intern).count
120
125
  label = assoc_name + '(' + count.to_s + ')'
121
126
  output = label
122
127
 
123
128
  if count > 0 then
124
- has_many_klass_name = AdminData::ActiveRecordUtil.new(model.class).klass_for_association_type_and_name(:has_and_belongs_to_many, assoc_name).name.underscore
129
+ has_many_klass_name = ActiveRecordUtil.new(model.class).klass_for_association_type_and_name(:has_and_belongs_to_many, assoc_name).name.underscore
125
130
  output = link_to(label, admin_data_search_path( :klass => has_many_klass_name,
126
131
  :children => assoc_name,
127
132
  :base => klass.name.underscore,
128
133
  :model_id => model.id))
129
134
  end
130
135
  rescue => e
131
- Rails.logger.info AdminData::Util.exception_info(e)
136
+ Rails.logger.info Util.exception_info(e)
132
137
  end
133
138
  output
134
139
  end.join(', ')
@@ -143,7 +148,7 @@ module AdminData
143
148
  column_value = model.send(col.name)
144
149
 
145
150
  if klass.serialized_attributes.has_key?(col.name)
146
- return AdminData::Util.get_serialized_value(html,column_value)
151
+ return Util.get_serialized_value(html,column_value)
147
152
  end
148
153
 
149
154
  if col.primary
@@ -172,7 +177,7 @@ module AdminData
172
177
  end
173
178
  html.join
174
179
  rescue Exception => e
175
- Rails.logger.info AdminData::Util.exception_info(e)
180
+ Rails.logger.info Util.exception_info(e)
176
181
  'could not retrieve' # returning nil
177
182
  end
178
183
  end
@@ -180,8 +185,8 @@ module AdminData
180
185
  def form_field_for_habtm_records(klass, model, f, html)
181
186
  begin
182
187
  html = []
183
- AdminData::ActiveRecordUtil.new(klass).delcared_habtm_association_names.each do |k|
184
- assoc_klass = AdminData::Util.get_class_name_for_habtm_association(model, k)
188
+ ActiveRecordUtil.new(klass).delcared_habtm_association_names.each do |k|
189
+ assoc_klass = Util.get_class_name_for_habtm_association(model, k)
185
190
 
186
191
  html << "<div class='col_box'>"
187
192
  html << " <span class='col_name'>#{assoc_klass.table_name}</span>"
@@ -197,7 +202,7 @@ module AdminData
197
202
  end
198
203
  html.join
199
204
  rescue Exception => e
200
- Rails.logger.info AdminData::Util.exception_info(e)
205
+ Rails.logger.info Util.exception_info(e)
201
206
  'could not retrieve' # returning nil
202
207
  end
203
208
  end
@@ -260,7 +265,7 @@ module AdminData
260
265
  def get_value_for_column(column, model, options = {})
261
266
  options.reverse_merge!(:limit => 400)
262
267
 
263
- value = AdminData::Util.custom_value_for_column(column, model)
268
+ value = Util.custom_value_for_column(column, model)
264
269
 
265
270
  if column.is_a?(String)
266
271
  value
@@ -1,3 +1 @@
1
- <div id="main">
2
- <%= render '/admin_data/search/search_base', :klass => @klass, :model => @model, :records => @records, :advance_search => true %>
3
- </div>
1
+ <%= render 'admin_data/search/search/advance_search_form', :klass => @klass %>
@@ -1,6 +1 @@
1
- <div id='main'>
2
- <%= render '/admin_data/search/search_base' , :klass => @klass,
3
- :model => @model,
4
- :records => @records,
5
- :advance_search => false %>
6
- </div>
1
+ <%= render 'admin_data/search/search/search_form', :klass => @klass %>
@@ -1,6 +1,6 @@
1
- <%= form_tag(admin_data_advance_search_path(:klass=>klass),
2
- :method => 'get',
3
- :class => 'form search_form',
1
+ <%= form_tag(admin_data_advance_search_path(:klass => klass),
2
+ :method => 'get',
3
+ :class => 'form search_form',
4
4
  :id => 'advance_search_form') %>
5
5
 
6
6
  <div id='advance_search' class='search_box'>
@@ -8,19 +8,19 @@
8
8
  </table>
9
9
 
10
10
  <div class='sortby_umbrella'>
11
- <div class='group'>
11
+ <div class='group'>
12
12
  <div class='sortby_text'>Sort by</div>
13
13
  <select name='sortby' id='sortby'>
14
14
  <%= AdminData::Util.build_sort_options(klass,params[:sortby]).html_safe %>
15
15
  </select>
16
16
  <br />
17
- </div>
17
+ </div>
18
18
  <div class='clear'></div>
19
19
  <input type="submit" value="Search" class='submit_search' />
20
- </div>
20
+ </div>
21
21
  </div>
22
22
 
23
- </form>
23
+ </form>
24
24
 
25
25
  <div style='display:none;' id='primary_column_type_info'>
26
26
  <%=@column_type_info%>
@@ -30,15 +30,15 @@
30
30
  </div>
31
31
 
32
32
  <style>
33
- .sortby_umbrella {
33
+ .sortby_umbrella {
34
34
  margin-top: 6px;
35
35
  }
36
36
  .sortby_umbrella .group {
37
37
  padding-left: 20px;
38
- }
38
+ }
39
39
  .sortby_umbrella .sortby_text {
40
40
  font-size: 16px;
41
- }
41
+ }
42
42
  .submit_search {
43
43
  margin-left: 15px;
44
44
  margin-right: 20px;
@@ -46,12 +46,12 @@
46
46
  .sortby_umbrella .group {
47
47
  float: left;
48
48
  }
49
- .sortby_text {
49
+ .sortby_text {
50
50
  float: left;
51
51
  margin-right: 5px;
52
52
  }
53
- #sortby {
54
- width: 200px;
53
+ #sortby {
54
+ width: 200px;
55
55
  float: left;
56
56
  }
57
57
  </style>
@@ -1,7 +1,6 @@
1
- <%@records = @relation.order(@order).paginate(:page => params[:page]) if @records.nil?%>
2
1
  <%= render :partial => 'admin_data/search/search/title', :locals => {
3
- :records => @records,
4
- :total_num_of_children => @total_num_of_children } %>
2
+ :records => @records,
3
+ :total_num_of_children => @total_num_of_children } %>
5
4
 
6
5
  <div class="pagination">
7
6
  <%= will_paginate @records, :container => false, :params => {:klass => klass.name} %>
@@ -1,4 +1,4 @@
1
- <%= form_tag(admin_data_search_path(:klass=>klass), :method => 'get', :class => 'form search_form', :id => 'search') %>
1
+ <%= form_tag(admin_data_search_path(:klass => klass), :method => 'get', :class => 'form search_form', :id => 'search') %>
2
2
 
3
3
  <div class='search_box'>
4
4
  <div id='quick_search'>
@@ -15,12 +15,12 @@
15
15
  <br />
16
16
 
17
17
  <style>
18
- .keyword_label {
18
+ .keyword_label {
19
19
  float: left;
20
20
  padding-right: 10px;
21
21
  margin-right: 10px;
22
22
  }
23
- #quick_search_input {
23
+ #quick_search_input {
24
24
  float: left;
25
25
  margin-left: 10px;
26
26
  margin-right: 20px;
@@ -1,23 +1,19 @@
1
+ <div id='main'>
1
2
  <div class="block" id="block-text">
2
3
 
3
4
  <div>
4
- <h1 class='listing_klass'> Listing <%=klass.name%></h1>
5
- <h3 class='total_records_info_klass'><%=total_records_info(klass)%></h3>
5
+ <h1 class='listing_klass'> Listing <%=@klass.name%></h1>
6
+ <h3 class='total_records_info_klass'><%=total_records_info(@klass)%></h3>
6
7
  <div class='clear'></div>
7
8
  </div>
8
9
 
9
-
10
10
  <div class="secondary-navigation">
11
- <%= render 'admin_data/shared/secondary_navigation', :klass => klass %>
11
+ <%= render 'admin_data/shared/secondary_navigation', :klass => @klass %>
12
12
  <div class="clear"></div>
13
13
  </div>
14
14
 
15
15
  <div class="content">
16
- <% if advance_search %>
17
- <%= render 'admin_data/search/search/advance_search_form', :klass => klass %>
18
- <% else %>
19
- <%= render 'admin_data/search/search/search_form', :klass => klass %>
20
- <% end %>
16
+ <%= yield %>
21
17
  </div>
22
18
 
23
19
  <div class='clear'></div>
@@ -28,7 +24,7 @@
28
24
  <div class='inner'>
29
25
  <div id='results'>
30
26
  <% if params[:action] == 'quick_search' %>
31
- <%= render 'admin_data/search/search/listing', :klass => klass, :records => records %>
27
+ <%= render 'admin_data/search/search/listing', :klass => @klass, :records => @records %>
32
28
  <% end %>
33
29
  </div>
34
30
  </div>
@@ -36,3 +32,6 @@
36
32
  </div>
37
33
  </div>
38
34
  </div>
35
+ </div>
36
+
37
+ <%= parent_layout 'admin_data' %>
data/config/routes.rb CHANGED
@@ -26,7 +26,7 @@ Rails.application.routes.draw do
26
26
 
27
27
  match '/feed/:klasss' => "feed#index", :defaults => { :format =>'rss' }, :as => :feed
28
28
 
29
- match '/public/*file' => "public#serve"
29
+ match '/public/*file' => "public#serve", :as => :public
30
30
 
31
31
  root :to => "home#index"
32
32
  end
@@ -1,3 +1,3 @@
1
1
  module AdminData
2
- VERSION = '1.1.10'
2
+ VERSION = '1.1.11'
3
3
  end
@@ -1,7 +1,3 @@
1
- Given /^a phone_number exists$/ do
2
- Factory(:phone_number)
3
- end
4
-
5
1
  When /^I visit (.*) page$/ do |target_page|
6
2
  case target_page
7
3
  when 'admin_data'
@@ -1,4 +1,8 @@
1
- Then /^page should have (\w*) field css "(.*)" with user_id value$/ do |tag_name,css_selector|
1
+ # Usage:
2
+ #
3
+ # Then page should have "select" field with selector "#phone_number_user_id"
4
+ # Then page should have "input" field with selector "#phone_number_user_id"
5
+ Then /^page should have "(.*)" field with selector "(.*)"$/ do |tag_name, css_selector|
2
6
  elem = page.find(css_selector)
3
7
  elem.tag_name.should == tag_name
4
8
  elem.value.should == PhoneNumber.last.user.id.to_s
@@ -8,15 +12,9 @@ Then /^page should have id "remove_row_3"$/ do
8
12
  page.has_css?("remove_row_3")
9
13
  end
10
14
 
11
- Then /^I should see only two rows in the (.*) result table$/ do |search_type|
12
- case search_type
13
- when 'quick search'
14
- table_id = 'view_table'
15
- when 'advance search'
16
- table_id = 'advance_search_table'
17
- end
15
+ Then /^I should see "(.*)" rows in table "(.*)"$/ do |count, table_id|
18
16
  table = page.find(:xpath, "//table[@id='#{table_id}']")
19
- table.find(:xpath, "./tbody/tr", :count => 2 )
17
+ table.find(:xpath, "./tbody/tr", :count => count.to_i )
20
18
  end
21
19
 
22
20
  Then /^async I should see "(.*)"$/ do |msg|
@@ -40,6 +38,13 @@ def handy_has_links(table)
40
38
  end
41
39
  end
42
40
 
41
+ # Usage:
42
+ #
43
+ # Then page should have following links:
44
+ # | url | text | within |
45
+ # | http://github.com/neerajdotname/admin_data | admin_data | #footer |
46
+ # | http://github.com/neerajdotname/admin_data/issues | Report Bug | #footer |
47
+ # | http://github.com/neerajdotname/admin_data/wiki | Documentation | #footer |
43
48
  Then /^page should have following links?:$/ do |table|
44
49
  handy_has_links(table)
45
50
  end
@@ -47,15 +52,15 @@ end
47
52
 
48
53
  # Usage :
49
54
  #
50
- # position: if the option is the very first option in the dropdown list then position should be 1.
51
- # css_selector: only class and id are supported at this time.
52
- # value_match_type: If specified as "regex" then Regular expression will be used to detect the match.
55
+ # position: if the option is the very first option in the dropdown list then position should be 1.
56
+ # css_selector: only class and id are supported at this time.
57
+ # value_match_type: If specified as "regex" then Regular expression will be used to detect the match.
53
58
  #
54
- # Then I should see dropdown with css_selector ".drop_down_value_klass" with following options:
55
- # | text | value | position | value_match_type |
56
- # | phone_number | /admin_data/quick_search/phone_number | 2 | regex |
57
- # | user | /admin_data/quick_search/user | 3 | regex |
58
- # | website | /admin_data/quick_search/website | 4 | regex |
59
+ # Then I should see dropdown with css_selector ".drop_down_value_klass" with following options:
60
+ # | text | value | position | value_match_type |
61
+ # | phone_number | /admin_data/quick_search/phone_number | 2 | regex |
62
+ # | user | /admin_data/quick_search/user | 3 | regex |
63
+ # | website | /admin_data/quick_search/website | 4 | regex |
59
64
  #
60
65
  def handy_has_select?(css_selector, select_options)
61
66
  selector = css_selector[1..-1]
@@ -60,7 +60,6 @@ end
60
60
 
61
61
  require 'factory_girl'
62
62
  require Rails.root.join('test', 'factories')
63
- Dir[Rails.root.join('test', 'factories', '*.rb')].each {|f| require f}
64
63
  require 'factory_girl/step_definitions'
65
64
  require 'shoulda'
66
65
 
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: admin_data
3
3
  version: !ruby/object:Gem::Version
4
- hash: 7
4
+ hash: 5
5
5
  prerelease: false
6
6
  segments:
7
7
  - 1
8
8
  - 1
9
- - 10
10
- version: 1.1.10
9
+ - 11
10
+ version: 1.1.11
11
11
  platform: ruby
12
12
  authors:
13
13
  - Neeraj Singh
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-12-23 00:00:00 -05:00
18
+ date: 2011-03-16 00:00:00 -04:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -132,7 +132,6 @@ files:
132
132
  - app/views/admin_data/home/index.html.erb
133
133
  - app/views/admin_data/migration/index.html.erb
134
134
  - app/views/admin_data/migration/jstest.html.erb
135
- - app/views/admin_data/search/_search_base.html.erb
136
135
  - app/views/admin_data/search/advance_search.html.erb
137
136
  - app/views/admin_data/search/quick_search.html.erb
138
137
  - app/views/admin_data/search/search/_advance_search_form.html.erb
@@ -149,6 +148,7 @@ files:
149
148
  - app/views/admin_data/shared/_secondary_navigation.html.erb
150
149
  - app/views/admin_data/table_structure/index.html.erb
151
150
  - app/views/layouts/admin_data.html.erb
151
+ - app/views/layouts/search.html.erb
152
152
  - config/routes.rb
153
153
  - lib/admin_data.rb
154
154
  - lib/admin_data/active_record_util.rb
@@ -236,8 +236,8 @@ homepage: http://github.com/neerajdotname/admin_data
236
236
  licenses: []
237
237
 
238
238
  post_install_message:
239
- rdoc_options:
240
- - --charset=UTF-8
239
+ rdoc_options: []
240
+
241
241
  require_paths:
242
242
  - lib
243
243
  required_ruby_version: !ruby/object:Gem::Requirement