Commit 4e2521e6c62d228ab77e1f793adafb905cbd75da

Authored by Andrey Karpikov
1 parent cf544207

check template update

@@ -94,49 +94,66 @@ module Kanjai @@ -94,49 +94,66 @@ module Kanjai
94 conditions: item[:conditions] 94 conditions: item[:conditions]
95 ) 95 )
96 96
97 - new_markers_general = item[:field_options].select{|item| item[:attributes]['repeat'] == 'false' }.collect{|item| item[:name] }  
98 - new_markers_general += item[:conditions].select{|item| item[:repeat_id].to_s.empty? }.collect{|item| item[:id] }  
99 - new_markers_repeat = item[:field_options].select{|item| item[:attributes]['repeat'] == 'true' }.collect{|item| item[:name] }  
100 - new_markers_repeat += item[:conditions].select{|item| !item[:repeat_id].to_s.empty? }.collect{|item| item[:id] }  
101 -  
102 Kanjai::PageContent.joins(page: :page_template).where(type_content: item[:code], kanjai_templates: {id: self.id}).each do |page_content| 97 Kanjai::PageContent.joins(page: :page_template).where(type_content: item[:code], kanjai_templates: {id: self.id}).each do |page_content|
103 if page_content.page_content_markers.count == 0 98 if page_content.page_content_markers.count == 0
104 page_content.build_markers(item[:code], true) 99 page_content.build_markers(item[:code], true)
105 else 100 else
106 langs = page_content.page_content_markers.pluck(:lang).uniq 101 langs = page_content.page_content_markers.pluck(:lang).uniq
107 - row_indexes = page_content.page_content_markers.pluck(:row_item).uniq  
108 - langs.each do |lang|  
109 - row_indexes.each do |index|  
110 -  
111 - work_new_markers = index.to_i == 0 ? new_markers_general : new_markers_repeat  
112 - #delete not exist more markers  
113 - page_content.page_content_markers.where(lang: lang, row_item: index).where.not(marker: work_new_markers).delete_all  
114 -  
115 - exist_markers = page_content.page_content_markers.where(lang: lang, row_item: index).pluck(:marker)  
116 - item[:field_options].select{|item| item[:attributes]['repeat'] == (index.to_i == 0 ? 'false' : 'true') }.each do |marker|  
117 - unless exist_markers.include?(marker[:name])  
118 - page_content.page_content_markers.create(  
119 - marker: marker[:name],  
120 - row_item: index,  
121 - marker_name: marker[:itemName],  
122 - lang: lang,  
123 - )  
124 - end  
125 - end 102 +
  103 + repeat_ids = page_content.page_content_markers.pluck(:repeat_id).uniq
126 104
  105 + langs.each do |lang|
  106 + repeat_ids.each do |repeat_id|
  107 + parent_ids = page_content.page_content_markers.where(repeat_id: repeat_id).pluck(:parent_id).uniq
  108 + parent_ids.each do |parent_id|
  109 + row_indexes = page_content.page_content_markers.where(repeat_id: repeat_id, parent_id: parent_id).pluck(:row_item).uniq
  110 + row_indexes.each do |index|
  111 +
  112 + work_new_markers = item[:field_options].select{|item| item[:attributes]['repeatItemId'].to_s == repeat_id.to_s }.collect{|item| item[:name] }
  113 + work_new_markers += item[:conditions].select{|item| item[:repeat_id].to_s == repeat_id.to_s }.collect{|item| item[:id] }
  114 +
  115 + #delete not exist more markers
  116 + page_content.page_content_markers.where(lang: lang, row_item: index, parent_id: parent_id, repeat_id: repeat_id).where.not(marker: work_new_markers).delete_all
  117 +
  118 + scope = {lang: lang, row_item: index, repeat_id: repeat_id, parent_id: parent_id}
  119 +
  120 + exist_markers = page_content.page_content_markers.where(scope).pluck(:marker)
  121 + item[:field_options].select{|item| item[:attributes]['repeatItemId'] == repeat_id.to_s }.each do |marker|
  122 + unless exist_markers.include?(marker[:name])
  123 + page_content.page_content_markers.create(
  124 + marker: marker[:name],
  125 + row_item: index,
  126 + marker_name: marker[:itemName],
  127 + lang: lang,
  128 + parent_id: parent_id,
  129 + repeat_id: repeat_id,
  130 + condition: false
  131 + )
  132 + end
  133 +
  134 + page_content.page_content_markers.where(scope).where(marker: marker[:name]).update_all(marker_name: marker[:itemName])
  135 +
  136 + end
  137 +
  138 +
  139 + item[:conditions].select{|item| item[:repeat_id].to_s == repeat_id.to_s }.each do |marker|
  140 + unless exist_markers.include?(marker[:id])
  141 + page_content.page_content_markers.create(
  142 + marker: marker[:id],
  143 + row_item: index,
  144 + marker_name: marker[:name],
  145 + lang: lang,
  146 + parent_id: parent_id,
  147 + repeat_id: repeat_id,
  148 + condition: true
  149 + )
  150 + end
  151 + page_content.page_content_markers.where(scope).where(marker: marker[:name]).update_all(marker_name: marker[:itemName])
  152 +
  153 + end
127 154
128 - item[:conditions].select{|item| index.to_i == 0 ? item[:repeat_id].to_s.empty? : item[:repeat_id].to_s.present? }.each do |marker|  
129 - unless exist_markers.include?(marker[:id])  
130 - page_content.page_content_markers.create(  
131 - marker: marker[:id],  
132 - row_item: index,  
133 - marker_name: marker[:name],  
134 - lang: lang,  
135 - condition: true  
136 - )  
137 end 155 end
138 end 156 end
139 -  
140 end 157 end
141 end 158 end
142 end 159 end
1 module Kanjai 1 module Kanjai
2 - VERSION = "0.0.271" 2 + VERSION = "0.0.272"
3 end 3 end