Commit c867520267ec69a4d13ec7964442f374ae445ec3

Authored by Andrey Karpikov
1 parent ef909843

support nested reepat and condition

1 1 PATH
2 2 remote: .
3 3 specs:
4   - kanjai (0.0.246)
  4 + kanjai (0.0.252)
5 5 acts-as-taggable-on (~> 6.5)
6 6 acts_as_list
7 7 acts_as_tree
... ...
... ... @@ -871,7 +871,7 @@ jQuery(document).ready(function () {
871 871 ],
872 872 });
873 873
874   - $("#accordion").append($data);
  874 + $this.closest(".wrapper-block").find('> .panel-group').append($data);
875 875
876 876 $data.find("input:file").each(function () {
877 877 ajaxFileUpload.initFileInput($(this));
... ... @@ -913,7 +913,9 @@ jQuery(document).ready(function () {
913 913 $wrapper = $this.closest(".panel-group"),
914 914 $currentItem = $this.closest(".panel"),
915 915 $prevItem = $currentItem.prev(),
916   - $nextItem = $currentItem.next();
  916 + $nextItem = $currentItem.next(),
  917 + repeat_id = $this.data('repeat-id');
  918 +
917 919
918 920 if ($this.hasClass("sort-up") && $prevItem) {
919 921 $currentItem.insertBefore($prevItem);
... ... @@ -925,14 +927,14 @@ jQuery(document).ready(function () {
925 927 var data = [],
926 928 position = 1;
927 929
928   - $wrapper.find(" > .panel").each(function () {
929   - data.push({ position: position, index: $(this).data("id") });
  930 + $wrapper.find(" > .panel").each(function (index) {
  931 + data.push({ position: position, index: $(this).data('id').split('_')[1] });
930 932 position += 1;
931 933 });
932 934 jQuery.ajax({
933 935 type: "POST",
934 936 url: $wrapper.data("update-url"),
935   - data: { data: data },
  937 + data: { data: data, repeat_id: repeat_id},
936 938 success: function (data) {
937 939 if ($this.hasClass("sort-up") && $prevItem) {
938 940 var prevItemId = $prevItem.data("id"),
... ...
... ... @@ -19,9 +19,12 @@ module Kanjai
19 19 def add_item
20 20 @obj = PageContent.find(params[:id])
21 21
22   - @row_item = @obj.build_markers_rows(@obj.type_content)
  22 + @row_item = @obj.build_markers_rows(@obj.type_content, params[:repeat_id], params[:parent_item_index])
23 23
24   - @current_row = @obj.page_content_markers.where('row_item != ?', @row_item).count
  24 + @current_row = @obj.page_content_markers.where(parent_id: params[:repeat_id]).where('row_item != ?', @row_item).count
  25 +
  26 + partial, locals = Kanjai::PageContent.edit_template(@obj.page, @obj.type_content)
  27 + @template_part = locals[:template_part]
25 28
26 29 render layout: false
27 30 end
... ... @@ -31,7 +34,7 @@ module Kanjai
31 34
32 35 @row_item = params[:row_item]
33 36
34   - @obj.delete_markers_row(@row_item)
  37 + @obj.delete_markers_row(@row_item, params[:repeat_id], params[:parent_item_index])
35 38
36 39 render :json => {status: 'ok'}
37 40 end
... ... @@ -44,7 +47,7 @@ module Kanjai
44 47 h[item[:index].to_i] = item[:position].to_i
45 48 end
46 49
47   - @obj.page_content_markers.each do |item|
  50 + @obj.page_content_markers.where(repeat_id: params[:repeat_id]).each do |item|
48 51 if h[item.row_item]
49 52 p item.row_item
50 53 p h[item.row_item]
... ...
... ... @@ -83,7 +83,7 @@ module Kanjai
83 83 markers_position[item[:name]] = index + 1
84 84 end
85 85
86   - return markers.sort{|a,b| (markers_position[a.marker] <=> markers_position[b.marker] ) }
  86 + return markers.sort{|a,b| (markers_position[a.marker].to_s <=> markers_position[b.marker].to_s ) }
87 87
88 88 return markers
89 89 end
... ...
... ... @@ -47,36 +47,49 @@ module Kanjai
47 47
48 48 subpart.field_options.each do |item|
49 49 if item[:name] != 'repeat'
50   -
51   - marker_obj = self.page_content_markers.find_by_marker(item[:name])
52   - unless marker_obj
53   - if item[:attributes]['repeat'].to_s == 'true'
54   - if count_repeat.to_i > 0
55   - (1..count_repeat).each do |index|
56   - self.page_content_markers.create({
57   - marker: item[:name],
58   - row_item: index,
59   - marker_name: item[:itemName]
60   - })
  50 + if item[:attributes]['repeatItemId'] == ""
  51 +
  52 + marker_obj = self.page_content_markers.find_by_marker(item[:name])
  53 + unless marker_obj
  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
61 63 end
62   - end
63   - else
  64 + else
64 65
65   - self.page_content_markers.create({
66   - marker: item[:name],
67   - marker_name: item[:itemName]
68   - })
  66 + self.page_content_markers.create({
  67 + marker: item[:name],
  68 + marker_name: item[:itemName]
  69 + })
  70 + end
69 71 end
70 72 end
71 73 end
72 74
73 75 end
  76 +
  77 +
  78 + subpart.conditions.select{|item| item["repeat_id"] == "" }.each do |cond|
  79 + self.page_content_markers.create({
  80 + marker: cond["name"],
  81 + marker_name: cond["name"],
  82 + condition: true
  83 + })
  84 + end
  85 +
  86 +
74 87 end
75 88 end
76 89 end
77 90 end
78 91
79   - def build_markers_rows(type_content)
  92 + def build_markers_rows(type_content, repeat_id, parent_item_index)
80 93 row_item = nil
81 94 if type_content != 'rte_editor'
82 95 page_template = self.page.page_template
... ... @@ -84,7 +97,7 @@ module Kanjai
84 97 subpart = page_template.template_parts.find_by_code(type_content)
85 98 if subpart
86 99 #find current max row_item
87   - row_item = self.page_content_markers.collect(&:row_item).max
  100 + row_item = self.page_content_markers.where(parent_id: parent_item_index, repeat_id: repeat_id).collect(&:row_item).max
88 101 row_item = 0 if row_item.nil?
89 102
90 103 row_item += 1
... ... @@ -92,16 +105,32 @@ module Kanjai
92 105 subpart.field_options.each do |item|
93 106 if item[:name] != 'repeat'
94 107
95   - if item[:attributes]['repeat'].to_s == 'true'
  108 + if item[:attributes]['repeatItemId'] == repeat_id
96 109 self.page_content_markers.create({
97 110 marker: item[:name],
98 111 row_item: row_item,
99   - marker_name: item[:itemName]
  112 + marker_name: item[:itemName],
  113 + parent_id: parent_item_index,
  114 + repeat_id: repeat_id,
  115 + condition: false
100 116 })
101 117 end
102 118
103 119 end
104 120 end
  121 +
  122 + subpart.conditions.select{|item| item["repeat_id"] == repeat_id }.each do |cond|
  123 + self.page_content_markers.create({
  124 + marker: cond["name"],
  125 + row_item: row_item,
  126 + marker_name: cond["name"],
  127 + parent_id: parent_item_index,
  128 + repeat_id: repeat_id,
  129 + condition: true
  130 + })
  131 + end
  132 +
  133 +
105 134 end
106 135 end
107 136
... ... @@ -110,8 +139,18 @@ module Kanjai
110 139 return row_item
111 140 end
112 141
113   - def delete_markers_row(row_item)
114   - self.page_content_markers.where(row_item: row_item).delete_all
  142 + def delete_markers_row(row_item, repeat_id, parent_item_index)
  143 + template_part = page.page_template.template_parts.find_by_code(type_content)
  144 + self.page_content_markers.where(row_item: row_item, repeat_id: repeat_id, parent_id: parent_item_index).delete_all
  145 +
  146 + repeat_element = template_part.field_options.select{|item| item[:name] == 'repeat' && item[:repeatItemId].to_s == repeat_id}.first
  147 + if repeat_element
  148 + ids = self.page_content_markers.where(repeat_id: repeat_element[:id], parent_id: row_item).pluck(:row_item).uniq
  149 + ids.each do |index|
  150 + delete_markers_row(index, repeat_element[:id], row_item)
  151 + end
  152 + end
  153 +
115 154 end
116 155
117 156 def get_content
... ... @@ -164,8 +203,8 @@ module Kanjai
164 203 result
165 204 end
166 205
167   - def formatted_conditions
168   - conditions || []
  206 + def formatted_conditions(repeat_id)
  207 + (conditions || [])[repeat_id]
169 208 end
170 209
171 210 end
... ...
... ... @@ -5,8 +5,8 @@ module Kanjai
5 5 serialize :elements, Array
6 6 serialize :field_options, Array
7 7
8   - def visibility_conditions
9   - conditions || []
  8 + def visibility_conditions(repeat_id)
  9 + (conditions || []).select{|item| item["repeat_id"] == repeat_id}.sort{|a,b| a["name"] <=> b["name"] }
10 10 end
11 11
12 12 end
... ...
  1 +<% uuid = SecureRandom.uuid %>
1 2 <% if @row_item.present? %>
2 3 <div class="panel panel-default" data-id="<%= @row_item %>">
3 4
... ... @@ -5,19 +6,19 @@
5 6 <h4>
6 7 <div class="row">
7 8 <div class="col-md-10">
8   - <a role="button" data-toggle="collapse" data-parent="#accordion" href="#collapse-<%= @row_item %>" aria-expanded="true" aria-controls="collapse-<%= @row_item %>" >
  9 + <a role="button" data-toggle="collapse" data-parent="#accordion" href="#collapse-<%= uuid %>-<%= @row_item %>" aria-expanded="true" aria-controls="collapse-<%= uuid %>-<%= @row_item %>" >
9 10 Item <%= @row_item %>
10 11 </a>
11 12 </div>
12 13 <div class="col-md-2">
13   - <%= link_to '#', class: 'sort-repeat-row sort-up' do %>
  14 + <%= link_to '#', class: 'sort-repeat-row sort-up', data: {repeat_id: params[:repeat_id]} do %>
14 15 <i class="fa fa-arrow-up"></i>
15 16 <% end %>
16   - <%= link_to '#', class: 'sort-repeat-row sort-down' do %>
  17 + <%= link_to '#', class: 'sort-repeat-row sort-down', data: {repeat_id: params[:repeat_id]} do %>
17 18 <i class="fa fa-arrow-down"></i>
18 19 <% end %>
19 20
20   - <%= link_to url_for(:controller => 'admin/page_contents', :action => 'delete_item', id: @obj.id, row_item: @row_item), class: 'delete-repeat-row' do %>
  21 + <%= link_to url_for(:controller => 'admin/page_contents', :action => 'delete_item', id: @obj.id, row_item: @row_item, parent_item_index: params[:parent_item_index], repeat_id: params[:repeat_id]), class: 'delete-repeat-row' do %>
21 22 <i class="fa fa-trash"></i>
22 23 <% end %>
23 24 </div>
... ... @@ -25,13 +26,17 @@
25 26
26 27 </h4>
27 28 </div>
28   - <div id="collapse-<%= @row_item %>" class="panel-collapse collapse" role="tabpanel" aria-labelledby="heading_<%= @row_item %>">
  29 +
  30 + <div id="collapse-<%= uuid %>-<%= @row_item %>" class="panel-collapse collapse" role="tabpanel" aria-labelledby="heading-<%= uuid %>-<%= @row_item %>">
29 31 <div class="panel-body">
30 32 <%= fields_for @obj do |form| %>
31   - <% sort_markers(@obj, @obj.page_content_markers.select{|item| item.row_item == @row_item}).each_with_index do |item, index| %>
  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| %>
32 34 <%= form.fields_for :page_content_markers, item, child_index: (@current_row + index) do |form2| %>
33 35 <div class="form-group">
34 36 <%= form2.label :text_value, form2.object.marker_name || form2.object.marker, :class => "control-label" %>
  37 + <% if form2.object.condition %>
  38 + <%= form2.check_box :text_value %>
  39 + <% end %>
35 40 <% if form2.object.get_marker_type(@obj.type_content) == 'string' %>
36 41 <%= form2.text_field :text_value, :class => "form-control" %>
37 42 <% end %>
... ... @@ -69,6 +74,17 @@
69 74 </div>
70 75 </div>
71 76
  77 + <% sub_repeat_elements = @template_part.field_options.select{|item| item[:name] == 'repeat' && item[:repeatItemId].to_s == params[:repeat_id] } %>
  78 +
  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 %>
  81 +
  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 +
72 85
73 86 </div>
  87 +
  88 +
  89 +
74 90 <% end %>
\ No newline at end of file
... ...
1 1 <%= fields_for @obj do |form| %>
2 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   -
10 3 <%= form.fields_for :page_content_markers, sort_markers(@obj, @obj.page_content_markers.where(:row_item => 0).order('id')) do |form2| %>
11 4 <div class="form-group">
12 5 <%= form2.label :text_value, form2.object.marker_name || form2.object.marker, :class => "control-label" %>
  6 + <% if form2.object.condition %>
  7 + <%= form2.check_box :text_value %>
  8 + <% end %>
  9 +
13 10 <% if form2.object.get_marker_type(@type_content) == 'string' %>
14 11 <%= form2.text_field :text_value, :class => "form-control" %>
15 12 <% end %>
... ... @@ -58,97 +55,12 @@
58 55 </div>
59 56 <% end %>
60 57
61   -
62   -
63 58 </div>
64 59
65   -
66   -
67 60 <% end %>
68   - <% row_items = @obj.page_content_markers.select{|item| item.row_item.to_i > 0}.collect(&:row_item).uniq %>
69   - <% repeat_element = template_part.field_options.select{|item| item[:name] == 'repeat' }.first %>
70   -
71   - <% if repeat_element.present? %>
72   - <h2>Repeat</h2>
73   -
74   - <% if repeat_element[:attributes]['count'].nil? %>
75   - <div class="text-right">
76   - <%= link_to 'Add Item', url_for(:controller => 'admin/page_contents', :action => 'add_item', id: @obj.id), class: 'btn btn-default add-repeat-row' %>
77   - </div>
78   - <% 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 %>
79 63
80   - <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) %>" >
81   - <% row_items.sort.each do |index| %>
82   - <div class="panel panel-default" data-id="<%= index %>" >
83   -
84   - <div class="panel-heading" role="tab" id="heading_<%= index %>">
85   - <h4>
86   - <div class="row">
87   - <div class="col-md-10">
88   - <a role="button" data-toggle="collapse" data-parent="#accordion" href="#collapse-<%= index %>" aria-expanded="true" aria-controls="collapse-<%= index %>" >
89   - <% header_content = @obj.page_content_markers.where(row_item: index, marker: @main_field).collect(&:text_value).join('-') %>
90   - <%= header_content.to_s.empty? ? "Item #{index}" : header_content %>
91   - </a>
92   - </div>
93   - <div class="col-md-2">
94   - <%= link_to '#', class: 'sort-repeat-row sort-up' do %>
95   - <i class="fa fa-arrow-up"></i>
96   - <% end %>
97   - <%= link_to '#', class: 'sort-repeat-row sort-down' do %>
98   - <i class="fa fa-arrow-down"></i>
99   - <% end %>
100   - <%= link_to url_for(:controller => 'admin/page_contents', :action => 'delete_item', id: @obj.id, row_item: index), class: 'delete-repeat-row' do %>
101   - <i class="fa fa-trash"></i>
102   - <% end %>
103   -
104   - </div>
105   - </div>
106   - </h4>
107   - </div>
108   - <div id="collapse-<%= index %>" class="panel-collapse collapse" role="tabpanel" aria-labelledby="heading_<%= index %>">
109   - <div class="panel-body">
110   - <%= form.fields_for :page_content_markers, sort_markers(@obj, @obj.page_content_markers.where(:row_item => index).order('id')) do |form2| %>
111   - <div class="form-group">
112   - <%= form2.label :text_value, form2.object.marker_name || form2.object.marker, :class => "control-label" %>
113   - <% if form2.object.get_marker_type(@type_content) == 'string' %>
114   - <%= form2.text_field :text_value, :class => "form-control" %>
115   - <% end %>
116   - <% if form2.object.get_marker_type(@type_content) == 'text' %>
117   - <%= form2.text_area :text_value, :class => "form-control page_html_content" %>
118   - <% end %>
119   - <% if form2.object.get_marker_type(@type_content) == 'textarea' %>
120   - <%= form2.text_area :text_value, :class => "form-control" %>
121   - <% end %>
122   - <% if form2.object.get_marker_type(@type_content) == 'file' %>
123   - <%= form2.hidden_field :text_value %>
124   - <div class="preview">
125   - <% if form2.object.text_value.present? %>
126   - <% if Kanjai::PageContentMarker.image?(form2.object.text_value) %>
127   - <div class="image-preview-block without-border">
128   - <div class="image-preview">
129   - <img src="<%= form2.object.text_value %>" alt="preview" />
130   - </div>
131   - </div>
132   - <% else %>
133   - <%= link_to 'file', form2.object.text_value %>
134   - <% end %>
135   - <% end %>
136   - </div>
137   - <div class="btn-group">
138   - <%= link_to t('actions.choose_file'), get_files_admin_images_url, class: 'btn btn-primary content-choose-image' %>
139   - <%= link_to t('actions.remove_file'), get_files_admin_images_url, class: "btn btn-danger content-remove-image #{form2.object.text_value.present? ? '' : 'not-visible'}" %>
140   - </div>
141   - <% end %>
142   -
143   - </div>
144   - <% end %>
145   - </div>
146   - </div>
147   -
148   -
149   - </div>
150   - <% end %>
151   - </div>
152   - <% end %>
  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} %>
153 65
154 66 <% end %>
\ No newline at end of file
... ...
  1 +<% if repeat_element.present? %>
  2 + <div class="wrapper-block" style="margin-left: <%= margin_index * 20 %>px">
  3 + <h2>Repeat <%= repeat_element[:itemName] %></h2>
  4 +
  5 + <% if repeat_element[:attributes]['count'].nil? %>
  6 + <div class="text-right">
  7 + <%= link_to 'Add Item', url_for(:controller => 'admin/page_contents', :action => 'add_item', id: @obj.id, parent_id: nil, repeat_id: repeat_element[:id], parent_item_index: parent_item_index, margin_index: margin_index ), class: 'btn btn-default add-repeat-row' %>
  8 + </div>
  9 + <% end %>
  10 + <% uuid = SecureRandom.uuid %>
  11 + <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) %>" >
  12 + <% row_items.sort.each do |index| %>
  13 + <div class="panel panel-default" data-id="<%= uuid %>_<%= index %>" >
  14 +
  15 + <div class="panel-heading" role="tab" id="heading_<%= uuid %>_<%= index %>">
  16 + <h4>
  17 + <div class="row">
  18 + <div class="col-md-10">
  19 + <a role="button" data-toggle="collapse" data-parent="#accordion" href="#collapse-<%= uuid %>-<%= index %>" aria-expanded="true" aria-controls="collapse-<%= uuid %>-<%= index %>" >
  20 + <% header_content = @obj.page_content_markers.where(row_item: index, marker: @main_field, parent_id: parent_item_index, repeat_id: repeat_element[:id]).collect(&:text_value).join('-') %>
  21 + <%= header_content.to_s.empty? ? "Item #{index}" : header_content %>
  22 + </a>
  23 + </div>
  24 + <div class="col-md-2">
  25 + <%= link_to '#', class: 'sort-repeat-row sort-up', data: {repeat_id: repeat_element[:id]} do %>
  26 + <i class="fa fa-arrow-up"></i>
  27 + <% end %>
  28 + <%= link_to '#', class: 'sort-repeat-row sort-down', data: {repeat_id: repeat_element[:id]} do %>
  29 + <i class="fa fa-arrow-down"></i>
  30 + <% end %>
  31 + <%= 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 %>
  32 + <i class="fa fa-trash"></i>
  33 + <% end %>
  34 +
  35 + </div>
  36 + </div>
  37 + </h4>
  38 + </div>
  39 + <div id="collapse-<%= uuid %>-<%= index %>" class="panel-collapse collapse" role="tabpanel" aria-labelledby="heading_<%= uuid %>-<%= index %>">
  40 + <div class="panel-body">
  41 + <%= 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| %>
  42 + <div class="form-group">
  43 + <%= form2.label :text_value, form2.object.marker_name || form2.object.marker, :class => "control-label" %>
  44 +
  45 + <% if form2.object.condition %>
  46 + <%= form2.check_box :text_value %>
  47 + <% end %>
  48 + <% if form2.object.get_marker_type(@type_content) == 'string' %>
  49 + <%= form2.text_field :text_value, :class => "form-control" %>
  50 + <% end %>
  51 + <% if form2.object.get_marker_type(@type_content) == 'text' %>
  52 + <%= form2.text_area :text_value, :class => "form-control page_html_content" %>
  53 + <% end %>
  54 + <% if form2.object.get_marker_type(@type_content) == 'textarea' %>
  55 + <%= form2.text_area :text_value, :class => "form-control" %>
  56 + <% end %>
  57 + <% if form2.object.get_marker_type(@type_content) == 'file' %>
  58 + <%= form2.hidden_field :text_value %>
  59 + <div class="preview">
  60 + <% if form2.object.text_value.present? %>
  61 + <% if Kanjai::PageContentMarker.image?(form2.object.text_value) %>
  62 + <div class="image-preview-block without-border">
  63 + <div class="image-preview">
  64 + <img src="<%= form2.object.text_value %>" alt="preview" />
  65 + </div>
  66 + </div>
  67 + <% else %>
  68 + <%= link_to 'file', form2.object.text_value %>
  69 + <% end %>
  70 + <% end %>
  71 + </div>
  72 + <div class="btn-group">
  73 + <%= link_to t('actions.choose_file'), get_files_admin_images_url, class: 'btn btn-primary content-choose-image' %>
  74 + <%= link_to t('actions.remove_file'), get_files_admin_images_url, class: "btn btn-danger content-remove-image #{form2.object.text_value.present? ? '' : 'not-visible'}" %>
  75 + </div>
  76 + <% end %>
  77 +
  78 + </div>
  79 + <% end %>
  80 + </div>
  81 + </div>
  82 +
  83 +
  84 + </div>
  85 +
  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 +
  94 + <% end %>
  95 + </div>
  96 +
  97 +
  98 +
  99 + </div>
  100 +<% end %>
\ No newline at end of file
... ...
  1 +class AddParentIdToKanjaiPageContentMarker < ActiveRecord::Migration[5.2]
  2 + def change
  3 + add_column :kanjai_page_content_markers, :parent_id, :integer
  4 + end
  5 +end
... ...
  1 +class AddRepeatIdToKanjaiPageContentMarker < ActiveRecord::Migration[5.2]
  2 + def change
  3 + add_column :kanjai_page_content_markers, :repeat_id, :string
  4 + end
  5 +end
... ...
  1 +class AddConditionToKanjaiPageContentMarker < ActiveRecord::Migration[5.2]
  2 + def change
  3 + add_column :kanjai_page_content_markers, :condition, :boolean, default: false
  4 + end
  5 +end
... ...
... ... @@ -42,16 +42,26 @@ module Kanjai
42 42 conditions = []
43 43 elements = html_to_hash(source_dom)
44 44
45   - p '1'
46 45 source_dom.traverse do |node|
47 46 if node.name.to_s == 'condition' && node.attributes && node.attributes['id'] && node.attributes['name']
  47 +
  48 + repeatItemId = ""
  49 + test = node.parent
  50 + while test
  51 + if test.name == 'repeat' && test.attributes["id"].present?
  52 + repeatItemId = test.attributes["id"].value
  53 + break
  54 + end
  55 + test = test.parent
  56 + end
  57 +
48 58 conditions << {
49 59 id: node.attributes['id'].value,
50 60 name: node.attributes['name'].value,
  61 + repeat_id: repeatItemId
51 62 }
52 63 end
53 64 end
54   - p '2'
55 65
56 66
57 67 #field_options = elements.select {|item| (item[:name] == 'element' or item[:name] == 'repeat' ) }
... ... @@ -108,8 +118,19 @@ module Kanjai
108 118 attr[key] = value.value
109 119 end
110 120
111   - if item.name == 'repeat'
112   - @field_options << {:name => item.name, :itemName => nil, :attributes => attr, :source => nil, :children => {}}
  121 + if item.name == 'repeat' && item.attributes["id"].present?
  122 + repeatItemId = ""
  123 + test = item.parent
  124 + while test
  125 + if test.name == 'repeat' && test.attributes["id"].present?
  126 + repeatItemId = test.attributes["id"].value
  127 + break
  128 + end
  129 + test = test.parent
  130 + end
  131 +
  132 +
  133 + @field_options << {:name => item.name, id: item.attributes["id"].value, :itemName => item.attributes["itemname"]&.value, repeatItemId: repeatItemId, :attributes => attr, :source => nil, :children => {}}
113 134 end
114 135
115 136 if item.name == "text"
... ... @@ -119,10 +140,13 @@ module Kanjai
119 140 end
120 141
121 142 repeat = "false"
  143 + repeatItemId = ""
122 144 test = item
123 145 while test
124   - if test.name == 'repeat'
  146 + if test.name == 'repeat' && test.attributes["id"].present?
125 147 repeat = "true"
  148 + repeatItemId = test.attributes["id"].value
  149 + break
126 150 end
127 151 test = test.parent
128 152 end
... ... @@ -130,7 +154,7 @@ module Kanjai
130 154
131 155 source.to_s.scan(/{"element":[\w\W\{]+?}}/).each do |str|
132 156 element_hash = JSON.parse(str)
133   - @field_options << {:name => element_hash["element"]["title"], :itemName => element_hash["element"]["itemName"] , main: element_hash["element"]["main"].to_i, :attributes => {'type' => element_hash["element"]["type"], 'repeat' => repeat}, :source => nil, :children => {}}
  157 + @field_options << {:name => element_hash["element"]["title"], :itemName => element_hash["element"]["itemName"] , main: element_hash["element"]["main"].to_i, :attributes => {'type' => element_hash["element"]["type"], 'repeat' => repeat, 'repeatItemId' => repeatItemId}, :source => nil, :children => {}}
134 158 source.gsub!(str, element_hash["element"]["title"])
135 159 end
136 160
... ... @@ -138,7 +162,7 @@ module Kanjai
138 162 value.to_s.scan(/{"element":[\w\W\{]+?}}/).each do |str|
139 163
140 164 element_hash = JSON.parse(str)
141   - @field_options << {:name => element_hash["element"]["title"], :itemName => element_hash["element"]["itemName"] , main: element_hash["element"]["main"].to_i, :attributes => {'type' => element_hash["element"]["type"], 'repeat' => repeat}, :source => nil, :children => {}}
  165 + @field_options << {:name => element_hash["element"]["title"], :itemName => element_hash["element"]["itemName"] , main: element_hash["element"]["main"].to_i, :attributes => {'type' => element_hash["element"]["type"], 'repeat' => repeat, 'repeatItemId' => repeatItemId}, :source => nil, :children => {}}
142 166 value.gsub!(str, element_hash["element"]["title"])
143 167 end
144 168 end
... ...
1 1 module Kanjai
2   - VERSION = "0.0.252"
  2 + VERSION = "0.0.253"
3 3 end
... ...