Commit c5f2dbf3c42f72b5b71a8e49043796203737d2d1

Authored by Andrey Karpikov
1 parent c7aeb4f1

sort field for edit in page content by name, add solution choose menu item

1 1 PATH
2 2 remote: .
3 3 specs:
4   - kanjai (0.0.245)
  4 + kanjai (0.0.246)
5 5 acts-as-taggable-on (~> 6.5)
6 6 acts_as_list
7 7 acts_as_tree
... ...
... ... @@ -47,7 +47,7 @@ module Kanjai
47 47
48 48 def update
49 49 @page_template = PageTemplate.find(params[:id])
50   - @page_template.unzip = false
  50 + @page_template.unzip = false if params[:page_template][:attachment_file_name].present?
51 51
52 52 if @page_template.update(permitted_params[:page_template])
53 53 render json: {status: 'ok'}
... ... @@ -99,7 +99,7 @@ module Kanjai
99 99 private
100 100
101 101 def permitted_params
102   - params.permit(:page_template => [:title, :attachment_file_name, :notice,
  102 + params.permit(:page_template => [:title, :attachment_file_name, :notice, :menu,
103 103 page_content_markers_attributes: [:id, :page_content_id, :marker, :text_value, :attachment_file_name]
104 104 ])
105 105 end
... ...
... ... @@ -78,13 +78,19 @@ module Kanjai
78 78 layer.gsub!('<meta name="csrf-token" content="###CSRF_TOKEN###"/>', '')
79 79 end
80 80
81   - layer.scan(/(<element name="([\w\W]+?)" type="([\w\W]+?)"><\/element>)/).each do |item|
  81 + layer.scan(/(<element name="([\w\W]*?)" type="([\w\W]+?)"><\/element>)/).each do |item|
82 82 content = item[0]
83   - name = item[1]
  83 + name = item[1].to_s
84 84 type = item[2]
85 85 code = name.parameterize
86 86
87   - template_part = page_template.template_parts.find_by_code(code)
  87 + if type == "menu" && name.to_s.empty?
  88 + template_part = nil
  89 + template_part = page_template.template_parts.find_by_code(page_template.menu) if template_part.nil? && page_template.menu.present?
  90 + template_part = page_template.template_parts.where(part_type: 'menu').order(:name).first if template_part.nil?
  91 + else
  92 + template_part = page_template.template_parts.find_by_code(code)
  93 + end
88 94
89 95 if template_part
90 96 html = TemplateGenerator::subpart_generate(session, domain, page_template, template_part.part_type, template_part.elements)
... ... @@ -93,9 +99,9 @@ module Kanjai
93 99 end
94 100
95 101 (0..1).each do |index|
96   - layer.scan(/(<element name="([\w\W]+?)"><\/element>)/).each do |item|
  102 + layer.scan(/(<element name="([\w\W]*?)"><\/element>)/).each do |item|
97 103 content = item[0]
98   - name = item[1]
  104 + name = item[1].to_s
99 105 code = name.parameterize
100 106
101 107 template_part = page_template.template_parts.find_by_code(code)
... ...
... ... @@ -78,9 +78,8 @@ module Kanjai
78 78 if page_template
79 79 subpart = page_template.template_parts.where(code: page_content.type_content).first
80 80 if subpart
81   - p '!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!'
82 81 markers_position = {}
83   - subpart.field_options.each_with_index do |item, index|
  82 + subpart.field_options.sort_by{|item| item[:name] }.each_with_index do |item, index|
84 83 markers_position[item[:name]] = index + 1
85 84 end
86 85
... ...
... ... @@ -12,6 +12,12 @@
12 12 </div>
13 13
14 14
  15 + <div class="form-group">
  16 + <%= f.label :menu, Kanjai::PageTemplate.human_attribute_name(:menu), class: 'col-form-label' %>
  17 + <%= f.select :menu, @page_template.template_parts.where(part_type: 'menu').order(:name).collect{|item| [item.name, item.code]}, {include_blank: true}, class: "form-control #{@page_template.errors.include?(:menu) ? 'parsley-error' : ''} " %>
  18 + <%= error_messages(@page_template, :menu) %>
  19 + </div>
  20 +
15 21 <fieldset>
16 22 <div class="form-group row">
17 23 <%= f.label :attachment_file_name, Kanjai::PageTemplate.human_attribute_name(:attachment), :class => "col-md-2 col-form-label" %>
... ...
  1 +class AddMenuToPageTemplate < ActiveRecord::Migration[5.2]
  2 + def change
  3 + add_column :kanjai_templates, :menu, :string
  4 + end
  5 +end
... ...
1 1 module Kanjai
2   - VERSION = "0.0.246"
  2 + VERSION = "0.0.247"
3 3 end
... ...