infopark_cloud_connector 6.9.0.3.197272233 → 6.9.1.3.22208381

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,10 @@
1
+ module RailsConnector
2
+
3
+ class BlobsController < WebserviceController
4
+ def upload_permission
5
+ permission = CmsRestApi.get('blobs/upload_permission')
6
+ render json: permission
7
+ end
8
+ end
9
+
10
+ end
@@ -1,41 +1,42 @@
1
1
  module RailsConnector
2
2
 
3
- class ObjsController < ActionController::Base
4
- rescue_from ClientError do |exception|
5
- render json: {error: exception.message}, status: exception.http_code
6
- end
7
-
8
- before_filter :merge_correctly_parsed_json_params
9
- before_filter :restrict_non_allow_access
3
+ class ObjsController < WebserviceController
10
4
  before_filter :load_object, only: [:update, :destroy, :create_widget]
11
5
 
12
- respond_to :json
6
+ def create
7
+ created_obj = CmsRestApi.post(
8
+ "revisions/#{Workspace.current.revision_id}/objs",
9
+ {obj: obj_params}
10
+ )
11
+ render json: created_obj
12
+ end
13
13
 
14
14
  def update
15
- raise "Required parameter 'obj' is missing." unless params[:obj].present?
16
- raise "Parameter 'obj' is not a hash." unless params[:obj].is_a?(Hash)
17
-
18
- convert_html_keys = params[:obj].keys.select do |key|
19
- @obj.type_of_attribute(key.to_s) == 'html'
20
- end
21
-
22
- convert_html_keys.each do |key|
23
- params[:obj][key] = ContentConversion.convert_html_links(
24
- params[:obj][key], request.host, request.port)
25
- end
26
-
27
15
  changed_obj = CmsRestApi.put(
28
16
  "revisions/#{Workspace.current.revision_id}/objs/#{params[:id]}",
29
- { :obj => params[:obj] }
17
+ {obj: obj_params}
30
18
  )
31
- render :json => changed_obj
19
+ render json: changed_obj
32
20
  end
33
21
 
34
22
  def destroy
35
- CmsRestApi.delete("revisions/#{Workspace.current.revision_id}/objs/#{params[:id]}")
23
+ @obj.destroy
36
24
  render json: {}
37
25
  end
38
26
 
27
+ def page_class_selection
28
+ thumbnails = {}
29
+ obj_classes = CmsRestApi.get("revisions/#{Workspace.current.revision_id}/obj_classes")
30
+ obj_classes['results'].each do |obj_class|
31
+ begin
32
+ name = obj_class['name']
33
+ thumbnails[name] = render_to_string("#{name.underscore}/thumbnail")
34
+ rescue ActionView::MissingTemplate
35
+ end
36
+ end
37
+ render json: thumbnails
38
+ end
39
+
39
40
  def widget_class_selection
40
41
  widgets = {}
41
42
  Dir[Rails.root + 'app/widgets/*'].each do |widget_path|
@@ -53,7 +54,7 @@ module RailsConnector
53
54
  }})
54
55
 
55
56
  @widget = Obj.find(widget['id'])
56
- @container = Obj.find(params[:container_id]) if params[:container_id].present?
57
+ @current_page = Obj.find(params[:current_page_id]) if params[:current_page_id].present?
57
58
 
58
59
  render json: {markup: render_to_string(layout: false)}
59
60
  end
@@ -64,25 +65,20 @@ module RailsConnector
64
65
  @obj = Obj.find(params[:id])
65
66
  end
66
67
 
67
- def restrict_non_allow_access
68
- unless allow_access?
69
- render(:text => 'Forbidden', :status => 403)
70
- end
71
- end
68
+ def obj_params
69
+ params[:obj].tap do |p|
70
+ raise "Required parameter 'obj' is missing." unless p.present?
71
+ raise "Parameter 'obj' is not a hash." unless p.is_a?(Hash)
72
72
 
73
- # If +true+, allow access to ObjsController, else deny access.
74
- # See {RailsConnector::Configuration.editing_auth} for details.
75
- # @return [Bool]
76
- def allow_access?
77
- Configuration.editing_auth_callback.call(request.env)
78
- end
73
+ if @obj
74
+ convert_html_keys = p.keys.select do |key|
75
+ @obj.type_of_attribute(key.to_s) == 'html'
76
+ end
79
77
 
80
- # Workaround for https://github.com/rails/rails/issues/8832
81
- def merge_correctly_parsed_json_params
82
- if request.format.json?
83
- body = request.body.read
84
- request.body.rewind
85
- params.merge!(ActiveSupport::JSON.decode(body)) if body.present?
78
+ convert_html_keys.each do |key|
79
+ p[key] = ContentConversion.convert_html_links(p[key], request.host, request.port)
80
+ end
81
+ end
86
82
  end
87
83
  end
88
84
  end
@@ -0,0 +1,11 @@
1
+ module RailsConnector
2
+
3
+ class TasksController < WebserviceController
4
+
5
+ def show
6
+ render json: CmsRestApi.get("tasks/#{params[:id]}")
7
+ end
8
+
9
+ end
10
+
11
+ end
@@ -0,0 +1,36 @@
1
+ module RailsConnector
2
+
3
+ class WebserviceController < ActionController::Base
4
+ rescue_from ClientError do |exception|
5
+ render json: {error: exception.message}, status: exception.http_code
6
+ end
7
+
8
+ before_filter :merge_correctly_parsed_json_params
9
+ before_filter :authorize
10
+
11
+ private
12
+
13
+ def authorize
14
+ unless allow_access?
15
+ render text: 'Forbidden', status: 403
16
+ end
17
+ end
18
+
19
+ # If +true+, allow access to ObjsController, else deny access.
20
+ # See {RailsConnector::Configuration.editing_auth} for details.
21
+ # @return [Bool]
22
+ def allow_access?
23
+ Configuration.editing_auth_callback.call(request.env)
24
+ end
25
+
26
+ # Workaround for https://github.com/rails/rails/issues/8832
27
+ def merge_correctly_parsed_json_params
28
+ if request.format.json?
29
+ body = request.body.read
30
+ request.body.rewind
31
+ params.merge!(ActiveSupport::JSON.decode(body)) if body.present?
32
+ end
33
+ end
34
+ end
35
+
36
+ end
@@ -0,0 +1,33 @@
1
+ module RailsConnector
2
+
3
+ class WorkspacesController < WebserviceController
4
+ def index
5
+ render json: CmsRestApi.get('workspaces')
6
+ end
7
+
8
+ def create
9
+ render json: CmsRestApi.post('workspaces', {workspace: workspace_params})
10
+ end
11
+
12
+ def update
13
+ render json: CmsRestApi.put("workspaces/#{params[:id]}", {workspace: workspace_params})
14
+ end
15
+
16
+ def destroy
17
+ render json: CmsRestApi.delete("workspaces/#{params[:id]}")
18
+ end
19
+
20
+ def publish
21
+ render json: CmsRestApi.put("workspaces/#{params[:id]}/publish", {})
22
+ end
23
+
24
+ private
25
+
26
+ def workspace_params
27
+ raise "Required parameter 'workspace' is missing." unless params[:workspace].present?
28
+ raise "Parameter 'workspace' is not a hash." unless params[:workspace].is_a?(Hash)
29
+ params[:workspace]
30
+ end
31
+ end
32
+
33
+ end
@@ -0,0 +1,100 @@
1
+ module RailsConnector
2
+
3
+ # This module contains helpers that can be used to reference images and other assets stored in the CMS.
4
+ #
5
+ # @api public
6
+ module CmsAssetHelper
7
+
8
+ # Calculates an HTML image tag for an image stored in the CMS.
9
+ #
10
+ # @note There are two different signatures of this method: the first one generates an HTML image tag with no
11
+ # inplace editing possible, the second one generated an HTML image tag for inplace editing.
12
+ #
13
+ # @overload cms_image_tag target, tag_options={}
14
+ # @note If you do not specify an HTML +alt+ attribute, the helper method will use +target+'s +display_title+.
15
+ # Calculates HTML image tag (no inplace editing possible).
16
+ #
17
+ # @param [Obj, Link] target Target containing image stored in CMS.
18
+ # @param [Hash] tag_options Additional HTML attributes for the tag.
19
+ #
20
+ # @example
21
+ # cms_image_tag @target
22
+ # cms_image_tag @target, alt: 'Interesting picture', class: 'my_image'
23
+ #
24
+ # @overload cms_image_tag obj, linklist, tag_options={}, editing_options={}
25
+ # @note If you do not specify an HTML +alt+ attribute, the helper method will use +obj+'s +display_title+.
26
+ # Calculates HTML image tag for inplace editing.
27
+ #
28
+ # @param [Obj] obj Obj with an attribute of type {LinkList}.
29
+ # @param [String, Symbol] linklist Name of {LinkList} attribute, which contains the image.
30
+ # @param [Hash] tag_options Additional HTML attributes for the tag.
31
+ #
32
+ # @param [Hash] editing_options Additional options for inplace editing.
33
+ # @option editing_options [String] :placeholder ('/assets/rails_connector/image_placeholder.png') URL or path to image to be displayed if target is missing.
34
+ #
35
+ # @example
36
+ # cms_image_tag @obj, :my_linklist
37
+ # cms_image_tag @obj, :my_linklist, alt: 'Interesting picture', class: 'my_image'
38
+ # cms_image_tag @obj, :my_linklist, {}, placeholder: image_path('my_placeholder.png')
39
+ # cms_image_tag @obj, :my_linklist, {class: 'my_image'}, placeholder: 'http://placehold.it/350x150'
40
+ #
41
+ # @return [String] HTML image tag
42
+ # @api public
43
+ def cms_image_tag(*args)
44
+ if args.second.nil? || args.second.is_a?(Hash)
45
+ target = args.first
46
+ if target.is_a?(LinkList)
47
+ ActiveSupport::Deprecation.warn(%{
48
+ Calling "cms_image_tag" with a "LinkList" is not allowed anymore.
49
+ Please use following syntax instead: cms_image_tag(@obj, :linklist).
50
+ })
51
+ end
52
+
53
+ tag_options = args.second || {}
54
+ tag_options.symbolize_keys!
55
+ tag_options[:src] = cms_path(target)
56
+ tag_options[:alt] ||= display_title(target)
57
+ else
58
+ obj = args.first
59
+ attribute_name = args.second
60
+ target = obj[attribute_name]
61
+ tag_options = args.third || {}
62
+ editing_options = args.fourth || {}
63
+
64
+ tag_options.symbolize_keys!
65
+ editing_options.symbolize_keys!
66
+
67
+ tag_options[:src] ||= begin
68
+ target_path = cms_path(target)
69
+ if target_path == RailsConnector::DefaultCmsRoutingHelper::LINK_TO_EMPTY_LINKLIST
70
+ editing_options[:placeholder] || image_path('rails_connector/image_placeholder.png')
71
+ else
72
+ target_path
73
+ end
74
+ end
75
+
76
+ if inplace_editing_allowed?
77
+ tag_options.merge!(
78
+ 'data-ip-resource-source-obj-id' => obj.id,
79
+ 'data-ip-resource-source-field-name' => attribute_name
80
+ )
81
+ end
82
+
83
+ tag_options.reverse_merge!(alt: display_title(target))
84
+ end
85
+
86
+ tag('img', tag_options)
87
+ end
88
+
89
+ private
90
+
91
+ def display_title(target)
92
+ if target.respond_to?(:display_title)
93
+ return target.display_title
94
+ elsif target.respond_to?(:first) && target.first.respond_to?(:display_title)
95
+ return target.first.display_title
96
+ end
97
+ end
98
+
99
+ end
100
+ end
@@ -13,7 +13,7 @@ module RailsConnector
13
13
  # @param tag_name [String, Symbol] Name of the html tag (e.g. +:h1+ or +:div+).
14
14
  # @param obj [Obj] A {Obj} from which attribute is read.
15
15
  # @param attribute [String, Symbol] Which attribute of the Obj should be rendered.
16
- # @param options [Hash] Additional options, which are passed to +content_tag+. Use them to add HTML attrbutes to the tag.
16
+ # @param options [Hash] Additional options, which are passed to +content_tag+. Use them to add HTML attributes to the tag.
17
17
  # @return [String] The rendered html tag
18
18
  #
19
19
  # Example Usage:
@@ -21,14 +21,18 @@ module RailsConnector
21
21
  # (renders an <h2> tag containing the text of the +headline+ attribute of +@obj+ and assigns the tag a css class called +very_important+.)
22
22
  # @api public
23
23
  def cms_tag(tag_name, obj, attribute, options = {})
24
- field_type = obj.type_of_attribute(attribute.to_s)
24
+ begin
25
+ field_type = obj.type_of_attribute(attribute.to_s)
26
+ rescue RailsConnectorError => e
27
+ return content_tag(tag_name, '', options)
28
+ end
25
29
 
26
30
  options = options.merge({
27
31
  'data-ip-field-id' => obj.id,
28
32
  'data-ip-field-obj-class' => obj.obj_class,
29
33
  'data-ip-field-name' => attribute,
30
34
  'data-ip-field-type' => field_type,
31
- }) if cms_editor_mode?
35
+ }) if inplace_editing_allowed?
32
36
 
33
37
  if field_type == 'widget'
34
38
  rendered_widgets = obj.widgets(attribute).map do |widget|
@@ -36,7 +40,7 @@ module RailsConnector
36
40
  end
37
41
  inner_html = safe_join(rendered_widgets)
38
42
  else
39
- if cms_editor_mode?
43
+ if inplace_editing_allowed?
40
44
  original_value = display_original_value(obj[attribute]) || ''
41
45
  # Concate with empty string to disable html_safe:
42
46
  options['data-ip-field-original-content'] = '' + original_value
@@ -47,15 +51,86 @@ module RailsConnector
47
51
  content_tag(tag_name, inner_html, options)
48
52
  end
49
53
 
50
- def cms_editor_mode?
51
- !Workspace.current.published?
54
+ class List
55
+
56
+ attr_reader :output
57
+
58
+ def initialize(template)
59
+ @template = template
60
+ end
61
+
62
+ # @param tag_name [String, Symbol] Name of the html tag (e.g. +:div+ or +:span+).
63
+ # @param options [Hash] Additional options, which are passed to +content_tag+. Use them to add HTML attributes to the tag.
64
+ # @return [String] The rendered html tag
65
+ #
66
+ # @example Render a <div> tag containing the text "random content" and assigns the tag a css class called +very_important+.
67
+ # <%= list.tag :div, class: "very_important" do %>
68
+ # random content
69
+ # <% end %>
70
+ def tag(tag_name, options = {}, &block)
71
+ if @output.present?
72
+ raise '"list.tag" can only be called once per iteration!'
73
+ else
74
+ @output = @template.content_tag(tag_name, options, &block) + "\n"
75
+
76
+ nil
77
+ end
78
+ end
79
+
80
+ end
81
+
82
+ # @param tag_name [String, Symbol] Name of the html tag (e.g. +:h1+ or +:div+).
83
+ # @param obj [Obj] A {Obj} from which method_name is read.
84
+ # @param method_name [String, Symbol] Which method_name of the Obj should be rendered. Currently only +toclist+ is supported
85
+ # @param options [Hash] Additional options, which are passed to +content_tag+. Use them to add HTML attributes to the tag.
86
+ # @yieldparam [List] list An instance, where +tag+ should be called once.
87
+ # @yieldparam [Obj] child Each child of +toclist+
88
+ # @return [String] The rendered html tag
89
+ #
90
+ # @example
91
+ # <%= cms_tag_list :div, @obj, :toclist, class: "very_important" do |list, child| %>
92
+ # <%= list.tag :div, class: "also_important" do %>
93
+ # <%= link_to cms_path(child) do %>
94
+ # <%= cms_tag :span, child, :title %>
95
+ # <% end %>
96
+ # <% end %>
97
+ # <% end %>
98
+ #
99
+ # # results for an obj with two children in
100
+ #
101
+ # <div class="very_important">
102
+ # <div class="also_important"><a href="/child1"><span>Child 1</span></a></div>
103
+ # <div class="also_important"><a href="/child2"><span>Child 2</span></a></div>
104
+ # </div>
105
+ def cms_tag_list(tag_name, obj, method_name, options = {})
106
+ if method_name.to_s == 'toclist'
107
+ items = obj.toclist
108
+ else
109
+ raise "#{method_name} is not (yet) supported. Currently only toclist is supported."
110
+ end
111
+
112
+ inner_html = "\n".html_safe
113
+
114
+ items.each do |item|
115
+ list = List.new(self)
116
+
117
+ yield list, item
118
+
119
+ inner_html << list.output
120
+ end
121
+
122
+ options = options.merge({
123
+ 'data-ip-child-list-path' => obj.path,
124
+ }) if inplace_editing_allowed?
125
+
126
+ content_tag(tag_name, inner_html, options)
52
127
  end
53
128
 
54
129
  def render_widget(widget, obj, field_name, container)
55
130
  options = {
56
131
  'data-ip-widget-id' => widget.id,
57
132
  'data-ip-widget-obj-class' => widget.obj_class,
58
- } if cms_editor_mode?
133
+ } if inplace_editing_allowed?
59
134
 
60
135
  content_tag(:div, options || {}) do
61
136
  WidgetRenderer.new(request).process('show', widget, obj, field_name, container)
@@ -2,8 +2,14 @@
2
2
  <%= javascript_tag do %>
3
3
  $(function() {
4
4
  infopark.i18n.set_locale("<%= I18n.locale %>");
5
- infopark.editing.initialize();
6
- infopark.obj.current_container_id = "<%= @obj.try(:id) %>";
5
+ infopark.editing.set_workspace(
6
+ infopark.workspace.from_data({
7
+ id: "<%= escape_javascript(RailsConnector::Workspace.current.id).html_safe %>",
8
+ title: "<%= escape_javascript(RailsConnector::Workspace.current.title).html_safe %>"
9
+ })
10
+ );
11
+ infopark.obj.current_page_id = "<%= @obj.try(:id) %>";
7
12
  infopark.admin_gui_base_url = "<%= RailsConnector::CmsRestApi.credentials[:url] %>";
13
+ infopark.editing.initialize();
8
14
  });
9
15
  <% end %>