netzke-core 0.6.5 → 0.6.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.
Files changed (54) hide show
  1. data/CHANGELOG.rdoc +7 -0
  2. data/TODO +2 -0
  3. data/app/controllers/netzke_controller.rb +72 -20
  4. data/features/actions.feature +1 -1
  5. data/features/component_loader.feature +13 -1
  6. data/features/ext.direct.feature +32 -0
  7. data/features/i18n.feature +32 -0
  8. data/features/inheritance.feature +2 -2
  9. data/features/step_definitions/generic_steps.rb +21 -5
  10. data/features/step_definitions/touch_steps.rb +3 -0
  11. data/features/support/env.rb +4 -0
  12. data/features/support/paths.rb +6 -0
  13. data/features/touch.feature +10 -0
  14. data/javascripts/core.js +10 -15
  15. data/javascripts/ext.js +92 -1
  16. data/javascripts/touch.js +11 -0
  17. data/lib/netzke/actions.rb +13 -8
  18. data/lib/netzke/base.rb +32 -45
  19. data/lib/netzke/configuration.rb +53 -0
  20. data/lib/netzke/core/options_hash.rb +27 -0
  21. data/lib/netzke/core/version.rb +1 -1
  22. data/lib/netzke/core.rb +15 -5
  23. data/lib/netzke/core_ext/hash.rb +10 -8
  24. data/lib/netzke/inheritance.rb +31 -0
  25. data/lib/netzke/javascript.rb +45 -2
  26. data/lib/netzke/railz/action_view_ext.rb +8 -0
  27. data/lib/netzke/railz/controller_extensions.rb +1 -1
  28. data/lib/netzke/railz/engine.rb +27 -0
  29. data/lib/netzke/railz.rb +1 -0
  30. data/lib/netzke/session.rb +4 -0
  31. data/lib/netzke/state.rb +6 -6
  32. data/lib/netzke-core.rb +0 -23
  33. data/netzke-core.gemspec +27 -4
  34. data/spec/component/actions_spec.rb +2 -2
  35. data/spec/component/configuration_spec.rb +61 -0
  36. data/test/rails_app/Gemfile +1 -1
  37. data/test/rails_app/Gemfile.lock +48 -46
  38. data/test/rails_app/app/components/component_loader.rb +34 -1
  39. data/test/rails_app/app/components/ext_direct/composite.rb +48 -0
  40. data/test/rails_app/app/components/ext_direct/details.rb +13 -0
  41. data/test/rails_app/app/components/ext_direct/selector.rb +31 -0
  42. data/test/rails_app/app/components/ext_direct/statistics.rb +13 -0
  43. data/test/rails_app/app/components/extended_localized_panel.rb +2 -0
  44. data/test/rails_app/app/components/extended_server_caller.rb +0 -1
  45. data/test/rails_app/app/components/localized_panel.rb +28 -0
  46. data/test/rails_app/app/components/server_caller.rb +1 -0
  47. data/test/rails_app/app/components/server_counter.rb +123 -0
  48. data/test/rails_app/app/controllers/application_controller.rb +7 -0
  49. data/test/rails_app/config/initializers/backtrace_silencers.rb +1 -1
  50. data/test/rails_app/config/initializers/netzke.rb +1 -1
  51. data/test/rails_app/config/locales/en.yml +9 -2
  52. data/test/rails_app/config/locales/es.yml +11 -0
  53. data/test/rails_app/config/routes.rb +2 -2
  54. metadata +28 -16
@@ -2,35 +2,35 @@ GEM
2
2
  remote: http://rubygems.org/
3
3
  specs:
4
4
  abstract (1.0.0)
5
- actionmailer (3.0.3)
6
- actionpack (= 3.0.3)
7
- mail (~> 2.2.9)
8
- actionpack (3.0.3)
9
- activemodel (= 3.0.3)
10
- activesupport (= 3.0.3)
5
+ actionmailer (3.0.4)
6
+ actionpack (= 3.0.4)
7
+ mail (~> 2.2.15)
8
+ actionpack (3.0.4)
9
+ activemodel (= 3.0.4)
10
+ activesupport (= 3.0.4)
11
11
  builder (~> 2.1.2)
12
12
  erubis (~> 2.6.6)
13
13
  i18n (~> 0.4)
14
14
  rack (~> 1.2.1)
15
15
  rack-mount (~> 0.6.13)
16
- rack-test (~> 0.5.6)
16
+ rack-test (~> 0.5.7)
17
17
  tzinfo (~> 0.3.23)
18
- activemodel (3.0.3)
19
- activesupport (= 3.0.3)
18
+ activemodel (3.0.4)
19
+ activesupport (= 3.0.4)
20
20
  builder (~> 2.1.2)
21
21
  i18n (~> 0.4)
22
- activerecord (3.0.3)
23
- activemodel (= 3.0.3)
24
- activesupport (= 3.0.3)
22
+ activerecord (3.0.4)
23
+ activemodel (= 3.0.4)
24
+ activesupport (= 3.0.4)
25
25
  arel (~> 2.0.2)
26
26
  tzinfo (~> 0.3.23)
27
- activeresource (3.0.3)
28
- activemodel (= 3.0.3)
29
- activesupport (= 3.0.3)
30
- activesupport (3.0.3)
31
- arel (2.0.6)
27
+ activeresource (3.0.4)
28
+ activemodel (= 3.0.4)
29
+ activesupport (= 3.0.4)
30
+ activesupport (3.0.4)
31
+ arel (2.0.8)
32
32
  builder (2.1.2)
33
- capybara (0.4.0)
33
+ capybara (0.4.1.2)
34
34
  celerity (>= 0.7.9)
35
35
  culerity (>= 0.2.4)
36
36
  mime-types (>= 1.16)
@@ -38,9 +38,9 @@ GEM
38
38
  rack (>= 1.0.0)
39
39
  rack-test (>= 0.5.4)
40
40
  selenium-webdriver (>= 0.0.27)
41
- xpath (~> 0.1.2)
41
+ xpath (~> 0.1.3)
42
42
  celerity (0.8.7)
43
- childprocess (0.1.6)
43
+ childprocess (0.1.7)
44
44
  ffi (~> 0.6.3)
45
45
  configuration (1.2.0)
46
46
  cucumber (0.10.0)
@@ -51,8 +51,8 @@ GEM
51
51
  term-ansicolor (~> 1.0.5)
52
52
  cucumber-rails (0.3.2)
53
53
  cucumber (>= 0.8.0)
54
- culerity (0.2.14)
55
- database_cleaner (0.6.0)
54
+ culerity (0.2.15)
55
+ database_cleaner (0.6.3)
56
56
  diff-lcs (1.1.2)
57
57
  erubis (2.6.6)
58
58
  abstract (>= 1.0.0)
@@ -62,11 +62,11 @@ GEM
62
62
  json (~> 1.4.6)
63
63
  i18n (0.5.0)
64
64
  json (1.4.6)
65
- json_pure (1.4.6)
65
+ json_pure (1.5.1)
66
66
  launchy (0.3.7)
67
67
  configuration (>= 0.0.5)
68
68
  rake (>= 0.8.1)
69
- mail (2.2.14)
69
+ mail (2.2.15)
70
70
  activesupport (>= 2.3.6)
71
71
  i18n (>= 0.4.0)
72
72
  mime-types (~> 1.16)
@@ -80,33 +80,33 @@ GEM
80
80
  rack (>= 1.0.0)
81
81
  rack-test (0.5.7)
82
82
  rack (>= 1.0)
83
- rails (3.0.3)
84
- actionmailer (= 3.0.3)
85
- actionpack (= 3.0.3)
86
- activerecord (= 3.0.3)
87
- activeresource (= 3.0.3)
88
- activesupport (= 3.0.3)
83
+ rails (3.0.4)
84
+ actionmailer (= 3.0.4)
85
+ actionpack (= 3.0.4)
86
+ activerecord (= 3.0.4)
87
+ activeresource (= 3.0.4)
88
+ activesupport (= 3.0.4)
89
89
  bundler (~> 1.0)
90
- railties (= 3.0.3)
91
- railties (3.0.3)
92
- actionpack (= 3.0.3)
93
- activesupport (= 3.0.3)
90
+ railties (= 3.0.4)
91
+ railties (3.0.4)
92
+ actionpack (= 3.0.4)
93
+ activesupport (= 3.0.4)
94
94
  rake (>= 0.8.7)
95
95
  thor (~> 0.14.4)
96
96
  rake (0.8.7)
97
- rspec (2.4.0)
98
- rspec-core (~> 2.4.0)
99
- rspec-expectations (~> 2.4.0)
100
- rspec-mocks (~> 2.4.0)
101
- rspec-core (2.4.0)
102
- rspec-expectations (2.4.0)
97
+ rspec (2.5.0)
98
+ rspec-core (~> 2.5.0)
99
+ rspec-expectations (~> 2.5.0)
100
+ rspec-mocks (~> 2.5.0)
101
+ rspec-core (2.5.1)
102
+ rspec-expectations (2.5.0)
103
103
  diff-lcs (~> 1.1.2)
104
- rspec-mocks (2.4.0)
105
- rspec-rails (2.4.1)
104
+ rspec-mocks (2.5.0)
105
+ rspec-rails (2.5.0)
106
106
  actionpack (~> 3.0)
107
107
  activesupport (~> 3.0)
108
108
  railties (~> 3.0)
109
- rspec (~> 2.4.0)
109
+ rspec (~> 2.5.0)
110
110
  rubyzip (0.9.4)
111
111
  selenium-webdriver (0.1.2)
112
112
  childprocess (~> 0.1.5)
@@ -114,12 +114,14 @@ GEM
114
114
  json_pure
115
115
  rubyzip
116
116
  spork (0.8.4)
117
- sqlite3-ruby (1.3.2)
117
+ sqlite3 (1.3.3)
118
+ sqlite3-ruby (1.3.3)
119
+ sqlite3 (>= 1.3.3)
118
120
  term-ansicolor (1.0.5)
119
121
  thor (0.14.6)
120
122
  treetop (1.4.9)
121
123
  polyglot (>= 0.3.1)
122
- tzinfo (0.3.23)
124
+ tzinfo (0.3.24)
123
125
  xpath (0.1.3)
124
126
  nokogiri (~> 1.3)
125
127
 
@@ -133,7 +135,7 @@ DEPENDENCIES
133
135
  database_cleaner
134
136
  launchy
135
137
  netzke-persistence
136
- rails (= 3.0.3)
138
+ rails (= 3.0.4)
137
139
  rspec-rails
138
140
  spork
139
141
  sqlite3-ruby
@@ -18,6 +18,7 @@ class ComponentLoader < Netzke::Base
18
18
 
19
19
  component :some_composite, :lazy_loading => true
20
20
 
21
+ # this action is using loadComponent "special" callback
21
22
  js_method :on_load_with_feedback, <<-JS
22
23
  function(){
23
24
  this.loadComponent({name: 'simple_component', callback: function(){
@@ -25,6 +26,38 @@ class ComponentLoader < Netzke::Base
25
26
  }, scope: this});
26
27
  }
27
28
  JS
29
+
30
+ # this action is using generic endpoint callback
31
+ action :load_with_generic_callback
32
+ js_method :on_load_with_generic_callback, <<-JS
33
+ function(){
34
+ this.doNothing({}, function () {
35
+ this.setTitle("Generic callback invoked!");
36
+ });
37
+ }
38
+ JS
39
+
40
+ # this action is using generic endpoint callback with scope
41
+ action :load_with_generic_callback_and_scope
42
+ js_method :on_load_with_generic_callback_and_scope, <<-JS
43
+ function(){
44
+ var that=this;
45
+ var fancyScope={
46
+ setFancyTitle: function () {
47
+ that.setTitle("Fancy title set!");
48
+ }
49
+ };
50
+ this.doNothing({}, function () {
51
+ this.setFancyTitle();
52
+ }, fancyScope);
53
+ }
54
+ JS
55
+
56
+ endpoint :do_nothing do |params|
57
+ # here be tumbleweed
58
+ # {}
59
+ end
60
+
28
61
 
29
62
  action :load_with_feedback
30
63
 
@@ -37,7 +70,7 @@ class ComponentLoader < Netzke::Base
37
70
  js_properties(
38
71
  :title => "Component Loader",
39
72
  :layout => "fit",
40
- :bbar => [{:text => "Load component", :ref => "../button"}, {:text => "Load in window", :ref => "../loadInWindowButton"}, :load_with_feedback.action, :load_window_with_simple_component.action, :load_composite.action, :load_with_params.action]
73
+ :bbar => [{:text => "Load component", :ref => "../button"}, {:text => "Load in window", :ref => "../loadInWindowButton"}, :load_with_feedback.action, :load_window_with_simple_component.action, :load_composite.action, :load_with_params.action, :load_with_generic_callback.action, :load_with_generic_callback_and_scope.action]
41
74
  )
42
75
 
43
76
  js_method :on_load_window_with_simple_component, <<-JS
@@ -0,0 +1,48 @@
1
+ module ExtDirect
2
+ class Composite < Netzke::Base
3
+ js_property :layout, :border
4
+ js_property :border, true
5
+
6
+ component :selector, :class_name => "ExtDirect::Selector" # a form that will allow us to select a user
7
+
8
+ component :details do
9
+ {
10
+ :class_name => "ExtDirect::Details", # a panel that will display details for the user
11
+ :user => component_session[:user]
12
+ }
13
+ end
14
+
15
+ component :statistics do
16
+ {
17
+ :class_name => "ExtDirect::Statistics", # a panel that will display details for the user
18
+ :user => component_session[:user]
19
+ }
20
+ end
21
+
22
+ def configuration
23
+ super.merge({
24
+ :items => [:selector.component(:region => :north, :height => 100),
25
+ :details.component(:region => :center),
26
+ :statistics.component(:region => :east, :width => 300, :split => true)
27
+ ]
28
+ })
29
+ end
30
+
31
+ endpoint :set_user do |params|
32
+ component_session[:user] = params
33
+ end
34
+
35
+ js_method :init_component, <<-JS
36
+ function(){
37
+ Netzke.classes.ExtDirect.Composite.superclass.initComponent.call(this);
38
+
39
+ this.getChildComponent('selector').on('userupdate', function(user){
40
+ this.setUser(user);
41
+ this.getChildComponent('details').update();
42
+ this.getChildComponent('statistics').update();
43
+ }, this);
44
+ }
45
+ JS
46
+
47
+ end
48
+ end
@@ -0,0 +1,13 @@
1
+ module ExtDirect
2
+ class Details < Netzke::Base
3
+ js_property :padding, 5
4
+
5
+ endpoint :update do |params|
6
+ {:set_title => title}
7
+ end
8
+
9
+ def title
10
+ "Details for user #{config[:user]}"
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,31 @@
1
+ module ExtDirect
2
+ class Selector < Netzke::Base
3
+ js_base_class "Ext.FormPanel"
4
+
5
+ js_property :padding, 5
6
+
7
+ action :update
8
+
9
+ def configuration
10
+ super.merge({
11
+ :items => [{:name => "user", :field_label => "User", :xtype => :textfield}],
12
+ :bbar => [:update.action]
13
+ })
14
+ end
15
+
16
+ js_method :init_component, <<-JS
17
+ function(){
18
+ Netzke.classes.ExtDirect.Selector.superclass.initComponent.call(this);
19
+ this.addEvents('userupdate');
20
+ }
21
+ JS
22
+
23
+
24
+ js_method :on_update, <<-JS
25
+ function(){
26
+ this.fireEvent('userupdate', this.getForm().findField('user').getValue());
27
+ }
28
+ JS
29
+
30
+ end
31
+ end
@@ -0,0 +1,13 @@
1
+ module ExtDirect
2
+ class Statistics < Netzke::Base
3
+ js_property :padding, 5
4
+
5
+ endpoint :update do |params|
6
+ {:set_title => title}
7
+ end
8
+
9
+ def title
10
+ "Statistics for user #{config[:user]}"
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,2 @@
1
+ class ExtendedLocalizedPanel < LocalizedPanel
2
+ end
@@ -1,5 +1,4 @@
1
1
  class ExtendedServerCaller < ServerCaller
2
-
3
2
  js_properties :title => "Extended Server Caller"
4
3
 
5
4
  js_method :on_bug_server, <<-JS
@@ -0,0 +1,28 @@
1
+ class LocalizedPanel < Netzke::Base
2
+ # This action will be translated per-class basis if the translation is available, and fall back to the default when it's not.
3
+ action :action_one
4
+
5
+ # If you want action's text to be inheritable, this is what you shold do:
6
+ action :action_two do
7
+ {:text => I18n.t('localized_panel.action_two')}
8
+ end
9
+
10
+ js_translate :property_one, :property_two
11
+
12
+ js_property :bbar, [:action_one.action, :action_two.action]
13
+
14
+ def configuration
15
+ super.tap do |c|
16
+ c[:title] = I18n.t('localized_panel.title')
17
+ end
18
+ end
19
+
20
+ js_method :on_render, <<-JS
21
+ function(ct){
22
+ Netzke.classes.LocalizedPanel.superclass.onRender.call(this, ct);
23
+
24
+ this.body.update(this.i18n.propertyOne + ", " + this.i18n.propertyTwo);
25
+ }
26
+ JS
27
+
28
+ end
@@ -15,6 +15,7 @@ class ServerCaller < Netzke::Base
15
15
  JS
16
16
 
17
17
  endpoint :whats_up do |params|
18
+ ::Rails.logger.debug "!!! params: #{params.inspect}\n"
18
19
  {:set_title => "All quiet here on the server"}
19
20
  end
20
21
 
@@ -0,0 +1,123 @@
1
+ class ServerCounter < Netzke::Base
2
+ action :count_one_time # 1 request
3
+ action :count_seven_times # 7 requests (should be batched)
4
+ action :count_eight_times_special # passing multiple arguments
5
+ action :fail_in_the_middle # calls 3 endpoints of which the second fails
6
+ action :do_ordered # used for test if call order is preserved
7
+ action :fail_two_out_of_five # sends 5 requests, 2 will fail, but the request should be processed in order
8
+
9
+ js_properties(
10
+ :title => "Server Counter",
11
+ :bbar => [:count_one_time.action, :count_seven_times.action, :count_eight_times_special.action, :fail_in_the_middle.action, :do_ordered.action, :fail_two_out_of_five.action]
12
+ )
13
+
14
+ js_method :on_count_one_time, <<-JS
15
+ function(){
16
+ this.count({how_many: 1});
17
+ }
18
+ JS
19
+
20
+ js_method :init_component, <<-JS
21
+ function () {
22
+ #{js_full_class_name}.superclass.initComponent.call(this);
23
+ Ext.Ajax.on('beforerequest',function (conn, options ) {
24
+ Netzke.connectionCount = Netzke.connectionCount || 0;
25
+ Netzke.connectionCount++;
26
+ Netzke.lastOptions=options;
27
+ });
28
+
29
+ }
30
+ JS
31
+
32
+ js_method :on_count_seven_times, <<-JS
33
+ function(){
34
+ for(var i=0; i<7; i++)
35
+ this.count({how_many: 1});
36
+ }
37
+ JS
38
+
39
+ js_method :on_count_eight_times_special, <<-JS
40
+ function(){
41
+ for(var i=0;i<8;i++)
42
+ this.count({how_many: 1, special: true});
43
+ }
44
+ JS
45
+
46
+ js_method :on_fail_in_the_middle, <<-JS
47
+ function() {
48
+ this.successingEndpoint();
49
+ this.failingEndpoint();
50
+ this.successingEndpoint();
51
+ }
52
+ JS
53
+
54
+ js_method :on_do_ordered, <<-JS
55
+ function () {
56
+ this.firstEp();
57
+ this.secondEp();
58
+ }
59
+ JS
60
+
61
+ js_method :update_appending, <<-JS
62
+ function(html){
63
+ if (!this.panelText) { this.panelText = ""; }
64
+ this.panelText += html + ",";
65
+ this.body.update(this.panelText);
66
+ }
67
+ JS
68
+
69
+ js_method :on_fail_two_out_of_five, <<-JS
70
+ function(){
71
+ for(var i=1; i<=5; i++) {
72
+ this.failTwoOutOfFive(i);
73
+ }
74
+ }
75
+ JS
76
+
77
+ def before_load
78
+ component_session[:is_retry] = false
79
+ component_session[:count] = 0
80
+ end
81
+
82
+ endpoint :count do |params|
83
+ component_session[:count] ||= 0
84
+ component_session[:count] += params[:how_many]
85
+ {:update => "I am at " + component_session[:count].to_s + (params[:special] ? ' and i was invoked specially' : '')}
86
+ end
87
+
88
+ endpoint :successing_endpoint do |params|
89
+ {:update => "Something successed "}
90
+ end
91
+
92
+ endpoint :failing_endpoint do |params|
93
+ throw "something happened"
94
+ {:update => "This will never get returned"}
95
+ end
96
+
97
+ endpoint :first_ep do |params|
98
+ component_session[:count]||=0
99
+ component_session[:count]+=1
100
+ {:update => "First. "+ component_session[:count].to_s}
101
+ end
102
+
103
+ endpoint :second_ep do |params|
104
+ component_session[:count]||=0
105
+ component_session[:count]+=1
106
+ {:update => "Second. "+ component_session[:count].to_s}
107
+ end
108
+
109
+ endpoint :fail_two_out_of_five do |count|
110
+ component_session[:count] ||= 0
111
+ component_session[:count] += 1
112
+
113
+ # 2nd and 4th request fail, but only first time, not at a retry
114
+ if ([2,4].include?(component_session[:count]) && !component_session[:is_retry])
115
+ component_session[:is_retry] = true
116
+ throw "Oops..."
117
+ end
118
+
119
+ component_session[:is_retry] = false
120
+ {:update_appending => count}
121
+ end
122
+
123
+ end
@@ -1,3 +1,10 @@
1
1
  class ApplicationController < ActionController::Base
2
2
  protect_from_forgery
3
+
4
+ before_filter :set_locale
5
+ def set_locale
6
+ # if params[:locale] is nil then I18n.default_locale will be used
7
+ I18n.locale = params[:locale]
8
+ end
9
+
3
10
  end
@@ -4,4 +4,4 @@
4
4
  # Rails.backtrace_cleaner.add_silencer { |line| line =~ /my_noisy_library/ }
5
5
 
6
6
  # You can also remove all the silencers if you're trying to debug a problem that might stem from framework code.
7
- # Rails.backtrace_cleaner.remove_silencers!
7
+ Rails.backtrace_cleaner.remove_silencers!
@@ -1,3 +1,3 @@
1
1
  Netzke::Core.setup do |config|
2
- # config.icons_uri = "/images/icons"
2
+ config.js_direct_max_retries = 3
3
3
  end
@@ -7,5 +7,12 @@ en:
7
7
  bug_server: "Call server"
8
8
  extended_server_caller:
9
9
  actions:
10
- bug_server: "Call server"
11
- bug_server_tooltip: "With tooltip"
10
+ bug_server: "Call server extensively"
11
+ bug_server_tooltip: "With custom tooltip"
12
+ localized_panel:
13
+ title: Localized Panel
14
+ property_one: First property
15
+ property_two: Second property
16
+ action_two: Second action
17
+ actions:
18
+ action_one: First action
@@ -0,0 +1,11 @@
1
+ # Sample localization file for English. Add more files in this directory for other locales.
2
+ # See http://github.com/svenfuchs/rails-i18n/tree/master/rails%2Flocale for starting points.
3
+
4
+ es:
5
+ localized_panel:
6
+ title: Panel Localizada
7
+ property_one: Primera propriedad
8
+ property_two: Segunda propriedad
9
+ action_two: Segunda acción
10
+ actions:
11
+ action_one: Primera acción
@@ -60,9 +60,9 @@ RailsApp::Application.routes.draw do
60
60
 
61
61
  # Components configured in Rails views
62
62
  match 'components/embedded/:action' => 'components', :as => "embedded_components"
63
-
63
+
64
64
  # Touch components
65
- match 'components/touch/:component' => 'touch#index', :as => "touch"
65
+ match 'components/touch/:component' => 'touch#index', :as => "touch_components"
66
66
 
67
67
  # Non-Netzke Ext components
68
68
  match 'ext/:component' => 'components#ext', :as => "ext"