netzke-core 0.6.7 → 0.7.0

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 (74) hide show
  1. data/CHANGELOG.rdoc +36 -1
  2. data/{README.markdown → README.md} +17 -15
  3. data/Rakefile +1 -1
  4. data/TODO +4 -4
  5. data/app/controllers/netzke_controller.rb +8 -3
  6. data/javascripts/base.js +71 -68
  7. data/javascripts/ext.js +182 -111
  8. data/lib/netzke/actions.rb +2 -1
  9. data/lib/netzke/base.rb +5 -1
  10. data/lib/netzke/composition.rb +2 -2
  11. data/lib/netzke/configuration.rb +1 -1
  12. data/lib/netzke/core/dynamic_assets.rb +7 -7
  13. data/lib/netzke/core/session.rb +4 -0
  14. data/lib/netzke/core/version.rb +2 -2
  15. data/lib/netzke/core.rb +23 -30
  16. data/lib/netzke/core_ext/symbol.rb +1 -1
  17. data/lib/netzke/embedding.rb +1 -1
  18. data/lib/netzke/ext_component.rb +2 -2
  19. data/lib/netzke/javascript.rb +70 -39
  20. data/lib/netzke/plugin.rb +15 -0
  21. data/lib/netzke/plugins.rb +29 -0
  22. data/lib/netzke/railz/action_view_ext/ext.rb +13 -16
  23. data/lib/netzke/railz/action_view_ext/touch.rb +3 -3
  24. data/lib/netzke/railz/action_view_ext.rb +0 -3
  25. data/lib/netzke/railz/engine.rb +34 -29
  26. data/lib/netzke/services.rb +1 -1
  27. data/lib/netzke/state.rb +2 -2
  28. data/lib/netzke-core.rb +1 -0
  29. data/netzke-core.gemspec +108 -9
  30. data/stylesheets/core.css +25 -5
  31. data/test/rails_app/Gemfile +1 -1
  32. data/test/rails_app/Gemfile.lock +37 -36
  33. data/test/rails_app/app/components/component_loader.rb +36 -24
  34. data/test/rails_app/app/components/component_with_js_mixin/javascripts/component_with_js_mixin.js +5 -0
  35. data/test/rails_app/app/components/component_with_js_mixin.rb +3 -1
  36. data/test/rails_app/app/components/component_with_nested_through.rb +28 -0
  37. data/test/rails_app/app/components/component_with_session_persistence.rb +7 -5
  38. data/test/rails_app/app/components/dynamic_tab_panel/javascripts/dynamic_tab_panel.js +9 -0
  39. data/test/rails_app/app/components/dynamic_tab_panel.rb +19 -0
  40. data/test/rails_app/app/components/extended_server_caller.rb +6 -5
  41. data/test/rails_app/app/components/loader_of_component_with_custom_css.rb +7 -8
  42. data/test/rails_app/app/components/localized_panel.rb +10 -1
  43. data/test/rails_app/app/components/nested_component.rb +18 -0
  44. data/test/rails_app/app/components/panel_with_plugin.rb +4 -0
  45. data/test/rails_app/app/components/panel_with_tools.rb +19 -0
  46. data/test/rails_app/app/components/plugin_with_components.rb +14 -0
  47. data/test/rails_app/app/components/server_caller.rb +1 -1
  48. data/test/rails_app/app/components/server_counter.rb +1 -1
  49. data/test/rails_app/app/components/simple_component.rb +2 -0
  50. data/test/rails_app/app/components/simple_tab_panel.rb +21 -21
  51. data/test/rails_app/app/components/simple_window.rb +1 -1
  52. data/test/rails_app/app/components/some_composite.rb +3 -2
  53. data/test/rails_app/app/components/some_plugin.rb +39 -0
  54. data/test/rails_app/app/controllers/application_controller.rb +1 -1
  55. data/test/rails_app/app/controllers/components_controller.rb +1 -1
  56. data/test/rails_app/app/views/layouts/touch.html.erb +1 -1
  57. data/test/rails_app/config/application.rb +0 -2
  58. data/test/rails_app/config/initializers/netzke.rb +2 -1
  59. data/test/rails_app/config/locales/es.yml +1 -0
  60. data/test/rails_app/features/{actions.feature → actions_and_tools.feature} +8 -0
  61. data/test/rails_app/features/client-server.feature +0 -1
  62. data/test/rails_app/features/complex_component.feature +1 -1
  63. data/test/rails_app/features/component_loader.feature +7 -0
  64. data/test/rails_app/features/composition.feature +2 -2
  65. data/test/rails_app/features/custom_css.feature +1 -1
  66. data/test/rails_app/features/i18n.feature +3 -0
  67. data/test/rails_app/features/js_include.feature +2 -0
  68. data/test/rails_app/features/nested_views.feature +5 -4
  69. data/test/rails_app/features/plugin.feature +16 -0
  70. data/test/rails_app/features/step_definitions/generic_steps.rb +21 -2
  71. data/test/rails_app/features/touch.feature +10 -10
  72. data/test/rails_app/spec/component/component_spec.rb +20 -0
  73. metadata +106 -10
  74. data/app/models/netzke_preference.rb +0 -170
@@ -2,14 +2,13 @@
2
2
  class LoaderOfComponentWithCustomCss < Netzke::Base
3
3
  component :component_with_custom_css, :class_name => "ComponentWithCustomCss", :lazy_loading => true
4
4
 
5
- js_properties :title => "LoaderOfComponentWithCustomCss", :layout => 'fit', :bbar => [{:text => "Load ComponentWithCustomCss", :ref => "../button"}]
5
+ action :load_component_with_custom_css
6
6
 
7
- js_method :init_component, <<-JS
8
- function(){
9
- #{js_full_class_name}.superclass.initComponent.call(this);
10
- this.button.on('click', function(){
11
- this.loadComponent({id: 'component_with_custom_css', container: this.getId()});
12
- }, this);
7
+ js_properties :title => "LoaderOfComponentWithCustomCss", :layout => 'fit', :bbar => [:load_component_with_custom_css.action]
8
+
9
+ js_method :on_load_component_with_custom_css, <<-JS
10
+ function(params){
11
+ this.loadComponent({name: 'component_with_custom_css'});
13
12
  }
14
13
  JS
15
- end
14
+ end
@@ -7,9 +7,11 @@ class LocalizedPanel < Netzke::Base
7
7
  {:text => I18n.t('localized_panel.action_two')}
8
8
  end
9
9
 
10
+ action :action_three
11
+
10
12
  js_translate :property_one, :property_two
11
13
 
12
- js_property :bbar, [:action_one.action, :action_two.action]
14
+ js_property :bbar, [:action_one.action, :action_two.action, :action_three.action]
13
15
 
14
16
  def configuration
15
17
  super.tap do |c|
@@ -25,4 +27,11 @@ class LocalizedPanel < Netzke::Base
25
27
  }
26
28
  JS
27
29
 
30
+ js_method :on_action_three, <<-JS
31
+ function(){
32
+ var mask = new Ext.LoadMask(this.body);
33
+ mask.show();
34
+ }
35
+ JS
36
+
28
37
  end
@@ -0,0 +1,18 @@
1
+ class NestedComponent < Netzke::Base
2
+ js_property :layout, :fit
3
+
4
+ def configuration
5
+ super.tap do |c|
6
+ c[:items] = [:child.component]
7
+ end
8
+ end
9
+
10
+ component :child,
11
+ :class_name => "SimpleComponent",
12
+ :layout => 'accordion',
13
+ :items => [:grand_child_one.component, :grand_child_two.component],
14
+ :components => {
15
+ :grand_child_one => {:class_name => "SimpleComponent", :title => "Grand Child One"},
16
+ :grand_child_two => {:class_name => "NestedComponent", :title => "Grand Child Two", :lazy_loading => true}
17
+ }
18
+ end
@@ -0,0 +1,4 @@
1
+ class PanelWithPlugin < Netzke::Base
2
+ plugin :some_plugin
3
+ plugin :plugin_with_components
4
+ end
@@ -0,0 +1,19 @@
1
+ class PanelWithTools < Netzke::Base
2
+ def configuration
3
+ super.tap do |c|
4
+ c[:tools] = [:refresh, :gear]
5
+ end
6
+ end
7
+
8
+ js_method :on_refresh, <<-JS
9
+ function(){
10
+ this.setTitle("Refresh" + " clicked");
11
+ }
12
+ JS
13
+
14
+ js_method :on_gear, <<-JS
15
+ function(){
16
+ this.setTitle("Gear" + " clicked")
17
+ }
18
+ JS
19
+ end
@@ -0,0 +1,14 @@
1
+ class PluginWithComponents < Netzke::Plugin
2
+ js_method :init, <<-JS
3
+ function(cmp){
4
+ this.cmp = cmp;
5
+ this.cmp.tools = this.cmp.tools || [];
6
+ this.cmp.tools.push({type: 'help', handler: function(){
7
+ var w = this.instantiateChildNetzkeComponent('simple_window');
8
+ w.show();
9
+ }, scope: this});
10
+ }
11
+ JS
12
+
13
+ component :simple_window, :width => 300, :height => 200, :title => "Window created by PluginWithComponents"
14
+ end
@@ -4,7 +4,7 @@ class ServerCaller < Netzke::Base
4
4
  js_properties(
5
5
  :title => "Server Caller",
6
6
  :html => "Wow",
7
- :bbar => [:bug_server.action]
7
+ :tbar => [:bug_server.action] # TODO: used to be bbar, but Ext 4.0.2 has problems with rendering it!
8
8
  )
9
9
 
10
10
  js_method :on_bug_server, <<-JS
@@ -25,7 +25,6 @@ class ServerCounter < Netzke::Base
25
25
  Netzke.connectionCount++;
26
26
  Netzke.lastOptions=options;
27
27
  });
28
-
29
28
  }
30
29
  JS
31
30
 
@@ -43,6 +42,7 @@ class ServerCounter < Netzke::Base
43
42
  }
44
43
  JS
45
44
 
45
+ # TODO: is it actually meant to succeed and display "Something succeeded"?..
46
46
  js_method :on_fail_in_the_middle, <<-JS
47
47
  function() {
48
48
  this.successingEndpoint();
@@ -1,5 +1,7 @@
1
1
  class SimpleComponent < Netzke::Base
2
2
  js_properties :title => "SimpleComponent",
3
3
  :html => "Inner text"
4
+
5
+ # component :one, :class_name => "SimplePanel", :title => "One"
4
6
  end
5
7
 
@@ -3,25 +3,25 @@ class SimpleTabPanel < Netzke::Base
3
3
 
4
4
  js_property :active_tab, 0
5
5
 
6
- config :items => [{
7
- # Loading a primitive BorderLayoutPanel here
8
- :class_name => "BorderLayoutPanel",
9
- :title => "A border layout panel",
10
- :items => [{
11
- :region => :north,
12
- :height => 100,
13
- :title => "I'm NOT a Netzke component",
14
- :html => "I'm a simple panel"
15
- },{
16
- :region => :center,
17
- :class_name => "ServerCaller"
18
- },{
19
- :region => :west,
20
- :width => 300,
21
- :split => true,
22
- :class_name => "ExtendedServerCaller"
23
- }]
24
- },{
25
- :class_name => "ExtendedServerCaller"
26
- }]
6
+ # config :items => [{
7
+ # # Loading a primitive BorderLayoutPanel here
8
+ # :class_name => "BorderLayoutPanel",
9
+ # :title => "A border layout panel",
10
+ # :items => [{
11
+ # :region => :north,
12
+ # :height => 100,
13
+ # :title => "I'm NOT a Netzke component",
14
+ # :html => "I'm a simple panel"
15
+ # },{
16
+ # :region => :center,
17
+ # :class_name => "ServerCaller"
18
+ # },{
19
+ # :region => :west,
20
+ # :width => 300,
21
+ # :split => true,
22
+ # :class_name => "ExtendedServerCaller"
23
+ # }]
24
+ # },{
25
+ # :class_name => "ExtendedServerCaller"
26
+ # }]
27
27
  end
@@ -1,3 +1,3 @@
1
1
  class SimpleWindow < Netzke::Base
2
- js_base_class "Ext.Window"
2
+ js_base_class "Ext.window.Window"
3
3
  end
@@ -1,5 +1,6 @@
1
1
  class SomeComposite < Netzke::Base
2
2
  js_properties :title => "Static Composite",
3
+ :height => 400,
3
4
  :layout => 'border',
4
5
  :bbar => [
5
6
  :update_west_panel.action,
@@ -26,9 +27,9 @@ class SomeComposite < Netzke::Base
26
27
 
27
28
  component :center_panel, :class_name => "ServerCaller"
28
29
 
29
- component :east_center_panel, :class_name => "SimpleComponent", :title => "A panel"
30
+ component :east_center_panel, :class_name => "SimpleComponent", :title => "A panel", :border => false
30
31
 
31
- component :east_south_panel, :class_name => "SimpleComponent", :title => "Another panel"
32
+ component :east_south_panel, :class_name => "SimpleComponent", :title => "Another panel", :border => false
32
33
 
33
34
  endpoint :update_east_south do |params|
34
35
  {:east_south_panel => {:set_title => "Here's an update for south panel in east panel"}}
@@ -0,0 +1,39 @@
1
+ class SomePlugin < Netzke::Plugin
2
+ action :action_one
3
+
4
+ js_method :init, <<-JS
5
+ function(){
6
+ this.callParent(arguments);
7
+ this.cmp.tools = [{id: 'gear', handler: this.onGear, scope: this}];
8
+
9
+ this.cmp.addDocked({
10
+ dock: 'bottom',
11
+ xtype: 'toolbar',
12
+ items: [this.actions.actionOne]
13
+ });
14
+ }
15
+ JS
16
+
17
+ js_method :on_action_one, <<-JS
18
+ function(){
19
+ this.cmp.setTitle('Action one ' + 'triggered');
20
+ }
21
+ JS
22
+
23
+ js_method :on_gear, <<-JS
24
+ function(){
25
+ this.processGear();
26
+ }
27
+ JS
28
+
29
+ js_method :process_gear_callback, <<-JS
30
+ function(newTitle){
31
+ this.cmp.setTitle(newTitle);
32
+ }
33
+ JS
34
+
35
+ endpoint :process_gear do |params|
36
+ {:process_gear_callback => "Server response"}
37
+ end
38
+
39
+ end
@@ -1,5 +1,5 @@
1
1
  class ApplicationController < ActionController::Base
2
- protect_from_forgery
2
+ # protect_from_forgery
3
3
 
4
4
  before_filter :set_locale
5
5
  def set_locale
@@ -1,7 +1,7 @@
1
1
  class ComponentsController < ApplicationController
2
2
  def index
3
3
  component_name = params[:component].gsub("::", "_").underscore
4
- render :inline => "<%= netzke :#{component_name}, :class_name => '#{params[:component]}' %>", :layout => true
4
+ render :inline => "<%= netzke :#{component_name}, :class_name => '#{params[:component]}', :height => 400 %>", :layout => true
5
5
  end
6
6
 
7
7
  # For panel_with_autoload
@@ -3,7 +3,7 @@
3
3
  <head>
4
4
  <title>Netzke Touch</title>
5
5
  <%= csrf_meta_tag %>
6
- <%= netzke_init :platform => :touch, :cache => "touch" %>
6
+ <%= netzke_init :platform => :touch %>
7
7
  </head>
8
8
  <body>
9
9
 
@@ -41,7 +41,5 @@ module RailsApp
41
41
 
42
42
  # Configure sensitive parameters which will be filtered from the log file.
43
43
  config.filter_parameters += [:password]
44
-
45
- # config.netzke.core.direct_max_retries = 2
46
44
  end
47
45
  end
@@ -1,3 +1,4 @@
1
1
  Netzke::Core.setup do |config|
2
- config.js_direct_max_retries = 3
2
+ # config.js_direct_max_retries = 3
3
+ config.ext_uri = "/extjs4"
3
4
  end
@@ -9,3 +9,4 @@ es:
9
9
  action_two: Segunda acción
10
10
  actions:
11
11
  action_one: Primera acción
12
+ action_three: Tercera acción
@@ -11,3 +11,11 @@ Scenario: Pressing button should result in corresponding actions
11
11
 
12
12
  When I press "Some Cool Action"
13
13
  Then I should see "Some action was triggered"
14
+
15
+ @javascript
16
+ Scenario: Pressing a tool should result in corresponding action
17
+ Given I am on the PanelWithTools test page
18
+ When I press tool "gear"
19
+ Then I should see "Gear clicked"
20
+ When I press tool "refresh"
21
+ Then I should see "Refresh clicked"
@@ -8,6 +8,5 @@ Scenario: Ask server to set our title
8
8
  Given I am on the ServerCaller test page
9
9
  Then I should see "Server Caller"
10
10
 
11
- # When I execute "Ext.getCmp('server_caller').buttons.first().fireEvent('click');"
12
11
  When I press "Call server"
13
12
  Then I should see "All quiet here on the server"
@@ -13,6 +13,6 @@ Feature: Complex component
13
13
  @javascript
14
14
  Scenario: The last tab of the complex component is a Netzke component that just works
15
15
  Given I am on the KindaComplexComponent test page
16
- When I follow "Server Caller"
16
+ When I press "Server Caller"
17
17
  And I press "Call server"
18
18
  Then I should see "All quiet here on the server"
@@ -43,3 +43,10 @@ Feature: Component loader
43
43
  Given I am on the ComponentLoader test page
44
44
  When I press "Load with params"
45
45
  Then I should see "Simple Component with changed HTML"
46
+
47
+ @javascript
48
+ Scenario: Component loader should report that it can't load a component
49
+ Given I am on the ComponentLoader test page
50
+ When I press "Non-existing component"
51
+ Then I should see "Couldn't load component 'non_existing_component'"
52
+ And I should not see "Loading"
@@ -23,9 +23,9 @@ Feature: Composition
23
23
  Scenario: Server should be able to address (deeply) nested components
24
24
  Given I am on the SomeComposite test page
25
25
  When I press "Update west from server"
26
- And I sleep 1 second
26
+ And I wait for response from server
27
27
  Then I should see "Here's an update for west panel"
28
28
 
29
29
  When I press "Update east south from server"
30
- And I sleep 1 second
30
+ And I wait for response from server
31
31
  Then I should see "Here's an update for south panel in east panel"
@@ -12,6 +12,6 @@ Feature: Custom css
12
12
  @javascript
13
13
  Scenario: A dynamically loaded component with a hidden body should not display its body
14
14
  When I go to the LoaderOfComponentWithCustomCss test page
15
- And I press "Load ComponentWithCustomCss"
15
+ And I press "Load component with custom css"
16
16
  Then I should see "ComponentWithCustomCss"
17
17
  But the body of LoaderOfComponentWithCustomCss/ComponentWithCustomCss component should not be invisible
@@ -17,6 +17,9 @@ Scenario: LocalizedPanel should be available in 2 languages
17
17
  And I should see "Primera acción"
18
18
  And I should see "Segunda acción"
19
19
 
20
+ When I press "Tercera acción"
21
+ Then I should see "Cargando..."
22
+
20
23
  When I go to the "es" version of the ExtendedLocalizedPanel page
21
24
  Then I should see "Panel Localizada"
22
25
  And I should see "Primera propriedad, Segunda propriedad"
@@ -10,6 +10,8 @@ Feature: JsMixins
10
10
  Then I should see "Action One triggered!"
11
11
  When I press "Action two"
12
12
  Then I should see "Action Two triggered!"
13
+ When I press "Action three"
14
+ Then I should see "Action Three triggered!"
13
15
 
14
16
  @javascript
15
17
  Scenario: ExtendedComponentWithJsMixin should behave, too
@@ -3,7 +3,8 @@ Feature: Nested views
3
3
  As a role
4
4
  I want feature
5
5
 
6
- @javascript
7
- Scenario: A component with auto loaded content should render properly
8
- When I go to the "panel with autoload" view
9
- Then I should see "Autoloaded Panel"
6
+ # @javascript
7
+ # WIP: This scenario may never be needed
8
+ # Scenario: A component with auto loaded content should render properly
9
+ # When I go to the "panel with autoload" view
10
+ # Then I should see "Autoloaded Panel"
@@ -0,0 +1,16 @@
1
+ Feature: Plugin
2
+ In order to value
3
+ As a role
4
+ I want feature
5
+
6
+ @javascript
7
+ Scenario: Plugin calling its server part
8
+ Given I am on the PanelWithPlugin test page
9
+ When I press tool "gear"
10
+ Then I should see "Server response"
11
+
12
+ @javascript
13
+ Scenario: Plugin inserting its action into component
14
+ Given I am on the PanelWithPlugin test page
15
+ When I press "Action one"
16
+ Then I should see "Action one triggered"
@@ -8,14 +8,14 @@ end
8
8
 
9
9
  Then /^button "([^"]*)" should be enabled$/ do |arg1|
10
10
  page.driver.browser.execute_script(<<-JS).should == true
11
- var btn = Ext.ComponentMgr.all.filter('text', '#{arg1}').filter('type','button').first();
11
+ var btn = Array.filter( Ext.ComponentManager.all.getValues(), function(o){ return o.text == '#{arg1}' })[0];
12
12
  return typeof(btn)!='undefined' ? !btn.disabled : false
13
13
  JS
14
14
  end
15
15
 
16
16
  Then /^button "([^"]*)" should be disabled$/ do |arg1|
17
17
  page.driver.browser.execute_script(<<-JS).should == true
18
- var btn = Ext.ComponentMgr.all.filter('text', '#{arg1}').filter('type','button').first();
18
+ var btn = Array.filter( Ext.ComponentManager.all.getValues(), function(o){ return o.text == '#{arg1}' })[0];
19
19
  return typeof(btn)!='undefined' ? btn.disabled : false
20
20
  JS
21
21
  end
@@ -26,6 +26,25 @@ When /^total requests made should be (\d+)$/ do |count|
26
26
  JS
27
27
  end
28
28
 
29
+ When /^I press tool "([^"]*)"$/ do |tool|
30
+ id = page.driver.browser.execute_script(<<-JS)
31
+ var toolCmp;
32
+ Ext.ComponentManager.all.each(function(k,v){
33
+ if (v.type == '#{tool}') {
34
+ toolCmp = v;
35
+ return false;
36
+ }
37
+ });
38
+ return toolCmp.getId();
39
+ JS
40
+
41
+ find("##{id} img").click
42
+ end
43
+
44
+ When /^I wait for response from server$/ do
45
+ page.wait_until{ page.driver.browser.execute_script("return !Netzke.ajaxIsLoading()") }
46
+ end
47
+
29
48
  When /I sleep (\d+) seconds?/ do |arg1|
30
49
  sleep arg1.to_i
31
50
  end
@@ -1,10 +1,10 @@
1
- Feature: Touch - to be run in Chrome only
2
- In order to value
3
- As a role
4
- I want feature
5
-
6
- @javascript
7
- Scenario: Client-server communication
8
- Given I am on the ServerCaller page for touch
9
- When I press button "Bug server"
10
- Then I should see "Hello from the server!"
1
+ # Feature: Touch - to be run in Chrome only
2
+ # In order to value
3
+ # As a role
4
+ # I want feature
5
+ #
6
+ # @javascript
7
+ # Scenario: Client-server communication
8
+ # Given I am on the ServerCaller page for touch
9
+ # When I press button "Bug server"
10
+ # Then I should see "Hello from the server!"
@@ -0,0 +1,20 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+ require "netzke-core"
3
+
4
+ describe "Any component" do
5
+
6
+ class TestComponent < Netzke::Base
7
+
8
+ endpoint :some_action do
9
+ {}
10
+ end
11
+ end
12
+
13
+ it "should be able to register endpoints" do
14
+ TestComponent.endpoints.should include :some_action
15
+ end
16
+
17
+ it "should have deliver_component endpoint by default" do
18
+ TestComponent.endpoints.should include :deliver_component
19
+ end
20
+ end