Commit e81d3997409fde8c7de0edfb21c7b1aca54c1d4c

Authored by Andrey Karpikov
1 parent ca026e51

check repeat element

1 PATH 1 PATH
2 remote: . 2 remote: .
3 specs: 3 specs:
4 - kanjai (0.0.252) 4 + kanjai (0.0.290)
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
@@ -914,7 +914,8 @@ jQuery(document).ready(function () { @@ -914,7 +914,8 @@ jQuery(document).ready(function () {
914 $currentItem = $this.closest(".panel"), 914 $currentItem = $this.closest(".panel"),
915 $prevItem = $currentItem.prev(), 915 $prevItem = $currentItem.prev(),
916 $nextItem = $currentItem.next(), 916 $nextItem = $currentItem.next(),
917 - repeat_id = $this.data('repeat-id'); 917 + repeat_id = $this.data('repeat-id'),
  918 + parent_id = $this.data('parent-id');
918 919
919 920
920 if ($this.hasClass("sort-up") && $prevItem) { 921 if ($this.hasClass("sort-up") && $prevItem) {
@@ -927,14 +928,14 @@ jQuery(document).ready(function () { @@ -927,14 +928,14 @@ jQuery(document).ready(function () {
927 var data = [], 928 var data = [],
928 position = 1; 929 position = 1;
929 930
930 - $wrapper.find(" > .panel").each(function (index) { 931 + $wrapper.children().each(function (index) {
931 data.push({ position: position, index: $(this).data('id').split('_')[1] }); 932 data.push({ position: position, index: $(this).data('id').split('_')[1] });
932 position += 1; 933 position += 1;
933 }); 934 });
934 jQuery.ajax({ 935 jQuery.ajax({
935 type: "POST", 936 type: "POST",
936 url: $wrapper.data("update-url"), 937 url: $wrapper.data("update-url"),
937 - data: { data: data, repeat_id: repeat_id}, 938 + data: { data: data, repeat_id: repeat_id, parent_id: parent_id},
938 success: function (data) { 939 success: function (data) {
939 if ($this.hasClass("sort-up") && $prevItem) { 940 if ($this.hasClass("sort-up") && $prevItem) {
940 var prevItemId = $prevItem.data("id"), 941 var prevItemId = $prevItem.data("id"),
@@ -42,15 +42,17 @@ module Kanjai @@ -42,15 +42,17 @@ module Kanjai
42 def sorting 42 def sorting
43 @obj = PageContent.find(params[:id]) 43 @obj = PageContent.find(params[:id])
44 44
  45 + template_part = @obj.page.page_template.template_parts.find_by_code(@obj.type_content)
  46 +
45 h = {} 47 h = {}
46 params[:data].each do |key, item| 48 params[:data].each do |key, item|
47 h[item[:index].to_i] = item[:position].to_i 49 h[item[:index].to_i] = item[:position].to_i
48 end 50 end
49 51
50 - @obj.page_content_markers.where(repeat_id: params[:repeat_id]).each do |item| 52 +
  53 +
  54 + @obj.page_content_markers.where(repeat_id: params[:repeat_id], parent_id: params[:parent_id]).each do |item|
51 if h[item.row_item] 55 if h[item.row_item]
52 - p item.row_item  
53 - p h[item.row_item]  
54 item.update_column(:row_item, h[item.row_item]) 56 item.update_column(:row_item, h[item.row_item])
55 end 57 end
56 end 58 end
@@ -44,7 +44,7 @@ module Kanjai @@ -44,7 +44,7 @@ module Kanjai
44 count_repeat = repeat_element[:attributes]['count'].to_i 44 count_repeat = repeat_element[:attributes]['count'].to_i
45 end 45 end
46 46
47 - 47 + uuid = SecureRandom.uuid
48 subpart.field_options.each do |item| 48 subpart.field_options.each do |item|
49 if item[:name] != 'repeat' 49 if item[:name] != 'repeat'
50 if item[:attributes]['repeatItemId'] == "" 50 if item[:attributes]['repeatItemId'] == ""
@@ -52,20 +52,22 @@ module Kanjai @@ -52,20 +52,22 @@ module Kanjai
52 marker_obj = self.page_content_markers.find_by_marker(item[:name]) 52 marker_obj = self.page_content_markers.find_by_marker(item[:name])
53 unless marker_obj 53 unless marker_obj
54 if item[:attributes]['repeat'].to_s == 'true' 54 if item[:attributes]['repeat'].to_s == 'true'
55 - if count_repeat.to_i > 0  
56 - (1..count_repeat).each do |index|  
57 - self.page_content_markers.create({  
58 - marker: item[:name],  
59 - row_item: index,  
60 - marker_name: item[:itemName]  
61 - })  
62 - end  
63 - end 55 + #TODO: Refactor
  56 + #if count_repeat.to_i > 0
  57 + # (1..count_repeat).each do |index|
  58 + # self.page_content_markers.create({
  59 + # marker: item[:name],
  60 + # row_item: index,
  61 + # marker_name: item[:itemName]
  62 + # })
  63 + # end
  64 + #end
64 else 65 else
65 66
66 self.page_content_markers.create({ 67 self.page_content_markers.create({
67 - marker: item[:name],  
68 - marker_name: item[:itemName] 68 + uuid: uuid,
  69 + marker: item[:name],
  70 + marker_name: item[:itemName]
69 }) 71 })
70 end 72 end
71 end 73 end
@@ -77,6 +79,7 @@ module Kanjai @@ -77,6 +79,7 @@ module Kanjai
77 79
78 subpart.conditions.select{|item| item["repeat_id"] == "" }.each do |cond| 80 subpart.conditions.select{|item| item["repeat_id"] == "" }.each do |cond|
79 self.page_content_markers.create({ 81 self.page_content_markers.create({
  82 + uuid: uuid,
80 marker: cond["id"], 83 marker: cond["id"],
81 marker_name: cond["name"], 84 marker_name: cond["name"],
82 condition: true 85 condition: true
@@ -102,11 +105,14 @@ module Kanjai @@ -102,11 +105,14 @@ module Kanjai
102 105
103 row_item += 1 106 row_item += 1
104 107
  108 + uuid = SecureRandom.uuid
  109 +
105 subpart.field_options.each do |item| 110 subpart.field_options.each do |item|
106 if item[:name] != 'repeat' 111 if item[:name] != 'repeat'
107 112
108 if item[:attributes]['repeatItemId'] == repeat_id 113 if item[:attributes]['repeatItemId'] == repeat_id
109 self.page_content_markers.create({ 114 self.page_content_markers.create({
  115 + uuid: uuid,
110 marker: item[:name], 116 marker: item[:name],
111 row_item: row_item, 117 row_item: row_item,
112 marker_name: item[:itemName], 118 marker_name: item[:itemName],
@@ -121,6 +127,7 @@ module Kanjai @@ -121,6 +127,7 @@ module Kanjai
121 127
122 subpart.conditions.select{|item| item["repeat_id"] == repeat_id }.each do |cond| 128 subpart.conditions.select{|item| item["repeat_id"] == repeat_id }.each do |cond|
123 self.page_content_markers.create({ 129 self.page_content_markers.create({
  130 + uuid: uuid,
124 marker: cond["id"], 131 marker: cond["id"],
125 row_item: row_item, 132 row_item: row_item,
126 marker_name: cond["name"], 133 marker_name: cond["name"],
@@ -29,8 +29,9 @@ @@ -29,8 +29,9 @@
29 29
30 <div id="collapse-<%= uuid %>-<%= @row_item %>" class="panel-collapse collapse" role="tabpanel" aria-labelledby="heading-<%= uuid %>-<%= @row_item %>"> 30 <div id="collapse-<%= uuid %>-<%= @row_item %>" class="panel-collapse collapse" role="tabpanel" aria-labelledby="heading-<%= uuid %>-<%= @row_item %>">
31 <div class="panel-body"> 31 <div class="panel-body">
  32 + <% scope = @obj.page_content_markers.select{|item| item.row_item == @row_item && item.parent_id.to_s == params[:parent_item_index].to_s && item.repeat_id == params[:repeat_id] } %>
32 <%= fields_for @obj do |form| %> 33 <%= fields_for @obj do |form| %>
33 - <% sort_markers(@obj, @obj.page_content_markers.select{|item| item.row_item == @row_item && item.parent_id.to_s == params[:parent_item_index].to_s && item.repeat_id == params[:repeat_id] }).each_with_index do |item, index| %> 34 + <% sort_markers(@obj, scope).each_with_index do |item, index| %>
34 <%= form.fields_for :page_content_markers, item, child_index: (@current_row + index) do |form2| %> 35 <%= form.fields_for :page_content_markers, item, child_index: (@current_row + index) do |form2| %>
35 <div class="form-group"> 36 <div class="form-group">
36 <%= form2.label :text_value, form2.object.marker_name || form2.object.marker, :class => "control-label" %> 37 <%= form2.label :text_value, form2.object.marker_name || form2.object.marker, :class => "control-label" %>
@@ -77,7 +78,7 @@ @@ -77,7 +78,7 @@
77 <% sub_repeat_elements.each do |sub_repeat_element| %> 78 <% 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 <% 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
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 + <%= 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: scope.first.uuid} %>
81 <% end %> 82 <% end %>
82 83
83 84
@@ -15,6 +15,7 @@ @@ -15,6 +15,7 @@
15 <% uuid = SecureRandom.uuid %> 15 <% uuid = SecureRandom.uuid %>
16 <div class="panel-group sortable-list" id="accordion" role="tablist" aria-multiselectable="true" data-update-url="<%= url_for(:controller => 'admin/page_contents', :action => 'sorting', id: @obj.id) %>" > 16 <div class="panel-group sortable-list" id="accordion" role="tablist" aria-multiselectable="true" data-update-url="<%= url_for(:controller => 'admin/page_contents', :action => 'sorting', id: @obj.id) %>" >
17 <% row_items.sort.each do |index| %> 17 <% row_items.sort.each do |index| %>
  18 + <% scope = @obj.page_content_markers.where(:row_item => index, parent_id: parent_item_index, repeat_id: repeat_element[:id]).order('id') %>
18 <div class="panel panel-default" data-id="<%= uuid %>_<%= index %>" > 19 <div class="panel panel-default" data-id="<%= uuid %>_<%= index %>" >
19 20
20 <div class="panel-heading" style="margin-top:20px;margin-bottom:20px;" role="tab" id="heading_<%= uuid %>_<%= index %>"> 21 <div class="panel-heading" style="margin-top:20px;margin-bottom:20px;" role="tab" id="heading_<%= uuid %>_<%= index %>">
@@ -27,10 +28,10 @@ @@ -27,10 +28,10 @@
27 </a> 28 </a>
28 </div> 29 </div>
29 <div class="col-md-2"> 30 <div class="col-md-2">
30 - <%= link_to '#', class: 'sort-repeat-row sort-up', data: {repeat_id: repeat_element[:id]} do %> 31 + <%= link_to '#', class: 'sort-repeat-row sort-up', data: {repeat_id: repeat_element[:id], parent_id: parent_item_index} do %>
31 <i class="fa fa-arrow-up"></i> 32 <i class="fa fa-arrow-up"></i>
32 <% end %> 33 <% end %>
33 - <%= link_to '#', class: 'sort-repeat-row sort-down', data: {repeat_id: repeat_element[:id]} do %> 34 + <%= link_to '#', class: 'sort-repeat-row sort-down', data: {repeat_id: repeat_element[:id], parent_id: parent_item_index} do %>
34 <i class="fa fa-arrow-down"></i> 35 <i class="fa fa-arrow-down"></i>
35 <% end %> 36 <% end %>
36 <%= link_to url_for(:controller => 'admin/page_contents', :action => 'delete_item', id: @obj.id, row_item: index, parent_item_index: parent_item_index, repeat_id: repeat_element[:id]), class: 'delete-repeat-row' do %> 37 <%= link_to url_for(:controller => 'admin/page_contents', :action => 'delete_item', id: @obj.id, row_item: index, parent_item_index: parent_item_index, repeat_id: repeat_element[:id]), class: 'delete-repeat-row' do %>
@@ -43,7 +44,7 @@ @@ -43,7 +44,7 @@
43 </div> 44 </div>
44 <div id="collapse-<%= uuid %>-<%= index %>" class="panel-collapse collapse" role="tabpanel" aria-labelledby="heading_<%= uuid %>-<%= index %>"> 45 <div id="collapse-<%= uuid %>-<%= index %>" class="panel-collapse collapse" role="tabpanel" aria-labelledby="heading_<%= uuid %>-<%= index %>">
45 <div class="panel-body"> 46 <div class="panel-body">
46 - <%= form.fields_for :page_content_markers, sort_markers(@obj, @obj.page_content_markers.where(:row_item => index, parent_id: parent_item_index, repeat_id: repeat_element[:id]).order('id')) do |form2| %> 47 + <%= form.fields_for :page_content_markers, sort_markers(@obj, scope) do |form2| %>
47 <div class="form-group"> 48 <div class="form-group">
48 <%= form2.label :text_value, form2.object.marker_name || form2.object.marker, :class => "control-label" %> 49 <%= form2.label :text_value, form2.object.marker_name || form2.object.marker, :class => "control-label" %>
49 50
@@ -87,9 +88,9 @@ @@ -87,9 +88,9 @@
87 <% sub_repeat_elements = template_part.field_options.select{|item| item[:name] == 'repeat' && item[:repeatItemId].to_s == repeat_element[:id] }.sort{|a,b| a[:itemName] <=> b[:itemName] } %> 88 <% sub_repeat_elements = template_part.field_options.select{|item| item[:name] == 'repeat' && item[:repeatItemId].to_s == repeat_element[:id] }.sort{|a,b| a[:itemName] <=> b[:itemName] } %>
88 89
89 <% sub_repeat_elements.each do |sub_repeat_element| %> 90 <% sub_repeat_elements.each do |sub_repeat_element| %>
90 - <% 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 %> 91 + <% sub_row_items = @obj.page_content_markers.select{|item| item.row_item.to_i > 0 && item.parent_id == scope.first.uuid && item.repeat_id == sub_repeat_element[:id]}.collect(&:row_item).uniq %>
91 92
92 - <%= 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} %> 93 + <%= 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: scope.first.uuid} %>
93 <% end %> 94 <% end %>
94 95
95 </div> 96 </div>
  1 +class AddUuidToKanjaiPageContentMarker < ActiveRecord::Migration[5.2]
  2 + def change
  3 + add_column :kanjai_page_content_markers, :uuid, :string
  4 + end
  5 +end
  1 +class ChangeParentIdTypeFromKanjaiPageContentMarker < ActiveRecord::Migration[5.2]
  2 + def change
  3 + change_column :kanjai_page_content_markers, :parent_id, :string
  4 + end
  5 +end
@@ -241,7 +241,7 @@ module Kanjai @@ -241,7 +241,7 @@ module Kanjai
241 end 241 end
242 value['###REPEAT_NUMBER###'] = "#{repeat_id}_#{row_index.to_s}_#{hash_value['PARENT_ITEM_ID'] || 0}" 242 value['###REPEAT_NUMBER###'] = "#{repeat_id}_#{row_index.to_s}_#{hash_value['PARENT_ITEM_ID'] || 0}"
243 value['###REPEAT_CYCLE_COUNT###'] = @repeat_type_index[repeat_id].to_s 243 value['###REPEAT_CYCLE_COUNT###'] = @repeat_type_index[repeat_id].to_s
244 - value['PARENT_ITEM_ID'] = row_index.to_s 244 + value['PARENT_ITEM_ID'] = scope.where(row_item: row_index).first.uuid.to_s
245 245
246 @repeat_type_index[repeat_id] += 1 246 @repeat_type_index[repeat_id] += 1
247 self.content_generator(session, domain, item[:children], subparts, value) 247 self.content_generator(session, domain, item[:children], subparts, value)
@@ -253,7 +253,7 @@ module Kanjai @@ -253,7 +253,7 @@ module Kanjai
253 if I18n.locale.to_s == code.to_s 253 if I18n.locale.to_s == code.to_s
254 self.content_generator(session, domain, item[:children], subparts, hash_value) 254 self.content_generator(session, domain, item[:children], subparts, hash_value)
255 end 255 end
256 - else 256 + when 'condition'
257 condition_process = true 257 condition_process = true
258 258
259 if item[:name] == 'condition' && @page_content.present? && item[:attributes] && item[:attributes]['id'] 259 if item[:name] == 'condition' && @page_content.present? && item[:attributes] && item[:attributes]['id']
@@ -261,21 +261,23 @@ module Kanjai @@ -261,21 +261,23 @@ module Kanjai
261 condition_process = hash_value[item[:attributes]['id']].to_i == 0 if item[:attributes]['type'].to_s == 'disable' 261 condition_process = hash_value[item[:attributes]['id']].to_i == 0 if item[:attributes]['type'].to_s == 'disable'
262 end 262 end
263 263
264 -  
265 if condition_process 264 if condition_process
266 - attributes = self.replace_attributes_marker(item[:attributes], hash_value)  
267 - if item[:name] == 'select'  
268 - subparts.select(attributes) do |next_subparts|  
269 - self.content_generator(session, domain, item[:children], next_subparts, hash_value)  
270 - end  
271 - elsif item[:name] == 'p'  
272 - if item[:children].count > 0  
273 - subparts.p(attributes, self.replace_text_marker(item[:children][0][:source], hash_value).html_safe)  
274 - end  
275 - else  
276 - subparts.send(item[:name], attributes) do |next_subparts|  
277 - self.content_generator(session, domain, item[:children], next_subparts, hash_value)  
278 - end 265 + self.content_generator(session, domain, item[:children], subparts, hash_value)
  266 + end
  267 +
  268 + else
  269 + attributes = self.replace_attributes_marker(item[:attributes], hash_value)
  270 + if item[:name] == 'select'
  271 + subparts.select(attributes) do |next_subparts|
  272 + self.content_generator(session, domain, item[:children], next_subparts, hash_value)
  273 + end
  274 + elsif item[:name] == 'p'
  275 + if item[:children].count > 0
  276 + subparts.p(attributes, self.replace_text_marker(item[:children][0][:source], hash_value).html_safe)
  277 + end
  278 + else
  279 + subparts.send(item[:name], attributes) do |next_subparts|
  280 + self.content_generator(session, domain, item[:children], next_subparts, hash_value)
279 end 281 end
280 end 282 end
281 end 283 end
1 module Kanjai 1 module Kanjai
2 - VERSION = "0.0.290" 2 + VERSION = "0.0.291"
3 end 3 end