padrino-admin 0.4.5 → 0.4.6

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/VERSION CHANGED
@@ -1 +1 @@
1
- 0.4.5
1
+ 0.4.6
@@ -49,78 +49,56 @@ module Padrino
49
49
  # end
50
50
  #
51
51
  module Controller
52
- def self.column_store_for(model, &block)
53
- ColumnStore.new(model, &block)
52
+ def self.column_store_for(model, config)
53
+ ColumnStore.new(model, config)
54
54
  end
55
55
 
56
56
  class ColumnStore #:nodoc:
57
57
  attr_reader :data
58
58
 
59
- def initialize(model, &block) #:nodoc
59
+ def initialize(model, config) #:nodoc
60
60
  @model = model
61
- @data = []
62
- yield self
63
- end
64
-
65
- # Method for add columns to the Column Model
66
- def add(*args)
67
-
68
- # First we need to check that our method is a symbol
69
- raise Padrino::ExtJs::ConfigError, "First args must be a symbol like: :name or :account.name" unless args[0].is_a?(Symbol)
70
-
71
- # Construct our options
72
- options = { :method => args[0] }
73
-
74
- # If we have a second args that is not an hash maybe an header
75
- options[:header] = args[1].is_a?(String) || args[1].is_a?(Symbol) ? args[1].to_s : nil
76
-
77
- args.each { |a| options.merge!(a) if a.is_a?(Hash) }
61
+ @data = config["columns"].map do |column|
62
+
63
+ # Reformat our config
64
+ column["header"] ||= column["method"].to_s
65
+ column["dataIndex"] ||= column["method"]
66
+ column["sortable"] ||= column["sortable"].nil? ? true : column["sortable"]
67
+ column["header"] = @model.human_attribute_name(column["header"]) # try to translate with I18n the column name
68
+
69
+ # Try to reformat the dataIndex
70
+ data_indexes = Array(column["dataIndex"]).collect do |data_index|
71
+ if data_index =~ /\./ # if we have some like categories.names we use this
72
+ cols = data_index.split(".")
73
+ column["name"] ||= cols[0] + "[" + cols[1..-1].join("][") + "]" # accounts.name will be => accounts[name]
74
+ else
75
+ column["name"] ||= "#{@model.table_name.singularize}[#{data_index}]"
76
+ data_index = "#{@model.table_name}.#{data_index}"
77
+ end
78
+ data_index
79
+ end
78
80
 
79
- # Add some defaults
80
- options[:header] ||= options[:method].to_s
81
- options[:sortable] = options[:sortable].nil? ? true : options[:sortable]
81
+ # Now we join our data indexes
82
+ column["dataIndex"] = data_indexes.compact.uniq.join(",")
82
83
 
83
- # Try to translate header
84
- options[:header] = @model.human_attribute_name(options[:header].to_s)
84
+ # Reformat mapping like a div id
85
+ column["mapping"] ||= column["name"].sub(/\[/,"_").sub(/\]$/, "").sub(/\]\[/,"_")
85
86
 
86
- # Reformat DataIndex
87
- #
88
- # If we don't have nothing we use the method
89
- options[:dataIndex] ||= options[:method]
87
+ # Now is necessary for our columns an ID
88
+ # TODO: check duplicates here
89
+ column["id"] = column["mapping"]
90
+
90
91
 
91
- data_indexes = Array(options[:dataIndex]).collect do |data_index|
92
- case data_index
93
- when String then data_index
94
- when Symbol
95
- if data_index.missing_methods.size == 1
96
- options[:name] ||= "#{@model.table_name.singularize}[#{data_index}]"
97
- data_index = "#{@model.table_name}.#{data_index}"
98
- else
99
- columns = data_index.missing_methods
100
- options[:name] ||= columns.at(0) + "[" + columns[1..-1].collect(&:to_s).join("][") + "]"
101
- data_index = columns[0..-2].collect { |c| c.to_s.pluralize }.join(".") + "." + columns.at(-1).to_s
102
- end
103
- end
104
- data_index
92
+ # Finally we can return our column
93
+ column
105
94
  end
106
-
107
- options[:dataIndex] = data_indexes.compact.uniq.join(",")
108
-
109
- # Reformat mapping like a div id
110
- options[:mapping] ||= options[:name].sub(/\[/,"_").sub(/\]$/, "").sub(/\]\[/,"_")
111
-
112
- # Now is necessary for our columns an ID
113
- # TODO: check duplicates here
114
- options[:id] = options[:mapping]
115
-
116
- @data << options
117
95
  end
118
96
 
119
97
  # Return an array config for build an Ext.grid.ColumnModel() config
120
98
  def column_fields
121
99
  @data.map do |data|
122
- data.delete(:method)
123
- data.delete(:mapping)
100
+ data.delete("method")
101
+ data.delete("mapping")
124
102
  data
125
103
  end
126
104
  end
@@ -128,8 +106,8 @@ module Padrino
128
106
  # Return an array config for build an Ext.data.GroupingStore()
129
107
  def store_fields
130
108
  @data.map do |data|
131
- hash = { :name => data[:dataIndex], :mapping => data[:mapping] }
132
- hash.merge!(:type => data[:renderer]) if data[:renderer] && [:date, :datetime, :time_to_date].include?(data[:renderer])
109
+ hash = { :name => data["dataIndex"], :mapping => data["mapping"] }
110
+ hash.merge!(:type => data["renderer"]) if data["renderer"] && [:date, :datetime, :time_to_date].include?(data["renderer"])
133
111
  hash
134
112
  end
135
113
  end
@@ -138,7 +116,7 @@ module Padrino
138
116
  def store_data_from(collection)
139
117
  collection.map do |c|
140
118
  @data.dup.inject({ "id" => c.id }) do |options, data|
141
- options[data[:mapping]] = (c.instance_eval(data[:method].to_s) rescue I18n.t("padrino.admin.labels.not_found"))
119
+ options[data["mapping"]] = (c.instance_eval(data["method"]) rescue I18n.t("padrino.admin.labels.not_found"))
142
120
  options
143
121
  end
144
122
  end
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{padrino-admin}
8
- s.version = "0.4.5"
8
+ s.version = "0.4.6"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Padrino Team", "Nathan Esquenazi", "Davide D'Agostino", "Arthur Chiu"]
12
- s.date = %q{2010-01-06}
12
+ s.date = %q{2010-01-07}
13
13
  s.description = %q{Admin View for Padrino applications}
14
14
  s.email = %q{nesquena@gmail.com}
15
15
  s.extra_rdoc_files = [
@@ -33,7 +33,6 @@ Gem::Specification.new do |s|
33
33
  "lib/padrino-admin/ext_js/controller.rb",
34
34
  "lib/padrino-admin/generators/backend.rb",
35
35
  "lib/padrino-admin/locale/en.yml",
36
- "lib/padrino-admin/support.rb",
37
36
  "lib/padrino-admin/utils/crypt.rb",
38
37
  "padrino-admin.gemspec",
39
38
  "test/fixtures/active_record.rb",
@@ -4,25 +4,76 @@ class TestController < Test::Unit::TestCase
4
4
 
5
5
  def setup
6
6
  load_fixture 'data_mapper'
7
- @column_store = Padrino::ExtJs::Controller.column_store_for(Account) do |cm|
8
- cm.add :name.upcase, "Name Upcase", :sortable => true, :dataIndex => :name
9
- cm.add :surname # Not exist but it's not a problem
10
- cm.add :category.name
11
- cm.add :email, "E-Mail", :sortable => true
12
- cm.add :role, :sortable => true
13
- end
7
+ config = Padrino::ExtJs::Config.load <<-YAML
8
+ columns:
9
+ - method: name.upcase
10
+ header: Name Upcase
11
+ dataIndex: name
12
+ - method: surname
13
+ - method: category.name
14
+ - method: email
15
+ header: E-mail
16
+ sortable: false
17
+ - method: role
18
+ YAML
19
+ @column_store = Padrino::ExtJs::Controller.column_store_for(Account, config)
14
20
  end
15
21
 
16
22
  should 'have correct column fileds' do
17
- assert_equal nil, @column_store.column_fields
23
+ result = [
24
+ {"name"=>"account[name]",
25
+ "sortable"=>true,
26
+ "header"=>"Name upcase",
27
+ "id"=>"account_name",
28
+ "dataIndex"=>"accounts.name"},
29
+ {"name"=>"account[surname]",
30
+ "sortable"=>true,
31
+ "header"=>"Surname",
32
+ "id"=>"account_surname",
33
+ "dataIndex"=>"accounts.surname"},
34
+ {"name"=>"category[name]",
35
+ "sortable"=>true,
36
+ "header"=>"Category.name",
37
+ "id"=>"category_name",
38
+ "dataIndex"=>"category.name"},
39
+ {"name"=>"account[email]",
40
+ "sortable"=>false,
41
+ "header"=>"E-mail",
42
+ "id"=>"account_email",
43
+ "dataIndex"=>"accounts.email"},
44
+ {"name"=>"account[role]",
45
+ "sortable"=>true,
46
+ "header"=>"Role",
47
+ "id"=>"account_role",
48
+ "dataIndex"=>"accounts.role"}]
49
+ assert_equal result, @column_store.column_fields
18
50
  end
19
51
 
20
52
  should 'have correct store fields' do
21
- assert_equal nil, @column_store.store_fields
53
+ result = [
54
+ {:mapping=>"account_name", :name=>"accounts.name"},
55
+ {:mapping=>"account_surname", :name=>"accounts.surname"},
56
+ {:mapping=>"category_name", :name=>"category.name"},
57
+ {:mapping=>"account_email", :name=>"accounts.email"},
58
+ {:mapping=>"account_role", :name=>"accounts.role"}]
59
+ assert_equal result, @column_store.store_fields
22
60
  end
23
61
 
24
62
  should 'store data' do
25
- assert_equal nil, @column_store.store_data(:fields => "name,role", :query => "d", :sort => :name, :dir => :asc, :limit => 2, :offset => 0)
63
+ result = {:results=>[
64
+ {"account_surname"=>"Not found",
65
+ "account_email"=>"d.dagostino@lipsiasoft.com",
66
+ "category_name"=>"Not found",
67
+ "id"=>1,
68
+ "account_role"=>"Admin",
69
+ "account_name"=>"DADDYE"},
70
+ {"account_surname"=>"Not found",
71
+ "account_email"=>"editor@lipsiasoft.com",
72
+ "category_name"=>"Not found",
73
+ "id"=>2,
74
+ "account_role"=>"Editor",
75
+ "account_name"=>"DEXTER"}], :count=>2}
76
+ assert_equal result, @column_store.store_data(:fields => "name,role", :query => "d", :sort => :name, :dir => :asc, :limit => 2, :offset => 0)
26
77
  end
27
78
 
28
79
  end
@@ -20,8 +20,10 @@ class TestMongoMapper < Test::Unit::TestCase
20
20
 
21
21
  should 'correctly authenticate an account' do
22
22
  account = Account.create(:email => "auth@lipsia.org", :role => "some", :password => "some", :password_confirmation => "some")
23
+ assert account.valid?
24
+ assert ! account.id.nil?
23
25
  assert_equal "some", account.password_clean
24
- account_r = Account.authenticate("auth@lipsia.org", "some")
26
+ account_r = Account.first(:conditions => { :email => "auth@lipsia.org" })
25
27
  assert_equal account_r, account
26
28
  end
27
29
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: padrino-admin
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.5
4
+ version: 0.4.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Padrino Team
@@ -12,7 +12,7 @@ autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
14
 
15
- date: 2010-01-06 00:00:00 +01:00
15
+ date: 2010-01-07 00:00:00 +01:00
16
16
  default_executable:
17
17
  dependencies:
18
18
  - !ruby/object:Gem::Dependency
@@ -121,7 +121,6 @@ files:
121
121
  - lib/padrino-admin/ext_js/controller.rb
122
122
  - lib/padrino-admin/generators/backend.rb
123
123
  - lib/padrino-admin/locale/en.yml
124
- - lib/padrino-admin/support.rb
125
124
  - lib/padrino-admin/utils/crypt.rb
126
125
  - padrino-admin.gemspec
127
126
  - test/fixtures/active_record.rb
@@ -1,12 +0,0 @@
1
- class Symbol
2
-
3
- def method_missing(method, *args)
4
- super and return if method.to_s =~ /table_name/
5
- (self.to_s + ".#{method}(#{args.collect(&:inspect).join(",")})").to_sym
6
- end
7
-
8
- def missing_methods
9
- self.to_s.gsub(/(\(.*\))/,"").split(".")
10
- end
11
-
12
- end