Commit a5f48c6972988f8378998274cccf572350dfa0ad

Authored by Andrey Karpikov
1 parent 6623b9b0

show and use condition for page render

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