skozlov-netzke-core 0.1.0.2 → 0.4.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (48) hide show
  1. data/CHANGELOG +108 -0
  2. data/LICENSE +2 -19
  3. data/Manifest +50 -0
  4. data/README.rdoc +12 -0
  5. data/Rakefile +2 -3
  6. data/TODO +2 -0
  7. data/autotest/discover.rb +3 -0
  8. data/generators/netzke_core/netzke_core_generator.rb +6 -6
  9. data/generators/netzke_core/templates/create_netzke_preferences.rb +2 -2
  10. data/javascripts/core.js +474 -111
  11. data/lib/app/controllers/netzke_controller.rb +76 -0
  12. data/lib/app/models/netzke_preference.rb +128 -39
  13. data/lib/netzke-core.rb +23 -9
  14. data/lib/netzke/action_view_ext.rb +26 -0
  15. data/lib/netzke/base.rb +440 -102
  16. data/lib/netzke/base_js.rb +258 -0
  17. data/lib/netzke/controller_extensions.rb +80 -29
  18. data/lib/netzke/core_ext.rb +72 -21
  19. data/lib/netzke/feedback_ghost.rb +43 -0
  20. data/lib/netzke/routing.rb +9 -0
  21. data/netzke-core.gemspec +10 -11
  22. data/stylesheets/core.css +12 -0
  23. data/test/app_root/app/controllers/{application.rb → application_controller.rb} +0 -0
  24. data/test/app_root/app/models/role.rb +3 -0
  25. data/test/app_root/app/models/user.rb +3 -0
  26. data/test/app_root/config/boot.rb +2 -1
  27. data/test/app_root/config/database.yml +10 -0
  28. data/test/app_root/config/environment.rb +1 -0
  29. data/test/app_root/db/migrate/20081222035855_create_netzke_preferences.rb +18 -0
  30. data/test/app_root/db/migrate/20090423214303_create_roles.rb +11 -0
  31. data/test/app_root/db/migrate/20090423222114_create_users.rb +12 -0
  32. data/test/app_root/lib/console_with_fixtures.rb +4 -0
  33. data/test/app_root/script/console +1 -0
  34. data/test/fixtures/roles.yml +7 -0
  35. data/test/fixtures/users.yml +9 -0
  36. data/test/test_helper.rb +3 -2
  37. data/test/unit/core_ext_test.rb +66 -0
  38. data/test/unit/netzke_core_test.rb +167 -0
  39. data/test/unit/netzke_preference_test.rb +103 -0
  40. metadata +45 -30
  41. data/README.mdown +0 -11
  42. data/generators/netzke_core/templates/create_netzke_layouts.rb +0 -14
  43. data/generators/netzke_core/templates/netzke.html.erb +0 -10
  44. data/lib/app/models/netzke_layout.rb +0 -75
  45. data/lib/netzke/js_class_builder.rb +0 -114
  46. data/lib/vendor/facets/hash/recursive_merge.rb +0 -28
  47. data/test/core_ext_test.rb +0 -35
  48. data/test/netzke_core_test.rb +0 -136
@@ -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.id
63
+ p[:test] = 100
64
+
65
+ # first user
66
+ session.clear
67
+ session[:netzke_user_id] = user1.id
68
+ assert_equal(100, p[:test])
69
+
70
+ # second user
71
+ session.clear
72
+ session[:netzke_user_id] = user2.id
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[:netzke_user_id] = user1.id
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.id
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.id
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[:netzke_user_id] = user3.id
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: skozlov-netzke-core
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0.2
4
+ version: 0.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sergei Kozlov
@@ -9,56 +9,62 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-12-28 00:00:00 -08:00
12
+ date: 2009-09-06 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
16
16
  description: Build ExtJS/Rails widgets with minimum effort
17
- email: sergei@writelesscode.com
17
+ email: sergei@playcode.nl
18
18
  executables: []
19
19
 
20
20
  extensions: []
21
21
 
22
22
  extra_rdoc_files:
23
23
  - CHANGELOG
24
+ - LICENSE
25
+ - README.rdoc
26
+ - TODO
24
27
  - lib/app/controllers/netzke_controller.rb
25
- - lib/app/models/netzke_layout.rb
26
28
  - lib/app/models/netzke_preference.rb
29
+ - lib/netzke-core.rb
30
+ - lib/netzke/action_view_ext.rb
27
31
  - lib/netzke/base.rb
32
+ - lib/netzke/base_js.rb
28
33
  - lib/netzke/controller_extensions.rb
29
34
  - lib/netzke/core_ext.rb
30
- - lib/netzke/js_class_builder.rb
31
- - lib/netzke-core.rb
32
- - lib/vendor/facets/hash/recursive_merge.rb
33
- - LICENSE
34
- - README.mdown
35
+ - lib/netzke/feedback_ghost.rb
36
+ - lib/netzke/routing.rb
35
37
  - tasks/netzke_core_tasks.rake
36
38
  files:
37
39
  - CHANGELOG
40
+ - LICENSE
41
+ - Manifest
42
+ - README.rdoc
43
+ - Rakefile
44
+ - TODO
45
+ - autotest/discover.rb
46
+ - generators/netzke_core/USAGE
38
47
  - generators/netzke_core/netzke_core_generator.rb
39
- - generators/netzke_core/templates/create_netzke_layouts.rb
40
48
  - generators/netzke_core/templates/create_netzke_preferences.rb
41
- - generators/netzke_core/templates/netzke.html.erb
42
- - generators/netzke_core/USAGE
43
49
  - init.rb
44
50
  - install.rb
45
51
  - javascripts/core.js
46
52
  - lib/app/controllers/netzke_controller.rb
47
- - lib/app/models/netzke_layout.rb
48
53
  - lib/app/models/netzke_preference.rb
54
+ - lib/netzke-core.rb
55
+ - lib/netzke/action_view_ext.rb
49
56
  - lib/netzke/base.rb
57
+ - lib/netzke/base_js.rb
50
58
  - lib/netzke/controller_extensions.rb
51
59
  - lib/netzke/core_ext.rb
52
- - lib/netzke/js_class_builder.rb
53
- - lib/netzke-core.rb
54
- - lib/vendor/facets/hash/recursive_merge.rb
55
- - LICENSE
56
- - Manifest
60
+ - lib/netzke/feedback_ghost.rb
61
+ - lib/netzke/routing.rb
57
62
  - netzke-core.gemspec
58
- - Rakefile
59
- - README.mdown
63
+ - stylesheets/core.css
60
64
  - tasks/netzke_core_tasks.rake
61
- - test/app_root/app/controllers/application.rb
65
+ - test/app_root/app/controllers/application_controller.rb
66
+ - test/app_root/app/models/role.rb
67
+ - test/app_root/app/models/user.rb
62
68
  - test/app_root/config/boot.rb
63
69
  - test/app_root/config/database.yml
64
70
  - test/app_root/config/environment.rb
@@ -68,13 +74,21 @@ files:
68
74
  - test/app_root/config/environments/sqlite.rb
69
75
  - test/app_root/config/environments/sqlite3.rb
70
76
  - test/app_root/config/routes.rb
77
+ - test/app_root/db/migrate/20081222035855_create_netzke_preferences.rb
78
+ - test/app_root/db/migrate/20090423214303_create_roles.rb
79
+ - test/app_root/db/migrate/20090423222114_create_users.rb
80
+ - test/app_root/lib/console_with_fixtures.rb
71
81
  - test/app_root/script/console
72
- - test/core_ext_test.rb
73
- - test/netzke_core_test.rb
82
+ - test/fixtures/roles.yml
83
+ - test/fixtures/users.yml
74
84
  - test/test_helper.rb
85
+ - test/unit/core_ext_test.rb
86
+ - test/unit/netzke_core_test.rb
87
+ - test/unit/netzke_preference_test.rb
75
88
  - uninstall.rb
76
- has_rdoc: true
77
- homepage: http://writelesscode.com
89
+ has_rdoc: false
90
+ homepage: http://playcode.nl
91
+ licenses:
78
92
  post_install_message:
79
93
  rdoc_options:
80
94
  - --line-numbers
@@ -82,7 +96,7 @@ rdoc_options:
82
96
  - --title
83
97
  - Netzke-core
84
98
  - --main
85
- - README.mdown
99
+ - README.rdoc
86
100
  require_paths:
87
101
  - lib
88
102
  required_ruby_version: !ruby/object:Gem::Requirement
@@ -100,10 +114,11 @@ required_rubygems_version: !ruby/object:Gem::Requirement
100
114
  requirements: []
101
115
 
102
116
  rubyforge_project: netzke-core
103
- rubygems_version: 1.2.0
117
+ rubygems_version: 1.3.5
104
118
  signing_key:
105
- specification_version: 2
119
+ specification_version: 3
106
120
  summary: Build ExtJS/Rails widgets with minimum effort
107
121
  test_files:
108
- - test/core_ext_test.rb
109
- - test/netzke_core_test.rb
122
+ - test/unit/core_ext_test.rb
123
+ - test/unit/netzke_core_test.rb
124
+ - test/unit/netzke_preference_test.rb
@@ -1,11 +0,0 @@
1
- netzke-core
2
- ==========
3
-
4
- Create ExtJS/Rails reusable components (widgets) with minimum effort.
5
-
6
- Example
7
- =======
8
-
9
- See the tutorials on http://blog.writelesscode.com
10
-
11
- Copyright (c) 2008 Sergei Kozlov, released under the MIT license
@@ -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,10 +0,0 @@
1
- <head>
2
- <meta http-equiv="Content-type" content="text/html; charset=utf-8">
3
- <title>netzke widget</title>
4
- <%= javascript_include_tag("/extjs/adapter/ext/ext-base.js", "/extjs/ext-all-debug.js") %>
5
- <%= javascript_include_tag("netzke/netzke.js") %>
6
- <%= stylesheet_link_tag("/extjs/resources/css/ext-all.css") %>
7
- </head>
8
- <body id="">
9
- <%= yield %>
10
- </body>
@@ -1,75 +0,0 @@
1
- class NetzkeLayout < ActiveRecord::Base
2
- # has_many :layout_items#, :class_name => "ExtWidget::LayoutItem", :order => :position
3
- # has_many :objects, :class_name => "Objects", :foreign_key => "class_name_id"
4
- # belongs_to :role
5
- # belongs_to :user
6
-
7
- UNRELATED_ATTRS = %w(created_at updated_at position layout_id)
8
-
9
- def self.user_id
10
- @@user_id ||= nil
11
- end
12
-
13
- def layout_items
14
- items_class.constantize.find_all_by_layout_id(id, :order => 'position')
15
- end
16
-
17
- #
18
- # def self.user_id=(user_id)
19
- # @@user_id = user_id
20
- # end
21
- #
22
- # def self.layout_items(widget_name)
23
- # layout = self.layout(widget_name)
24
- # layout.nil? ? nil : layout.layout_items.map(&:attributes).map{|item| item.delete_if{|k,v| UNRELATED_ATTRS.include?(k)}}
25
- # end
26
- #
27
- def self.by_widget(widget_name)
28
- self.find(:first, :conditions => {:widget_name => widget_name, :user_id => self.user_id})
29
- end
30
-
31
- def move_item(old_index, new_index)
32
- layout_item = layout_items[old_index]
33
- layout_item.remove_from_list
34
- layout_item.insert_at(new_index + 1)
35
- end
36
-
37
- # def self.layout_items(widget_name)
38
- # layout = self.by_widget(widget_name)
39
- # if layout
40
- # layout.layout_items
41
- # else
42
- # # create new layout and fill it out with default values
43
- # layout = Layout.create({:widget_name => widget_name, :user_id => self.user_id})
44
- # end
45
- # end
46
-
47
- def items_hash
48
- layout_items.map(&:attributes).map{|item| item.delete_if{|k,v| UNRELATED_ATTRS.include?(k)}}.map{ |i| i.convert_keys{ |k| k.to_sym } }
49
- end
50
-
51
- # if layout items are provided, use them instead of defaults (exsposed) layout items, but merge their configs with the default
52
- # def self.create_layout_for_widget(widget_name, data_class_name, layout_item_class_name, items = nil)
53
- # layout = self.create(:widget_name => widget_name, :items_class => layout_item_class_name, :user_id => self.user_id)
54
- # data_class = data_class_name.constantize
55
- # layout_item_class = layout_item_class_name.constantize
56
- #
57
- #
58
- # if items.nil?
59
- # complete_items = data_class.exposed_columns
60
- # else
61
- # # normalize columns
62
- # columns = columns.
63
- # default_columns = data_class.exposed_columns.map{|c| c.is_a?(Symbol) ? {:name => c} : c}
64
- # columns.each
65
- #
66
- # complete_columns = columns.nil? ? : columns
67
- # complete_columns.each do |c|
68
- # config = c.is_a?(Hash) ? c : {:name => c}
69
- # # we have to merge layout_id in order to have :position set up properly
70
- # item = layout_item_class.create_with_defaults(config.merge({:layout_id => layout.id}), data_class)
71
- # end
72
- # layout
73
- # end
74
-
75
- end
@@ -1,114 +0,0 @@
1
- module Netzke
2
- #
3
- # Module which provides JS-class generation functionality for the widgets ("client-side"). This code is executed only once per widget class, and the results are cached at the server (unless widget specifies config[:no_caching] => true).
4
- # Included into Netzke::Base class
5
- # Most of the methods below are meant to be overwritten by a concrete widget class.
6
- #
7
- module JsClassBuilder
8
- # the JS (Ext) class that we inherit from
9
- def js_base_class; "Ext.Panel"; end
10
-
11
- # widget's actions that are loaded at the moment of instantiating a widget
12
- def actions; null; end
13
-
14
- # widget's tools that are loaded at the moment of instantiating a widget see (js_config method)
15
- def tools; []; end
16
-
17
- def tbar; null; end
18
-
19
- def bbar; null; end
20
-
21
- # functions and properties that will be used to extend the functionality of (Ext) JS-class specified in js_base_class
22
- def js_extend_properties; {}; end
23
-
24
- # code executed before and after the constructor
25
- def js_before_constructor; ""; end
26
- def js_after_constructor; ""; end
27
-
28
- # widget's listeners
29
- def js_listeners; {}; end
30
-
31
- # widget's menus
32
- def js_menus; []; end
33
-
34
- # items
35
- def js_items; null; end
36
-
37
- # default config that is passed into the constructor
38
- def js_default_config
39
- {
40
- :title => short_widget_class_name,
41
- :listeners => js_listeners,
42
- :tools => "config.tools".l,
43
- :actions => "config.actions".l,
44
- :tbar => "config.tbar".l,
45
- :bbar => "config.bbar".l,
46
- :items => js_items,
47
- :height => 400,
48
- :width => 800,
49
- :border => false
50
- }
51
- end
52
-
53
- # declaration of widget's class (stored directly in the cache storage at the client side to be reused at the moment of widget instantiation)
54
- def js_class
55
- <<-JS
56
- Ext.componentCache['#{short_widget_class_name}'] = Ext.extend(#{js_base_class}, Ext.chainApply([Ext.widgetMixIn, {
57
- constructor: function(config){
58
- this.widgetInit(config);
59
- #{js_before_constructor}
60
- Ext.componentCache['#{short_widget_class_name}'].superclass.constructor.call(this, Ext.apply(#{js_default_config.to_js}, config));
61
- #{js_after_constructor}
62
- this.setEvents();
63
- this.addMenus(#{js_menus.to_js});
64
- }
65
- }, #{js_extend_properties.to_js}]))
66
- JS
67
- end
68
-
69
- # generate instantiating - used when a widget is generated stand-alone (as a part of a HTML page)
70
- def js_widget_instance
71
- %Q(var #{config[:name].to_js} = new Ext.componentCache['#{short_widget_class_name}'](#{js_config.to_js});)
72
- end
73
-
74
- # the config that is send from the server and is used for instantiating a widget
75
- def js_config
76
- res = {}
77
-
78
- # recursively include configs of all (non-late) aggregatees, so that the widget can instantiate them, too
79
- aggregatees.each_pair do |aggr_name, aggr_config|
80
- next if aggr_config[:late_aggregation]
81
- res["#{aggr_name}_config".to_sym] = aggregatee_instance(aggr_name.to_sym).js_config
82
- end
83
-
84
- # interface
85
- interface = interface_points.inject({}){|h,interfacep| h.merge(interfacep => widget_action(interfacep))}
86
- res.merge!(:interface => interface)
87
-
88
- res.merge!(:widget_class_name => short_widget_class_name)
89
-
90
- res.merge!(config[:ext_config])
91
- res.merge!(:id => @id_name)
92
-
93
- # include tools and actions
94
- res.merge!(:tools => tools)
95
- res.merge!(:actions => actions)
96
- res
97
- end
98
-
99
- # class definition of the widget plus that of all the dependencies, minus those that are specified as dependencies_to_exclude
100
- def js_missing_code(dependencies_to_exclude = [])
101
- result = ""
102
- dependencies.each do |dep_name|
103
- dependency_class = "Netzke::#{dep_name}".constantize
104
- result << dependency_class.new(config).js_missing_code(dependencies_to_exclude)
105
- end
106
- result << js_class.strip_js_comments unless dependencies_to_exclude.include?(short_widget_class_name) && !config[:no_caching]
107
- result
108
- end
109
-
110
- # little helpers
111
- def this; "this".l; end
112
- def null; "null".l; end
113
- end
114
- end