constructor-pages 0.7.10 → 0.8.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8c3ad880702d0787d409bd4990d73fc3016d12c7
4
- data.tar.gz: d4a2b4044023da44df7bf14790eb6af7225bbea8
3
+ metadata.gz: d0457fa097a8f3640bda13ce1f9699d1de07fe13
4
+ data.tar.gz: 2dbd8ce3ee79fd7a4faa636823dc87ee6710b532
5
5
  SHA512:
6
- metadata.gz: 548992f46464ebcaca5bd68d21e74efd877a4495b7c1670c3ecacb8008fc9407fdbe9eb5d6f613092765753cccc7c8fcae0734622b1a82d40bf79dfe8d642a00
7
- data.tar.gz: cee707598161a23679cacc9faed3c04bfe67ca1b68674f4fe6e9b22326a4f5da473f11f1d81423aef64c70e28291d81a8eda0e3d0d35cae25e0482e43d7a4c3c
6
+ metadata.gz: 41e7f40d889a96c0210994feb7362c743912c700c373e49091a7d4b7ac51bb40a2896fa2899016d30bea7659420cbf88d54399aee5346051418c2c071f087732
7
+ data.tar.gz: 1384f5b705a64fda65ae8d1ef04c62c29071d487bdd038ee9322179b2c046b5aa3f68100e51ae4b9810c9b291dd7d073ae11a7c43699078702939fc1d75aee8a
@@ -6,9 +6,11 @@ module ConstructorPages
6
6
 
7
7
  movable :page
8
8
 
9
- before_filter -> {@roots = Page.roots}, except: [:show, :create, :update, :destroy, :search]
9
+ before_filter -> {@pages = Page.all}, only: [:new, :edit]
10
10
 
11
11
  def index
12
+ @pages = Page.includes(:template).load
13
+ @pages_cache = Digest::MD5.hexdigest(@pages.map{|p| [p.name, p.lft, p.template_id]}.join)
12
14
  @template_exists = Template.count != 0
13
15
  flash[:notice] = 'Create at least one template' unless @template_exists
14
16
  end
@@ -6,7 +6,12 @@ module ConstructorPages
6
6
 
7
7
  movable :template
8
8
 
9
- before_filter {@roots = Template.roots}
9
+ before_filter -> {@roots = Template.roots}, only: [:new, :edit]
10
+
11
+ def index
12
+ @templates = Template.all
13
+ @templates_cache = Digest::MD5.hexdigest(@templates.map{|t| [t.name, t.lft]}.join)
14
+ end
10
15
 
11
16
  def new
12
17
  @template = Template.new
@@ -2,14 +2,6 @@ module ConstructorPages
2
2
  module PagesHelper
3
3
  include TreeviewHelper
4
4
 
5
- def for_select(roots)
6
- result = []
7
- roots.each do |r|
8
- r.self_and_descendants.each {|i| result.push(["#{'--'*i.level} #{i.name}", i.id, {'data-full_url' => i.full_url}])}
9
- end
10
- result
11
- end
12
-
13
5
  def templates
14
6
  Template.all.map{|t| ["#{'--'*t.level} #{t.name}", t.id]}
15
7
  end
@@ -1,13 +1,5 @@
1
1
  module ConstructorPages
2
2
  module TemplatesHelper
3
3
  include TreeviewHelper
4
-
5
- def for_select(roots)
6
- result = []
7
- roots.each do |r|
8
- r.self_and_descendants.each {|i| result.push(["#{'--'*i.level} #{i.name}", i.id])}
9
- end
10
- result
11
- end
12
4
  end
13
5
  end
@@ -1,35 +1,5 @@
1
1
  module ConstructorPages
2
2
  module TreeviewHelper
3
- def render_tree(roots, &block)
4
- output = '<ul>'
5
-
6
- roots.each do |root|
7
- level, last = root.level, nil
8
-
9
- root.self_and_descendants.each do |item|
10
- if item.level > level
11
- output += '<ul>'
12
- elsif item.level < level
13
- output += '</li>'
14
- output += '</ul></li>' * (level-item.level)
15
- elsif !item.root?
16
- output += '</li>'
17
- end
18
-
19
- output += '<li>'
20
-
21
- output += capture(item, &block)
22
-
23
- level, last = item.level, item
24
- end
25
-
26
- output += '</li>'
27
- output += '</ul></li>' * last.level
28
- end
29
-
30
- output.html_safe
31
- end
32
-
33
3
  def arrow_buttons_for(item)
34
4
  output = "<div class='btn-group'>"
35
5
 
@@ -43,5 +13,13 @@ module ConstructorPages
43
13
  output += "</div>"
44
14
  output.html_safe
45
15
  end
16
+
17
+ def for_select(items, full_url = false)
18
+ result = []
19
+ items && items.each do |i|
20
+ result.push(["#{'--'*i.level} #{i.name}", i.id, ({'data-full_url' => i.full_url} if full_url) ])
21
+ end
22
+ result
23
+ end
46
24
  end
47
25
  end
@@ -164,6 +164,8 @@ module ConstructorPages
164
164
  end
165
165
 
166
166
  # Reload all descendants
167
- def descendants_update; descendants.map(&:save) end
167
+ def descendants_update
168
+ descendants.map(&:save) if self.url_changed?
169
+ end
168
170
  end
169
171
  end
@@ -41,7 +41,7 @@
41
41
  .control-group
42
42
  = f.label :parent_id, class: 'control-label'
43
43
  .controls
44
- = f.select :parent_id, options_for_select(for_select(@roots), selected: @parent_id), disabled: @page.self_and_descendants.map(&:id), include_blank: t(:no)
44
+ = f.select :parent_id, options_for_select(for_select(@pages, true), selected: @parent_id), disabled: @page.self_and_descendants.map(&:id), include_blank: t(:no)
45
45
 
46
46
  .control-group
47
47
  = f.label :template_id, :class => 'control-label'
@@ -10,26 +10,28 @@
10
10
 
11
11
  %section.b-tree.span12
12
12
  %ul
13
- = render_tree @roots do |page|
14
- - if page.published?
15
- = link_to page.name, page.full_url, class: 'btn btn-link'
16
- - else
17
- %button.btn.disabled= page.name
13
+ - cache @pages_cache do
14
+ - @pages.each do |page|
15
+ %li{class: "level#{page.level}"}
16
+ - if page.published?
17
+ = link_to page.name, page.full_url, class: 'btn btn-link'
18
+ - else
19
+ %button.btn.disabled= page.name
18
20
 
19
- .b-tree__buttons
20
- = arrow_buttons_for(page)
21
+ .b-tree__buttons
22
+ = arrow_buttons_for(page)
21
23
 
22
- = link_to edit_page_path(page), class: 'btn btn-primary btn-mini' do
23
- %i.icon-pencil
24
- =t :edit
25
- = page.template.to_accusative
24
+ = link_to edit_page_path(page), class: 'btn btn-primary btn-mini' do
25
+ %i.icon-pencil
26
+ =t :edit
27
+ = page.template.to_accusative
26
28
 
27
- - if page.template.child
28
- = link_to new_child_page_path(page), class: 'btn btn-success btn-mini' do
29
- %i.icon-chevron-down
30
- =t :add
31
- = page.template.child.to_accusative
29
+ - if page.template.child
30
+ = link_to new_child_page_path(page), class: 'btn btn-success btn-mini' do
31
+ %i.icon-chevron-down
32
+ =t :add
33
+ = page.template.child.to_accusative
32
34
 
33
- = link_to page, method: :delete, class: 'btn btn-danger btn-mini pull-right', data: {confirm: t(:are_you_sure?)} do
34
- %i.icon-remove
35
- =t :delete
35
+ = link_to page, method: :delete, class: 'btn btn-danger btn-mini pull-right', data: {confirm: t(:are_you_sure?)} do
36
+ %i.icon-remove
37
+ =t :delete
@@ -8,17 +8,20 @@
8
8
  =t :new_template
9
9
 
10
10
  %section.b-tree.span12
11
- = render_tree(@roots) do |template|
12
- %button.btn.btn-link.disabled= template.name
11
+ %ul
12
+ - cache @templates_cache do
13
+ - @templates.each do |template|
14
+ %li{class: "level#{template.level}"}
15
+ %button.btn.btn-link.disabled= template.name
13
16
 
14
- .b-tree__buttons
15
- = arrow_buttons_for(template)
17
+ .b-tree__buttons
18
+ = arrow_buttons_for(template)
16
19
 
17
- = link_to edit_template_path(template), class: 'btn btn-primary btn-mini' do
18
- %i.icon-pencil
19
- =t :edit
20
- = t(:template).mb_chars.downcase
20
+ = link_to edit_template_path(template), class: 'btn btn-primary btn-mini' do
21
+ %i.icon-pencil
22
+ =t :edit
23
+ = t(:template).mb_chars.downcase
21
24
 
22
- = link_to template, method: :delete, class: 'btn btn-danger btn-mini pull-right', data: {confirm: t(:are_you_sure?)} do
23
- %i.icon-remove
24
- =t :delete
25
+ = link_to template, method: :delete, class: 'btn btn-danger btn-mini pull-right', data: {confirm: t(:are_you_sure?)} do
26
+ %i.icon-remove
27
+ =t :delete
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: constructor-pages
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.10
4
+ version: 0.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ivan Zotov
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - '='
18
18
  - !ruby/object:Gem::Version
19
- version: 0.7.10
19
+ version: 0.8.0
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - '='
25
25
  - !ruby/object:Gem::Version
26
- version: 0.7.10
26
+ version: 0.8.0
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: dragonfly
29
29
  requirement: !ruby/object:Gem::Requirement