infopark_fiona7 0.30.0.2 → 0.70.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (73) hide show
  1. checksums.yaml +4 -4
  2. data/app/assets/javascripts/fiona7.js +1 -282
  3. data/app/assets/javascripts/fiona7_ui.js +335 -0
  4. data/app/assets/stylesheets/fiona7.css.scss +4 -36
  5. data/app/assets/stylesheets/fiona7_ui.css.scss +39 -0
  6. data/app/controllers/fiona7/blobs_controller.rb +13 -23
  7. data/app/controllers/fiona7/release_controller.rb +1 -0
  8. data/app/controllers/fiona7/sessions_controller.rb +3 -5
  9. data/app/helpers/fiona7_override_helper.rb +6 -2
  10. data/app/models/fiona7/edited_obj.rb +6 -1
  11. data/app/models/fiona7/released_obj.rb +11 -3
  12. data/app/models/fiona7/write_obj.rb +18 -3
  13. data/app/models/fiona7_login_page.rb +3 -0
  14. data/app/views/scrivito/ui/index.html.erb +16 -0
  15. data/config/routes.rb +2 -0
  16. data/infopark_fiona7.gemspec +6 -4
  17. data/lib/fiona7/builder/batch_widget_writer.rb +7 -3
  18. data/lib/fiona7/builder/obj_builder.rb +130 -42
  19. data/lib/fiona7/builder/obj_class_builder.rb +3 -59
  20. data/lib/fiona7/builder/obj_class_updater.rb +7 -44
  21. data/lib/fiona7/builder/obj_updater.rb +25 -7
  22. data/lib/fiona7/builder/widget_builder.rb +24 -0
  23. data/lib/fiona7/builder/widget_building.rb +2 -7
  24. data/lib/fiona7/builder/widget_updater.rb +21 -0
  25. data/lib/fiona7/controllers/content_service/obj_controller.rb +16 -25
  26. data/lib/fiona7/controllers/rest_api/blob_controller.rb +41 -2
  27. data/lib/fiona7/controllers/rest_api/obj_controller.rb +19 -7
  28. data/lib/fiona7/controllers/rest_api/workspace_controller.rb +1 -1
  29. data/lib/fiona7/engine.rb +58 -7
  30. data/lib/fiona7/fiona_connector_patches/basic_obj.rb +46 -0
  31. data/lib/fiona7/initializer.rb +15 -11
  32. data/lib/fiona7/json/obj_decorator.rb +53 -31
  33. data/lib/fiona7/json/reverse_obj_decorator.rb +36 -0
  34. data/lib/fiona7/json/widget_decorator.rb +3 -1
  35. data/lib/fiona7/link_converter/fiona_to_scrivito.rb +45 -13
  36. data/lib/fiona7/link_converter/scrivito_to_fiona.rb +1 -1
  37. data/lib/fiona7/middleware/server_detection_middleware.rb +27 -0
  38. data/lib/fiona7/middleware/table_switching_middleware.rb +33 -0
  39. data/lib/fiona7/mode_switch/cms_routes/scrivito_sdk.rb +5 -11
  40. data/lib/fiona7/mode_switch/composite.rb +2 -4
  41. data/lib/fiona7/naive_search_engine.rb +66 -16
  42. data/lib/fiona7/routers/rest_api.rb +50 -45
  43. data/lib/fiona7/routing_monkey_patch.rb +5 -3
  44. data/lib/fiona7/scrivito_patches/attribute_content.rb +9 -10
  45. data/lib/fiona7/scrivito_patches/attribute_serializer.rb +15 -0
  46. data/lib/fiona7/scrivito_patches/basic_obj.rb +25 -19
  47. data/lib/fiona7/scrivito_patches/basic_widget.rb +4 -0
  48. data/lib/fiona7/scrivito_patches/binary.rb +452 -33
  49. data/lib/fiona7/scrivito_patches/client_config.rb +0 -19
  50. data/lib/fiona7/scrivito_patches/cms_backend.rb +48 -0
  51. data/lib/fiona7/scrivito_patches/cms_field_tag.rb +19 -0
  52. data/lib/fiona7/scrivito_patches/cms_rest_api.rb +20 -3
  53. data/lib/fiona7/scrivito_patches/cms_routing.rb +20 -34
  54. data/lib/fiona7/scrivito_patches/controller_actions.rb +0 -8
  55. data/lib/fiona7/scrivito_patches/migrator.rb +4 -0
  56. data/lib/fiona7/scrivito_patches/objs_controller.rb +18 -0
  57. data/lib/fiona7/scrivito_patches/type_computer.rb +12 -12
  58. data/lib/fiona7/scrivito_patches/webservice_controller.rb +21 -0
  59. data/lib/fiona7/scrivito_patches/workspace.rb +8 -5
  60. data/lib/fiona7/shadow_classes.rb +74 -0
  61. data/lib/fiona7/table_switcher.rb +39 -0
  62. data/lib/fiona7/type_loader.rb +63 -0
  63. data/lib/fiona7/type_register.rb +170 -89
  64. data/lib/fiona7/type_synchronizer.rb +68 -0
  65. data/lib/fiona7/version.rb +1 -1
  66. data/lib/fiona7/version_helper.rb +35 -54
  67. data/lib/fiona7/widget_resolver.rb +1 -1
  68. data/lib/tasks/fiona7_tasks.rake +0 -8
  69. metadata +57 -18
  70. data/lib/fiona7/controllers/rest_api/obj_class_controller.rb +0 -39
  71. data/lib/fiona7/json/obj_class_decorator.rb +0 -45
  72. data/lib/fiona7/mode_switch/constants.rb +0 -86
  73. data/lib/fiona7/type_register_mixin.rb +0 -9
@@ -1,18 +1,8 @@
1
1
  /*
2
- *= require scrivito
3
- *= require scrivito_editors
4
- */
5
- /* here goes logo */
6
- body > div.scrivito_topbar > div > div.scrivito_button_bar.scrivito_app.scrivito_no_hover {
7
- width: 170px !important;
8
- }
9
- body > div.scrivito_topbar > div > div.scrivito_button_bar.scrivito_app.scrivito_no_hover .scrivito_logo {
10
- background-image: asset-url('fiona7-logo.png') !important;
11
- height: 43px !important;
12
- width: 163px !important;
13
- top: 0px;
14
- left: 0px;
15
- }
2
+ *= require scrivito
3
+ *= require_self
4
+ */
5
+
16
6
  /* colors */
17
7
  body.scrivito_widget_dragging_active[data-scrivito-display-mode="editing"] *[data-scrivito-widget-obj-class],
18
8
  body.scrivito_widget_dragging_active[data-scrivito-display-mode="editing"] *[data-scrivito-widget-obj-class] *[data-scrivito-field-type="widget"],
@@ -59,25 +49,3 @@ body.scrivito_widget_dragging_active[data-scrivito-display-mode="editing"] *[dat
59
49
  .scrivito_editing_marker {
60
50
  padding: 0 !important;
61
51
  }
62
- .scrivito_input_new_ws_name, #scrivito_delete_workspace, #scrivito_rename_workspace, #scrivito_create_workspace, #scrivito_rebase_workspace, #scrivito_workspace_settings {
63
- display: none !important;
64
- }
65
-
66
- .scrivito_editing_widget_visualization .scrivito_icon {
67
- line-height: 118px !important;
68
- }
69
-
70
- /* for removing edit toggle */
71
- .scrivito_viewmodes_wrapper {
72
- text-align: center !important;
73
- }
74
- .scrivito_viewmodes {
75
- width: auto !important;
76
- display: inline-block !important;
77
- }
78
- .scrivito_viewmodes.scrivito_viewmode_diff_active .scrivito_viewmode_pill,
79
- .scrivito_viewmodes.scrivito_viewmode_deleted_active .scrivito_viewmode_pill,
80
- .scrivito_viewmodes.scrivito_viewmode_added_active .scrivito_viewmode_pill {
81
- left: auto !important;
82
- right: 0px !important;
83
- }
@@ -0,0 +1,39 @@
1
+ body > div.scrivito_topbar > div > div.scrivito_button_bar.scrivito_app.scrivito_no_hover {
2
+ width: 170px !important;
3
+ }
4
+ body > div.scrivito_topbar > div > div.scrivito_button_bar.scrivito_app.scrivito_no_hover .scrivito_logo {
5
+ background-image: asset-url('fiona7-logo.png') !important;
6
+ height: 43px !important;
7
+ width: 163px !important;
8
+ top: 0px;
9
+ left: 0px;
10
+ }
11
+
12
+ .scrivito_menu_box #scrivito_sdk_workspace_settings, .scrivito_menu_box #scrivito_sdk_rename_workspace, .scrivito_menu_box #scrivito_sdk_rebase_workspace, .scrivito_menu_box #scrivito_sdk_delete_workspace, .scrivito_menu_box #scrivito_sdk_create_workspace {
13
+ display: none;
14
+ }
15
+
16
+ /*
17
+ .scrivito_input_new_ws_name, #scrivito_delete_workspace, #scrivito_rename_workspace, #scrivito_create_workspace, #scrivito_rebase_workspace, #scrivito_workspace_settings {
18
+ display: none !important;
19
+ }
20
+
21
+ .scrivito_editing_widget_visualization .scrivito_icon {
22
+ line-height: 118px !important;
23
+ }
24
+
25
+ // for removing edit toggle
26
+ .scrivito_viewmodes_wrapper {
27
+ text-align: center !important;
28
+ }
29
+ .scrivito_viewmodes {
30
+ width: auto !important;
31
+ display: inline-block !important;
32
+ }
33
+ .scrivito_viewmodes.scrivito_viewmode_diff_active .scrivito_viewmode_pill,
34
+ .scrivito_viewmodes.scrivito_viewmode_deleted_active .scrivito_viewmode_pill,
35
+ .scrivito_viewmodes.scrivito_viewmode_added_active .scrivito_viewmode_pill {
36
+ left: auto !important;
37
+ right: 0px !important;
38
+ }
39
+ */
@@ -1,34 +1,24 @@
1
1
  module Fiona7
2
2
  class BlobsController < ActionController::Base
3
- # required for ensure_object_is_permitted
4
- cattr_accessor :current_user_proc
5
- self.current_user_proc = proc { nil }
6
3
 
7
- include RailsConnector::CmsAccessible
8
- before_filter :load_object
9
- before_filter :ensure_object_is_active
10
- before_filter :ensure_object_is_permitted
11
- before_filter :set_google_expire_header
4
+ include Fiona7::BinaryHandling::DeliveryMixin
12
5
 
13
- def show
14
- if @obj.binary?
15
- deliver_file
16
- else
17
- head :bad_request
18
- end
6
+ protected
7
+
8
+ def binary_id_from_params
9
+ params[:id]
19
10
  end
20
11
 
21
- protected
22
- def load_object
23
- obj_id = params[:id].to_i
24
- @obj = InternalReleasedObj.find(obj_id)
25
- rescue ActiveRecord::RecordNotFound
26
- head :not_found
27
- return false
12
+ def transformation_from_params
13
+ if params[:t]
14
+ BinaryHandling::ParamEncoder.new.decode(
15
+ params[:t]
16
+ )
17
+ end
28
18
  end
29
19
 
30
- def current_user
31
- self.class.current_user_proc.try(:call, self)
20
+ def set_header(name, value)
21
+ response.headers[name] = value
32
22
  end
33
23
  end
34
24
  end
@@ -9,6 +9,7 @@ module Fiona7
9
9
  @releasable << @obj
10
10
 
11
11
  @releasable.each do |obj|
12
+ obj.take
12
13
  obj.release! if obj.really_edited?
13
14
  end
14
15
 
@@ -39,11 +39,9 @@ module Fiona7
39
39
  end
40
40
 
41
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
42
+ Reactor::Sudo.su(Fiona7.root) do
43
+ Reactor::Cm::User.new(login).has_password?(password)
44
+ end
47
45
  end
48
46
  end
49
47
  end
@@ -16,7 +16,7 @@ module Fiona7OverrideHelper
16
16
 
17
17
  def scrivito_body_tags
18
18
  obj = @obj.kind_of?(RailsConnector::BasicObj) ? @obj.scrivito_obj : @obj
19
- Scrivito::LayoutTags.new(self).client_config(obj, @scrivito_resource)
19
+ Scrivito::LayoutTags.new(self).page_config(obj)
20
20
  end
21
21
 
22
22
  def fiona7_head_tags
@@ -37,9 +37,13 @@ module Fiona7OverrideHelper
37
37
  def fiona7_tag_list(tag_name, obj, field_name, options = {}, &block)
38
38
  raise "This method can only be used in legacy mode" unless Fiona7.mode == :legacy
39
39
 
40
+ fiona_obj = obj.kind_of?(RailsConnector::BasicObj) ? obj : obj.fiona_obj
40
41
  obj = obj.kind_of?(RailsConnector::BasicObj) ? obj.scrivito_obj : obj
42
+ children_map = Hash[fiona_obj.children.map {|c| [c.id.to_s, c] }]
43
+
41
44
  scrivito_tag_list(tag_name, obj, field_name, options) do |list, scrivito_child|
42
- block.call(list, scrivito_child.fiona_obj)
45
+ fiona_child = children_map[scrivito_child.id]
46
+ block.call(list, fiona_child)
43
47
  end
44
48
  end
45
49
 
@@ -7,7 +7,12 @@ module Fiona7
7
7
  has_many :children, :class_name => self.name, :foreign_key => 'parent_obj_id'
8
8
  belongs_to :parent, :class_name => self.name, :foreign_key => 'parent_obj_id'
9
9
 
10
- default_scope { where('suppress_export = 0 AND obj_class NOT IN (?)', ['X_Generic', 'X_Image', 'X_Container']) }
10
+ if Fiona7.mode == :standalone
11
+ default_scope { where('suppress_export = 0 AND obj_class NOT IN (?)', ['X_Generic', 'X_Image', 'X_Container']) }
12
+ else
13
+ # suppress_export can be misused in legacy mode
14
+ default_scope { where('obj_class NOT IN (?)', ['X_Generic', 'X_Image', 'X_Container']) }
15
+ end
11
16
 
12
17
  # disable STI
13
18
  self.inheritance_column = :_type_disabled
@@ -7,9 +7,17 @@ module Fiona7
7
7
  has_many :children, :class_name => self.name, :foreign_key => 'parent_obj_id'
8
8
  belongs_to :parent, :class_name => self.name, :foreign_key => 'parent_obj_id'
9
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)
10
+ if Fiona7.mode == :standalone
11
+ default_scope do
12
+ now = Time.now.utc.to_iso
13
+ 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)
14
+ end
15
+ else
16
+ # suppress_export can be misused in legacy mode
17
+ default_scope do
18
+ now = Time.now.utc.to_iso
19
+ where("is_released = 1").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)
20
+ end
13
21
  end
14
22
 
15
23
  # disable STI
@@ -14,9 +14,19 @@ module Fiona7
14
14
  'Fiona7::InternalReleasedObj'
15
15
  ]
16
16
 
17
- self.configure_for_content(:edited)
18
- # disable STI
17
+ # in legacy mode the app decides the default
18
+ # and per request table-switching does the rest
19
+ if Fiona7.mode == :standalone
20
+ self.configure_for_content(:edited)
21
+ end
22
+
23
+ # Workaround for constant reloading breaking
24
+ # otherwise dangling references
25
+ # Obj.reflections["children"].klass != Obj
26
+ has_many :children, :class_name => 'RailsConnector::AbstractObj', :foreign_key => 'parent_obj_id'
27
+ belongs_to :parent, :class_name => 'RailsConnector::AbstractObj', :foreign_key => 'parent_obj_id'
19
28
 
29
+ # disable STI
20
30
  if Fiona7.mode == :standalone
21
31
  # In standalone mode Obj belongs to scrivito
22
32
  # hence no inheritance
@@ -25,6 +35,10 @@ module Fiona7
25
35
  def self.descends_from_active_record?
26
36
  true
27
37
  end
38
+
39
+ def self.subclass_from_attributes(attrs)
40
+ nil
41
+ end
28
42
  else
29
43
  # If this method returns true no STI handling occurs
30
44
  def self.descends_from_active_record?
@@ -44,9 +58,10 @@ module Fiona7
44
58
  end
45
59
 
46
60
  # TODO: use this to simulate deleted objects
61
+ # but not in legacy mode !!
47
62
  #default_scope { where('suppress_export != 0') }
48
63
 
49
- self.logger = Logger.new(nil)
64
+ #self.logger = Logger.new(nil)
50
65
 
51
66
  include RailsConnector::Meta
52
67
 
@@ -1,4 +1,7 @@
1
1
  class Fiona7LoginPage < Scrivito::BasicObj
2
+ attribute :title, :string
3
+ attribute :body, :html
4
+
2
5
  def self.instance
3
6
  self.all.first
4
7
  end
@@ -0,0 +1,16 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>Fiona7</title>
5
+ <%= stylesheet_link_tag 'scrivito_ui' %>
6
+ <%= stylesheet_link_tag 'fiona7_ui' %>
7
+ <%= javascript_include_tag 'scrivito_ui' %>
8
+ <%= javascript_include_tag 'scrivito_ui_extensions' %>
9
+ <%= javascript_include_tag 'fiona7_ui' %>
10
+ <meta content="width=device-width, initial-scale=1.0" name="viewport"/>
11
+ </head>
12
+ <body id="scrivito_ui">
13
+ <iframe name="scrivito_application" src="<%= @application_src %>"></iframe>
14
+ <%= content_tag(:div, '', 'data-scrivito-private-ui-config' => @ui_config) %>
15
+ </body>
16
+ </html>
data/config/routes.rb CHANGED
@@ -1,6 +1,8 @@
1
1
  Rails.application.routes.draw do
2
2
  get '/_b/:id(/:name)' => 'fiona7/blobs#show', as: :fiona7_blob
3
3
 
4
+ match '/_b/:id(/:name)' => 'fiona7/blobs#query', as: :fiona7_blob_meta, via: [:head]
5
+
4
6
  post '/_f7/login', to: 'fiona7/sessions#create', as: :fiona7_login
5
7
 
6
8
  delete '/_f/logout', to: 'fiona7/sessions#destroy', as: :fiona7_logout
@@ -16,10 +16,12 @@ Gem::Specification.new do |s|
16
16
 
17
17
  s.files = Dir["{app,config,db,lib}/**/*", "Rakefile", "README.md", "infopark_fiona7.gemspec"]
18
18
 
19
- s.add_dependency "rails", "~> 4.1.5"
20
- s.add_dependency "scrivito", "~> 0.30"
19
+ s.add_dependency "rails", "~> 4.2.2"
20
+ s.add_dependency "scrivito", "= 0.70.0.rc1"
21
21
  s.add_dependency "scrivito_sdk"
22
22
  s.add_dependency "scrivito_editors"
23
- s.add_dependency "infopark_fiona_connector", "~> 7.0.0"
24
- s.add_dependency "infopark_reactor", "1.12.0"
23
+ s.add_dependency "infopark_fiona_connector", "= 7.0.1.beta2"
24
+ s.add_dependency "infopark_reactor", "= 1.15.0.beta1"
25
+ s.add_dependency "mini_magick"
26
+ s.add_development_dependency "ruby-prof"
25
27
  end
@@ -43,9 +43,13 @@ module Fiona7
43
43
 
44
44
  def dependencies
45
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']})
46
+ values.each do |attribute_name, (type, val)|
47
+ if type == "widgetlist"
48
+ if val.kind_of?(Array)
49
+ dependencies.merge(val)
50
+ elsif val.kind_of?(Hash)
51
+ dependencies.merge((val["list"]||[]).map {|w| w["widget"] })
52
+ end
49
53
  end
50
54
  end
51
55
  end
@@ -5,7 +5,7 @@ module Fiona7
5
5
  end
6
6
  end
7
7
 
8
- require 'fiona7/type_register_mixin'
8
+ require 'fiona7/type_register'
9
9
  require 'fiona7/recursive_link_resolver'
10
10
  #require 'fiona7/write_obj'
11
11
  #require 'fiona7/released_obj'
@@ -17,19 +17,21 @@ require 'fiona7/widget_resolver'
17
17
  module Fiona7
18
18
  module Builder
19
19
  class ObjBuilder
20
- include TypeRegisterMixin
21
20
 
22
21
  def initialize(values)
23
22
  @values = values.symbolize_keys
23
+ # garbage
24
+ @values.delete(:_modification)
25
+ # revert command sends this info. which is silly.
26
+ @values.delete(:_last_changed)
27
+ puts "CREATING/UPDATING: #{@values.inspect}"
24
28
  end
25
29
 
26
30
  def build
27
31
  assert_valid
28
32
  prepare_object
29
33
 
30
- create_object
31
34
  write_widget_pool
32
- namespace_attributes
33
35
  store_attributes
34
36
 
35
37
  @obj
@@ -40,37 +42,37 @@ module Fiona7
40
42
  end
41
43
 
42
44
  protected
45
+ def update?
46
+ false
47
+ end
48
+
43
49
  def assert_valid
44
50
  validate || (raise Scrivito::ClientError.new(@error_msg || "Invalid input", 422))
45
51
  end
46
52
 
47
53
  def prepare_object
48
- @path = @values.delete(:_path)
54
+ @path = @values.delete(:_path) || generate_orphaned_path
49
55
  @obj_class = @values.delete(:_obj_class)
56
+ @real_obj_class = TypeRegister::NameAliaser.new(virtual: @obj_class).real_obj_class
50
57
  @widget_pool = @values.delete(:_widget_pool)
51
58
  @permalink = @values.delete(:_permalink)
52
- if @path
53
- @path = "/#{@path}" unless @path.start_with?('/')
54
- @name, parent_path = name_and_parent_path_from_path(@path)
55
- end
59
+
60
+ @path = "/#{@path}" unless @path.start_with?('/')
61
+ @name, parent_path = name_and_parent_path_from_path(@path)
56
62
  @parent = ensure_parent_exists(parent_path) if parent_path
57
- end
58
63
 
59
- def namespace_attributes
60
- # nop
61
- end
64
+ ensure_obj_class_exists
62
65
 
63
- def create_object
64
66
  # bottom one is faster, but can only work when there are no widgets and no uploads
65
- if (@widget_pool && !@widget_pool.empty?) || (@values.any? {|_, v| v.kind_of?(File) || v.kind_of?(ActionDispatch::Http::UploadedFile) } )
66
- @obj = WriteObj.create!(name: @name, parent_obj_id: @parent.id, obj_class: @obj_class)
67
+ if (@widget_pool && !@widget_pool.empty?) || (@values.any? {|_, (_, v)| v.kind_of?(File) || v.kind_of?(ActionDispatch::Http::UploadedFile) } )
68
+ @obj = WriteObj.create!(name: @name, parent_obj_id: @parent.id, obj_class: @real_obj_class)
67
69
  else
68
- @obj = WriteObj.new(name: @name, parent_obj_id: @parent.id, obj_class: @obj_class)
70
+ @obj = WriteObj.create!(name: @name, parent_obj_id: @parent.id, obj_class: @real_obj_class)
69
71
  end
70
72
  end
71
73
 
72
74
  def write_widget_pool
73
- resolver = WidgetResolver.new(@obj[:X_widget_pool]||[])
75
+ resolver = WidgetResolver.new(@obj.attr_values["X_widget_pool"]||[], WriteObj)
74
76
 
75
77
  @id_map = resolver.id_map
76
78
  @widget_path_map = resolver.path_map
@@ -83,25 +85,45 @@ module Fiona7
83
85
  if @widgets.pool_changed?
84
86
  # after widget writing this either has new widgets
85
87
  # or some widgets have been removed
86
- @new_widget_pool = @widget_path_map.map do |widget_id, path|
87
- {title: widget_id, destination_object: path}
88
+
89
+ @new_widget_pool = @widget_pool.map do |widget_id, definition|
90
+ # widget deleted
91
+ next if definition.nil?
92
+ {title: widget_id, destination_object: @widget_path_map[widget_id]}
93
+ end.compact
94
+
95
+ # newly added widgets
96
+ @widget_path_map.each do |widget_id, path|
97
+ next if !@widget_pool[widget_id].nil?
98
+ @new_widget_pool << {title: widget_id, destination_object: path}
88
99
  end
100
+
89
101
  end
90
102
  end
91
103
  end
92
104
 
93
105
  def store_attributes
94
- if @obj.obj_class != @obj_class
95
- @obj.obj_class = @obj_class
106
+ if @obj.obj_class != @real_obj_class
107
+ @obj.obj_class = @real_obj_class
96
108
  @obj.save!
97
109
  @obj.reload
98
110
  end
99
- # TODO: reload into singleton class
100
111
  @obj.send(:reload_attributes)
101
- @values.each do |attribute_name, value|
102
- virtual_name = attribute_name.to_sym
103
- attribute_name = real_name = type_register.real_attribute_name(@obj.obj_class, virtual_name)
104
- virtual_type = type_register.attribute_type(@obj.obj_class, virtual_name)
112
+ type_definition = Fiona7::TypeRegister.instance.write(@obj_class)
113
+ if type_definition.nil?
114
+ raise "Definition not found for #{@obj_class}"
115
+ end
116
+ @values.each do |attribute_name, possible_pair|
117
+ (claimed_type, value) = *possible_pair
118
+ attribute = type_definition.find_attribute(attribute_name)
119
+ if attribute.nil?
120
+ debugger
121
+ raise "Attribute #{attribute_name} not found in #{@obj_class}"
122
+ end
123
+
124
+ virtual_name = attribute.name.to_sym
125
+ attribute_name = real_name = attribute.real_name.to_sym
126
+ virtual_type = attribute.type.to_sym
105
127
 
106
128
  case virtual_type
107
129
  when :linklist
@@ -162,38 +184,64 @@ module Fiona7
162
184
  if ids.empty?
163
185
  @obj.set(attribute_name.to_s, [])
164
186
  else
165
- objects_map = Hash[WriteObj.where(obj_id: ids).map {|o| [o.id, o]}]
187
+ objects_map = Hash[WriteObj.where(obj_id: ids).map {|o| [o.id.to_s, o]}]
166
188
  objects = ids.map {|id| objects_map[id] }.compact
167
189
  @obj.set(attribute_name, objects)
168
190
  end
169
- when :widget
191
+ when :widgetlist
170
192
  links = []
171
- value = (value || {}).symbolize_keys
172
- (value[:list] || []).each do |crap|
173
- widget_id = (crap[:widget] || crap['widget']).to_sym
174
-
175
- if (path=@widget_path_map[widget_id]||@widget_path_map[widget_id.to_s])
176
- links << {destination_object: path, title: widget_id}
177
- else
178
- raise Scrivito::ScrivitoError, "Inconsistent widget pool state detected, unable to store widgets"
193
+ if value.kind_of?(Array)
194
+ (value || []).each do |widget_id|
195
+ if (path=@widget_path_map[widget_id]||@widget_path_map[widget_id.to_s])
196
+ links << {destination_object: path, title: widget_id}
197
+ else
198
+ raise Scrivito::ScrivitoError, "Inconsistent widget pool state detected, unable to store widgets (unable to find #{widget_id} in #{@widget_path_map.inspect})"
199
+ end
200
+ end
201
+ elsif value.kind_of?(Hash)
202
+ # stupid shits could not use one consistent format
203
+ (value || {})["list"].each do |crap|
204
+ widget_id = crap["widget"]
205
+ if (path=@widget_path_map[widget_id]||@widget_path_map[widget_id.to_s])
206
+ links << {destination_object: path, title: widget_id}
207
+ else
208
+ raise Scrivito::ScrivitoError, "Inconsistent widget pool state detected, unable to store widgets (unable to find #{widget_id} in #{@widget_path_map.inspect})"
209
+ end
179
210
  end
180
211
  end
181
212
  @obj.set(attribute_name.to_s, links)
182
213
  when :text, :string, :enum, :multienum, :date
214
+ #if value.nil? && value != @obj[attribute_name]
183
215
  @obj.set(attribute_name.to_s, value)
216
+ #end
217
+ when :stringlist
218
+ @obj.set(attribute_name.to_s, value.to_json)
184
219
  when :html
185
220
  converted_links = LinkConverter::ScrivitoToFiona.new(WriteObj, value.to_s).convert
186
221
  @obj.set(attribute_name.to_s, converted_links)
187
222
  when :binary
188
223
  if value.kind_of?(String)
189
224
  # NOTE: this code path has not been tested yet.
190
- target = {title: value, destination_object: ReleasedObj.find(value.to_i)}
225
+ target = {title: value, destination_object: InternalReleasedObj.find(value.to_i)}
191
226
  @obj.set(attribute_name.to_s, target)
192
227
  elsif value.kind_of?(File)
193
- @obj.set(attribute_name.to_s, upload_file(value))
228
+ if !Fiona7.mode == :legacy || attribute_name.to_s != "blob"
229
+ @obj.set(attribute_name.to_s, upload_file(value))
230
+ else
231
+ special_upload_handling(attribute_name, value)
232
+ end
194
233
  elsif value.kind_of?(ActionDispatch::Http::UploadedFile)
195
- @obj.set(attribute_name.to_s, upload_uploaded_file(value))
234
+ if !Fiona7.mode == :legacy || attribute_name.to_s != "blob"
235
+ @obj.set(attribute_name.to_s, upload_file(value))
236
+ else
237
+ special_upload_uploaded_handling(attribute_name, value)
238
+ end
196
239
  elsif value.nil?
240
+ @obj.set(attribute_name.to_s, [])
241
+ elsif value.kind_of?(Hash)
242
+ #TODO: legacy mode!
243
+ target = {title: value["id"], destination_object: InternalReleasedObj.find(value["id"].to_i)}
244
+ @obj.set(attribute_name.to_s, target)
197
245
  else
198
246
  raise Scrivito::ClientError.new("Invalid input for binary field", 422)
199
247
  end
@@ -203,11 +251,37 @@ module Fiona7
203
251
  end
204
252
  @obj.set(:X_widget_pool, @new_widget_pool) if @new_widget_pool
205
253
  @obj.set(:permalink, @permalink) if @permalink
254
+
206
255
  @obj.save!
207
256
 
208
- @obj.edit! unless @obj.really_edited?
257
+ #if !@values.empty? || !@new_widget_pool.nil?
258
+ @obj.edit! unless @obj.really_edited?
259
+ #end
260
+ end
261
+
262
+ def special_upload_handling(attribute_name, file)
263
+ if !@obj.binary?
264
+ # standard handling!
265
+ @obj.set(attribute_name.to_s, upload_file(file))
266
+ else
267
+ ext = ::File.extname(file.path).to_s[1..-1]
268
+ @obj.upload(file, ext)
269
+ end
209
270
  end
210
271
 
272
+ def special_upload_uploaded_handling(attribute_name, file)
273
+ if !@obj.binary?
274
+ # standard handling!
275
+ @obj.set(attribute_name.to_s, upload_uploaded_file(file))
276
+ else
277
+ ext = ::File.extname(file.original_filename).to_s[1..-1]
278
+ @obj.upload(file.open, ext)
279
+ end
280
+ end
281
+
282
+
283
+
284
+
211
285
  def upload_file(file)
212
286
  # only publication type can contain children (code = "5")
213
287
  # also handle / this way
@@ -290,7 +364,21 @@ module Fiona7
290
364
  end
291
365
  end
292
366
 
293
- WriteObj.find_by_path(original)
367
+ WriteObj.find_by_path(original) || (raise "Tried to make sure that the parent under '#{original}' exist, but it does not :(")
368
+ end
369
+
370
+ def generate_orphaned_path
371
+ return nil if update?
372
+ "_orphaned/#{SecureRandom.hex(16)}"
373
+ end
374
+
375
+ def ensure_obj_class_exists
376
+ values = @values.with_indifferent_access
377
+ obj_class = @obj_class
378
+
379
+ Fiona7::TypeRegister.instance.ad_hoc_synchronize(
380
+ Fiona7::TypeRegister::AdHocTypeDefinition.new(values, obj_class).type_definition
381
+ )
294
382
  end
295
383
  end
296
384
  end