infopark_fiona7 0.30.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/README.md +3 -0
- data/Rakefile +21 -0
- data/app/assets/images/fiona7-logo.png +0 -0
- data/app/assets/images/fiona7-marker.png +0 -0
- data/app/assets/javascripts/fiona7.js +284 -0
- data/app/assets/stylesheets/fiona7-login.css.scss +15 -0
- data/app/assets/stylesheets/fiona7.css.scss +83 -0
- data/app/controllers/fiona7/blobs_controller.rb +35 -0
- data/app/controllers/fiona7/default_scrivito_cms_controller.rb +16 -0
- data/app/controllers/fiona7/release_controller.rb +24 -0
- data/app/controllers/fiona7/sessions_controller.rb +49 -0
- data/app/controllers/fiona7_login_page_controller.rb +27 -0
- data/app/helpers/fiona7_login_helper.rb +18 -0
- data/app/helpers/fiona7_override_helper.rb +47 -0
- data/app/models/fiona7/edited_obj.rb +15 -0
- data/app/models/fiona7/internal_released_obj.rb +18 -0
- data/app/models/fiona7/released_obj.rb +18 -0
- data/app/models/fiona7/write_obj.rb +63 -0
- data/app/models/fiona7_login_page.rb +5 -0
- data/app/models/x_container.rb +5 -0
- data/app/models/x_generic.rb +5 -0
- data/app/models/x_image.rb +5 -0
- data/app/views/fiona7_login_page/index.html.erb +14 -0
- data/app/views/layouts/fiona7_login_page_layout.html.erb +23 -0
- data/config/locales/login.yml +19 -0
- data/config/locales/permissions.yml +7 -0
- data/config/routes.rb +9 -0
- data/lib/fiona7/assert.rb +17 -0
- data/lib/fiona7/builder/batch_widget_writer.rb +107 -0
- data/lib/fiona7/builder/obj_builder.rb +297 -0
- data/lib/fiona7/builder/obj_class_builder.rb +111 -0
- data/lib/fiona7/builder/obj_class_updater.rb +69 -0
- data/lib/fiona7/builder/obj_updater.rb +25 -0
- data/lib/fiona7/builder/widget_builder.rb +13 -0
- data/lib/fiona7/builder/widget_building.rb +35 -0
- data/lib/fiona7/builder/widget_updater.rb +13 -0
- data/lib/fiona7/controllers/content_service/obj_controller.rb +125 -0
- data/lib/fiona7/controllers/content_service/workspace_controller.rb +19 -0
- data/lib/fiona7/controllers/rest_api/blob_controller.rb +11 -0
- data/lib/fiona7/controllers/rest_api/obj_class_controller.rb +39 -0
- data/lib/fiona7/controllers/rest_api/obj_controller.rb +175 -0
- data/lib/fiona7/controllers/rest_api/workspace_controller.rb +58 -0
- data/lib/fiona7/engine.rb +138 -0
- data/lib/fiona7/fiona_connector_patches/basic_obj.rb +9 -0
- data/lib/fiona7/initializer.rb +78 -0
- data/lib/fiona7/json/obj_class_decorator.rb +45 -0
- data/lib/fiona7/json/obj_decorator.rb +153 -0
- data/lib/fiona7/json/typeless_obj_decorator.rb +30 -0
- data/lib/fiona7/json/widget_decorator.rb +18 -0
- data/lib/fiona7/link_converter/fiona_to_scrivito.rb +37 -0
- data/lib/fiona7/link_converter/scrivito_to_fiona.rb +42 -0
- data/lib/fiona7/mode_switch.rb +7 -0
- data/lib/fiona7/mode_switch/abstract_mode_switch.rb +19 -0
- data/lib/fiona7/mode_switch/cms_routes.rb +33 -0
- data/lib/fiona7/mode_switch/cms_routes/fiona_connector.rb +17 -0
- data/lib/fiona7/mode_switch/cms_routes/scrivito_sdk.rb +20 -0
- data/lib/fiona7/mode_switch/cms_routes/scrivito_sdk_slave.rb +20 -0
- data/lib/fiona7/mode_switch/composite.rb +33 -0
- data/lib/fiona7/mode_switch/constants.rb +86 -0
- data/lib/fiona7/mode_switch/views.rb +37 -0
- data/lib/fiona7/naive_search_engine.rb +111 -0
- data/lib/fiona7/recursive_link_resolver.rb +93 -0
- data/lib/fiona7/routers/content_service.rb +19 -0
- data/lib/fiona7/routers/rest_api.rb +135 -0
- data/lib/fiona7/routing_monkey_patch.rb +33 -0
- data/lib/fiona7/scrivito_patches/attribute_content.rb +19 -0
- data/lib/fiona7/scrivito_patches/basic_obj.rb +92 -0
- data/lib/fiona7/scrivito_patches/basic_widget.rb +14 -0
- data/lib/fiona7/scrivito_patches/binary.rb +55 -0
- data/lib/fiona7/scrivito_patches/client_config.rb +19 -0
- data/lib/fiona7/scrivito_patches/cms_dispatch_controller.rb +31 -0
- data/lib/fiona7/scrivito_patches/cms_rest_api.rb +11 -0
- data/lib/fiona7/scrivito_patches/cms_routing.rb +66 -0
- data/lib/fiona7/scrivito_patches/controller_actions.rb +14 -0
- data/lib/fiona7/scrivito_patches/link_parser.rb +22 -0
- data/lib/fiona7/scrivito_patches/migrator.rb +13 -0
- data/lib/fiona7/scrivito_patches/obj_class.rb +16 -0
- data/lib/fiona7/scrivito_patches/type_computer.rb +25 -0
- data/lib/fiona7/scrivito_patches/workspace.rb +12 -0
- data/lib/fiona7/scrivito_user.rb +44 -0
- data/lib/fiona7/search_engine.rb +20 -0
- data/lib/fiona7/type_register.rb +140 -0
- data/lib/fiona7/type_register_mixin.rb +9 -0
- data/lib/fiona7/version.rb +3 -0
- data/lib/fiona7/version_helper.rb +84 -0
- data/lib/fiona7/widget_resolver.rb +37 -0
- data/lib/fiona7/workspace.rb +76 -0
- data/lib/infopark_fiona7.rb +4 -0
- data/lib/tasks/fiona7_tasks.rake +13 -0
- metadata +216 -0
@@ -0,0 +1,16 @@
|
|
1
|
+
module Fiona7
|
2
|
+
class DefaultScrivitoCmsController < ActionController::Base
|
3
|
+
include Scrivito::ControllerActions
|
4
|
+
before_filter :assert_legacy_mode
|
5
|
+
|
6
|
+
def index
|
7
|
+
return deliver_file if @obj.binary?
|
8
|
+
return redirect_to cms_path(@obj.fiona_obj)
|
9
|
+
end
|
10
|
+
|
11
|
+
protected
|
12
|
+
def assert_legacy_mode
|
13
|
+
raise "This controller should not be invoked outside legacy mode" unless Fiona7.mode == :legacy
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module Fiona7
|
2
|
+
class ReleaseController < ActionController::Base
|
3
|
+
def release
|
4
|
+
@releasable = Set.new
|
5
|
+
|
6
|
+
@obj = WriteObj.find(params[:id])
|
7
|
+
|
8
|
+
@releasable.merge(widgets(@obj))
|
9
|
+
@releasable << @obj
|
10
|
+
|
11
|
+
@releasable.each do |obj|
|
12
|
+
obj.release! if obj.really_edited?
|
13
|
+
end
|
14
|
+
|
15
|
+
render json: {}
|
16
|
+
end
|
17
|
+
|
18
|
+
protected
|
19
|
+
def widgets(obj)
|
20
|
+
links = @obj[:X_widget_pool] || []
|
21
|
+
WriteObj.where(obj_id: links.map {|l| l.destination_object_id }).to_a
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
module Fiona7
|
2
|
+
class SessionsController < ActionController::Base
|
3
|
+
before_filter :load_login_page
|
4
|
+
|
5
|
+
def create
|
6
|
+
login, password = params[:login], params[:password]
|
7
|
+
if valid_credentials?(login, password)
|
8
|
+
rsession.user_name = login
|
9
|
+
|
10
|
+
redirect_to true_root_path
|
11
|
+
else
|
12
|
+
flash[:error] = I18n.t(:"fiona7.invalid_credentails")
|
13
|
+
begin
|
14
|
+
redirect_to :back
|
15
|
+
rescue ActionController::RedirectBackError
|
16
|
+
redirect_to scrivito_path(@login_page)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def destroy
|
22
|
+
rsession.destroy
|
23
|
+
redirect_to true_root_path
|
24
|
+
end
|
25
|
+
|
26
|
+
protected
|
27
|
+
def load_login_page
|
28
|
+
@login_page = Fiona7LoginPage.instance || Scrivito::BasicObj.root
|
29
|
+
end
|
30
|
+
|
31
|
+
def true_root_path
|
32
|
+
if Fiona7.mode == :standalone
|
33
|
+
scrivito_root_path
|
34
|
+
elsif Fiona7.mode == :legacy
|
35
|
+
root_path
|
36
|
+
else
|
37
|
+
raise "Invalid Fiona7.mode = #{Fiona7.mode}"
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def valid_credentials?(login, password)
|
42
|
+
current_login = rsession.user_name
|
43
|
+
rsession.user_name = 'root'
|
44
|
+
Reactor::Cm::User.new(login).has_password?(password)
|
45
|
+
ensure
|
46
|
+
rsession.user_name = current_login unless rsession.user_name == current_login
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
begin
|
2
|
+
parent_class = CmsController
|
3
|
+
if !parent_class.include?(Scrivito::ControllerActions)
|
4
|
+
parent_class = ActionController::Base
|
5
|
+
end
|
6
|
+
rescue NameError
|
7
|
+
begin
|
8
|
+
parent_class = ApplicationController
|
9
|
+
rescue NameError
|
10
|
+
parent_class = ActionController::Base
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
class Fiona7LoginPageController < parent_class
|
15
|
+
if !self.include?(Scrivito::ControllerActions)
|
16
|
+
layout "fiona7_login_page_layout"
|
17
|
+
include Scrivito::ControllerActions
|
18
|
+
end
|
19
|
+
|
20
|
+
def index
|
21
|
+
super
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.use_for_obj_dispatch?
|
25
|
+
true
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module Fiona7LoginHelper
|
2
|
+
def fiona7_logged_in?
|
3
|
+
rsession.user?
|
4
|
+
end
|
5
|
+
|
6
|
+
def fiona7_login_button(classes='navbar-btn navbar-right')
|
7
|
+
if fiona7_logged_in?
|
8
|
+
link_to fiona7_logout_path, class: classes, method: :delete do
|
9
|
+
"<button class=\"btn btn-warning\">#{t(:'fiona7.logout')}</button>".html_safe
|
10
|
+
end
|
11
|
+
else
|
12
|
+
|
13
|
+
link_to scrivito_path(Fiona7LoginPage.instance || raise("Object of class 'Fiona7LoginPage' count not be found in the CM")), class: classes do
|
14
|
+
"<button class=\"btn btn-success\">#{t(:'fiona7.login')}</button>".html_safe
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
module Fiona7OverrideHelper
|
2
|
+
include ScrivitoHelper
|
3
|
+
{
|
4
|
+
'cms_image_tag' => 'scrivito_image_tag',
|
5
|
+
'cms_path' => 'scrivito_path',
|
6
|
+
'cms_tag' => 'scrivito_tag',
|
7
|
+
'cms_tag_list' => 'scrivito_tag_list',
|
8
|
+
'cms_url' => 'scrivito_url',
|
9
|
+
'display_field' => 'scrivito_field',
|
10
|
+
'display_value' => 'scrivito_value',
|
11
|
+
'scrivito_after_content_tags' => 'scrivito_body_tags',
|
12
|
+
'scrivito_header_tags' => 'scrivito_head_tags',
|
13
|
+
}.each_pair do |old_method_name, new_method_name|
|
14
|
+
ScrivitoHelper.send(:remove_method, old_method_name) if ScrivitoHelper.method_defined?(old_method_name)
|
15
|
+
end
|
16
|
+
|
17
|
+
def scrivito_body_tags
|
18
|
+
obj = @obj.kind_of?(RailsConnector::BasicObj) ? @obj.scrivito_obj : @obj
|
19
|
+
Scrivito::LayoutTags.new(self).client_config(obj, @scrivito_resource)
|
20
|
+
end
|
21
|
+
|
22
|
+
def fiona7_head_tags
|
23
|
+
scrivito_head_tags
|
24
|
+
end
|
25
|
+
|
26
|
+
def fiona7_body_tags
|
27
|
+
scrivito_body_tags
|
28
|
+
end
|
29
|
+
|
30
|
+
def fiona7_tag(tag_name, obj_or_widget, field_name, html_options = {}, &block)
|
31
|
+
raise "This method can only be used in legacy mode" unless Fiona7.mode == :legacy
|
32
|
+
|
33
|
+
obj_or_widget = obj_or_widget.kind_of?(RailsConnector::BasicObj) ? obj_or_widget.scrivito_obj : obj_or_widget
|
34
|
+
scrivito_tag(tag_name, obj_or_widget, field_name, html_options, &block)
|
35
|
+
end
|
36
|
+
|
37
|
+
def fiona7_tag_list(tag_name, obj, field_name, options = {}, &block)
|
38
|
+
raise "This method can only be used in legacy mode" unless Fiona7.mode == :legacy
|
39
|
+
|
40
|
+
obj = obj.kind_of?(RailsConnector::BasicObj) ? obj.scrivito_obj : obj
|
41
|
+
scrivito_tag_list(tag_name, obj, field_name, options) do |list, scrivito_child|
|
42
|
+
block.call(list, scrivito_child.fiona_obj)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
|
47
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
#require 'fiona7/write_obj'
|
2
|
+
|
3
|
+
module Fiona7
|
4
|
+
class EditedObj < WriteObj
|
5
|
+
self.configure_for_content(:edited)
|
6
|
+
|
7
|
+
has_many :children, :class_name => self.name, :foreign_key => 'parent_obj_id'
|
8
|
+
belongs_to :parent, :class_name => self.name, :foreign_key => 'parent_obj_id'
|
9
|
+
|
10
|
+
default_scope { where('suppress_export = 0 AND obj_class NOT IN (?)', ['X_Generic', 'X_Image', 'X_Container']) }
|
11
|
+
|
12
|
+
# disable STI
|
13
|
+
self.inheritance_column = :_type_disabled
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
#require 'fiona7/write_obj'
|
2
|
+
|
3
|
+
module Fiona7
|
4
|
+
class InternalReleasedObj < WriteObj
|
5
|
+
self.configure_for_content(:released)
|
6
|
+
|
7
|
+
has_many :children, :class_name => self.name, :foreign_key => 'parent_obj_id'
|
8
|
+
belongs_to :parent, :class_name => self.name, :foreign_key => 'parent_obj_id'
|
9
|
+
|
10
|
+
default_scope do
|
11
|
+
now = Time.now.utc.to_iso
|
12
|
+
where("is_released = 1 AND suppress_export = 0").where("(valid_from IS NULL or valid_from <= :now) and (valid_until IS NULL or valid_until >= :now)", :now => now)
|
13
|
+
end
|
14
|
+
|
15
|
+
# disable STI
|
16
|
+
self.inheritance_column = :_type_disabled
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
#require 'fiona7/write_obj'
|
2
|
+
|
3
|
+
module Fiona7
|
4
|
+
class ReleasedObj < WriteObj
|
5
|
+
self.configure_for_content(:released)
|
6
|
+
|
7
|
+
has_many :children, :class_name => self.name, :foreign_key => 'parent_obj_id'
|
8
|
+
belongs_to :parent, :class_name => self.name, :foreign_key => 'parent_obj_id'
|
9
|
+
|
10
|
+
default_scope do
|
11
|
+
now = Time.now.utc.to_iso
|
12
|
+
where("is_released = 1 AND suppress_export = 0").where('obj_class NOT IN (?)', ['X_Generic', 'X_Image', 'X_Container']).where("(valid_from IS NULL or valid_from <= :now) and (valid_until IS NULL or valid_until >= :now)", :now => now)
|
13
|
+
end
|
14
|
+
|
15
|
+
# disable STI
|
16
|
+
self.inheritance_column = :_type_disabled
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
require 'set'
|
2
|
+
require 'fiona7/json/obj_decorator'
|
3
|
+
|
4
|
+
module Fiona7
|
5
|
+
WriteObj = RailsConnector::AbstractObj
|
6
|
+
|
7
|
+
class WriteObj
|
8
|
+
BLACKLISTED_CLASSES = Set[
|
9
|
+
'RailsConnector::BasicObj',
|
10
|
+
'RailsConnector::AbstractObj',
|
11
|
+
'Fiona7::WriteObj',
|
12
|
+
'Fiona7::EditedObj',
|
13
|
+
'Fiona7::ReleasedObj',
|
14
|
+
'Fiona7::InternalReleasedObj'
|
15
|
+
]
|
16
|
+
|
17
|
+
self.configure_for_content(:edited)
|
18
|
+
# disable STI
|
19
|
+
|
20
|
+
if Fiona7.mode == :standalone
|
21
|
+
# In standalone mode Obj belongs to scrivito
|
22
|
+
# hence no inheritance
|
23
|
+
self.inheritance_column = :_type_disabled
|
24
|
+
|
25
|
+
def self.descends_from_active_record?
|
26
|
+
true
|
27
|
+
end
|
28
|
+
else
|
29
|
+
# If this method returns true no STI handling occurs
|
30
|
+
def self.descends_from_active_record?
|
31
|
+
super || BLACKLISTED_CLASSES.include?(self.name)
|
32
|
+
end
|
33
|
+
|
34
|
+
# xxxWidget < Scrivito::BasicWidget clashes with obj STI
|
35
|
+
def self.subclass_from_attributes(attrs)
|
36
|
+
subclass_name = attrs.with_indifferent_access[inheritance_column]
|
37
|
+
|
38
|
+
if subclass_name.present? && subclass_name != self.name
|
39
|
+
subclass = subclass_name.safe_constantize
|
40
|
+
|
41
|
+
return subclass if subclass && descendants.include?(subclass)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
# TODO: use this to simulate deleted objects
|
47
|
+
#default_scope { where('suppress_export != 0') }
|
48
|
+
|
49
|
+
self.logger = Logger.new(nil)
|
50
|
+
|
51
|
+
include RailsConnector::Meta
|
52
|
+
|
53
|
+
include Reactor::Legacy::Base
|
54
|
+
include Reactor::Attributes::Base
|
55
|
+
include Reactor::Persistence::Base
|
56
|
+
include Reactor::Validations::Base
|
57
|
+
include Reactor::Permission::Base
|
58
|
+
|
59
|
+
include Reactor::Workflow::Base
|
60
|
+
include Reactor::StreamingUpload::Base
|
61
|
+
|
62
|
+
end
|
63
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
<%= scrivito_tag :h1, @obj, :title %>
|
2
|
+
<%= scrivito_tag :div, @obj, :body %>
|
3
|
+
|
4
|
+
<%= form_tag fiona7_login_path, role: 'form' do %>
|
5
|
+
<div class="form-group">
|
6
|
+
<%= label_tag :login, t(:"fiona7.login_field") %>
|
7
|
+
<%= text_field_tag :login, '', class: 'form-control', placeholder: t(:"fiona7.login_placeholder") %>
|
8
|
+
</div>
|
9
|
+
<div class="form-group">
|
10
|
+
<%= label_tag :password, t(:"fiona7.password_field") %>
|
11
|
+
<%= password_field_tag :password, '', class: 'form-control', placeholder: t(:"fiona7.password_placeholder") %>
|
12
|
+
</div>
|
13
|
+
<button type="submit" class="btn btn-default"><%= t(:"fiona7.login") %></button>
|
14
|
+
<% end %>
|
@@ -0,0 +1,23 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<title>Fiona 7</title>
|
5
|
+
<%= stylesheet_link_tag 'fiona7-login', media: 'all' %>
|
6
|
+
<%= csrf_meta_tags %>
|
7
|
+
</head>
|
8
|
+
<body>
|
9
|
+
<div id="wrap">
|
10
|
+
|
11
|
+
<div class="container">
|
12
|
+
<%= yield %>
|
13
|
+
</div>
|
14
|
+
</div>
|
15
|
+
|
16
|
+
<div class="footer">
|
17
|
+
<div class="container">
|
18
|
+
<p class="text-muted">
|
19
|
+
</p>
|
20
|
+
</div>
|
21
|
+
</div>
|
22
|
+
</body>
|
23
|
+
</html>
|
@@ -0,0 +1,19 @@
|
|
1
|
+
de:
|
2
|
+
fiona7:
|
3
|
+
login: 'Anmelden'
|
4
|
+
logout: 'Abmelden'
|
5
|
+
invalid_credentails: 'Zugangsdaten ungültig'
|
6
|
+
login_field: 'Benutzername'
|
7
|
+
password_field: 'Passwort'
|
8
|
+
login_placeholder: 'Benutzernamen eingeben'
|
9
|
+
password_placeholder: 'Passwort eingeben'
|
10
|
+
|
11
|
+
en:
|
12
|
+
fiona7:
|
13
|
+
login: 'Login'
|
14
|
+
logout: 'Logout'
|
15
|
+
invalid_credentails: 'Invalid credentials'
|
16
|
+
login_field: 'Login'
|
17
|
+
password_field: 'Password'
|
18
|
+
login_placeholder: 'Enter login'
|
19
|
+
password_placeholder: 'Enter password'
|
data/config/routes.rb
ADDED
@@ -0,0 +1,9 @@
|
|
1
|
+
Rails.application.routes.draw do
|
2
|
+
get '/_b/:id(/:name)' => 'fiona7/blobs#show', as: :fiona7_blob
|
3
|
+
|
4
|
+
post '/_f7/login', to: 'fiona7/sessions#create', as: :fiona7_login
|
5
|
+
|
6
|
+
delete '/_f/logout', to: 'fiona7/sessions#destroy', as: :fiona7_logout
|
7
|
+
|
8
|
+
put '/__scrivito/objs/:id/release(.:format)', to: 'fiona7/release#release', as: :fiona7_release
|
9
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module Fiona7
|
2
|
+
class Assert
|
3
|
+
class << self
|
4
|
+
def constraint(condition, message, code=418)
|
5
|
+
raise Scrivito::ClientError.new(message, code) unless condition
|
6
|
+
end
|
7
|
+
|
8
|
+
def input(condition, message, code=422)
|
9
|
+
raise Scrivito::ClientError.new(message, code) unless condition
|
10
|
+
end
|
11
|
+
|
12
|
+
def success(condition, message)
|
13
|
+
raise Scrivito::ScrivitoError, message unless condition
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,107 @@
|
|
1
|
+
require 'fiona7/builder/widget_builder'
|
2
|
+
require 'fiona7/builder/widget_updater'
|
3
|
+
|
4
|
+
require 'set'
|
5
|
+
require 'tsort'
|
6
|
+
|
7
|
+
module Fiona7
|
8
|
+
module Builder
|
9
|
+
class BatchWidgetWriter
|
10
|
+
|
11
|
+
class WidgetGraph
|
12
|
+
include TSort
|
13
|
+
|
14
|
+
def initialize(nodes)
|
15
|
+
@nodes = nodes
|
16
|
+
@dependencies = {}
|
17
|
+
|
18
|
+
@nodes.each do |node|
|
19
|
+
@dependencies[node] = node.dependencies.map do |id|
|
20
|
+
node = @nodes.find {|n| n.id.to_sym == id.to_sym }
|
21
|
+
end.compact
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def tsort_each_node(&block)
|
26
|
+
@nodes.each(&block)
|
27
|
+
end
|
28
|
+
|
29
|
+
def tsort_each_child(node, &block)
|
30
|
+
if !@dependencies[node]
|
31
|
+
raise Scrivito::ScrivitoError, "Broken widget dependency graph"
|
32
|
+
end
|
33
|
+
@dependencies[node].each(&block)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
class WidgetNode
|
38
|
+
attr_reader :id, :values, :builder
|
39
|
+
|
40
|
+
def initialize(id, values, builder)
|
41
|
+
@id, @values, @builder = id, values, builder
|
42
|
+
end
|
43
|
+
|
44
|
+
def dependencies
|
45
|
+
Set.new.tap do |dependencies|
|
46
|
+
values.each do |_, value|
|
47
|
+
if value.kind_of?(Hash) && (list = value[:list] || value["list"])
|
48
|
+
dependencies.merge(list.map {|c| c[:widget] || c['widget']})
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def eql?(other)
|
55
|
+
id.eql?(other.id)
|
56
|
+
end
|
57
|
+
|
58
|
+
def hash
|
59
|
+
id.hash
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
|
64
|
+
def initialize(obj, id_map, widget_pool, path_map)
|
65
|
+
@obj, @id_map, @widget_pool, @path_map = obj, id_map, widget_pool, path_map
|
66
|
+
@pool_changed = false
|
67
|
+
end
|
68
|
+
|
69
|
+
def write
|
70
|
+
widget_nodes = @widget_pool.map do |widget_id, values|
|
71
|
+
obj_id = @id_map[widget_id]
|
72
|
+
|
73
|
+
if values.nil?
|
74
|
+
# TODO: this widget can be GC-ed
|
75
|
+
@pool_changed = true
|
76
|
+
@path_map.delete(widget_id)
|
77
|
+
next
|
78
|
+
end
|
79
|
+
|
80
|
+
if obj_id
|
81
|
+
builder = WidgetUpdater.new(@obj, widget_id, values.merge(_id: obj_id), @path_map)
|
82
|
+
else
|
83
|
+
builder = WidgetBuilder.new(@obj, widget_id, values, @path_map)
|
84
|
+
@pool_changed = true
|
85
|
+
end
|
86
|
+
|
87
|
+
WidgetNode.new(widget_id, values, builder)
|
88
|
+
end.compact
|
89
|
+
|
90
|
+
widget_graph = WidgetGraph.new(widget_nodes)
|
91
|
+
|
92
|
+
widget_graph.tsort.each do |widget_node|
|
93
|
+
widget_node.builder.build
|
94
|
+
@path_map[widget_node.id] = widget_node.builder.path
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
def pool_changed?
|
99
|
+
!!@pool_changed
|
100
|
+
end
|
101
|
+
|
102
|
+
def path_map
|
103
|
+
@path_map
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|