Commit a5f48c6972988f8378998274cccf572350dfa0ad

Authored by Andrey Karpikov
1 parent 6623b9b0

show and use condition for page render

No preview for this file type
1 1 PATH
2 2 remote: .
3 3 specs:
4   - kanjai (0.0.239)
  4 + kanjai (0.0.245)
5 5 acts-as-taggable-on (~> 6.5)
6 6 acts_as_list
7 7 acts_as_tree
... ... @@ -1198,7 +1198,7 @@ GEM
1198 1198 builder (3.2.4)
1199 1199 concurrent-ruby (1.1.9)
1200 1200 crass (1.0.6)
1201   - devise (4.8.0)
  1201 + devise (4.8.1)
1202 1202 bcrypt (~> 3.0)
1203 1203 orm_adapter (~> 0.1)
1204 1204 railties (>= 4.1.0)
... ... @@ -1220,11 +1220,9 @@ GEM
1220 1220 method_source (1.0.0)
1221 1221 mini_magick (4.11.0)
1222 1222 mini_mime (1.1.1)
1223   - mini_portile2 (2.6.1)
1224 1223 minitest (5.14.4)
1225 1224 nio4r (2.5.8)
1226   - nokogiri (1.12.4)
1227   - mini_portile2 (~> 2.6.1)
  1225 + nokogiri (1.12.4-x86_64-darwin)
1228 1226 racc (~> 1.4)
1229 1227 orm_adapter (0.5.0)
1230 1228 pg (1.0.0)
... ...
... ... @@ -13,9 +13,6 @@ module Kanjai
13 13 @type_content = content_type
14 14
15 15 render :partial => partial, locals: locals
16   -
17   -
18   -
19 16 end
20 17
21 18
... ... @@ -47,8 +44,6 @@ module Kanjai
47 44 h[item[:index].to_i] = item[:position].to_i
48 45 end
49 46
50   - p h
51   -
52 47 @obj.page_content_markers.each do |item|
53 48 if h[item.row_item]
54 49 p item.row_item
... ...
... ... @@ -170,6 +170,9 @@ module Kanjai
170 170 @obj = PageContent.create({:page => @page, :page_datum => @page_data, :structure_id => @structure_id})
171 171 end
172 172
  173 + params[:page_content] ||= {}
  174 + params[:page_content][:conditions] ||= []
  175 +
173 176 @obj.update(permitted_params[:page_content])
174 177
175 178 if params[:frontend_part].to_i == 1
... ... @@ -300,7 +303,8 @@ module Kanjai
300 303 params.permit(:page => [:parent_id, :domain_id, :page_template_id, :title, :private_flag, :default_private_page, :root_page, :show_public_only,
301 304 :page_data_attributes => [:id, :title, :url, :meta_title, :meta_description, :meta_keywords]],
302 305 :page_content => [:type_content, :text_html, :controller_name, :action_name,
303   - page_content_markers_attributes: [:id, :page_content_id, :marker, :text_value, :attachment_file_name, :form_subject, :form_body, :from_mail, :to_mail, :form_answer_text, :_destroy]
  306 + page_content_markers_attributes: [:id, :page_content_id, :marker, :text_value, :attachment_file_name, :form_subject, :form_body, :from_mail, :to_mail, :form_answer_text, :_destroy],
  307 + conditions: []
304 308 ],
305 309 :page_datum => [:id, :title, :url, :meta_title, :meta_description, :meta_keywords]
306 310 )
... ...
... ... @@ -90,10 +90,8 @@ module Kanjai
90 90 html = TemplateGenerator::subpart_generate(session, domain, page_template, template_part.part_type, template_part.elements)
91 91 layer.gsub!(content, html)
92 92 end
93   -
94   -
95   -
96 93 end
  94 +
97 95 (0..1).each do |index|
98 96 layer.scan(/(<element name="([\w\W]+?)"><\/element>)/).each do |item|
99 97 content = item[0]
... ...
... ... @@ -72,11 +72,7 @@ module Kanjai
72 72
73 73 end
74 74 end
75   -
76 75 end
77   -
78   -
79   -
80 76 end
81 77 end
82 78
... ... @@ -168,5 +164,9 @@ module Kanjai
168 164 result
169 165 end
170 166
  167 + def formatted_conditions
  168 + conditions || []
  169 + end
  170 +
171 171 end
172 172 end
\ No newline at end of file
... ...
... ... @@ -90,7 +90,8 @@ module Kanjai
90 90 code: item[:code],
91 91 source: item[:source],
92 92 elements: item[:elements],
93   - field_options: item[:field_options]
  93 + field_options: item[:field_options],
  94 + conditions: item[:conditions]
94 95 )
95 96
96 97 new_markers_general = item[:field_options].select{|item| item[:attributes]['repeat'] == 'false' }.collect{|item| item[:name] }
... ...
... ... @@ -4,5 +4,10 @@ module Kanjai
4 4
5 5 serialize :elements, Array
6 6 serialize :field_options, Array
  7 +
  8 + def visibility_conditions
  9 + conditions || []
  10 + end
  11 +
7 12 end
8 13 end
\ No newline at end of file
... ...
1 1 <%= fields_for @obj do |form| %>
  2 +
  3 + <% template_part.visibility_conditions.each do |item| %>
  4 + <div>
  5 + <%= check_box_tag "page_content[conditions][]", item['id'], @obj.formatted_conditions.include?(item['id']) %>
  6 + <%= item['name'] %>
  7 + </div>
  8 + <% end %>
  9 +
2 10 <%= form.fields_for :page_content_markers, sort_markers(@obj, @obj.page_content_markers.where(:row_item => 0).order('id')) do |form2| %>
3 11 <div class="form-group">
4 12 <%= form2.label :text_value, form2.object.marker_name || form2.object.marker, :class => "control-label" %>
... ...
  1 +class AddConditionsToTemplatePart < ActiveRecord::Migration[5.2]
  2 + def change
  3 + add_column :kanjai_template_parts, :conditions, :jsonb
  4 + end
  5 +end
... ...
  1 +class AddConditionsToPageContent < ActiveRecord::Migration[5.2]
  2 + def change
  3 + add_column :kanjai_page_contents, :conditions, :jsonb
  4 + end
  5 +end
... ...
... ... @@ -8,6 +8,7 @@ module Kanjai
8 8 @original_hash_value ||= {}
9 9
10 10 @page_content_id = page_content_id
  11 + @page_content = page_content_id.present? ? Kanjai::PageContent.find(page_content_id) : nil
11 12
12 13 Nokogiri::HTML::Builder.with(@doc) do |subparts|
13 14 TemplateGenerator.method("#{type}_generator").call(session, domain, elements, subparts, @original_hash_value[0])
... ... @@ -229,18 +230,28 @@ module Kanjai
229 230 end
230 231 end
231 232 else
232   - attributes = self.replace_attributes_marker(item[:attributes], hash_value)
233   - if item[:name] == 'select'
234   - subparts.select(attributes) do |next_subparts|
235   - self.content_generator(session, domain, item[:children], next_subparts, hash_value)
236   - end
237   - elsif item[:name] == 'p'
238   - if item[:children].count > 0
239   - subparts.p(attributes, self.replace_text_marker(item[:children][0][:source], hash_value).html_safe)
240   - end
241   - else
242   - subparts.send(item[:name], attributes) do |next_subparts|
243   - self.content_generator(session, domain, item[:children], next_subparts, hash_value)
  233 + condition_process = true
  234 +
  235 + if item[:name] == 'condition' && @page_content.present? && item[:attributes] && item[:attributes]['id']
  236 + condition_process = @page_content.formatted_conditions.include?(item[:attributes]['id'])
  237 + end
  238 +
  239 + #condition_process = false
  240 +
  241 + if condition_process
  242 + attributes = self.replace_attributes_marker(item[:attributes], hash_value)
  243 + if item[:name] == 'select'
  244 + subparts.select(attributes) do |next_subparts|
  245 + self.content_generator(session, domain, item[:children], next_subparts, hash_value)
  246 + end
  247 + elsif item[:name] == 'p'
  248 + if item[:children].count > 0
  249 + subparts.p(attributes, self.replace_text_marker(item[:children][0][:source], hash_value).html_safe)
  250 + end
  251 + else
  252 + subparts.send(item[:name], attributes) do |next_subparts|
  253 + self.content_generator(session, domain, item[:children], next_subparts, hash_value)
  254 + end
244 255 end
245 256 end
246 257 end
... ...
... ... @@ -39,24 +39,35 @@ module Kanjai
39 39 source_dom = Nokogiri::HTML::fragment(source)
40 40
41 41 @field_options = []
  42 + conditions = []
42 43 elements = html_to_hash(source_dom)
43 44
  45 + p '1'
  46 + source_dom.traverse do |node|
  47 + if node.name.to_s == 'condition' && node.attributes && node.attributes['id'] && node.attributes['name']
  48 + conditions << {
  49 + id: node.attributes['id'].value,
  50 + name: node.attributes['name'].value,
  51 + }
  52 + end
  53 + end
  54 + p '2'
44 55
45 56
46 57 #field_options = elements.select {|item| (item[:name] == 'element' or item[:name] == 'repeat' ) }
47 58 #field_options = get_elements(elements)
48 59 #elements.delete_if {|item| item[:name] == 'element' }
49 60
50   -
51   -
52 61 result << {
53 62 name: name,
54 63 type: type,
55 64 code: code,
56 65 source: source,
57 66 elements: elements,
58   - field_options: @field_options
  67 + field_options: @field_options,
  68 + conditions: conditions
59 69 }
  70 + p '3'
60 71 end
61 72 end
62 73
... ...