Showing
2 changed files
with
23 additions
and
22 deletions
| @@ -97,31 +97,32 @@ module Kanjai | @@ -97,31 +97,32 @@ module Kanjai | ||
| 97 | new_markers_repeat = item[:field_options].select{|item| item[:attributes]['repeat'] == 'true' }.collect{|item| item[:name] } | 97 | new_markers_repeat = item[:field_options].select{|item| item[:attributes]['repeat'] == 'true' }.collect{|item| item[:name] } |
| 98 | 98 | ||
| 99 | Kanjai::PageContent.where(type_content: item[:code]).each do |page_content| | 99 | Kanjai::PageContent.where(type_content: item[:code]).each do |page_content| |
| 100 | - langs = page_content.page_content_markers.pluck(:lang).uniq | ||
| 101 | - row_indexes = page_content.page_content_markers.pluck(:row_item).uniq | ||
| 102 | - langs.each do |lang| | ||
| 103 | - row_indexes.each do |index| | ||
| 104 | - | ||
| 105 | - work_new_markers = index.to_i == 0 ? new_markers_general : new_markers_repeat | ||
| 106 | - #delete not exist more markers | ||
| 107 | - page_content.page_content_markers.where(lang: lang, row_item: index).where.not(marker: work_new_markers).delete_all | ||
| 108 | - | ||
| 109 | - exist_markers = page_content.page_content_markers.where(lang: lang, row_item: index).pluck(:marker) | ||
| 110 | - item[:field_options].select{|item| item[:attributes]['repeat'] == (index.to_i == 0 ? 'false' : 'true') }.each do |marker| | ||
| 111 | - unless exist_markers.include?(marker[:name]) | ||
| 112 | - page_content.page_content_markers.create( | ||
| 113 | - marker: marker[:name], | ||
| 114 | - row_item: index, | ||
| 115 | - marker_name: marker[:itemName], | ||
| 116 | - lang: lang | ||
| 117 | - ) | 100 | + if page_content.page_content_markers.count == 0 |
| 101 | + page_content.build_markers(item[:code]) | ||
| 102 | + else | ||
| 103 | + langs = page_content.page_content_markers.pluck(:lang).uniq | ||
| 104 | + row_indexes = page_content.page_content_markers.pluck(:row_item).uniq | ||
| 105 | + langs.each do |lang| | ||
| 106 | + row_indexes.each do |index| | ||
| 107 | + | ||
| 108 | + work_new_markers = index.to_i == 0 ? new_markers_general : new_markers_repeat | ||
| 109 | + #delete not exist more markers | ||
| 110 | + page_content.page_content_markers.where(lang: lang, row_item: index).where.not(marker: work_new_markers).delete_all | ||
| 111 | + | ||
| 112 | + exist_markers = page_content.page_content_markers.where(lang: lang, row_item: index).pluck(:marker) | ||
| 113 | + item[:field_options].select{|item| item[:attributes]['repeat'] == (index.to_i == 0 ? 'false' : 'true') }.each do |marker| | ||
| 114 | + unless exist_markers.include?(marker[:name]) | ||
| 115 | + page_content.page_content_markers.create( | ||
| 116 | + marker: marker[:name], | ||
| 117 | + row_item: index, | ||
| 118 | + marker_name: marker[:itemName], | ||
| 119 | + lang: lang | ||
| 120 | + ) | ||
| 121 | + end | ||
| 118 | end | 122 | end |
| 119 | end | 123 | end |
| 120 | end | 124 | end |
| 121 | - end | ||
| 122 | 125 | ||
| 123 | - exist_markers = page_content.page_content_markers.pluck(:marker) | ||
| 124 | - p exist_markers | ||
| 125 | end | 126 | end |
| 126 | end | 127 | end |
| 127 | 128 |