admin_data 1.0.18 → 1.0.19

Sign up to get free protection for your applications and to get access to all the features.
data/History.txt CHANGED
@@ -1,4 +1,8 @@
1
1
 
2
+ === 2010-11-08 v1.0.19
3
+ * used unscoped on the model to have basic search result always in the order user wants
4
+ * remove inline css
5
+
2
6
  === 2010-11-08 v1.0.18
3
7
  * disable the columns not being used
4
8
  * use parseJSON instead of eval
data/README.md CHANGED
@@ -1,15 +1,16 @@
1
+ # admin_data #
1
2
 
2
3
  # This plugin works with both Rails 2.3.x and Rails 3.
3
- * master branch hosts code where admin_data is a plugin and it works with Rails 2.3.x .
4
- * rails3_gem branch hosts code where admin_data is a gem and it works with Rails 3.x .
5
-
6
- [More info about Rails3](http://github.com/neerajdotname/admin_data/wiki/Installing-admin_data-in-a-Rails-3-project)
4
+ * [Installing in Rails3 project](http://github.com/neerajdotname/admin_data/wiki/Installing-admin_data-in-a-Rails-3-project)
5
+ * [Installing in Rails 2.3.x project](https://github.com/neerajdotname/admin_data/wiki/Installing-admin_data-in-a-Rails-2.3.x-project)
7
6
 
8
7
  ## [Live Demo](http://admin-data-test.heroku.com/admin_data)
9
8
 
10
9
  ## [Documentation](http://github.com/neerajdotname/admin_data/wiki)
11
10
 
12
- ## [Source Code](http://github.com/neerajdotname/admin_data)
11
+ ## Source Code ##
12
+ * admin_data works as a gem with Rails 3.x project. Source for that resides in master branch.
13
+ * admin_data works as a plugin with Rails 2.3.x project. Source code for that resides in branch called [rails2](https://github.com/neerajdotname/admin_data/tree/rails2) .
13
14
 
14
15
  #Test#
15
16
 
@@ -20,7 +20,7 @@ class AdminData::BaseController < ApplicationController
20
20
  end
21
21
 
22
22
  def ensure_is_allowed_to_view
23
- render :text => '<h2>not authorized</h2>' unless admin_data_is_allowed_to_view?
23
+ render :text => 'not authorized' unless admin_data_is_allowed_to_view?
24
24
  end
25
25
 
26
26
  def ensure_is_allowed_to_view_klass
@@ -49,7 +49,7 @@ class AdminData::BaseController < ApplicationController
49
49
  end
50
50
 
51
51
  def build_klasses
52
- # if is_allowed_to_view_klass option is passed then golbal constant can't be used since
52
+ # if is_allowed_to_view_klass option is passed then global constant can't be used since
53
53
  # list of klasses need to be built for each user. It will slow down the speed a bit since
54
54
  # every single the list needs to be built
55
55
  if AdminData::Config.setting[:is_allowed_to_view_klass]
@@ -9,6 +9,9 @@ class AdminData::FeedController < AdminData::BaseController
9
9
 
10
10
  begin
11
11
  @klass = AdminData::Util.camelize_constantize(params[:klasss])
12
+ @title = "Feeds from admin_data #{@klass.name}"
13
+ @description = "feeds from AdminData #{@klass.name}"
14
+ @records = @klass.find(:all, :order => "#{@klass.primary_key} desc", :limit => 100)
12
15
  rescue NameError => e
13
16
  render :text => "No constant was found with name #{params[:klasss]}" and return
14
17
  end
@@ -117,7 +117,7 @@ class AdminData::MainController < AdminData::BaseController
117
117
 
118
118
  @model = @klass.send('find', :first, :conditions => condition)
119
119
  unless @model
120
- render :text => "<h2>#{@klass.name} not found: #{params[:id]}</h2>", :status => :not_found
120
+ render :text => "#{@klass.name} not found: #{params[:id]}", :status => :not_found
121
121
  end
122
122
  end
123
123
 
@@ -1,6 +1,6 @@
1
1
  require File.join(File.dirname(__FILE__) , '..', '..', '..', 'lib', 'admin_data', 'search')
2
2
 
3
- class AdminData::SearchController < AdminData::BaseController
3
+ class AdminData::SearchController < AdminData::BaseController
4
4
 
5
5
  include Search
6
6
 
@@ -11,7 +11,7 @@ class AdminData::SearchController < AdminData::BaseController
11
11
  before_filter :ensure_is_allowed_to_view_klass
12
12
  before_filter :ensure_valid_children_klass, :only => [:quick_search]
13
13
  before_filter :ensure_is_authorized_for_update_opration, :only => [:advance_search]
14
- before_filter :set_collection_of_columns, :only => [:advance_search]
14
+ before_filter :set_column_type_info, :only => [:advance_search]
15
15
 
16
16
  def quick_search
17
17
  @page_title = "Search #{@klass.name.underscore}"
@@ -28,7 +28,7 @@ class AdminData::SearchController < AdminData::BaseController
28
28
  params[:query] = params[:query].strip unless params[:query].blank?
29
29
  cond = build_quick_search_conditions(@klass, params[:query])
30
30
  h = { :page => params[:page], :per_page => per_page, :order => @order, :conditions => cond }
31
- @records = @klass.paginate(h)
31
+ @records = @klass.unscoped.paginate(h)
32
32
  end
33
33
  respond_to {|format| format.html}
34
34
  end
@@ -46,8 +46,9 @@ class AdminData::SearchController < AdminData::BaseController
46
46
  format.html { render }
47
47
  format.js {
48
48
 
49
- if !hash[:errors].blank?
50
- render :file => "#{plugin_dir}/app/views/admin_data/search/search/_errors.html.erb", :locals => {:errors => errors}
49
+ unless hash[:errors].blank?
50
+ file = "#{plugin_dir}/app/views/admin_data/search/search/_errors.html.erb"
51
+ render :file => file, :locals => {:errors => errors}
51
52
  return
52
53
  end
53
54
  if params[:admin_data_advance_search_action_type] == 'destroy'
@@ -61,7 +62,8 @@ class AdminData::SearchController < AdminData::BaseController
61
62
  if @success_message
62
63
  render :json => {:success => @success_message }
63
64
  else
64
- render :partial => "/admin_data/search/search/listing.html.erb", :locals => {:klass => @klass}, :layout => false
65
+ file = "/admin_data/search/search/listing.html.erb"
66
+ render :partial => file, :locals => {:klass => @klass}, :layout => false
65
67
  end
66
68
  }
67
69
  end
@@ -109,13 +111,13 @@ class AdminData::SearchController < AdminData::BaseController
109
111
  params[:sortby] || "#{@klass.send(:table_name)}.#{@klass.send(:primary_key)} desc"
110
112
  end
111
113
 
112
- def set_collection_of_columns
113
- collection_of_columns = @klass.columns.collect { |column|
114
+ def set_column_type_info
115
+ column_type_info = @klass.columns.collect { |column|
114
116
  #JSLint complains if a hash has key named boolean. So I am changing the key to booleant
115
117
  column_type = (column.type.to_s == 'boolean') ? 'booleant' : column.type.to_s
116
118
  %Q{ "#{column.name}":"#{column_type}" }
117
119
  }.join(',')
118
- @collection_of_columns = "{#{collection_of_columns}}"
120
+ @column_type_info = "{#{column_type_info}}"
119
121
  end
120
122
 
121
123
  end
@@ -1,12 +1,12 @@
1
1
  xml.instruct! :xml, :version => "1.0"
2
2
  xml.rss(:version => "2.0" ){
3
3
  xml.channel{
4
- xml.title("Feeds from admin_data #{@klass.name}")
4
+ xml.title(@title)
5
5
  xml.link(request.host_with_port)
6
- xml.description("feeds from AdminData #{@klass.name}")
6
+ xml.description(@description)
7
7
  xml.language('en-us')
8
8
  h = {:order => "#{@klass.primary_key} desc", :limit => 100}
9
- @klass.find(:all, h).each do |record|
9
+ @records.each do |record|
10
10
  xml.item do
11
11
  xml.title("#{@klasss} id: #{record.id}")
12
12
 
@@ -1,7 +1,7 @@
1
1
  <div class="block rounded">
2
2
  <h3>Association Information</h3>
3
3
  <div class='content association_info'>
4
- <% if AdminData::Util.admin_data_association_info_size(klass) %>
4
+ <% if AdminData::Util.association_info_size(klass) %>
5
5
  <%= render 'admin_data/main/association/belongs_to_info' , :klass => klass, :model => model %>
6
6
  <%= render 'admin_data/main/association/has_one_info', :klass => klass, :model => model %>
7
7
  <%= render 'admin_data/main/association/has_many_info' , :klass => klass, :model => model %>
@@ -1,4 +1,4 @@
1
- <% if AdminData::Util.belongs_to_what(klass).size > 0 %>
1
+ <% if AdminData::Util.belongs_to_what(klass).any? %>
2
2
  <p class='belongs_to'>
3
3
  <strong>belongs_to :</strong>
4
4
  &nbsp;
@@ -1,4 +1,4 @@
1
- <% if AdminData::Util.has_many_what(klass).size > 0 %>
1
+ <% if AdminData::Util.has_many_what(klass).any? %>
2
2
  <p>
3
3
  <strong>has_many :</strong>
4
4
  <%= admin_data_has_many_data(model, klass).html_safe %>
@@ -1,4 +1,4 @@
1
- <% if AdminData::Util.has_one_what(klass).size > 0 %>
1
+ <% if AdminData::Util.has_one_what(klass).any? %>
2
2
  <p>
3
3
  <strong>has_one :</strong>
4
4
  <%= admin_data_has_one(model, klass).html_safe %>
@@ -1,6 +1,6 @@
1
1
  <div id="main">
2
2
  <div>
3
- <h1 style='float:left;font-weight:bold;font-size: 35px;'>
3
+ <h1 class='search_path'>
4
4
  <%= link_to @klass, admin_data_search_path(:klass => @klass.name) %>
5
5
  >
6
6
  <%= link_to "ID #{@model.id}", ''%>
@@ -1,6 +1,4 @@
1
1
  <% if controller.send(:admin_data_is_allowed_to_update?) %>
2
- <% @help = link_to('[?]','http://neerajdotname.github.com/admin_data/#deletevs-destroy') %>
3
-
4
2
  <div class="block rounded">
5
3
  <h3>Modify Record</h3>
6
4
  <div style='padding-left:15px'>
@@ -10,12 +8,10 @@
10
8
  <p>
11
9
  <%= link_to 'Delete', del_admin_data_on_k_path(:klass => klass.name.underscore, :id => model) ,
12
10
  { :confirm => ' You are deleting (not destroying) a record. Are you sure?', :method => :delete} %>
13
- <%= @help %>
14
11
  </p>
15
12
  <p>
16
13
  <%= link_to "Destroy", admin_data_on_k_path(:klass => klass.name.underscore, :id => model),
17
14
  { :confirm => 'You are destroying a record. Are you sure?', :method => :delete} %>
18
- <%= @help %>
19
15
  </p>
20
16
  </div>
21
17
  </div>
@@ -1,7 +1,7 @@
1
1
  <div id="main">
2
2
 
3
3
  <div>
4
- <h1 style='float:left;font-weight:bold;font-size: 35px;'>
4
+ <h1 class='search_path'>
5
5
  <%= link_to @klass, admin_data_search_path(:klass => @klass.name) %>
6
6
  >
7
7
  <%= link_to "ID #{@model.id}", ''%>
@@ -1,8 +1,8 @@
1
1
  <div class="block" id="block-text">
2
2
 
3
3
  <div>
4
- <h1 style='float:left;font-weight:bold;font-size: 35px;'> Listing <%=klass.name%></h1>
5
- <h3 style='float:left;margin:22px 0 0 10px;color:gray;'><%=total_records_info(klass)%></h3>
4
+ <h1 class='listing_klass'> Listing <%=klass.name%></h1>
5
+ <h3 class='total_records_info_klass'><%=total_records_info(klass)%></h3>
6
6
  <div class='clear'></div>
7
7
  </div>
8
8
 
@@ -3,33 +3,42 @@
3
3
  :class => 'form search_form',
4
4
  :id => 'advance_search_form') %>
5
5
 
6
- <div id='advance_search' class='search_box'>
7
- <table id='advance_search_table' class='advtable'>
8
- </table>
6
+ <div id='advance_search' class='search_box'>
7
+ <table id='advance_search_table' class='advtable'>
8
+ </table>
9
9
 
10
- <div class='sortby_umbrella'>
11
- <div class='group' style='padding-left:20px;'>
12
- <div class='sortby_text' style='font-size:16px;'>Sort by</div>
13
- <select name='sortby' id='sortby'>
14
- <%= AdminData::Util.build_sort_options(klass,params[:sortby]).html_safe %>
15
- </select>
16
- <br />
17
- </div>
18
- <div class='clear'></div>
19
- <input type="submit" value="Search" class='submit_search' />
10
+ <div class='sortby_umbrella'>
11
+ <div class='group'>
12
+ <div class='sortby_text'>Sort by</div>
13
+ <select name='sortby' id='sortby'>
14
+ <%= AdminData::Util.build_sort_options(klass,params[:sortby]).html_safe %>
15
+ </select>
16
+ <br />
20
17
  </div>
21
- </div>
18
+ <div class='clear'></div>
19
+ <input type="submit" value="Search" class='submit_search' />
20
+ </div>
21
+ </div>
22
22
 
23
23
  </form>
24
24
 
25
- <div style='display:none;' id='admin_data_table_structure_data'>
26
- <%=@collection_of_columns%>
25
+ <div style='display:none;' id='primary_column_type_info'>
26
+ <%=@column_type_info%>
27
+ </div>
28
+ <div style='display:none;' id='association_info'>
29
+ <%=@association_info%>
27
30
  </div>
28
31
 
29
32
  <style>
30
33
  .sortby_umbrella {
31
34
  margin-top: 6px;
32
35
  }
36
+ .sortby_umbrella .group {
37
+ padding-left: 20px;
38
+ }
39
+ .sortby_umbrella .sortby_text {
40
+ font-size: 16px;
41
+ }
33
42
  .submit_search {
34
43
  margin-left: 15px;
35
44
  margin-right: 20px;
@@ -4,15 +4,15 @@
4
4
  </select>
5
5
 
6
6
  <style>
7
- .sortby_label {
8
- float: left;
9
- vertical-align: bottom;
10
- margin-left: 40px;
11
- width: 70px;
12
- }
13
- #sortyby {
14
- width: 200px;
15
- float: left;
16
- }
7
+ .sortby_label {
8
+ float: left;
9
+ vertical-align: bottom;
10
+ margin-left: 40px;
11
+ width: 70px;
12
+ }
13
+ #sortyby {
14
+ width: 200px;
15
+ float: left;
16
+ }
17
17
  </style>
18
18
 
@@ -24,7 +24,7 @@
24
24
  float: left;
25
25
  margin-top: 5px;
26
26
  padding-top: 5px;
27
- }
27
+ }
28
28
  .delete_destroy_box {
29
29
  float: left;
30
30
  margin-top: 6px;
@@ -1,19 +1,20 @@
1
1
  <div id="header">
2
- <h1> &nbsp;
3
- </h1>
2
+ <h1> &nbsp; </h1>
4
3
 
5
- <ul id='subnav'>
6
- <li>
7
- <% label = "Back to Site " + image_tag('https://github.com/neerajdotname/admin_data/raw/rails3_gem/public/images/site.png', :width => '12') %>
8
- <%= link_to label.html_safe, '/' %>
9
- </li>
10
- <li> <%= link_to AdminData::Config.setting[:app_name] , admin_data_index_path %> </li>
11
- </ul>
4
+ <ul id='subnav'>
5
+ <li>
6
+ <% label = "Back to Site " + image_tag('https://github.com/neerajdotname/admin_data/raw/master/public/images/site.png', :width => '12') %>
7
+ <%= link_to label.html_safe, '/' %>
8
+ </li>
9
+ <li>
10
+ <%= link_to AdminData::Config.setting[:app_name] , admin_data_index_path %>
11
+ </li>
12
+ </ul>
12
13
 
13
- <div id='model_drop_down'>
14
- <%= render '/admin_data/shared/drop_down_klasses', :drop_down_for_klasses => drop_down_for_klasses %>
15
- </div>
14
+ <div id='model_drop_down'>
15
+ <%= render '/admin_data/shared/drop_down_klasses', :drop_down_for_klasses => drop_down_for_klasses %>
16
+ </div>
16
17
 
17
- <div class='clear'></div>
18
+ <div class='clear'></div>
18
19
 
19
20
  </div>
@@ -193,11 +193,8 @@ class AdminData::Util
193
193
  associations_for(klass, :has_and_belongs_to_many).map(&:name).map(&:to_s)
194
194
  end
195
195
 
196
- def self.admin_data_association_info_size(klass)
197
- (belongs_to_what(klass).size > 0) ||
198
- (has_many_what(klass).size > 0) ||
199
- (has_one_what(klass).size > 0) ||
200
- (habtm_what(klass).size > 0)
196
+ def self.association_info_size(k)
197
+ belongs_to_what(k).any? || has_many_what(k).any? || has_one_what(k).any? || habtm_what(k).any?
201
198
  end
202
199
 
203
200
  def self.string_representation_of_data(value)
@@ -1,3 +1,3 @@
1
1
  module AdminData
2
- VERSION = '1.0.18'
2
+ VERSION = '1.0.19'
3
3
  end
data/lib/css/base.css CHANGED
@@ -1089,3 +1089,20 @@ ul#subnav li a:hover {
1089
1089
  font-weight: bold;
1090
1090
  font-size: 18px;
1091
1091
  }
1092
+ #main h2.search_path {
1093
+ float:left;
1094
+ font-weight:bold;
1095
+ font-size: 35px;
1096
+ }
1097
+
1098
+ .listing_klass {
1099
+ float:left;
1100
+ font-weight:bold;
1101
+ font-size: 35px;
1102
+ }
1103
+
1104
+ .total_records_info_klass {
1105
+ float:left;
1106
+ margin:22px 0 0 10px;
1107
+ color:gray;
1108
+ }
@@ -5,7 +5,7 @@ AdminData.advanceSearch = {
5
5
  buildFirstRow: function() {
6
6
 
7
7
  var img = $('<img />', {
8
- src: 'https://github.com/neerajdotname/admin_data/raw/rails3_gem/public/images/add.png'
8
+ src: 'https://github.com/neerajdotname/admin_data/raw/master/public/images/add.png'
9
9
  });
10
10
 
11
11
  $('#advance_search_table').append(this.buildRow())
@@ -42,7 +42,7 @@ AdminData.advanceSearch = {
42
42
 
43
43
  buildCol4: function() {
44
44
  var img = $('<img />', {
45
- src: 'https://github.com/neerajdotname/admin_data/raw/rails3_gem/public/images/no.png'
45
+ src: 'https://github.com/neerajdotname/admin_data/raw/master/public/images/no.png'
46
46
  });
47
47
 
48
48
  return $('<td />').append($('<a />', {
@@ -63,7 +63,7 @@ AdminData.advanceSearch = {
63
63
  currentRowNumber = 1;
64
64
  $(document).data('currentRowNumber', currentRowNumber);
65
65
  } else {
66
- currentRowNumber = parseInt(currentRowNumber) + 1;
66
+ currentRowNumber = parseInt(currentRowNumber, 10) + 1;
67
67
  $(document).data('currentRowNumber', currentRowNumber);
68
68
  }
69
69
 
@@ -1,6 +1,6 @@
1
1
  $(function() {
2
2
 
3
- var json = $.parseJSON( $('#admin_data_table_structure_data').html());
3
+ var json = $.parseJSON( $('#primary_column_type_info').html());
4
4
  $('#advance_search_table').data('table_structure', json);
5
5
  AdminData.advanceSearch.buildFirstRow();
6
6
 
@@ -1,5 +1,10 @@
1
1
  var AdminData = AdminData || {};
2
2
 
3
+ /**
4
+ * A general Utility
5
+ * @namespace AdminData
6
+ * @class jsUtil
7
+ */
3
8
  AdminData.jsUtil = {
4
9
 
5
10
  // TODO since advance search was not working with util confirm , window.confirm is used directly
@@ -21,7 +26,12 @@ AdminData.jsUtil = {
21
26
  $('.colorize tr:even').addClass('even');
22
27
  },
23
28
 
24
- // returns date in string format. example: 07-September-2009
29
+ /**
30
+ * Returns the input date in string format.
31
+ *
32
+ * @param {date} input date
33
+ * @return {string} The string value of input date
34
+ */
25
35
  dateToString: function(date) {
26
36
  var month = (date.getMonth() + 1).toString();
27
37
  var day = date.getDate().toString();
@@ -31,6 +41,12 @@ AdminData.jsUtil = {
31
41
  return day + "-" + months[month - 1] + "-" + date.getFullYear();
32
42
  },
33
43
 
44
+ /**
45
+ * Generate a random number between 1 and 10000000
46
+ *
47
+ * @return {Integer} a random Integer
48
+ *
49
+ */
34
50
  randomNumber: function() {
35
51
  var maxVal = 100000000,
36
52
  minVal = 1;
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: 51
4
+ hash: 49
5
5
  prerelease: false
6
6
  segments:
7
7
  - 1
8
8
  - 0
9
- - 18
10
- version: 1.0.18
9
+ - 19
10
+ version: 1.0.19
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-11-08 00:00:00 -05:00
18
+ date: 2010-11-17 00:00:00 -05:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency