netzke-core 0.2.11 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG CHANGED
@@ -1,3 +1,13 @@
1
+ v0.3.0
2
+ Refactor: got rid of NetzkeLayout model, now all layouts are stored in netzke_preferences
3
+ New: persistent_config now has a method for_widget that accepts a block
4
+ autotest compatibility
5
+ New: String#to_b converts a string to true/false
6
+ New: Netzke::Base.session introduced for session data
7
+ New: weak_children_config and strong_children_config can now be declared by a widget, which specifies weak and strong configuration that every child of this widget will receive (e.g. display/hide configuration tool)
8
+ Fix: (degradation) flash message is now shown again in case of erroneous attempt to load a widget
9
+ New: widgets now can check session[:netzke_just_logged_in] and session[:netzke_just_logged_out] automatically set by Netzke after login/logout
10
+
1
11
  v0.2.11
2
12
  Introduction of getOwnerWidget()-method to Ext.Component. It provides the Netzke widget this Component belongs to.
3
13
 
data/Manifest CHANGED
@@ -1,13 +1,12 @@
1
+ autotest/discover.rb
1
2
  CHANGELOG
2
3
  generators/netzke_core/netzke_core_generator.rb
3
- generators/netzke_core/templates/create_netzke_layouts.rb
4
4
  generators/netzke_core/templates/create_netzke_preferences.rb
5
5
  generators/netzke_core/USAGE
6
6
  init.rb
7
7
  install.rb
8
8
  javascripts/core.js
9
9
  lib/app/controllers/netzke_controller.rb
10
- lib/app/models/netzke_layout.rb
11
10
  lib/app/models/netzke_preference.rb
12
11
  lib/netzke/action_view_ext.rb
13
12
  lib/netzke/base.rb
@@ -26,7 +25,9 @@ Rakefile
26
25
  README.mdown
27
26
  stylesheets/core.css
28
27
  tasks/netzke_core_tasks.rake
29
- test/app_root/app/controllers/application.rb
28
+ test/app_root/app/controllers/application_controller.rb
29
+ test/app_root/app/models/role.rb
30
+ test/app_root/app/models/user.rb
30
31
  test/app_root/config/boot.rb
31
32
  test/app_root/config/database.yml
32
33
  test/app_root/config/environment.rb
@@ -37,10 +38,15 @@ test/app_root/config/environments/sqlite.rb
37
38
  test/app_root/config/environments/sqlite3.rb
38
39
  test/app_root/config/routes.rb
39
40
  test/app_root/db/migrate/20081222035855_create_netzke_preferences.rb
41
+ test/app_root/db/migrate/20090423214303_create_roles.rb
42
+ test/app_root/db/migrate/20090423222114_create_users.rb
43
+ test/app_root/lib/console_with_fixtures.rb
40
44
  test/app_root/script/console
41
- test/core_ext_test.rb
42
- test/netzke_core_test.rb
43
- test/netzke_preference_test.rb
45
+ test/fixtures/roles.yml
46
+ test/fixtures/users.yml
44
47
  test/test_helper.rb
48
+ test/unit/core_ext_test.rb
49
+ test/unit/netzke_core_test.rb
50
+ test/unit/netzke_preference_test.rb
45
51
  TODO
46
52
  uninstall.rb
data/TODO CHANGED
@@ -1 +1 @@
1
- * Re-factor JS-level inheritance mechanisms
1
+ * Re-factor JS-level inheritance mechanisms
@@ -0,0 +1,3 @@
1
+ Autotest.add_discovery do
2
+ "rails"
3
+ end
@@ -3,13 +3,10 @@ class NetzkeCoreGenerator < Rails::Generator::Base
3
3
  def manifest
4
4
  record do |m|
5
5
  # FIXME: how do we avoid getting the same migration timestamps?
6
- # m.migration_template 'create_netzke_preferences.rb', "db/migrate", {:migration_file_name => "create_netzke_preferences"}
7
- # m.migration_template 'create_netzke_layouts.rb', "db/migrate", {:migration_file_name => "create_netzke_layouts"}
8
-
9
6
  # Work-around
10
7
  time = Time.now.utc.strftime("%Y%m%d%H%M%S")
11
8
  m.directory 'db/migrate'
12
- m.file 'create_netzke_layouts.rb', "db/migrate/#{time}_create_netzke_layouts.rb"
9
+ # m.file 'create_netzke_layouts.rb', "db/migrate/#{time}_create_netzke_layouts.rb"
13
10
  m.file 'create_netzke_preferences.rb', "db/migrate/#{time.to_i+1}_create_netzke_preferences.rb"
14
11
  end
15
12
  end
data/javascripts/core.js CHANGED
@@ -317,7 +317,7 @@ Ext.override(Ext.Panel, {
317
317
 
318
318
  } else {
319
319
  // we didn't get normal response - desplay the flash with eventual errors
320
- this.ownerCt.feedback(responseObj.flash);
320
+ this.getOwnerWidget().feedback(responseObj.flash);
321
321
  }
322
322
 
323
323
  // reenable the panel
@@ -1,18 +1,19 @@
1
1
  #
2
- # TODO: would be great to support somethnig like:
2
+ # TODO: would be great to support something like this:
3
3
  # NetzkePreference["name"].merge!({:a => 1, :b => 2}) # if NetzkePreference["name"] returns a hash
4
4
  # or
5
5
  # NetzkePreference["name"] << 2 # if NetzkePreference["name"] returns an array
6
6
  # etc
7
7
  #
8
8
  class NetzkePreference < ActiveRecord::Base
9
- named_scope :for_current_user, lambda { {:conditions => {:user_id => user_id}} }
9
+ belongs_to :user
10
+ belongs_to :role
10
11
 
11
12
  ELEMENTARY_CONVERTION_METHODS= {'Fixnum' => 'to_i', 'String' => 'to_s', 'Float' => 'to_f', 'Symbol' => 'to_sym'}
12
13
 
13
- def self.user_id
14
- Netzke::Base.user && Netzke::Base.user.id
15
- end
14
+ # def self.user_id
15
+ # Netzke::Base.user && Netzke::Base.user.id
16
+ # end
16
17
 
17
18
  def self.widget_name=(value)
18
19
  @@widget_name = value
@@ -48,25 +49,112 @@ class NetzkePreference < ActiveRecord::Base
48
49
 
49
50
  def self.[](pref_name)
50
51
  pref_name = normalize_preference_name(pref_name)
51
- conditions = {:name => pref_name, :user_id => user_id, :widget_name => self.widget_name}
52
- pref = self.find(:first, :conditions => conditions)
52
+ pref = self.pref_to_read(pref_name)
53
53
  pref && pref.normalized_value
54
54
  end
55
55
 
56
56
  def self.[]=(pref_name, new_value)
57
57
  pref_name = normalize_preference_name(pref_name)
58
- conditions = {:name => pref_name, :user_id => user_id, :widget_name => self.widget_name}
59
- pref = self.find(:first, :conditions => conditions)
58
+ pref = self.pref_to_write(pref_name)
60
59
 
61
60
  # if assigning nil, simply delete the eventually found preference
62
61
  if new_value.nil?
63
62
  pref && pref.destroy
64
63
  else
65
- pref ||= self.new(conditions)
64
+ # pref ||= self.new(conditions(pref_name))
66
65
  pref.normalized_value = new_value
67
66
  pref.save!
68
67
  end
69
68
  end
69
+
70
+ # execute set/get operation for a specified widget, e.g.:
71
+ # NetzkePreference.for_widget('my_widget') { |p| p[:key] = "value" }
72
+ def self.for_widget(widget, &block)
73
+ raise ArgumentError, "Block is required for #{self.name}\#for_widget" if !block_given?
74
+ backup_widget_name = self.widget_name
75
+ self.widget_name = widget
76
+ res = yield(self)
77
+ self.widget_name = backup_widget_name
78
+ res
79
+ end
80
+
81
+ #
82
+ # Overwrite pref_to_read, pref_to_write methods, and find_all_for_widget if you want a different way of
83
+ # identifying the proper preference based on your own authorization strategy.
84
+ #
85
+ # The default strategy is:
86
+ # 1) if no masq_user or masq_role defined
87
+ # pref_to_read will search for the preference for user first, then for user's role
88
+ # pref_to_write will always find or create a preference for the current user (never for its role)
89
+ # 2) if masq_user or masq_role is defined
90
+ # pref_to_read and pref_to_write will always take the masquerade into account, e.g. reads/writes will go to
91
+ # the user/role specified
92
+ #
93
+ def self.pref_to_read(name)
94
+ name = name.to_s
95
+ session = Netzke::Base.session
96
+ cond = {:name => name, :widget_name => self.widget_name}
97
+
98
+ if session[:masq_user]
99
+ # first, get the prefs for this user it they exist
100
+ res = self.find(:first, :conditions => cond.merge({:user_id => session[:masq_user].id}))
101
+ # if it doesn't exist, get them for the user's role
102
+ res ||= self.find(:first, :conditions => cond.merge({:role_id => session[:masq_user].role.id}))
103
+ elsif session[:masq_role]
104
+ res = self.find(:first, :conditions => cond.merge({:role_id => session[:masq_role].id}))
105
+ elsif session[:user]
106
+ res = self.find(:first, :conditions => cond.merge({:user_id => session[:user].id}))
107
+ res ||= self.find(:first, :conditions => cond.merge({:role_id => session[:user].role.try(:id)}))
108
+ else
109
+ res = self.find(:first, :conditions => cond)
110
+ end
111
+
112
+ res
113
+ end
114
+
115
+ def self.pref_to_write(name)
116
+ name = name.to_s
117
+ session = Netzke::Base.session
118
+ cond = {:name => name, :widget_name => self.widget_name}
119
+
120
+ if session[:masq_user]
121
+ cond.merge!({:user_id => session[:masq_user].id})
122
+ res = self.find(:first, :conditions => cond)
123
+ res ||= self.new(cond)
124
+ elsif session[:masq_role]
125
+ # first, delete all the corresponding preferences for the users that have this role
126
+ Role.find(session[:masq_role].id).users.each do |u|
127
+ self.delete_all(cond.merge({:user_id => u.id}))
128
+ end
129
+ cond.merge!({:role_id => session[:masq_role].id})
130
+ res = self.find(:first, :conditions => cond)
131
+ res ||= self.new(cond)
132
+ elsif session[:user]
133
+ res = self.find(:first, :conditions => cond.merge({:user_id => session[:user].id}))
134
+ res ||= self.new(cond.merge({:user_id => session[:user].id}))
135
+ else
136
+ res = self.find(:first, :conditions => cond)
137
+ res ||= self.new(cond)
138
+ end
139
+ res
140
+ end
141
+
142
+ def self.find_all_for_widget(name)
143
+ session = Netzke::Base.session
144
+ cond = {:widget_name => name}
145
+
146
+ if session[:masq_user] || session[:masq_role]
147
+ cond.merge!({:user_id => session[:masq_user].try(:id), :role_id => session[:masq_role].try(:id)})
148
+ res = self.find(:all, :conditions => cond)
149
+ elsif session[:user]
150
+ res = self.find(:all, :conditions => cond.merge({:user_id => session[:user].id}))
151
+ res += self.find(:all, :conditions => cond.merge({:role_id => session[:user].role.try(:id)}))
152
+ else
153
+ res = self.find(:all, :conditions => cond)
154
+ end
155
+
156
+ res
157
+ end
70
158
 
71
159
  private
72
160
  def self.normalize_preference_name(name)
data/lib/netzke/base.rb CHANGED
@@ -11,7 +11,6 @@ module Netzke
11
11
  :javascripts => [],
12
12
  :stylesheets => [],
13
13
 
14
- :layout_manager => "NetzkeLayout",
15
14
  :persistent_config_manager => "NetzkePreference",
16
15
 
17
16
  :ext_location => defined?(RAILS_ROOT) && "#{RAILS_ROOT}/public/extjs"
@@ -28,7 +27,7 @@ module Netzke
28
27
  self.name.split("::").last
29
28
  end
30
29
 
31
- # Multi-user support
30
+ # Multi-user support (deprecated in favor of controller sessions)
32
31
  def user
33
32
  @@user ||= nil
34
33
  end
@@ -37,6 +36,25 @@ module Netzke
37
36
  @@user = user
38
37
  end
39
38
 
39
+ # Access to controller sessions
40
+ def session
41
+ @@session ||= {}
42
+ end
43
+
44
+ def session=(s)
45
+ @@session = s
46
+ end
47
+
48
+ # called by controller at the moment of successfull login
49
+ def login
50
+ session[:_netzke_next_request_is_first_after_login] = true
51
+ end
52
+
53
+ # called by controller at the moment of logout
54
+ def logout
55
+ session[:_netzke_next_request_is_first_after_logout] = true
56
+ end
57
+
40
58
  #
41
59
  # Use this class method to declare connection points between client side of a widget and its server side. A method in a widget class with the same name will be (magically) called by the client side of the widget. See Grid widget for an example
42
60
  #
@@ -76,12 +94,7 @@ module Netzke
76
94
  nil
77
95
  end
78
96
 
79
- def layout_manager_class
80
- Netzke::Base.config[:layout_manager].constantize
81
- rescue NameError
82
- nil
83
- end
84
-
97
+
85
98
  private
86
99
  def set_default_config(default_config)
87
100
  @@config ||= {}
@@ -92,12 +105,22 @@ module Netzke
92
105
  end
93
106
  extend ClassMethods
94
107
 
95
- attr_accessor :config, :server_confg, :parent, :logger, :id_name, :permissions
108
+ attr_accessor :config, :server_confg, :parent, :logger, :id_name, :permissions, :session
96
109
  attr_reader :pref
97
110
 
98
111
  def initialize(config = {}, parent = nil)
112
+ @session = Netzke::Base.session
113
+
114
+ # Uncomment for application-wide weak/strong default config for widgets
115
+ # @config = (session[:weak_default_config] || {}).
116
+ # recursive_merge(initial_config).
117
+ # recursive_merge(config).
118
+ # recursive_merge(session[:strong_default_config] || {})
119
+
99
120
  @config = initial_config.recursive_merge(config)
121
+
100
122
  @parent = parent
123
+
101
124
  @id_name = parent.nil? ? config[:name].to_s : "#{parent.id_name}__#{config[:name]}"
102
125
 
103
126
  @flash = []
@@ -111,6 +134,24 @@ module Netzke
111
134
  def logger
112
135
  Rails.logger
113
136
  end
137
+
138
+ # configuration of all children will get recursive_merge'd with strong_children_config
139
+ def strong_children_config= (c)
140
+ @strong_children_config = c
141
+ end
142
+
143
+ def strong_children_config
144
+ @strong_children_config ||= {}
145
+ end
146
+
147
+ # configuration of all children will get reverse_recursive_merge'd with weak_children_config
148
+ def weak_children_config= (c)
149
+ @weak_children_config = c
150
+ end
151
+
152
+ def weak_children_config
153
+ @weak_children_config ||= {}
154
+ end
114
155
 
115
156
  def dependency_classes
116
157
  res = []
@@ -194,7 +235,15 @@ module Netzke
194
235
  short_class_name = aggregator.aggregatees[aggr][:widget_class_name]
195
236
  raise ArgumentError, "No widget_class_name specified for aggregatee #{aggr} of #{aggregator.config[:name]}" if short_class_name.nil?
196
237
  widget_class = "Netzke::#{short_class_name}".constantize
197
- aggregator = widget_class.new(aggregator.aggregatees[aggr].merge(:name => aggr), aggregator)
238
+
239
+ conf = weak_children_config.
240
+ recursive_merge(aggregator.aggregatees[aggr]).
241
+ recursive_merge(strong_children_config).
242
+ merge(:name => aggr)
243
+
244
+ aggregator = widget_class.new(conf, aggregator) # params: config, parent
245
+ aggregator.weak_children_config = weak_children_config
246
+ aggregator.strong_children_config = strong_children_config
198
247
  end
199
248
  aggregator
200
249
  end
@@ -284,10 +333,6 @@ module Netzke
284
333
  end
285
334
 
286
335
  # some convenience for instances
287
- def layout_manager_class
288
- self.class.layout_manager_class
289
- end
290
-
291
336
  def persistent_config_manager_class
292
337
  self.class.persistent_config_manager_class
293
338
  end
@@ -2,12 +2,29 @@ module Netzke
2
2
  module ControllerExtensions
3
3
  def self.included(base)
4
4
  base.extend ControllerClassMethods
5
- base.send(:before_filter, :set_user)
5
+ base.send(:before_filter, :set_session_data)
6
6
  end
7
7
 
8
- # pickup
9
- def set_user
10
- Netzke::Base.user = current_user if defined?(current_user)
8
+ def set_session_data
9
+ Netzke::Base.session = session
10
+ session[:user] = defined?(current_user) ? current_user : nil
11
+
12
+ Netzke::Base.user = session[:user] # for backward compatibility (TODO: eliminate the need for this)
13
+
14
+ # set netzke_just_logged_in and netzke_just_logged_out states (may be used by Netzke widgets)
15
+ if session[:_netzke_next_request_is_first_after_login]
16
+ session[:netzke_just_logged_in] = true
17
+ session[:_netzke_next_request_is_first_after_login] = false
18
+ else
19
+ session[:netzke_just_logged_in] = false
20
+ end
21
+
22
+ if session[:_netzke_next_request_is_first_after_logout]
23
+ session[:netzke_just_logged_out] = true
24
+ session[:_netzke_next_request_is_first_after_logout] = false
25
+ else
26
+ session[:netzke_just_logged_out] = false
27
+ end
11
28
  end
12
29
 
13
30
  def method_missing(method_name)
@@ -29,6 +29,18 @@ class Hash
29
29
  h
30
30
  end
31
31
  end
32
+
33
+ # Javascrit-like access to Hash values
34
+ def method_missing(method, *args)
35
+ if method.to_s =~ /=$/
36
+ method_base = method.to_s.sub(/=$/,'').to_sym
37
+ key = self[method_base.to_s].nil? ? method_base : method_base.to_s
38
+ self[key] = args.first
39
+ else
40
+ key = self[method.to_s].nil? ? method : method.to_s
41
+ self[key]
42
+ end
43
+ end
32
44
 
33
45
  end
34
46
 
@@ -72,6 +84,11 @@ class String
72
84
  regexp = /^\s*\n/
73
85
  self.gsub!(regexp, '')
74
86
  end
87
+
88
+ # "false" => false, "whatever_else" => true
89
+ def to_b
90
+ self != "false"
91
+ end
75
92
  end
76
93
 
77
94
  class Symbol
@@ -20,7 +20,7 @@ module Netzke
20
20
  }
21
21
 
22
22
  var showBox = function(msg, lvl){
23
- if (!lvl) lvl = 'notice';
23
+ if (!lvl) {lvl = 'notice'};
24
24
  var msgCt = Ext.DomHelper.insertFirst(document.body, {'class':'netzke-feedback'}, true);
25
25
  var m = Ext.DomHelper.append(msgCt, {html:createBox(msg,lvl)}, true);
26
26
  m.slideIn('t').pause(2).ghost("b", {remove:true});
@@ -30,10 +30,10 @@ module Netzke
30
30
  var compoundMsg = "";
31
31
  Ext.each(msg, function(m){
32
32
  compoundMsg += m.msg + '<br>';
33
- })
34
- if (compoundMsg != "") showBox(compoundMsg, null) // the second parameter will be level
33
+ });
34
+ if (compoundMsg != "") showBox(compoundMsg, null); // the second parameter will be level
35
35
  } else {
36
- showBox(msg)
36
+ showBox(msg);
37
37
  }
38
38
  }
39
39
  JS
data/netzke-core.gemspec CHANGED
@@ -2,27 +2,27 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{netzke-core}
5
- s.version = "0.2.11"
5
+ s.version = "0.3.0"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["Sergei Kozlov"]
9
- s.date = %q{2009-04-17}
9
+ s.date = %q{2009-05-07}
10
10
  s.description = %q{Build ExtJS/Rails widgets with minimum effort}
11
11
  s.email = %q{sergei@writelesscode.com}
12
- s.extra_rdoc_files = ["CHANGELOG", "lib/app/controllers/netzke_controller.rb", "lib/app/models/netzke_layout.rb", "lib/app/models/netzke_preference.rb", "lib/netzke/action_view_ext.rb", "lib/netzke/base.rb", "lib/netzke/base_extras/interface.rb", "lib/netzke/base_extras/js_builder.rb", "lib/netzke/controller_extensions.rb", "lib/netzke/core_ext.rb", "lib/netzke/feedback_ghost.rb", "lib/netzke/routing.rb", "lib/netzke-core.rb", "lib/vendor/facets/hash/recursive_merge.rb", "LICENSE", "README.mdown", "tasks/netzke_core_tasks.rake", "TODO"]
13
- s.files = ["CHANGELOG", "generators/netzke_core/netzke_core_generator.rb", "generators/netzke_core/templates/create_netzke_layouts.rb", "generators/netzke_core/templates/create_netzke_preferences.rb", "generators/netzke_core/USAGE", "init.rb", "install.rb", "javascripts/core.js", "lib/app/controllers/netzke_controller.rb", "lib/app/models/netzke_layout.rb", "lib/app/models/netzke_preference.rb", "lib/netzke/action_view_ext.rb", "lib/netzke/base.rb", "lib/netzke/base_extras/interface.rb", "lib/netzke/base_extras/js_builder.rb", "lib/netzke/controller_extensions.rb", "lib/netzke/core_ext.rb", "lib/netzke/feedback_ghost.rb", "lib/netzke/routing.rb", "lib/netzke-core.rb", "lib/vendor/facets/hash/recursive_merge.rb", "LICENSE", "Manifest", "netzke-core.gemspec", "Rakefile", "README.mdown", "stylesheets/core.css", "tasks/netzke_core_tasks.rake", "test/app_root/app/controllers/application.rb", "test/app_root/config/boot.rb", "test/app_root/config/database.yml", "test/app_root/config/environment.rb", "test/app_root/config/environments/in_memory.rb", "test/app_root/config/environments/mysql.rb", "test/app_root/config/environments/postgresql.rb", "test/app_root/config/environments/sqlite.rb", "test/app_root/config/environments/sqlite3.rb", "test/app_root/config/routes.rb", "test/app_root/db/migrate/20081222035855_create_netzke_preferences.rb", "test/app_root/script/console", "test/core_ext_test.rb", "test/netzke_core_test.rb", "test/netzke_preference_test.rb", "test/test_helper.rb", "TODO", "uninstall.rb"]
12
+ s.extra_rdoc_files = ["CHANGELOG", "lib/app/controllers/netzke_controller.rb", "lib/app/models/netzke_preference.rb", "lib/netzke/action_view_ext.rb", "lib/netzke/base.rb", "lib/netzke/base_extras/interface.rb", "lib/netzke/base_extras/js_builder.rb", "lib/netzke/controller_extensions.rb", "lib/netzke/core_ext.rb", "lib/netzke/feedback_ghost.rb", "lib/netzke/routing.rb", "lib/netzke-core.rb", "lib/vendor/facets/hash/recursive_merge.rb", "LICENSE", "README.mdown", "tasks/netzke_core_tasks.rake", "TODO"]
13
+ s.files = ["autotest/discover.rb", "CHANGELOG", "generators/netzke_core/netzke_core_generator.rb", "generators/netzke_core/templates/create_netzke_preferences.rb", "generators/netzke_core/USAGE", "init.rb", "install.rb", "javascripts/core.js", "lib/app/controllers/netzke_controller.rb", "lib/app/models/netzke_preference.rb", "lib/netzke/action_view_ext.rb", "lib/netzke/base.rb", "lib/netzke/base_extras/interface.rb", "lib/netzke/base_extras/js_builder.rb", "lib/netzke/controller_extensions.rb", "lib/netzke/core_ext.rb", "lib/netzke/feedback_ghost.rb", "lib/netzke/routing.rb", "lib/netzke-core.rb", "lib/vendor/facets/hash/recursive_merge.rb", "LICENSE", "Manifest", "netzke-core.gemspec", "Rakefile", "README.mdown", "stylesheets/core.css", "tasks/netzke_core_tasks.rake", "test/app_root/app/controllers/application_controller.rb", "test/app_root/app/models/role.rb", "test/app_root/app/models/user.rb", "test/app_root/config/boot.rb", "test/app_root/config/database.yml", "test/app_root/config/environment.rb", "test/app_root/config/environments/in_memory.rb", "test/app_root/config/environments/mysql.rb", "test/app_root/config/environments/postgresql.rb", "test/app_root/config/environments/sqlite.rb", "test/app_root/config/environments/sqlite3.rb", "test/app_root/config/routes.rb", "test/app_root/db/migrate/20081222035855_create_netzke_preferences.rb", "test/app_root/db/migrate/20090423214303_create_roles.rb", "test/app_root/db/migrate/20090423222114_create_users.rb", "test/app_root/lib/console_with_fixtures.rb", "test/app_root/script/console", "test/fixtures/roles.yml", "test/fixtures/users.yml", "test/test_helper.rb", "test/unit/core_ext_test.rb", "test/unit/netzke_core_test.rb", "test/unit/netzke_preference_test.rb", "TODO", "uninstall.rb"]
14
14
  s.has_rdoc = true
15
15
  s.homepage = %q{http://writelesscode.com}
16
16
  s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Netzke-core", "--main", "README.mdown"]
17
17
  s.require_paths = ["lib"]
18
18
  s.rubyforge_project = %q{netzke-core}
19
- s.rubygems_version = %q{1.3.1}
19
+ s.rubygems_version = %q{1.3.2}
20
20
  s.summary = %q{Build ExtJS/Rails widgets with minimum effort}
21
- s.test_files = ["test/core_ext_test.rb", "test/netzke_core_test.rb", "test/netzke_preference_test.rb"]
21
+ s.test_files = ["test/unit/core_ext_test.rb", "test/unit/netzke_core_test.rb", "test/unit/netzke_preference_test.rb"]
22
22
 
23
23
  if s.respond_to? :specification_version then
24
24
  current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
25
- s.specification_version = 2
25
+ s.specification_version = 3
26
26
 
27
27
  if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
28
28
  else
@@ -0,0 +1,3 @@
1
+ class Role < ActiveRecord::Base
2
+ has_many :users
3
+ end
@@ -0,0 +1,3 @@
1
+ class User < ActiveRecord::Base
2
+ belongs_to :role
3
+ end
@@ -47,6 +47,7 @@ module Rails
47
47
  def load_initializer
48
48
  require "#{RAILS_FRAMEWORK_ROOT}/railties/lib/initializer"
49
49
  Rails::Initializer.run(:install_gem_spec_stubs)
50
+ Rails::GemDependency.add_frozen_gem_path
50
51
  end
51
52
  end
52
53
 
@@ -85,7 +86,7 @@ module Rails
85
86
 
86
87
  def load_rubygems
87
88
  require 'rubygems'
88
- min_version = '1.1.1'
89
+ min_version = '1.3.1'
89
90
  unless rubygems_version >= min_version
90
91
  $stderr.puts %Q(Rails requires RubyGems >= #{min_version} (you have #{rubygems_version}). Please `gem update --system` and try again.)
91
92
  exit 1
@@ -2,20 +2,30 @@ in_memory:
2
2
  adapter: sqlite3
3
3
  database: ":memory:"
4
4
  verbosity: quiet
5
+ pool: 5
6
+ timeout: 5000
5
7
  sqlite:
6
8
  adapter: sqlite
7
9
  dbfile: plugin_test.sqlite.db
10
+ pool: 5
11
+ timeout: 5000
8
12
  sqlite3:
9
13
  adapter: sqlite3
10
14
  dbfile: plugin_test.sqlite3.db
15
+ pool: 5
16
+ timeout: 5000
11
17
  postgresql:
12
18
  adapter: postgresql
13
19
  username: postgres
14
20
  password: postgres
15
21
  database: plugin_test
22
+ pool: 5
23
+ timeout: 5000
16
24
  mysql:
17
25
  adapter: mysql
18
26
  host: localhost
19
27
  username: root
20
28
  password:
21
29
  database: plugin_test
30
+ pool: 5
31
+ timeout: 5000
@@ -3,7 +3,7 @@ require File.join(File.dirname(__FILE__), 'boot')
3
3
  Rails::Initializer.run do |config|
4
4
  config.cache_classes = false
5
5
  config.whiny_nils = true
6
- config.action_controller.session = { :key => "_myapp_session", :secret => "some very long secret phrase required by action pack" }
6
+ config.action_controller.session = {:key => 'rails_session', :secret => 'd229e4d22437432705ab3985d4d246'}
7
7
  config.plugin_locators.unshift(
8
8
  Class.new(Rails::Plugin::Locator) do
9
9
  def plugins
@@ -0,0 +1,11 @@
1
+ class CreateRoles < ActiveRecord::Migration
2
+ def self.up
3
+ create_table :roles do |t|
4
+ t.string :name
5
+ end
6
+ end
7
+
8
+ def self.down
9
+ drop_table :roles
10
+ end
11
+ end
@@ -0,0 +1,12 @@
1
+ class CreateUsers < ActiveRecord::Migration
2
+ def self.up
3
+ create_table :users do |t|
4
+ t.string :login
5
+ t.integer :role_id
6
+ end
7
+ end
8
+
9
+ def self.down
10
+ drop_table :users
11
+ end
12
+ end
@@ -0,0 +1,4 @@
1
+ # Loads fixtures into the database when running the test app via the console
2
+ (ENV['FIXTURES'] ? ENV['FIXTURES'].split(/,/) : Dir.glob(File.join(Rails.root, '../fixtures/*.{yml,csv}'))).each do |fixture_file|
3
+ Fixtures.create_fixtures(File.join(Rails.root, '../fixtures'), File.basename(fixture_file, '.*'))
4
+ end
@@ -3,4 +3,5 @@ libs = " -r irb/completion"
3
3
  libs << " -r test/test_helper"
4
4
  libs << " -r console_app"
5
5
  libs << " -r console_with_helpers"
6
+ libs << " -r console_with_fixtures"
6
7
  exec "#{irb} #{libs} --simple-prompt"
@@ -0,0 +1,7 @@
1
+ # Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
2
+
3
+ one:
4
+ name: MyString
5
+
6
+ two:
7
+ name: MyString
@@ -0,0 +1,9 @@
1
+ # Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
2
+
3
+ one:
4
+ login: MyString
5
+ role_id: 1
6
+
7
+ two:
8
+ login: MyString
9
+ role_id: 1
data/test/test_helper.rb CHANGED
@@ -9,4 +9,13 @@ require 'test_help'
9
9
  silence_warnings {RAILS_ENV = ENV['RAILS_ENV']}
10
10
 
11
11
  # Run the migrations
12
- ActiveRecord::Migrator.migrate("#{Rails.root}/db/migrate")
12
+ ActiveRecord::Migrator.migrate("#{Rails.root}/db/migrate")
13
+
14
+ # Set default fixture loading properties
15
+ ActiveSupport::TestCase.class_eval do
16
+ self.use_transactional_fixtures = true
17
+ self.use_instantiated_fixtures = false
18
+ self.fixture_path = "#{File.dirname(__FILE__)}/fixtures"
19
+
20
+ fixtures :all
21
+ end
@@ -30,4 +30,16 @@ class CoreExtTest < ActiveSupport::TestCase
30
30
  {:aB => 1, :cDD => [{:lookMa => true},{:wowNow => true}]}
31
31
  ],[:a_b => 1, :c_d_d => [{:look_ma => true},{:wow_now => true}]].convert_keys{|k| k.camelize(:lower)})
32
32
  end
33
+
34
+ test "javascript-like access to hash data" do
35
+ a = {}
36
+ a["key"] = 100
37
+ assert_equal(100, a.key)
38
+
39
+ a.key = 200
40
+ assert_equal(200, a["key"])
41
+
42
+ a.another_key = 300
43
+ assert_equal(300, a[:another_key])
44
+ end
33
45
  end
@@ -1,8 +1,6 @@
1
1
  require 'test_helper'
2
-
3
2
  require 'netzke-core'
4
3
 
5
- # test widgets
6
4
  module Netzke
7
5
  class Widget < Base
8
6
  interface :method_one, :method_two
@@ -46,24 +44,10 @@ module Netzke
46
44
  end
47
45
  end
48
46
 
49
- # mocking the User class
50
- class User
51
- attr_accessor :id
52
- def initialize(id)
53
- @id = id
54
- end
55
- end
56
-
57
47
  class NetzkeCoreTest < ActiveSupport::TestCase
58
48
  include Netzke
59
49
 
60
50
  def setup
61
- # object = mock()
62
- # object.stubs(:normalized_value)
63
- # object.stubs(:normalized_value=)
64
- # # object.stubs(:save!)
65
- # NetzkePreference.stubs(:find).returns(object)
66
-
67
51
  end
68
52
 
69
53
  test "base class loaded" do
@@ -134,14 +118,6 @@ class NetzkeCoreTest < ActiveSupport::TestCase
134
118
  assert(!widget.dependencies.include?('DeepNestedWidget'))
135
119
  end
136
120
 
137
- # test "dependencies in JS class generators" do
138
- # widget = Widget.new
139
- # assert(widget.js_missing_code.index("Ext.netzke.cache['NestedWidgetOne']"))
140
- # assert(widget.js_missing_code.index("Ext.netzke.cache['NestedWidgetTwo']"))
141
- # assert(widget.js_missing_code.index("Ext.netzke.cache['DeepNestedWidget']"))
142
- # assert(widget.js_missing_code.index("Ext.netzke.cache['Widget']"))
143
- # end
144
-
145
121
  test "dependency classes" do
146
122
  widget = Widget.new
147
123
  # not testing the order
@@ -154,29 +130,10 @@ class NetzkeCoreTest < ActiveSupport::TestCase
154
130
  assert('a_widget', widget.config[:name])
155
131
  end
156
132
 
157
- test "class configuration" do
158
- assert_equal(NetzkeLayout, Netzke::Base.layout_manager_class)
159
- end
160
-
161
133
  test "js inheritance" do
162
134
  widget = JsInheritanceWidget.new
163
135
  assert(widget.js_missing_code.index("Ext.netzke.cache.JsInheritanceWidget"))
164
136
  assert(widget.js_missing_code.index("Ext.netzke.cache.Widget"))
165
137
  end
166
- # test "multiuser" do
167
- # Netzke::Base.current_user = User.new(1)
168
- # Widget.new(:prohibit => :all, :name => 'widget')
169
- #
170
- # Netzke::Base.current_user = User.new(2)
171
- # Widget.new(:prohibit => :read, :name => 'widget')
172
- #
173
- # Netzke::Base.current_user = User.new(1)
174
- # widget = Widget.new(:name => 'widget')
175
- # assert_equal({:read => false, :update => false}, widget.permissions)
176
- #
177
- # Netzke::Base.current_user = User.new(2)
178
- # widget = Widget.new(:name => 'widget')
179
- # assert_equal({:read => false, :update => true}, widget.permissions)
180
- #
181
- # end
138
+
182
139
  end
@@ -0,0 +1,103 @@
1
+ require 'test_helper'
2
+ require 'netzke-core'
3
+ class NetzkePreferenceTest < ActiveSupport::TestCase
4
+ test "pref to read-write" do
5
+ p = NetzkePreference
6
+ session = Netzke::Base.session
7
+ session.clear
8
+
9
+ assert_not_nil(p.pref_to_write(:test))
10
+ p[:test] = "a value"
11
+ assert_not_nil(p.pref_to_read(:test))
12
+ end
13
+
14
+ test "basic values" do
15
+ an_integer = 1976
16
+ a_float = 1976.1345
17
+ a_symbol = :a_symbol
18
+ a_true = true
19
+ a_false = false
20
+ a_nil = nil
21
+ a_hash = {"a" => an_integer, "b" => a_true, "c" => nil, "d" => a_float}
22
+ an_array = [1, "a", a_hash, [1,3,4], a_true, a_false, a_nil, a_float]
23
+
24
+
25
+ p = NetzkePreference
26
+ p[:a_hash] = a_hash
27
+ p["an_integer"] = an_integer
28
+ p[:a_true] = a_true
29
+ p[:a_false] = a_false
30
+ p[:a_nil] = a_nil
31
+ p[:an_array] = an_array
32
+ p[:a_symbol] = a_symbol
33
+ p[:a_float] = a_float
34
+
35
+ assert_equal(a_hash, p[:a_hash])
36
+ assert_equal(an_integer, p[:an_integer])
37
+ assert_equal(a_true, p[:a_true])
38
+ assert_equal(a_false, p[:a_false])
39
+ assert_equal(an_array, p[:an_array])
40
+ assert_equal(a_nil, p[:a_nil])
41
+ assert_equal(a_symbol, p[:a_symbol])
42
+ assert_equal(a_float, p[:a_float])
43
+
44
+ assert_equal(nil, p[:non_existing])
45
+ end
46
+
47
+ test "multi-user/multi-role support" do
48
+ p = NetzkePreference
49
+ session = Netzke::Base.session
50
+
51
+ admin_role = Role.create(:name => 'admin')
52
+ user_role = Role.create(:name => 'user')
53
+
54
+ admin1 = User.create(:login => 'admin1', :role => admin_role)
55
+ user1 = User.create(:login => 'user1', :role => user_role)
56
+ user2 = User.create(:login => 'user2', :role => user_role)
57
+
58
+ #
59
+ # assign a value for a role, then read it back by users with the same role
60
+ #
61
+ session.clear
62
+ session[:masq_role] = user_role
63
+ p[:test] = 100
64
+
65
+ # first user
66
+ session.clear
67
+ session[:user] = user1
68
+ assert_equal(100, p[:test])
69
+
70
+ # second user
71
+ session.clear
72
+ session[:user] = user2
73
+ assert_equal(100, p[:test])
74
+
75
+ #
76
+ # now overwrite the value for user2
77
+ #
78
+ p[:test] = 200
79
+ assert_equal(200, p[:test])
80
+ # .. and check that its still the same for user1
81
+ session.clear
82
+ session[:user] = user1
83
+ assert_equal(100, p[:test])
84
+
85
+ #
86
+ # now overwrite it for user1 by means of masq_user
87
+ #
88
+ session.clear
89
+ session[:masq_user] = user1
90
+ p[:test] = 300
91
+ assert_equal(300, p[:test])
92
+ # .. and check it's still the same for user2
93
+ session.clear
94
+ session[:masq_user] = user2
95
+ assert_equal(200, p[:test])
96
+ # .. and that a new user with role 'user' will still read the original value assigned for the role
97
+ user3 = User.create(:login => "user3", :role => user_role)
98
+ session.clear
99
+ session[:user] = user3
100
+ assert_equal(100, p[:test])
101
+
102
+ end
103
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: netzke-core
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.11
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sergei Kozlov
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-04-17 00:00:00 -04:00
12
+ date: 2009-05-07 00:00:00 -05:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
@@ -22,7 +22,6 @@ extensions: []
22
22
  extra_rdoc_files:
23
23
  - CHANGELOG
24
24
  - lib/app/controllers/netzke_controller.rb
25
- - lib/app/models/netzke_layout.rb
26
25
  - lib/app/models/netzke_preference.rb
27
26
  - lib/netzke/action_view_ext.rb
28
27
  - lib/netzke/base.rb
@@ -39,16 +38,15 @@ extra_rdoc_files:
39
38
  - tasks/netzke_core_tasks.rake
40
39
  - TODO
41
40
  files:
41
+ - autotest/discover.rb
42
42
  - CHANGELOG
43
43
  - generators/netzke_core/netzke_core_generator.rb
44
- - generators/netzke_core/templates/create_netzke_layouts.rb
45
44
  - generators/netzke_core/templates/create_netzke_preferences.rb
46
45
  - generators/netzke_core/USAGE
47
46
  - init.rb
48
47
  - install.rb
49
48
  - javascripts/core.js
50
49
  - lib/app/controllers/netzke_controller.rb
51
- - lib/app/models/netzke_layout.rb
52
50
  - lib/app/models/netzke_preference.rb
53
51
  - lib/netzke/action_view_ext.rb
54
52
  - lib/netzke/base.rb
@@ -67,7 +65,9 @@ files:
67
65
  - README.mdown
68
66
  - stylesheets/core.css
69
67
  - tasks/netzke_core_tasks.rake
70
- - test/app_root/app/controllers/application.rb
68
+ - test/app_root/app/controllers/application_controller.rb
69
+ - test/app_root/app/models/role.rb
70
+ - test/app_root/app/models/user.rb
71
71
  - test/app_root/config/boot.rb
72
72
  - test/app_root/config/database.yml
73
73
  - test/app_root/config/environment.rb
@@ -78,15 +78,22 @@ files:
78
78
  - test/app_root/config/environments/sqlite3.rb
79
79
  - test/app_root/config/routes.rb
80
80
  - test/app_root/db/migrate/20081222035855_create_netzke_preferences.rb
81
+ - test/app_root/db/migrate/20090423214303_create_roles.rb
82
+ - test/app_root/db/migrate/20090423222114_create_users.rb
83
+ - test/app_root/lib/console_with_fixtures.rb
81
84
  - test/app_root/script/console
82
- - test/core_ext_test.rb
83
- - test/netzke_core_test.rb
84
- - test/netzke_preference_test.rb
85
+ - test/fixtures/roles.yml
86
+ - test/fixtures/users.yml
85
87
  - test/test_helper.rb
88
+ - test/unit/core_ext_test.rb
89
+ - test/unit/netzke_core_test.rb
90
+ - test/unit/netzke_preference_test.rb
86
91
  - TODO
87
92
  - uninstall.rb
88
93
  has_rdoc: true
89
94
  homepage: http://writelesscode.com
95
+ licenses: []
96
+
90
97
  post_install_message:
91
98
  rdoc_options:
92
99
  - --line-numbers
@@ -112,11 +119,11 @@ required_rubygems_version: !ruby/object:Gem::Requirement
112
119
  requirements: []
113
120
 
114
121
  rubyforge_project: netzke-core
115
- rubygems_version: 1.3.1
122
+ rubygems_version: 1.3.2
116
123
  signing_key:
117
- specification_version: 2
124
+ specification_version: 3
118
125
  summary: Build ExtJS/Rails widgets with minimum effort
119
126
  test_files:
120
- - test/core_ext_test.rb
121
- - test/netzke_core_test.rb
122
- - test/netzke_preference_test.rb
127
+ - test/unit/core_ext_test.rb
128
+ - test/unit/netzke_core_test.rb
129
+ - test/unit/netzke_preference_test.rb
@@ -1,14 +0,0 @@
1
- class CreateNetzkeLayouts < ActiveRecord::Migration
2
- def self.up
3
- create_table :netzke_layouts do |t|
4
- t.string :widget_name
5
- t.string :items_class
6
- t.integer :user_id
7
- t.timestamps
8
- end
9
- end
10
-
11
- def self.down
12
- drop_table :netzke_layouts
13
- end
14
- end
@@ -1,40 +0,0 @@
1
- class NetzkeLayout < ActiveRecord::Base
2
- EXT_UNRELATED_ATTRIBUTES = %w{ id layout_id position created_at updated_at }
3
-
4
- # Multi user support
5
- def self.user_id
6
- Netzke::Base.user && Netzke::Base.user.id
7
- end
8
-
9
- # normal create, but with a user_id merged-in
10
- def self.create_with_user(config)
11
- create(config.merge(:user_id => user_id))
12
- end
13
-
14
- def items
15
- items_class.constantize.find_all_by_layout_id(id, :order => 'position')
16
- end
17
-
18
- def self.by_widget(widget_name)
19
- self.find(:first, :conditions => {:widget_name => widget_name.to_s, :user_id => user_id})
20
- end
21
-
22
- def move_item(old_index, new_index)
23
- layout_item = items[old_index]
24
- layout_item.remove_from_list
25
- layout_item.insert_at(new_index + 1)
26
- end
27
-
28
- def items_arry
29
- unrelated_attrs_eraser = EXT_UNRELATED_ATTRIBUTES.inject({}){|h,el| h.merge(el => nil)} # => {:id => nil, :layout_id => nil, ...}
30
- items.map(&:attributes).map do |i|
31
- # delete unrelated attributes
32
- i.merge(unrelated_attrs_eraser).convert_keys {|k| k.to_sym}
33
- end
34
- end
35
-
36
- def items_arry_without_hidden
37
- items_arry.reject{|i| i[:hidden] && !i[:name] == :id} # 'id' is exceptional, should always be sent
38
- end
39
-
40
- end
@@ -1,36 +0,0 @@
1
- require 'test_helper'
2
- require 'netzke-core'
3
- class NetzkePreferenceTest < ActiveSupport::TestCase
4
- test "basic values" do
5
- an_integer = 1976
6
- a_float = 1976.1345
7
- a_symbol = :a_symbol
8
- a_true = true
9
- a_false = false
10
- a_nil = nil
11
- a_hash = {"a" => an_integer, "b" => a_true, "c" => nil, "d" => a_float}
12
- an_array = [1, "a", a_hash, [1,3,4], a_true, a_false, a_nil, a_float]
13
-
14
-
15
- p = NetzkePreference
16
- p[:a_hash] = a_hash
17
- p["an_integer"] = an_integer
18
- p[:a_true] = a_true
19
- p[:a_false] = a_false
20
- p[:a_nil] = a_nil
21
- p[:an_array] = an_array
22
- p[:a_symbol] = a_symbol
23
- p[:a_float] = a_float
24
-
25
- assert_equal(a_hash, p[:a_hash])
26
- assert_equal(an_integer, p[:an_integer])
27
- assert_equal(a_true, p[:a_true])
28
- assert_equal(a_false, p[:a_false])
29
- assert_equal(an_array, p[:an_array])
30
- assert_equal(a_nil, p[:a_nil])
31
- assert_equal(a_symbol, p[:a_symbol])
32
- assert_equal(a_float, p[:a_float])
33
-
34
- assert_equal(nil, p[:non_existing])
35
- end
36
- end