scrivito_sdk 1.1.1 → 1.2.0.rc1
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.
- checksums.yaml +4 -4
- data/app/controllers/scrivito/blobs_controller.rb +7 -0
- data/app/controllers/scrivito/objs_controller.rb +0 -6
- data/app/controllers/scrivito/ui_controller.rb +2 -0
- data/app/views/scrivito/blobs/{activate_upload.json.jbuilder → blob.json.jbuilder} +0 -0
- data/config/ca-bundle.crt +1 -1
- data/config/precedence_routes.rb +1 -1
- data/lib/assets/javascripts/scrivito_ui.js +20072 -19687
- data/lib/assets/stylesheets/scrivito.css +1 -1
- data/lib/assets/stylesheets/scrivito_ui.css +1 -1
- data/lib/generators/scrivito/install/install_generator.rb +2 -8
- data/lib/generators/scrivito/install/templates/app/views/download/details.html.erb +11 -0
- data/lib/generators/scrivito/install/templates/app/views/headline_widget/thumbnail.html.erb +1 -1
- data/lib/generators/scrivito/install/templates/app/views/image/details.html.erb +17 -0
- data/lib/generators/scrivito/install/templates/app/views/image_widget/thumbnail.html.erb +1 -1
- data/lib/generators/scrivito/install/templates/app/views/page/details.html.erb +4 -2
- data/lib/generators/scrivito/install/templates/app/views/page/thumbnail.html.erb +1 -3
- data/lib/generators/scrivito/install/templates/app/views/text_widget/thumbnail.html.erb +2 -2
- data/lib/generators/scrivito/page/page_generator.rb +8 -0
- data/lib/generators/scrivito/page/templates/details.html.erb +4 -2
- data/lib/generators/scrivito/page/templates/thumbnail.html.erb +1 -3
- data/lib/generators/scrivito/widget/templates/details.html.erb +4 -2
- data/lib/generators/scrivito/widget/templates/show.html.erb +1 -2
- data/lib/generators/scrivito/widget/templates/thumbnail.html.erb +1 -3
- data/lib/generators/scrivito/widget/widget_generator.rb +0 -4
- data/lib/scrivito/attribute_content.rb +44 -15
- data/lib/scrivito/attribute_definition.rb +59 -3
- data/lib/scrivito/basic_obj.rb +11 -18
- data/lib/scrivito/basic_widget.rb +42 -0
- data/lib/scrivito/binary.rb +5 -5
- data/lib/scrivito/cache_middleware.rb +13 -17
- data/lib/scrivito/class_collection.rb +1 -1
- data/lib/scrivito/client_attribute_serializer.rb +5 -1
- data/lib/scrivito/cms_backend.rb +43 -60
- data/lib/scrivito/cms_data_cache.rb +18 -14
- data/lib/scrivito/cms_field_tag.rb +2 -2
- data/lib/scrivito/cms_rest_api.rb +9 -8
- data/lib/scrivito/cms_routing.rb +1 -1
- data/lib/scrivito/configuration.rb +15 -4
- data/lib/scrivito/connection_manager.rb +29 -23
- data/lib/scrivito/model_library.rb +43 -11
- data/lib/scrivito/obj_collection.rb +1 -1
- data/lib/scrivito/obj_params_parser.rb +1 -19
- data/lib/scrivito/obj_search_enumerator/query_executor.rb +1 -1
- data/lib/scrivito/obj_search_enumerator.rb +1 -1
- data/lib/scrivito/ui_config.rb +13 -2
- data/lib/scrivito/widget_collection.rb +1 -1
- data/lib/scrivito/workspace.rb +25 -26
- data/lib/scrivito_sdk.rb +67 -40
- metadata +21 -8
- data/lib/generators/scrivito/install/templates/app/views/download/embed.html.erb +0 -1
- data/lib/generators/scrivito/install/templates/app/views/image/embed.html.erb +0 -1
- data/lib/scrivito/widget_garbage_collection.rb +0 -97
data/lib/scrivito/workspace.rb
CHANGED
@@ -19,21 +19,22 @@ class Workspace
|
|
19
19
|
# @api public
|
20
20
|
# @param [Scrivito::Workspace] workspace
|
21
21
|
def self.current=(workspace)
|
22
|
-
|
22
|
+
Thread.current[:scrivito_current_workspace] = workspace
|
23
23
|
end
|
24
24
|
|
25
25
|
def self.current_using_proc=(workspace_proc)
|
26
|
-
|
26
|
+
Thread.current[:scrivito_current_workspace] = workspace_proc
|
27
27
|
end
|
28
28
|
|
29
29
|
# Returns the currently used workspace.
|
30
30
|
# @api public
|
31
31
|
# @return [Scrivito::Workspace]
|
32
32
|
def self.current
|
33
|
-
|
34
|
-
|
33
|
+
workspace = Thread.current[:scrivito_current_workspace]
|
34
|
+
if workspace.respond_to?(:call)
|
35
|
+
Thread.current[:scrivito_current_workspace] = workspace.call
|
35
36
|
else
|
36
|
-
|
37
|
+
Thread.current[:scrivito_current_workspace] ||= published
|
37
38
|
end
|
38
39
|
end
|
39
40
|
|
@@ -57,11 +58,11 @@ class Workspace
|
|
57
58
|
end
|
58
59
|
|
59
60
|
def self.published_with_fallback
|
60
|
-
cached_workspace_data = CmsBackend.
|
61
|
+
cached_workspace_data = CmsBackend.find_workspace_data_from_cache('published')
|
61
62
|
|
62
63
|
if cached_workspace_data
|
63
64
|
workspace_data = begin
|
64
|
-
CmsBackend.
|
65
|
+
CmsBackend.find_workspace_data_by_id('published', 0.5)
|
65
66
|
rescue => e
|
66
67
|
warn_backend_not_available(e.message)
|
67
68
|
cached_workspace_data
|
@@ -80,7 +81,7 @@ class Workspace
|
|
80
81
|
# @raise [Scrivito::ResourceNotFound]
|
81
82
|
def self.find(id)
|
82
83
|
cache.fetch(id) do
|
83
|
-
workspace_data = CmsBackend.
|
84
|
+
workspace_data = CmsBackend.find_workspace_data_by_id(id)
|
84
85
|
|
85
86
|
from_workspace_data(id, workspace_data)
|
86
87
|
end
|
@@ -97,33 +98,31 @@ class Workspace
|
|
97
98
|
end
|
98
99
|
|
99
100
|
#
|
100
|
-
# Find a workspace by its
|
101
|
+
# Find a workspace by its title or ID and set it as the currently used workspace.
|
101
102
|
#
|
102
103
|
# @api public
|
103
104
|
#
|
104
|
-
# @param [String]
|
105
|
+
# @param [String] title_or_id title or id of the workspace
|
105
106
|
# @raise [Scrivito::ResourceNotFound]
|
106
|
-
# @
|
107
|
+
# @note This method is intended to be used in the Rails console. Please avoid using it in
|
108
|
+
# application code.
|
107
109
|
#
|
108
110
|
# @example
|
109
|
-
# Scrivito::Workspace.use("6a75fe694eeeb093")
|
110
|
-
# Scrivito::Workspace.current.id
|
111
|
-
# # => "6a75fe694eeeb093"
|
112
|
-
#
|
113
111
|
# Scrivito::Workspace.use("my working copy")
|
114
112
|
# Scrivito::Workspace.current.title
|
115
113
|
# # => "my working copy"
|
116
114
|
#
|
117
|
-
#
|
115
|
+
# Scrivito::Workspace.use("6a75fe694eeeb093")
|
116
|
+
# Scrivito::Workspace.current.id
|
117
|
+
# # => "6a75fe694eeeb093"
|
118
|
+
#
|
119
|
+
# # Raises Scrivito::ResourceNotFound:
|
118
120
|
# Scrivito::Workspace.use("missing")
|
119
121
|
#
|
120
|
-
def self.use(
|
121
|
-
self.current =
|
122
|
-
|
123
|
-
|
124
|
-
find_by_title(id_or_title) or
|
125
|
-
raise ResourceNotFound, "Could not find #{self} with title #{id_or_title}"
|
126
|
-
end
|
122
|
+
def self.use(title_or_id)
|
123
|
+
self.current = find_by_title(title_or_id) || find(title_or_id)
|
124
|
+
rescue ResourceNotFound
|
125
|
+
raise ResourceNotFound, %{Could not find #{self} with title or ID "#{title_or_id}"}
|
127
126
|
end
|
128
127
|
|
129
128
|
delegate :content_state_id, :base_content_state_id, :content_state,
|
@@ -196,11 +195,11 @@ class Workspace
|
|
196
195
|
end
|
197
196
|
|
198
197
|
def create_obj(attributes)
|
199
|
-
CmsBackend.
|
198
|
+
CmsBackend.create_obj(id, attributes).tap { reload }
|
200
199
|
end
|
201
200
|
|
202
201
|
def update_obj(obj_id, attributes)
|
203
|
-
CmsBackend.
|
202
|
+
CmsBackend.update_obj(id, obj_id, attributes).tap { reload }
|
204
203
|
end
|
205
204
|
|
206
205
|
def task_unaware_api_request(verb, path, payload = nil)
|
@@ -376,7 +375,7 @@ class Workspace
|
|
376
375
|
end
|
377
376
|
|
378
377
|
def fetch_workspace_data
|
379
|
-
CmsBackend.
|
378
|
+
CmsBackend.find_workspace_data_by_id(id)
|
380
379
|
end
|
381
380
|
|
382
381
|
def backend_url
|
data/lib/scrivito_sdk.rb
CHANGED
@@ -19,77 +19,94 @@ module Scrivito
|
|
19
19
|
end
|
20
20
|
|
21
21
|
#
|
22
|
-
# Configures which
|
22
|
+
# Configures which classes Scrivito regards as CMS models.
|
23
23
|
#
|
24
24
|
# @api public
|
25
25
|
#
|
26
|
-
# In order to
|
27
|
-
#
|
28
|
-
# the Rails application itself or in 3rd-party gems.
|
26
|
+
# In order to provide access to CMS class details, Scrivito needs to know which CMS model classes
|
27
|
+
# are available. These models can be defined in the Rails application itself or in 3rd-party gems.
|
29
28
|
#
|
30
|
-
# Scrivito assumes that all the classes descending from {Scrivito::BasicObj}, whose
|
31
|
-
#
|
32
|
-
#
|
33
|
-
#
|
29
|
+
# Scrivito assumes that all the classes descending from {Scrivito::BasicObj}, whose class names
|
30
|
+
# end with +"Page"+ are pages (e.g. +MyPage+, +HomePage+, +BlogPostPage+ etc.) and all the classes
|
31
|
+
# descending from {Scrivito::BasicWidget}, whose class names end with +"Widget"+ are widgets (e.g.
|
32
|
+
# +TextWidget+, +ImageWidget+ etc.).
|
33
|
+
# It also assumes that all the classes descending from {Scrivito::BasicObj}, regardless of the
|
34
|
+
# class names, are CMS object models (e.g. all pages, but also +Obj+, +Image+, +Download+ etc.).
|
34
35
|
#
|
35
|
-
#
|
36
|
+
# The loaded pages can be inspected with {Scrivito::ModelLibrary#pages Scrivito.models.pages},
|
37
|
+
# which will return a {Scrivito::ClassCollection} containing the available pages and the loaded
|
38
|
+
# widgets can be inspected with {Scrivito::ModelLibrary#widgets Scrivito.models.widgets}, which
|
39
|
+
# will return a {Scrivito::ClassCollection} containing the available widgets.
|
40
|
+
# All available CMS object models can be inspected with
|
41
|
+
# {Scrivito::ModelLibrary#objs Scrivito.models.objs}.
|
42
|
+
# The {Scrivito::ModelLibrary#pages Scrivito.models.pages} will also include the +Page+ model, if
|
43
|
+
# it is defined in +page.rb+, and {Scrivito::ModelLibrary#objs Scrivito.models.objs} will include
|
44
|
+
# the +Obj+ model.
|
45
|
+
#
|
46
|
+
# Scrivito recursively scans for CMS models in all directories from
|
36
47
|
# {Scrivito::ModelLibrary#paths Scrivito.models.paths}, which is an array of strings.
|
37
48
|
# By default, Scrivito includes the +app/models+ directory of the Rails application when searching
|
38
|
-
# for models. It will, for example, find the following page and
|
39
|
-
#
|
40
|
-
# +app/models/my_page.rb+
|
41
|
-
#
|
42
|
-
# +app/models/my_widget.rb+
|
49
|
+
# for models. It will, for example, find the following page, widget and obj models:
|
43
50
|
#
|
44
|
-
#
|
51
|
+
# app/models/my_page.rb
|
52
|
+
# app/models/my_widget.rb
|
53
|
+
# app/models/my_obj.rb
|
45
54
|
#
|
46
|
-
#
|
55
|
+
# app/models/my_namespace/my_other_page.rb
|
56
|
+
# app/models/my_namespace/my_other_widget.rb
|
57
|
+
# app/models/my_namespace/my_other_obj.rb
|
47
58
|
#
|
48
|
-
#
|
49
|
-
#
|
50
|
-
#
|
59
|
+
# app/models/my_namespace/my_other_namespace/my_other_special_page.rb
|
60
|
+
# app/models/my_namespace/my_other_namespace/my_other_special_widget.rb
|
61
|
+
# app/models/my_namespace/my_other_namespace/my_other_special_obj.rb
|
51
62
|
#
|
52
63
|
# Also, {Scrivito::ModelLibrary#paths Scrivito.models.paths} includes all +app/models+
|
53
64
|
# directories of any available Rails engine, provided that these directories are included in the
|
54
|
-
# autoload paths of Rails (which is the default). For example, it will find the following page
|
55
|
-
# and
|
56
|
-
#
|
57
|
-
# +/../some_engine/app/models/my_page.rb+
|
65
|
+
# autoload paths of Rails (which is the default). For example, it will find the following page,
|
66
|
+
# widget and obj models in an engine:
|
58
67
|
#
|
59
|
-
#
|
68
|
+
# /../some_engine/app/models/my_page.rb
|
69
|
+
# /../some_engine/app/models/my_widget.rb
|
70
|
+
# /../some_engine/app/models/my_obj.rb
|
60
71
|
#
|
61
|
-
#
|
72
|
+
# /../some_engine/app/models/my_namespace/my_other_page.rb
|
73
|
+
# /../some_engine/app/models/my_namespace/my_other_widget.rb
|
74
|
+
# /../some_engine/app/models/my_namespace/my_other_obj.rb
|
62
75
|
#
|
63
|
-
#
|
64
|
-
#
|
65
|
-
#
|
66
|
-
#
|
67
|
-
# +/../some_engine/app/models/my_namespace/my_other_namespace/my_other_special_widget.rb+
|
76
|
+
# /../some_engine/app/models/my_namespace/my_other_namespace/my_other_special_page.rb
|
77
|
+
# /../some_engine/app/models/my_namespace/my_other_namespace/my_other_special_widget.rb
|
78
|
+
# /../some_engine/app/models/my_namespace/my_other_namespace/my_other_special_obj.rb
|
68
79
|
#
|
69
80
|
# You can add custom directories to scan for models and register single page and widget models
|
70
81
|
# using {Scrivito::ModelLibrary#define Scrivito.models.define} (see examples below).
|
71
82
|
#
|
72
|
-
# The loaded pages can be inspected with {Scrivito::ModelLibrary#pages Scrivito.models.pages},
|
73
|
-
# which will return a {Scrivito::ClassCollection} containing the available pages.
|
74
|
-
# The loaded widgets can be inspected with {Scrivito::ModelLibrary#widgets Scrivito.models.widgets},
|
75
|
-
# which will return a {Scrivito::ClassCollection} containing the available widgets.
|
76
|
-
#
|
77
83
|
# The scan results are cached. If +Rails.application.config.cache_classes+ is +false+, the
|
78
84
|
# cache is cleared on every request. Otherwise, the cache is kept between the requests.
|
79
85
|
# You can clear the cache using {Scrivito::ModelLibrary#clear_cache Scrivito.models.clear_cache}.
|
80
86
|
#
|
81
87
|
# @example Register a custom path:
|
82
88
|
# Scrivito.models.define do
|
83
|
-
# paths << Rails.root +
|
89
|
+
# paths << Rails.root + "lib/special_models"
|
84
90
|
# end
|
85
91
|
#
|
86
92
|
# @example Register pages and widgets with unusual names:
|
87
93
|
# Scrivito.models.define do
|
88
|
-
# page
|
89
|
-
# page
|
94
|
+
# page "MyCrazyPageModel"
|
95
|
+
# page "MyOtherCrazyPageModel1", "MyOtherCrazyPageModel2"
|
90
96
|
#
|
91
|
-
# widget
|
92
|
-
# widget
|
97
|
+
# widget "MyCrazyWidgetModel"
|
98
|
+
# widget "MyOtherCrazyWidgetModel1", "MyOtherCrazyWidgetModel2"
|
99
|
+
# end
|
100
|
+
#
|
101
|
+
# @example Register CMS model classes, whose files Scrivito would _not_ find in {Scrivito::ModelLibrary#paths paths}:
|
102
|
+
# class MyPage < Obj; end
|
103
|
+
# class MyWidget < Widget; end
|
104
|
+
# class MyObj < Obj; end
|
105
|
+
#
|
106
|
+
# Scrivito.models.define do
|
107
|
+
# page "MyPage"
|
108
|
+
# widget "MyWidget"
|
109
|
+
# obj "MyObj"
|
93
110
|
# end
|
94
111
|
#
|
95
112
|
# @example Iterate over the available pages:
|
@@ -108,6 +125,16 @@ module Scrivito
|
|
108
125
|
# #=> "MyOtherWidget"
|
109
126
|
# # ...
|
110
127
|
#
|
128
|
+
# @example Iterate over the available CMS object models:
|
129
|
+
# Scrivito.models.objs.each do |obj_class|
|
130
|
+
# puts obj_class.name
|
131
|
+
# end
|
132
|
+
# #=> "MyPage"
|
133
|
+
# #=> "MyOtherPage"
|
134
|
+
# #=> "MyObj"
|
135
|
+
# #=> "MyOtherObj"
|
136
|
+
# # ...
|
137
|
+
#
|
111
138
|
def self.models
|
112
139
|
@models ||= ModelLibrary.new
|
113
140
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: scrivito_sdk
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.0.rc1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Infopark AG
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-02-
|
11
|
+
date: 2016-02-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: addressable
|
@@ -24,6 +24,20 @@ dependencies:
|
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '2.3'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: connection_pool
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '2.2'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '2.2'
|
27
41
|
- !ruby/object:Gem::Dependency
|
28
42
|
name: diff-lcs
|
29
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -174,7 +188,7 @@ files:
|
|
174
188
|
- app/views/cms/index.html.erb
|
175
189
|
- app/views/google_maps_widget/show.html.erb
|
176
190
|
- app/views/scrivito/_editing_auth_warning.html.erb
|
177
|
-
- app/views/scrivito/blobs/
|
191
|
+
- app/views/scrivito/blobs/blob.json.jbuilder
|
178
192
|
- app/views/scrivito/blobs/upload_permission.json.jbuilder
|
179
193
|
- app/views/scrivito/completion/suggest.json.jbuilder
|
180
194
|
- app/views/scrivito/content_widget/show.html.erb
|
@@ -233,10 +247,10 @@ files:
|
|
233
247
|
- lib/generators/scrivito/install/templates/app/models/page.rb
|
234
248
|
- lib/generators/scrivito/install/templates/app/models/text_widget.rb
|
235
249
|
- lib/generators/scrivito/install/templates/app/models/widget.rb
|
236
|
-
- lib/generators/scrivito/install/templates/app/views/download/
|
250
|
+
- lib/generators/scrivito/install/templates/app/views/download/details.html.erb
|
237
251
|
- lib/generators/scrivito/install/templates/app/views/headline_widget/show.html.erb
|
238
252
|
- lib/generators/scrivito/install/templates/app/views/headline_widget/thumbnail.html.erb
|
239
|
-
- lib/generators/scrivito/install/templates/app/views/image/
|
253
|
+
- lib/generators/scrivito/install/templates/app/views/image/details.html.erb
|
240
254
|
- lib/generators/scrivito/install/templates/app/views/image_widget/show.html.erb
|
241
255
|
- lib/generators/scrivito/install/templates/app/views/image_widget/thumbnail.html.erb
|
242
256
|
- lib/generators/scrivito/install/templates/app/views/layouts/scrivito_dialog.html.erb
|
@@ -380,7 +394,6 @@ files:
|
|
380
394
|
- lib/scrivito/user_definition.rb
|
381
395
|
- lib/scrivito/warning.rb
|
382
396
|
- lib/scrivito/widget_collection.rb
|
383
|
-
- lib/scrivito/widget_garbage_collection.rb
|
384
397
|
- lib/scrivito/widget_tag.rb
|
385
398
|
- lib/scrivito/workspace.rb
|
386
399
|
- lib/scrivito/workspace/publish_checker.rb
|
@@ -405,9 +418,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
405
418
|
version: 2.1.0
|
406
419
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
407
420
|
requirements:
|
408
|
-
- - "
|
421
|
+
- - ">"
|
409
422
|
- !ruby/object:Gem::Version
|
410
|
-
version:
|
423
|
+
version: 1.3.1
|
411
424
|
requirements: []
|
412
425
|
rubyforge_project:
|
413
426
|
rubygems_version: 2.4.5
|
@@ -1 +0,0 @@
|
|
1
|
-
<%= link_to obj.display_title, obj.binary_url %>
|
@@ -1 +0,0 @@
|
|
1
|
-
<%= scrivito_image_tag obj %>
|
@@ -1,97 +0,0 @@
|
|
1
|
-
module Scrivito
|
2
|
-
|
3
|
-
class WidgetGarbageCollection
|
4
|
-
|
5
|
-
# @param [Scrivito::BasicObj] obj the Obj that the update applies to
|
6
|
-
# @param [Hash] update the keys are content objects (Obj or Widget)
|
7
|
-
# and the values are their update params.
|
8
|
-
# update params are accepted in the same format as accepted by Obj.create or Obj#update.
|
9
|
-
# each content object must either be the obj itself or a widget that lives inside the obj.
|
10
|
-
def initialize(obj, update)
|
11
|
-
if update.blank?
|
12
|
-
raise ScrivitoError, "blank update!"
|
13
|
-
end
|
14
|
-
|
15
|
-
update.keys.each do |content|
|
16
|
-
if content.is_a?(BasicObj)
|
17
|
-
raise "invalid obj given" unless content == obj
|
18
|
-
elsif content.is_a?(BasicWidget)
|
19
|
-
raise "invalid widget given" unless content.obj == obj
|
20
|
-
else
|
21
|
-
raise "invalid key"
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
@update = update
|
26
|
-
@obj = obj
|
27
|
-
end
|
28
|
-
|
29
|
-
# @return [Array] list containing the widgets that are no longer needed after the update.
|
30
|
-
def widgets_to_delete
|
31
|
-
dereferenced = []
|
32
|
-
newreferenced = []
|
33
|
-
|
34
|
-
@update.each do |content, params|
|
35
|
-
(deref, newref) = changed_references_from(content, params)
|
36
|
-
dereferenced += deref
|
37
|
-
newreferenced += newref
|
38
|
-
end
|
39
|
-
|
40
|
-
deleted_by_dereference = dereferenced - newreferenced
|
41
|
-
|
42
|
-
recursively_deleted = []
|
43
|
-
deleted_by_dereference.each do |widget|
|
44
|
-
recursively_deleted += all_widgets_contained_in_except(widget, newreferenced)
|
45
|
-
end
|
46
|
-
|
47
|
-
# we dont want to slow down every request by scanning for orphans, so
|
48
|
-
# we only do this when widgets are being deleted
|
49
|
-
if deleted_by_dereference.present?
|
50
|
-
orphans = @obj.all_widgets_from_pool - @obj.contained_widgets - newreferenced
|
51
|
-
else
|
52
|
-
orphans = []
|
53
|
-
end
|
54
|
-
|
55
|
-
deleted_by_dereference + recursively_deleted + orphans
|
56
|
-
end
|
57
|
-
|
58
|
-
private
|
59
|
-
|
60
|
-
def all_widgets_contained_in_except(widget, exceptions)
|
61
|
-
widget_children = widget.referenced_widgets - exceptions
|
62
|
-
|
63
|
-
widget_descendants = widget_children.map do |child|
|
64
|
-
all_widgets_contained_in_except(child, exceptions)
|
65
|
-
end.flatten
|
66
|
-
|
67
|
-
widget_children + widget_descendants
|
68
|
-
end
|
69
|
-
|
70
|
-
def changed_references_from(content, params)
|
71
|
-
dereferenced_ids = []
|
72
|
-
newreferenced_ids = []
|
73
|
-
|
74
|
-
if content.kind_of?(BasicWidget) && !content.persisted?
|
75
|
-
params.each_value do |value|
|
76
|
-
if value.kind_of?(Array)
|
77
|
-
newreferenced_ids += value.select { |v| v.kind_of?(BasicWidget) }
|
78
|
-
end
|
79
|
-
end
|
80
|
-
else
|
81
|
-
params.each do |key, value|
|
82
|
-
if content.type_of_attribute(key) == 'widgetlist'
|
83
|
-
current = content[key] || []
|
84
|
-
new = value || []
|
85
|
-
|
86
|
-
dereferenced_ids += current - new
|
87
|
-
newreferenced_ids += new - current
|
88
|
-
end
|
89
|
-
end
|
90
|
-
end
|
91
|
-
|
92
|
-
[dereferenced_ids, newreferenced_ids]
|
93
|
-
end
|
94
|
-
|
95
|
-
end
|
96
|
-
|
97
|
-
end
|