Commit e81d3997409fde8c7de0edfb21c7b1aca54c1d4c

Authored by Andrey Karpikov
1 parent ca026e51

check repeat element

1 1 PATH
2 2 remote: .
3 3 specs:
4   - kanjai (0.0.252)
  4 + kanjai (0.0.290)
5 5 acts-as-taggable-on (~> 6.5)
6 6 acts_as_list
7 7 acts_as_tree
... ...
... ... @@ -914,7 +914,8 @@ jQuery(document).ready(function () {
914 914 $currentItem = $this.closest(".panel"),
915 915 $prevItem = $currentItem.prev(),
916 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 921 if ($this.hasClass("sort-up") && $prevItem) {
... ... @@ -927,14 +928,14 @@ jQuery(document).ready(function () {
927 928 var data = [],
928 929 position = 1;
929 930
930   - $wrapper.find(" > .panel").each(function (index) {
  931 + $wrapper.children().each(function (index) {
931 932 data.push({ position: position, index: $(this).data('id').split('_')[1] });
932 933 position += 1;
933 934 });
934 935 jQuery.ajax({
935 936 type: "POST",
936 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 939 success: function (data) {
939 940 if ($this.hasClass("sort-up") && $prevItem) {
940 941 var prevItemId = $prevItem.data("id"),
... ...
... ... @@ -42,15 +42,17 @@ module Kanjai
42 42 def sorting
43 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 47 h = {}
46 48 params[:data].each do |key, item|
47 49 h[item[:index].to_i] = item[:position].to_i
48 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 55 if h[item.row_item]
52   - p item.row_item
53   - p h[item.row_item]
54 56 item.update_column(:row_item, h[item.row_item])
55 57 end
56 58 end
... ...
... ... @@ -44,7 +44,7 @@ module Kanjai
44 44 count_repeat = repeat_element[:attributes]['count'].to_i
45 45 end
46 46
47   -
  47 + uuid = SecureRandom.uuid
48 48 subpart.field_options.each do |item|
49 49 if item[:name] != 'repeat'
50 50 if item[:attributes]['repeatItemId'] == ""
... ... @@ -52,20 +52,22 @@ module Kanjai
52 52 marker_obj = self.page_content_markers.find_by_marker(item[:name])
53 53 unless marker_obj
54 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 65 else
65 66
66 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 72 end
71 73 end
... ... @@ -77,6 +79,7 @@ module Kanjai
77 79
78 80 subpart.conditions.select{|item| item["repeat_id"] == "" }.each do |cond|
79 81 self.page_content_markers.create({
  82 + uuid: uuid,
80 83 marker: cond["id"],
81 84 marker_name: cond["name"],
82 85 condition: true
... ... @@ -102,11 +105,14 @@ module Kanjai
102 105
103 106 row_item += 1
104 107
  108 + uuid = SecureRandom.uuid
  109 +
105 110 subpart.field_options.each do |item|
106 111 if item[:name] != 'repeat'
107 112
108 113 if item[:attributes]['repeatItemId'] == repeat_id
109 114 self.page_content_markers.create({
  115 + uuid: uuid,
110 116 marker: item[:name],
111 117 row_item: row_item,
112 118 marker_name: item[:itemName],
... ... @@ -121,6 +127,7 @@ module Kanjai
121 127
122 128 subpart.conditions.select{|item| item["repeat_id"] == repeat_id }.each do |cond|
123 129 self.page_content_markers.create({
  130 + uuid: uuid,
124 131 marker: cond["id"],
125 132 row_item: row_item,
126 133 marker_name: cond["name"],
... ...
... ... @@ -29,8 +29,9 @@
29 29
30 30 <div id="collapse-<%= uuid %>-<%= @row_item %>" class="panel-collapse collapse" role="tabpanel" aria-labelledby="heading-<%= uuid %>-<%= @row_item %>">
31 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 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 35 <%= form.fields_for :page_content_markers, item, child_index: (@current_row + index) do |form2| %>
35 36 <div class="form-group">
36 37 <%= form2.label :text_value, form2.object.marker_name || form2.object.marker, :class => "control-label" %>
... ... @@ -77,7 +78,7 @@
77 78 <% sub_repeat_elements.each do |sub_repeat_element| %>
78 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 82 <% end %>
82 83
83 84
... ...
... ... @@ -15,6 +15,7 @@
15 15 <% uuid = SecureRandom.uuid %>
16 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 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 19 <div class="panel panel-default" data-id="<%= uuid %>_<%= index %>" >
19 20
20 21 <div class="panel-heading" style="margin-top:20px;margin-bottom:20px;" role="tab" id="heading_<%= uuid %>_<%= index %>">
... ... @@ -27,10 +28,10 @@
27 28 </a>
28 29 </div>
29 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 32 <i class="fa fa-arrow-up"></i>
32 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 35 <i class="fa fa-arrow-down"></i>
35 36 <% end %>
36 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 44 </div>
44 45 <div id="collapse-<%= uuid %>-<%= index %>" class="panel-collapse collapse" role="tabpanel" aria-labelledby="heading_<%= uuid %>-<%= index %>">
45 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 48 <div class="form-group">
48 49 <%= form2.label :text_value, form2.object.marker_name || form2.object.marker, :class => "control-label" %>
49 50
... ... @@ -87,9 +88,9 @@
87 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 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 94 <% end %>
94 95
95 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 241 end
242 242 value['###REPEAT_NUMBER###'] = "#{repeat_id}_#{row_index.to_s}_#{hash_value['PARENT_ITEM_ID'] || 0}"
243 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 246 @repeat_type_index[repeat_id] += 1
247 247 self.content_generator(session, domain, item[:children], subparts, value)
... ... @@ -253,7 +253,7 @@ module Kanjai
253 253 if I18n.locale.to_s == code.to_s
254 254 self.content_generator(session, domain, item[:children], subparts, hash_value)
255 255 end
256   - else
  256 + when 'condition'
257 257 condition_process = true
258 258
259 259 if item[:name] == 'condition' && @page_content.present? && item[:attributes] && item[:attributes]['id']
... ... @@ -261,21 +261,23 @@ module Kanjai
261 261 condition_process = hash_value[item[:attributes]['id']].to_i == 0 if item[:attributes]['type'].to_s == 'disable'
262 262 end
263 263
264   -
265 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 281 end
280 282 end
281 283 end
... ...
1 1 module Kanjai
2   - VERSION = "0.0.290"
  2 + VERSION = "0.0.291"
3 3 end
... ...