netzke-core 0.7.7 → 0.8.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.travis.yml +1 -2
- data/CHANGELOG.md +572 -0
- data/LICENSE +7 -1
- data/README.md +345 -29
- data/Rakefile +3 -3
- data/app/controllers/netzke_controller.rb +37 -48
- data/config/ci/before-travis.sh +3 -4
- data/javascripts/base.js +86 -150
- data/javascripts/ext.js +180 -210
- data/javascripts/{core_extensions.js → js_extensions.js} +0 -0
- data/lib/netzke-core.rb +16 -6
- data/lib/netzke/base.rb +84 -107
- data/lib/netzke/core.rb +7 -41
- data/lib/netzke/core/action_config.rb +37 -0
- data/lib/netzke/core/actions.rb +123 -0
- data/lib/netzke/core/client_class.rb +252 -0
- data/lib/netzke/core/component_config.rb +12 -0
- data/lib/netzke/core/composition.rb +274 -0
- data/lib/netzke/core/config_to_dsl_delegator.rb +69 -0
- data/lib/netzke/core/configuration.rb +63 -0
- data/lib/netzke/core/css_config.rb +51 -0
- data/lib/netzke/core/dynamic_assets.rb +19 -49
- data/lib/netzke/{embedding.rb → core/embedding.rb} +4 -6
- data/lib/netzke/core/endpoint_response.rb +15 -0
- data/lib/netzke/core/javascript.rb +111 -0
- data/lib/netzke/core/panel.rb +11 -0
- data/lib/netzke/{plugins.rb → core/plugins.rb} +10 -5
- data/lib/netzke/core/railz.rb +4 -0
- data/lib/netzke/{railz → core/railz}/action_view_ext.rb +22 -18
- data/lib/netzke/core/railz/action_view_ext/ext.rb +49 -0
- data/lib/netzke/core/railz/controller_extensions.rb +17 -0
- data/lib/netzke/core/railz/engine.rb +16 -0
- data/lib/netzke/core/railz/routes.rb +10 -0
- data/lib/netzke/core/ruby_ext.rb +5 -0
- data/lib/netzke/core/ruby_ext/array.rb +23 -0
- data/lib/netzke/core/ruby_ext/hash.rb +47 -0
- data/lib/netzke/{core_ext → core/ruby_ext}/string.rb +2 -7
- data/lib/netzke/core/ruby_ext/symbol.rb +13 -0
- data/lib/netzke/{core_ext → core/ruby_ext}/time_with_zone.rb +0 -0
- data/lib/netzke/core/services.rb +130 -0
- data/lib/netzke/core/session.rb +15 -19
- data/lib/netzke/core/state.rb +40 -0
- data/lib/netzke/core/stylesheets.rb +48 -0
- data/lib/netzke/core/version.rb +2 -2
- data/lib/netzke/plugin.rb +8 -11
- data/netzke-core.gemspec +69 -59
- data/test/core_test_app/Gemfile +2 -20
- data/test/core_test_app/Gemfile.lock +65 -74
- data/test/core_test_app/app/components/card_component_loader.rb +4 -4
- data/test/core_test_app/app/components/component_loader.rb +40 -120
- data/test/core_test_app/app/components/component_loader/javascripts/component_loader.js +49 -0
- data/test/core_test_app/app/components/component_with_actions.rb +61 -47
- data/test/core_test_app/app/components/component_with_custom_css.rb +8 -5
- data/test/core_test_app/app/components/component_with_js_mixin.rb +11 -5
- data/test/core_test_app/app/components/component_with_js_mixin/javascripts/extra_one.js +1 -1
- data/test/core_test_app/app/components/component_with_js_mixin/javascripts/extra_two.js +1 -1
- data/test/core_test_app/app/components/component_with_js_mixin/javascripts/method_set_one.js +1 -1
- data/test/core_test_app/app/components/component_with_nested_through.rb +2 -2
- data/test/core_test_app/app/components/component_with_prebuilt_toolbar_control.rb +12 -0
- data/test/core_test_app/app/components/component_with_prebuilt_toolbar_control/javascripts/component_with_prebuilt_toolbar_control.js +12 -0
- data/test/core_test_app/app/components/component_with_required_js.rb +24 -0
- data/test/core_test_app/app/components/configurable_on_class_level.rb +8 -0
- data/test/core_test_app/app/components/dsl_delegated_properties.rb +4 -0
- data/test/core_test_app/app/components/dsl_delegated_properties_base.rb +5 -0
- data/test/core_test_app/app/components/dynamic_tab_panel/javascripts/dynamic_tab_panel.js +2 -2
- data/test/core_test_app/app/components/ext_direct/composite.rb +32 -33
- data/test/core_test_app/app/components/ext_direct/details.rb +2 -4
- data/test/core_test_app/app/components/ext_direct/selector.rb +20 -22
- data/test/core_test_app/app/components/ext_direct/statistics.rb +2 -4
- data/test/core_test_app/app/components/extended_component_with_actions.rb +7 -3
- data/test/core_test_app/app/components/extended_component_with_js_mixin.rb +7 -4
- data/test/core_test_app/app/components/extended_component_with_js_mixin/javascripts/some_method_set.js +1 -1
- data/test/core_test_app/app/components/extended_server_caller.rb +20 -14
- data/test/core_test_app/app/components/hello_world.rb +23 -0
- data/test/core_test_app/app/components/hello_world/javascripts/hello_world.js +12 -0
- data/test/core_test_app/app/components/included.js +2 -2
- data/test/core_test_app/app/components/kinda_complex_component.rb +1 -3
- data/test/core_test_app/app/components/kinda_complex_component/basic_stuff.rb +15 -17
- data/test/core_test_app/app/components/kinda_complex_component/extra_stuff.rb +4 -5
- data/test/core_test_app/app/components/loader_of_component_with_custom_css.rb +14 -5
- data/test/core_test_app/app/components/localized_panel.rb +23 -25
- data/test/core_test_app/app/components/multipane_component_loader.rb +19 -20
- data/test/core_test_app/app/components/nested_component.rb +4 -5
- data/test/core_test_app/app/components/panel_with_plugin.rb +8 -3
- data/test/core_test_app/app/components/panel_with_tools.rb +15 -14
- data/test/core_test_app/app/components/plugin_with_components.rb +20 -12
- data/test/core_test_app/app/components/scoped_components/deep_scoped_components/some_deep_scoped_component.rb +5 -2
- data/test/core_test_app/app/components/scoped_components/extended_scoped_component.rb +5 -2
- data/test/core_test_app/app/components/scoped_components/some_scoped_component.rb +5 -2
- data/test/core_test_app/app/components/server_caller.rb +39 -17
- data/test/core_test_app/app/components/server_caller/javascripts/server_caller.js +42 -0
- data/test/core_test_app/app/components/server_counter.rb +18 -82
- data/test/core_test_app/app/components/server_counter/javascripts/server_counter.js +53 -0
- data/test/core_test_app/app/components/simple_authentication_component.rb +46 -0
- data/test/core_test_app/app/components/simple_component.rb +8 -3
- data/test/core_test_app/app/components/simple_composite.rb +12 -0
- data/test/core_test_app/app/components/simple_form_with_file_upload.rb +49 -0
- data/test/core_test_app/app/components/simple_panel.rb +2 -2
- data/test/core_test_app/app/components/simple_tab_panel.rb +24 -3
- data/test/core_test_app/app/components/simple_window.rb +4 -2
- data/test/core_test_app/app/components/some_composite.rb +77 -48
- data/test/core_test_app/app/components/some_plugin.rb +31 -30
- data/test/core_test_app/app/components/stateful_component.rb +46 -0
- data/test/core_test_app/app/components/stateful_component_with_shared_state.rb +11 -0
- data/test/core_test_app/app/components/window_with_simple_component.rb +14 -0
- data/test/core_test_app/app/views/layouts/application.html.erb +1 -1
- data/test/core_test_app/app/views/simple_rails/multiple_nested.html.erb +7 -19
- data/test/core_test_app/app/views/simple_rails/panel.html.erb +1 -0
- data/test/core_test_app/config/database.yml.travis +3 -5
- data/test/core_test_app/config/environments/production.rb +1 -1
- data/test/core_test_app/config/initializers/netzke.rb +3 -1
- data/test/core_test_app/config/locales/en.yml +9 -4
- data/test/core_test_app/config/locales/es.yml +4 -2
- data/test/core_test_app/config/routes.rb +2 -8
- data/test/core_test_app/db/schema.rb +3 -11
- data/test/core_test_app/features/actions_and_tools.feature +1 -0
- data/test/core_test_app/features/client-server.feature +7 -0
- data/test/core_test_app/features/component_loader.feature +13 -13
- data/test/core_test_app/features/composition.feature +14 -0
- data/test/core_test_app/features/config_to_dsl_delegation.feature +10 -0
- data/test/core_test_app/features/file_inclusion.feature +1 -1
- data/test/core_test_app/features/i18n.feature +4 -4
- data/test/core_test_app/features/js_include.feature +1 -1
- data/test/core_test_app/features/persistence.feature +21 -5
- data/test/core_test_app/features/step_definitions/generic_steps.rb +14 -0
- data/test/core_test_app/features/support/paths.rb +0 -3
- data/test/core_test_app/public/images/icons/accept.png +0 -0
- data/test/core_test_app/public/images/icons/anchor.png +0 -0
- data/test/core_test_app/public/images/icons/tick.png +0 -0
- data/test/core_test_app/spec/action_config_spec.rb +15 -0
- data/test/core_test_app/spec/{component/actions_spec.rb → actions_spec.rb} +38 -36
- data/test/core_test_app/spec/base_spec.rb +35 -0
- data/test/core_test_app/spec/client_class_spec.rb +17 -0
- data/test/core_test_app/spec/component +0 -0
- data/test/core_test_app/spec/composition_spec.rb +118 -0
- data/test/core_test_app/spec/core_ext_spec.rb +3 -14
- data/test/core_test_app/spec/endpoint_response_spec.rb +17 -0
- data/test/core_test_app/spec/javascript_spec.rb +33 -0
- data/test/core_test_app/spec/js_class_config_scope.rb +37 -0
- data/test/core_test_app/spec/panel_spec.rb +11 -0
- data/test/core_test_app/spec/services_spec.rb +16 -0
- data/test/core_test_app/spec/state_spec.rb +20 -0
- data/test/unit/core_ext_test.rb +0 -53
- data/test/unit/netzke_core_test.rb +11 -11
- metadata +76 -62
- data/CHANGELOG.rdoc +0 -325
- data/javascripts/touch.js +0 -58
- data/lib/netzke/actions.rb +0 -107
- data/lib/netzke/composition.rb +0 -224
- data/lib/netzke/config_to_dsl_delegator.rb +0 -43
- data/lib/netzke/configuration.rb +0 -195
- data/lib/netzke/core/masquerading.rb +0 -34
- data/lib/netzke/core_ext.rb +0 -6
- data/lib/netzke/core_ext/array.rb +0 -30
- data/lib/netzke/core_ext/hash.rb +0 -86
- data/lib/netzke/core_ext/symbol.rb +0 -21
- data/lib/netzke/ext_component.rb +0 -25
- data/lib/netzke/inheritance.rb +0 -31
- data/lib/netzke/javascript.rb +0 -382
- data/lib/netzke/javascript/scopes.rb +0 -39
- data/lib/netzke/railz.rb +0 -4
- data/lib/netzke/railz/action_view_ext/ext.rb +0 -64
- data/lib/netzke/railz/action_view_ext/touch.rb +0 -52
- data/lib/netzke/railz/controller_extensions.rb +0 -33
- data/lib/netzke/railz/engine.rb +0 -48
- data/lib/netzke/railz/routes.rb +0 -7
- data/lib/netzke/services.rb +0 -101
- data/lib/netzke/session.rb +0 -54
- data/lib/netzke/state.rb +0 -91
- data/lib/netzke/stylesheets.rb +0 -65
- data/test/core_test_app/app/components/component_with_included_js.rb +0 -16
- data/test/core_test_app/app/components/component_with_session_persistence.rb +0 -35
- data/test/core_test_app/app/components/deprecated/server_caller.rb +0 -20
- data/test/core_test_app/app/components/dynamic_tab_panel.rb +0 -19
- data/test/core_test_app/app/components/hello_world_component.rb +0 -31
- data/test/core_test_app/app/components/touch/hello_world_component.rb +0 -25
- data/test/core_test_app/app/components/touch/server_caller.rb +0 -28
- data/test/core_test_app/app/components/touch/simple_carousel.rb +0 -17
- data/test/core_test_app/app/controllers/touch_controller.rb +0 -6
- data/test/core_test_app/app/helpers/touch_helper.rb +0 -2
- data/test/core_test_app/app/views/layouts/touch.html.erb +0 -13
- data/test/core_test_app/db/migrate/20110110132720_create_netzke_component_states.rb +0 -20
- data/test/core_test_app/features/step_definitions/touch_steps.rb +0 -3
- data/test/core_test_app/features/touch.feature +0 -10
- data/test/core_test_app/gemfiles/rails3_1.gemfile +0 -16
- data/test/core_test_app/gemfiles/rails3_2.gemfile +0 -16
- data/test/core_test_app/spec/component/base_spec.rb +0 -36
- data/test/core_test_app/spec/component/component_spec.rb +0 -20
- data/test/core_test_app/spec/component/composition_spec.rb +0 -132
- data/test/core_test_app/spec/component/configuration_spec.rb +0 -61
- data/test/core_test_app/spec/component/javascript_spec.rb +0 -16
- data/test/core_test_app/spec/component/state_spec.rb +0 -18
@@ -1,39 +0,0 @@
|
|
1
|
-
module Netzke
|
2
|
-
module Javascript
|
3
|
-
module Scopes
|
4
|
-
extend ActiveSupport::Concern
|
5
|
-
|
6
|
-
module ClassMethods
|
7
|
-
# Given class name, e.g. GridPanelLib::Components::RecordFormWindow,
|
8
|
-
# returns its scope: "Components.RecordFormWindow"
|
9
|
-
def js_class_name_to_scope(name)
|
10
|
-
name.split("::")[0..-2].join(".")
|
11
|
-
end
|
12
|
-
|
13
|
-
# Top level scope which will be used to scope out Netzke classes
|
14
|
-
def js_default_scope
|
15
|
-
"Netzke.classes"
|
16
|
-
end
|
17
|
-
|
18
|
-
# Scope of this component without default scope
|
19
|
-
# e.g.: GridPanelLib.Components
|
20
|
-
def js_scope
|
21
|
-
js_class_name_to_scope(short_component_class_name)
|
22
|
-
end
|
23
|
-
|
24
|
-
# Returns the scope of this component
|
25
|
-
# e.g. "Netzke.classes.GridPanelLib"
|
26
|
-
def js_full_scope
|
27
|
-
js_scope.empty? ? js_default_scope : [js_default_scope, js_scope].join(".")
|
28
|
-
end
|
29
|
-
|
30
|
-
# Returns the full name of the JavaScript class, including the scopes *and* the common scope, which is
|
31
|
-
# Netzke.classes.
|
32
|
-
# E.g.: "Netzke.classes.Netzke.GridPanelLib.RecordFormWindow"
|
33
|
-
def js_full_class_name
|
34
|
-
[js_full_scope, short_component_class_name.split("::").last].join(".")
|
35
|
-
end
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|
data/lib/netzke/railz.rb
DELETED
@@ -1,64 +0,0 @@
|
|
1
|
-
module Netzke
|
2
|
-
module Railz
|
3
|
-
module ActionViewExt
|
4
|
-
# Implementation of Ext-specific helpers
|
5
|
-
module Ext #:nodoc:
|
6
|
-
|
7
|
-
protected
|
8
|
-
|
9
|
-
def netzke_ext_css_include(params)
|
10
|
-
# ExtJS base
|
11
|
-
res = ["#{Netzke::Core.ext_uri}/resources/css/ext-all"]
|
12
|
-
|
13
|
-
# Netzke-related dynamic css
|
14
|
-
res << "/netzke/ext"
|
15
|
-
|
16
|
-
res += Netzke::Core.external_ext_css
|
17
|
-
|
18
|
-
stylesheet_link_tag(*res)
|
19
|
-
end
|
20
|
-
|
21
|
-
def netzke_ext_js_include(params)
|
22
|
-
res = []
|
23
|
-
|
24
|
-
# ExtJS
|
25
|
-
res << (Rails.env.development? ? "#{Netzke::Core.ext_uri}/ext-all-debug" : "#{Netzke::Core.ext_uri}/ext-all")
|
26
|
-
|
27
|
-
# ExtJS 3 compatibility layer
|
28
|
-
if compat_uri = Netzke::Core.ext3_compat_uri
|
29
|
-
res << "#{compat_uri}/ext3-core-compat"
|
30
|
-
res << "#{compat_uri}/ext3-compat"
|
31
|
-
end
|
32
|
-
|
33
|
-
# Ext I18n
|
34
|
-
res << "#{Netzke::Core.ext_uri}/locale/ext-lang-#{I18n.locale}" if I18n.locale != :en
|
35
|
-
|
36
|
-
# Netzke-related dynamic JavaScript
|
37
|
-
res << "/netzke/ext"
|
38
|
-
|
39
|
-
javascript_include_tag(*res)
|
40
|
-
end
|
41
|
-
|
42
|
-
def netzke_ext_js(params)
|
43
|
-
res = []
|
44
|
-
res << content_for(:netzke_js_classes)
|
45
|
-
|
46
|
-
res << "Ext.onReady(function(){"
|
47
|
-
res << content_for(:netzke_on_ready)
|
48
|
-
res << "});"
|
49
|
-
|
50
|
-
javascript_tag(res.join("\n"))
|
51
|
-
end
|
52
|
-
|
53
|
-
# (Experimental) Embeds a "pure" (non-Netzke) Ext component into the view, e.g.:
|
54
|
-
# <%= ext :my_panel, :xtype => :panel, :html => "Simple Panel"
|
55
|
-
def ext(name, config = {}) #:doc:
|
56
|
-
comp = Netzke::ExtComponent.new(name, config)
|
57
|
-
content_for :netzke_on_ready, raw("#{comp.js_component_render}")
|
58
|
-
raw(comp.js_component_html)
|
59
|
-
end
|
60
|
-
|
61
|
-
end
|
62
|
-
end
|
63
|
-
end
|
64
|
-
end
|
@@ -1,52 +0,0 @@
|
|
1
|
-
module Netzke
|
2
|
-
module Railz
|
3
|
-
module ActionViewExt
|
4
|
-
# Implementation of Touch-specific helpers
|
5
|
-
module Touch #:nodoc:
|
6
|
-
|
7
|
-
protected
|
8
|
-
|
9
|
-
def netzke_touch_css_include(params)
|
10
|
-
# Note: no themes for now
|
11
|
-
|
12
|
-
res = stylesheet_link_tag("#{Netzke::Core.touch_uri}/resources/css/sencha-touch")
|
13
|
-
|
14
|
-
# Netzke-related (dynamically generated by NetzkeController)
|
15
|
-
res << "\n" << stylesheet_link_tag("/netzke/touch")
|
16
|
-
|
17
|
-
res
|
18
|
-
end
|
19
|
-
|
20
|
-
def netzke_touch_js(params)
|
21
|
-
res = []
|
22
|
-
res << content_for(:netzke_js_classes)
|
23
|
-
res << "\n"
|
24
|
-
|
25
|
-
res << "Ext.setup({"
|
26
|
-
res << "onReady: function(){"
|
27
|
-
res << content_for(:netzke_on_ready)
|
28
|
-
res << "}"
|
29
|
-
res << "});"
|
30
|
-
|
31
|
-
javascript_tag res.join("\n")
|
32
|
-
end
|
33
|
-
|
34
|
-
|
35
|
-
def netzke_touch_js_include(params)
|
36
|
-
# ExtJS
|
37
|
-
res = if ENV['RAILS_ENV'] == 'development'
|
38
|
-
["#{Netzke::Core.touch_uri}/sencha-touch-debug.js"]
|
39
|
-
else
|
40
|
-
["#{Netzke::Core.touch_uri}/sencha-touch"]
|
41
|
-
end
|
42
|
-
|
43
|
-
# Netzke
|
44
|
-
res << "/netzke/touch"
|
45
|
-
|
46
|
-
javascript_include_tag(res, :cache => params[:cache])
|
47
|
-
end
|
48
|
-
|
49
|
-
end
|
50
|
-
end
|
51
|
-
end
|
52
|
-
end
|
@@ -1,33 +0,0 @@
|
|
1
|
-
module Netzke
|
2
|
-
module Railz
|
3
|
-
module ControllerExtensions
|
4
|
-
def self.included(base)
|
5
|
-
base.send(:before_filter, :set_session_data)
|
6
|
-
base.send(:before_filter, :set_controller)
|
7
|
-
end
|
8
|
-
|
9
|
-
def set_session_data
|
10
|
-
::Netzke::Core.session = session
|
11
|
-
session[:netzke_user_id] = defined?(current_user) ? current_user.try(:id) : nil
|
12
|
-
# set netzke_just_logged_in and netzke_just_logged_out states (may be used by Netzke components)
|
13
|
-
if session[:_netzke_next_request_is_first_after_login]
|
14
|
-
session[:netzke_just_logged_in] = true
|
15
|
-
session[:_netzke_next_request_is_first_after_login] = false
|
16
|
-
else
|
17
|
-
session[:netzke_just_logged_in] = false
|
18
|
-
end
|
19
|
-
|
20
|
-
if session[:_netzke_next_request_is_first_after_logout]
|
21
|
-
session[:netzke_just_logged_out] = true
|
22
|
-
session[:_netzke_next_request_is_first_after_logout] = false
|
23
|
-
else
|
24
|
-
session[:netzke_just_logged_out] = false
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
def set_controller
|
29
|
-
::Netzke::Core.controller = self
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
data/lib/netzke/railz/engine.rb
DELETED
@@ -1,48 +0,0 @@
|
|
1
|
-
module Netzke
|
2
|
-
module Railz
|
3
|
-
class Engine < Rails::Engine
|
4
|
-
config.netzke = Netzke::Core::OptionsHash.new
|
5
|
-
|
6
|
-
initializer "netzke.core" do |app|
|
7
|
-
app.config.eager_load_paths -= ["#{app.config.root}/app/components"]
|
8
|
-
app.config.autoload_paths += ["#{app.config.root}/app/components"]
|
9
|
-
end
|
10
|
-
|
11
|
-
# before loading initializers
|
12
|
-
config.before_initialize do |app|
|
13
|
-
Netzke::Core.config = config.netzke # passing app-level config to Netzke::Core
|
14
|
-
Netzke::Core.persistence_manager_class = Netzke::Core.persistence_manager.constantize rescue nil
|
15
|
-
end
|
16
|
-
|
17
|
-
# after loading initializers
|
18
|
-
config.after_initialize do
|
19
|
-
Netzke::Core.ext_path = Rails.root.join('public', Netzke::Core.ext_uri[1..-1])
|
20
|
-
Netzke::Core.with_icons = File.exists?("#{::Rails.root}/public#{Netzke::Core.icons_uri}") if Netzke::Core.with_icons.nil?
|
21
|
-
|
22
|
-
# Dynamic generation of Netzke js and css.
|
23
|
-
# WIP: the problem with this is that on Heroku, for example, you don't have write access to 'public'.
|
24
|
-
# dynamic_assets = %w[ext.js ext.css touch.js touch.css]
|
25
|
-
#
|
26
|
-
# if Rails.configuration.cache_classes
|
27
|
-
# # Memoize Netzke::Base.constantize_class_name for performance
|
28
|
-
# class << Netzke::Base
|
29
|
-
# memoize :constantize_class_name
|
30
|
-
# end
|
31
|
-
#
|
32
|
-
# # Generate dynamic assets and put them into public/netzke
|
33
|
-
# require 'fileutils'
|
34
|
-
# FileUtils.mkdir_p(Rails.root.join('public', 'netzke'))
|
35
|
-
#
|
36
|
-
# dynamic_assets.each do |asset|
|
37
|
-
# File.open(Rails.root.join('public', 'netzke', asset), 'w') {|f| f.write(Netzke::Core::DynamicAssets.send(asset.sub(".", "_"))) }
|
38
|
-
# end
|
39
|
-
# else
|
40
|
-
# dynamic_assets.each do |asset|
|
41
|
-
# file_path = Rails.root.join('public', 'netzke', asset)
|
42
|
-
# File.delete(file_path) if File.exists?(file_path)
|
43
|
-
# end
|
44
|
-
# end
|
45
|
-
end
|
46
|
-
end
|
47
|
-
end
|
48
|
-
end
|
data/lib/netzke/railz/routes.rb
DELETED
data/lib/netzke/services.rb
DELETED
@@ -1,101 +0,0 @@
|
|
1
|
-
module Netzke
|
2
|
-
# This module takes care of components' client-server communication.
|
3
|
-
module Services
|
4
|
-
extend ActiveSupport::Concern
|
5
|
-
|
6
|
-
included do
|
7
|
-
# Returns all endpoints as a hash
|
8
|
-
class_attribute :endpoints
|
9
|
-
self.endpoints = {}
|
10
|
-
end
|
11
|
-
|
12
|
-
module ClassMethods
|
13
|
-
# Defines an endpoint - a connection point between the client side of a component and its server side. For example:
|
14
|
-
#
|
15
|
-
# endpoint :do_something do |params|
|
16
|
-
# # ...
|
17
|
-
# end
|
18
|
-
#
|
19
|
-
# By defining the endpoint on the server, the client side automatically gets a method that is used to call the server, in this case `doSomething` (note conversion from underscore to camelcase). It can be called like this:
|
20
|
-
#
|
21
|
-
# this.doSomething(argsObject, callbackFunction, scope);
|
22
|
-
#
|
23
|
-
# * +argsObject+ is what the server side will receive as the +params+ argument
|
24
|
-
# * +callbackFunction+ (optional) will be called after the server successfully processes the request
|
25
|
-
# * +scope+ (optional) the scope in which +callbackFunction+ will be called
|
26
|
-
#
|
27
|
-
# The callback function may receive an argument which will be set to the value that the server passes to the special +set_result+ key in the resulting hash:
|
28
|
-
#
|
29
|
-
# endpoint :do_something do |params|
|
30
|
-
# # ...
|
31
|
-
# {:set_result => 42}
|
32
|
-
# end
|
33
|
-
#
|
34
|
-
# Any other key in the resulting hash will result in a corresponding JavaScript-side function call, with the parameter set to the value of that key. For example:
|
35
|
-
#
|
36
|
-
# endpoint :do_something do |params|
|
37
|
-
# # ...
|
38
|
-
# {:set_result => 42, :set_title => "New title, set by the server"}
|
39
|
-
# end
|
40
|
-
#
|
41
|
-
# This will result in the call to the +setTitle+ method on the client side of the component, with "New title, set by the server" as the parameter.
|
42
|
-
def endpoint(name, options = {}, &block)
|
43
|
-
register_endpoint(name, options)
|
44
|
-
define_method("#{name}_endpoint", &block) if block # if no block is given, the method is supposed to be defined elsewhere
|
45
|
-
|
46
|
-
# define_method name, &block if block # if no block is given, the method is supposed to be defined elsewhere
|
47
|
-
define_method :"_#{name}_ep_wrapper" do |*args|
|
48
|
-
res = send("#{name}_endpoint", *args)
|
49
|
-
res.respond_to?(:to_nifty_json) && res.to_nifty_json || ""
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
|
-
def api(*api_points) #:nodoc:
|
54
|
-
::ActiveSupport::Deprecation.warn("Using the 'api' call has no longer effect. Define endpoints instead.", caller)
|
55
|
-
end
|
56
|
-
|
57
|
-
protected
|
58
|
-
|
59
|
-
# Registers an endpoint
|
60
|
-
def register_endpoint(ep, options)
|
61
|
-
self.endpoints = self.endpoints.dup.merge(ep => options)
|
62
|
-
end
|
63
|
-
|
64
|
-
end
|
65
|
-
|
66
|
-
# Invokes endpoint calls
|
67
|
-
# +endpoint+ may contain the path to the endpoint in a component down the hierarchy, e.g.:
|
68
|
-
#
|
69
|
-
# invoke_endpoint(:users__center__get_data, params)
|
70
|
-
def invoke_endpoint(endpoint, params)
|
71
|
-
ep_config = self.class.endpoints[endpoint.to_sym]
|
72
|
-
|
73
|
-
if respond_to?("_#{endpoint}_ep_wrapper")
|
74
|
-
# we have this endpoint defined
|
75
|
-
send("_#{endpoint}_ep_wrapper", params)
|
76
|
-
elsif respond_to?(endpoint)
|
77
|
-
# for backward compatibility
|
78
|
-
::ActiveSupport::Deprecation.warn("When overriding endpoints, use the '_endpoint' suffix (concerns: #{endpoint})", caller)
|
79
|
-
send(endpoint, params)
|
80
|
-
elsif respond_to?("#{endpoint}_endpoint")
|
81
|
-
# for backward compatibility
|
82
|
-
send("#{endpoint}_endpoint", params)
|
83
|
-
else
|
84
|
-
# Let's try to find it recursively in a component down the hierarchy
|
85
|
-
child_component, *action = endpoint.to_s.split('__')
|
86
|
-
child_component = child_component.to_sym
|
87
|
-
action = !action.empty? && action.join("__").to_sym
|
88
|
-
|
89
|
-
raise RuntimeError, "Component '#{self.class.name}' does not have endpoint '#{endpoint}'" if !action
|
90
|
-
|
91
|
-
if components[child_component]
|
92
|
-
component_instance(child_component).invoke_endpoint(action, params)
|
93
|
-
else
|
94
|
-
# component_missing can be overridden if necessary
|
95
|
-
component_missing(child_component)
|
96
|
-
end
|
97
|
-
end
|
98
|
-
end
|
99
|
-
|
100
|
-
end
|
101
|
-
end
|
data/lib/netzke/session.rb
DELETED
@@ -1,54 +0,0 @@
|
|
1
|
-
module Netzke
|
2
|
-
# This modules provides (component-specific) session manupulation.
|
3
|
-
# The :session_persistence config option should be set to true in order for the component to make use of this.
|
4
|
-
module Session
|
5
|
-
class ComponentSessionProxy < Hash #:nodoc:
|
6
|
-
def initialize(component_id)
|
7
|
-
@component_id = component_id
|
8
|
-
super
|
9
|
-
end
|
10
|
-
|
11
|
-
def [](key)
|
12
|
-
(Netzke::Core.session[@component_id] || {})[key]
|
13
|
-
end
|
14
|
-
|
15
|
-
def []=(key, value)
|
16
|
-
(Netzke::Core.session[@component_id] ||= {})[key] = value
|
17
|
-
# super
|
18
|
-
end
|
19
|
-
|
20
|
-
def clear
|
21
|
-
Netzke::Core.session[@component_id].clear if Netzke::Core.session[@component_id]
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
# Top-level session (straight from the controller).
|
26
|
-
def session
|
27
|
-
::Netzke::Core.session
|
28
|
-
end
|
29
|
-
|
30
|
-
# Component-specific session.
|
31
|
-
def component_session
|
32
|
-
@component_session_proxy ||= ComponentSessionProxy.new(global_id)
|
33
|
-
end
|
34
|
-
|
35
|
-
# Returns this component's configuration options stored in the session. Those get merged into the component's configuration at instantiation.
|
36
|
-
def session_options
|
37
|
-
session_persistence_enabled? && component_session[:options] || {}
|
38
|
-
end
|
39
|
-
|
40
|
-
# Updates the session options
|
41
|
-
def update_session_options(hash)
|
42
|
-
if session_persistence_enabled?
|
43
|
-
component_session.deep_merge!(:options => hash)
|
44
|
-
else
|
45
|
-
logger.debug "Netzke warning: No session persistence enabled for component '#{global_id}'"
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
|
-
private
|
50
|
-
def session_persistence_enabled?
|
51
|
-
initial_config[:session_persistence]
|
52
|
-
end
|
53
|
-
end
|
54
|
-
end
|
data/lib/netzke/state.rb
DELETED
@@ -1,91 +0,0 @@
|
|
1
|
-
require 'active_support/core_ext/hash/indifferent_access'
|
2
|
-
module Netzke
|
3
|
-
# When a persistence subsystem (such as {netzke-persistence}[https://github.com/skozlov/netzke-persistence]) is used, a widget can store its state using the +update_state+ method that accepts a hash, e.g.:
|
4
|
-
# update_state(:position => {:x => 100, :y => 200})
|
5
|
-
#
|
6
|
-
# Later the state can be retrieved by calling the +state+ method:
|
7
|
-
#
|
8
|
-
# state[:position] #=> {:x => 100, :y => 200}
|
9
|
-
#
|
10
|
-
# To enable persistence for a specific component, configure it with +persistence+ option set to +true+.
|
11
|
-
#
|
12
|
-
# == Sharing state
|
13
|
-
#
|
14
|
-
# Different components can share the state by sharing the persistence key, which can be provided as configuration option, e.g.:
|
15
|
-
#
|
16
|
-
# netzke :books, :class_name => "Basepack::GridPanel", :persistence_key => "books_state_identifier"
|
17
|
-
# netzke :deleted_books, :class_name => "Basepack::GridPanel", :persistence_key => "books_state_identifier"
|
18
|
-
#
|
19
|
-
# Make sure that the provided persistence_key has effect on _application_ level, _not_ only within the view.
|
20
|
-
# By default persistence_key is set to component's global id. Thus, <i>two components named equally will share the state even being used in different views</i>.
|
21
|
-
#
|
22
|
-
module State
|
23
|
-
# A string which will identify the component in persistence subsystem.
|
24
|
-
# If +persistence_key+ is passed, use it. Otherwise use global_id.
|
25
|
-
def persistence_key
|
26
|
-
initial_config[:persistence_key] ? initial_config[:persistence_key] : global_id
|
27
|
-
end
|
28
|
-
|
29
|
-
# Component's persistent state.
|
30
|
-
def state
|
31
|
-
@state ||= (state_manager.try(:state) || {}).symbolize_keys
|
32
|
-
end
|
33
|
-
|
34
|
-
# Merges passed hash into component's state.
|
35
|
-
# Can also accept 2 arguments which will be treated as a hash pair. E.g.:
|
36
|
-
#
|
37
|
-
# update_state(:peoples_most_feared_number, 13)
|
38
|
-
#
|
39
|
-
# is equivalent to:
|
40
|
-
#
|
41
|
-
# update_state(:peoples_most_feared_number => 13)
|
42
|
-
def update_state(*args)
|
43
|
-
state_manager.try(:update_state!, args.first.is_a?(Hash) ? args.first : {args.first => args.last})
|
44
|
-
@state = nil # reset cache
|
45
|
-
end
|
46
|
-
|
47
|
-
# Component's persistent state.
|
48
|
-
def global_state
|
49
|
-
@global_state ||= (global_state_manager.try(:state) || {}).symbolize_keys
|
50
|
-
end
|
51
|
-
|
52
|
-
# Merges passed hash into component's state.
|
53
|
-
def update_global_state(hsh)
|
54
|
-
global_state_manager.try(:update_state!, hsh)
|
55
|
-
@global_state = nil # reset cache
|
56
|
-
end
|
57
|
-
|
58
|
-
# Options merged into component's configuration right after default and user-passed config, thus being reflected in +Netzke::Base#independent_config+ (see Netzke::Configuration).
|
59
|
-
def persistent_options
|
60
|
-
(state[:persistent_options] || {}).symbolize_keys
|
61
|
-
end
|
62
|
-
|
63
|
-
# Updates +persistent_options+
|
64
|
-
def update_persistent_options(hsh)
|
65
|
-
new_persistent_options = persistent_options.merge(hsh)
|
66
|
-
new_persistent_options.delete_if{ |k,v| v.nil? } # setting values to nil means deleting them
|
67
|
-
update_state(:persistent_options => new_persistent_options)
|
68
|
-
end
|
69
|
-
|
70
|
-
protected
|
71
|
-
|
72
|
-
# Initialized state manager class. At this moment this class has current_user, component, and session set.
|
73
|
-
def state_manager
|
74
|
-
Netzke::Core.persistence_manager_class && Netzke::Core.persistence_manager_class.init({
|
75
|
-
:component => persistence_key,
|
76
|
-
:current_user => Netzke::Core.controller.respond_to?(:current_user) && Netzke::Core.controller.current_user,
|
77
|
-
:session => Netzke::Core.session
|
78
|
-
})
|
79
|
-
end
|
80
|
-
|
81
|
-
# Initialized state manager class, configured for managing global (not component specific) settings. At this moment this class has current_user and session set.
|
82
|
-
def global_state_manager
|
83
|
-
Netzke::Core.persistence_manager_class && Netzke::Core.persistence_manager_class.init({
|
84
|
-
:current_user => Netzke::Core.controller.respond_to?(:current_user) && Netzke::Core.controller.current_user,
|
85
|
-
:session => Netzke::Core.session
|
86
|
-
})
|
87
|
-
end
|
88
|
-
|
89
|
-
|
90
|
-
end
|
91
|
-
end
|