Commit 5bf144b30b55801dced99cdf9cd7cb1cb78390d9

Authored by Andrey Karpikov
1 parent 2637e37e

check config and render reepat element and condition part

... ... @@ -28,6 +28,8 @@ module Kanjai
28 28 end
29 29 end
30 30
  31 + use_cache = false
  32 +
31 33 if current_admin_user || @page_data.page.private_flag == true || use_cache == false
32 34 layer = @page_data.page.page_template.get_html_content
33 35 content_for_render = setTemplateContent(@page_data.page.domain, @page_data.page.page_template, layer, @page_data)
... ...
... ... @@ -83,7 +83,7 @@ module Kanjai
83 83 names_array = {}
84 84
85 85 (subpart.conditions || []).each do |item|
86   - names_array[item["name"]] = item["name"]
  86 + names_array[item["name"]] = item["id"]
87 87 end
88 88 subpart.field_options.each do |item|
89 89 names_array[item[:itemName]] = item[:name]
... ...
... ... @@ -77,7 +77,7 @@ module Kanjai
77 77
78 78 subpart.conditions.select{|item| item["repeat_id"] == "" }.each do |cond|
79 79 self.page_content_markers.create({
80   - marker: cond["name"],
  80 + marker: cond["id"],
81 81 marker_name: cond["name"],
82 82 condition: true
83 83 })
... ... @@ -121,7 +121,7 @@ module Kanjai
121 121
122 122 subpart.conditions.select{|item| item["repeat_id"] == repeat_id }.each do |cond|
123 123 self.page_content_markers.create({
124   - marker: cond["name"],
  124 + marker: cond["id"],
125 125 row_item: row_item,
126 126 marker_name: cond["name"],
127 127 parent_id: parent_item_index,
... ...
... ... @@ -71,16 +71,19 @@
71 71 <% end %>
72 72 <% end %>
73 73 <% end %>
74   - </div>
75   - </div>
76 74
77   - <% sub_repeat_elements = @template_part.field_options.select{|item| item[:name] == 'repeat' && item[:repeatItemId].to_s == params[:repeat_id] } %>
  75 + <% sub_repeat_elements = @template_part.field_options.select{|item| item[:name] == 'repeat' && item[:repeatItemId].to_s == params[:repeat_id] } %>
  76 +
  77 + <% sub_repeat_elements.each do |sub_repeat_element| %>
  78 + <% sub_row_items = @obj.page_content_markers.select{|item| item.row_item.to_i > 0 && item.parent_id == params[:parent_item_index] && item.repeat_id == sub_repeat_element[:id]}.collect(&:row_item).uniq %>
  79 +
  80 + <%= render partial: 'kanjai/admin/pages/content_types/repeat_item', locals: {repeat_element: sub_repeat_element, row_items: sub_row_items, template_part: @template_part, form: nil, margin_index: params[:margin_index].to_i + 1, parent_item_index: @row_item} %>
  81 + <% end %>
  82 +
78 83
79   - <% sub_repeat_elements.each do |sub_repeat_element| %>
80   - <% sub_row_items = @obj.page_content_markers.select{|item| item.row_item.to_i > 0 && item.parent_id == params[:parent_item_index] && item.repeat_id == sub_repeat_element[:id]}.collect(&:row_item).uniq %>
  84 + </div>
  85 + </div>
81 86
82   - <%= render partial: 'kanjai/admin/pages/content_types/repeat_item', locals: {repeat_element: sub_repeat_element, row_items: sub_row_items, template_part: @template_part, form: nil, margin_index: params[:margin_index].to_i + 1, parent_item_index: @row_item} %>
83   - <% end %>
84 87
85 88
86 89 </div>
... ...
... ... @@ -58,9 +58,12 @@
58 58 </div>
59 59
60 60 <% end %>
61   - <% row_items = @obj.page_content_markers.select{|item| item.row_item.to_i > 0 && item.parent_id.nil?}.collect(&:row_item).uniq %>
62   - <% repeat_element = template_part.field_options.select{|item| item[:name] == 'repeat' && item[:repeatItemId].to_s.empty? }.first %>
  61 + <% repeat_elements = template_part.field_options.select{|item| item[:name] == 'repeat' && item[:repeatItemId].to_s.empty? } %>
63 62
64   - <%= render partial: 'kanjai/admin/pages/content_types/repeat_item', locals: {repeat_element: repeat_element, row_items: row_items, template_part: template_part, form: form, margin_index: 0, parent_item_index: nil} %>
  63 + <% repeat_elements.each do |repeat_element| %>
  64 + <% row_items = @obj.page_content_markers.select{|item| item.row_item.to_i > 0 && item.parent_id.nil? && item.repeat_id == repeat_element[:id] }.collect(&:row_item).uniq %>
  65 +
  66 + <%= render partial: 'kanjai/admin/pages/content_types/repeat_item', locals: {repeat_element: repeat_element, row_items: row_items, template_part: template_part, form: form, margin_index: 0, parent_item_index: nil} %>
  67 + <% end %>
65 68
66 69 <% end %>
\ No newline at end of file
... ...
... ... @@ -77,19 +77,22 @@
77 77
78 78 </div>
79 79 <% end %>
  80 +
  81 +
  82 + <% sub_repeat_elements = template_part.field_options.select{|item| item[:name] == 'repeat' && item[:repeatItemId].to_s == repeat_element[:id] } %>
  83 +
  84 + <% sub_repeat_elements.each do |sub_repeat_element| %>
  85 + <% sub_row_items = @obj.page_content_markers.select{|item| item.row_item.to_i > 0 && item.parent_id == index && item.repeat_id == sub_repeat_element[:id]}.collect(&:row_item).uniq %>
  86 +
  87 + <%= render partial: 'kanjai/admin/pages/content_types/repeat_item', locals: {repeat_element: sub_repeat_element, row_items: sub_row_items, template_part: template_part, form: form, margin_index: margin_index + 1, parent_item_index: index} %>
  88 + <% end %>
  89 +
80 90 </div>
81 91 </div>
82 92
83 93
84 94 </div>
85 95
86   - <% sub_repeat_elements = template_part.field_options.select{|item| item[:name] == 'repeat' && item[:repeatItemId].to_s == repeat_element[:id] } %>
87   -
88   - <% sub_repeat_elements.each do |sub_repeat_element| %>
89   - <% sub_row_items = @obj.page_content_markers.select{|item| item.row_item.to_i > 0 && item.parent_id == index && item.repeat_id == sub_repeat_element[:id]}.collect(&:row_item).uniq %>
90   -
91   - <%= render partial: 'kanjai/admin/pages/content_types/repeat_item', locals: {repeat_element: sub_repeat_element, row_items: sub_row_items, template_part: template_part, form: form, margin_index: margin_index + 1, parent_item_index: index} %>
92   - <% end %>
93 96
94 97 <% end %>
95 98 </div>
... ...
... ... @@ -218,25 +218,37 @@ module Kanjai
218 218 when 'text'
219 219 subparts << self.replace_text_marker(item[:source], hash_value)
220 220 when 'repeat'
221   - @original_hash_value.each do |key, value|
222   - if key > 0
223   - if(key == 1)
224   - value['###FIRST_ITEM_ACTIVE###'] = 'active'
225   - else
226   - value['###FIRST_ITEM_ACTIVE###'] = ''
227   - end
228   - value['###REPEAT_NUMBER###'] = key.to_s
229   - self.content_generator(session, domain, item[:children], subparts, value)
  221 + repeat_id = item[:attributes]['id']
  222 + scope = @page_content.page_content_markers.where(repeat_id: repeat_id)
  223 + if hash_value && hash_value['PARENT_ITEM_ID'].present?
  224 + scope = scope.where(parent_id: hash_value['PARENT_ITEM_ID'])
  225 + end
  226 + row_index = scope.pluck(:row_item).uniq.sort
  227 +
  228 + row_index.each do |row_index|
  229 + value = scope.where(row_item: row_index).collect{|item| [item.marker, item.text_value] }.to_h
  230 +
  231 + if(row_index == 1)
  232 + value['###FIRST_ITEM_ACTIVE###'] = 'active'
  233 + else
  234 + value['###FIRST_ITEM_ACTIVE###'] = ''
230 235 end
  236 + value['###REPEAT_NUMBER###'] = row_index.to_s
  237 + value['PARENT_ITEM_ID'] = row_index.to_s
  238 +
  239 + self.content_generator(session, domain, item[:children], subparts, value)
  240 +
231 241 end
  242 +
232 243 else
233 244 condition_process = true
234   -
  245 + p '!!!!!!!!!!!!!!!!!!!!!!'
  246 + p hash_value
  247 + p item[:attributes]['id']
235 248 if item[:name] == 'condition' && @page_content.present? && item[:attributes] && item[:attributes]['id']
236   - condition_process = @page_content.formatted_conditions.include?(item[:attributes]['id'])
  249 + condition_process = hash_value[item[:attributes]['id']].to_i == 1
237 250 end
238 251
239   - #condition_process = false
240 252
241 253 if condition_process
242 254 attributes = self.replace_attributes_marker(item[:attributes], hash_value)
... ...
1 1 module Kanjai
2   - VERSION = "0.0.261"
  2 + VERSION = "0.0.262"
3 3 end
... ...