aerogel-pages 1.4.12 → 1.4.14
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/routes/admin-pages.rb +22 -1
- data/assets/javascripts/admin-pages/pages-widget.js.coffee +12 -0
- data/assets/javascripts/admin-pages/pane-tree.js.coffee +56 -5
- data/assets/stylesheets/admin-pages/_admin-pages-alert.css.scss +1 -0
- data/db/model/page.rb +12 -29
- data/db/model/page_node.rb +12 -0
- data/db/model/pages/blocks/pages_list.rb +8 -10
- data/lib/aerogel/pages/core.rb +13 -0
- data/lib/aerogel/pages/version.rb +1 -1
- data/locales/actions.en.yml +5 -0
- data/locales/actions.ru.yml +5 -0
- data/views/admin/pages/index/_pane_tree.html.erb +13 -2
- data/views/admin/pages/index/_pane_tree_tabs.html.erb +8 -3
- data/views/layouts/pages/_menu.html.erb +3 -1
- data/views/layouts/pages/_menu_item.html.erb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a7fc6805efa9811f6d76a551bf6d7d2c1000f0bc
|
4
|
+
data.tar.gz: 24021121763b86687a79764e6d2554e12a4a58e2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 82155ceec35741890c97862ab65862934fa7890b98ef178a8beff3bfda82995f947b1d1e7d7d91597302c03f3f0d260678335883aca5a70bccfe1fb55c3aa943
|
7
|
+
data.tar.gz: 9fc7908a47cdfbcd5bd31556f1b17fce9c5fc18b1ceebb6f98d30f14edfaa2060904845a1c6c6aefcc0c3fe944086e92a90f958ebabcf48fd416c78969149255
|
data/app/routes/admin-pages.rb
CHANGED
@@ -8,6 +8,27 @@ namespace "/admin/pages" do
|
|
8
8
|
pass
|
9
9
|
end
|
10
10
|
|
11
|
+
post "/pages_reorder" do
|
12
|
+
positions = {}
|
13
|
+
params[:page_nodes].each do |id, data|
|
14
|
+
parent_id = data['parent_id']
|
15
|
+
page_node = PageNode.find( id ) or halt 404
|
16
|
+
if positions.key? parent_id
|
17
|
+
new_position = ( positions[parent_id] += 1 )
|
18
|
+
else
|
19
|
+
new_position = ( positions[parent_id] = 0 )
|
20
|
+
end
|
21
|
+
page_node.parent_id = parent_id
|
22
|
+
page_node.position = new_position
|
23
|
+
unless page_node.save
|
24
|
+
halt 500, page_node.errors.full_messages
|
25
|
+
end
|
26
|
+
end
|
27
|
+
redirect "/admin/pages/", notice: t.aerogel.admin.pages.reordered
|
28
|
+
# pass
|
29
|
+
end
|
30
|
+
|
31
|
+
|
11
32
|
namespace "/:lang-:id" do
|
12
33
|
before do
|
13
34
|
@lang = params[:lang]
|
@@ -68,7 +89,7 @@ namespace "/admin/pages" do
|
|
68
89
|
parent_id = @page_node.parent_id
|
69
90
|
@page_node.destroy
|
70
91
|
redirect "/admin/pages/#{@lang}-#{parent_id}",
|
71
|
-
notice:
|
92
|
+
notice: t.aerogel.admin.pages.deleted( title: admin_pages_title_as_text( @page_node, @lang ) )
|
72
93
|
end
|
73
94
|
|
74
95
|
|
@@ -30,6 +30,13 @@ class @PagesWidget
|
|
30
30
|
@push_state()
|
31
31
|
log "on_page_selected: id:#{@current_state.page_node_id}"
|
32
32
|
|
33
|
+
# Callback invoked by tree 'reorder pages' action
|
34
|
+
on_pages_reorder_started: () =>
|
35
|
+
@current_state.pages_reorder_enabled = true
|
36
|
+
# @current_state.page_attributes = object.attributes
|
37
|
+
@push_state()
|
38
|
+
log "on_pages_reorder: started!"
|
39
|
+
|
33
40
|
|
34
41
|
# Callback invoked on pane open/close events
|
35
42
|
on_pane_open: ( left_middle_right ) =>
|
@@ -43,12 +50,17 @@ class @PagesWidget
|
|
43
50
|
|
44
51
|
push_state: ->
|
45
52
|
# push current state to history,
|
53
|
+
#@history_id ?= 1
|
54
|
+
#@history_id += 1
|
46
55
|
url = ''
|
47
56
|
if @current_state.page_node_id?
|
48
57
|
url = "#{@current_state.lang}-#{@current_state.page_node_id}"
|
58
|
+
# if !!@current_state.pages_reorder_enabled
|
59
|
+
# url = "#{url}#reorder_pages"
|
49
60
|
log "setting url to '#{url}'"
|
50
61
|
log "setting lang '#{@current_state.lang}'"
|
51
62
|
History.pushState( @current_state, @current_title, url )
|
63
|
+
@update( @current_state )
|
52
64
|
|
53
65
|
|
54
66
|
set_state: ( state ) ->
|
@@ -11,6 +11,7 @@ class @PaneTree
|
|
11
11
|
@tree_table = new SmartTreeTable @element.find( tree_selector ).first(),
|
12
12
|
column: tree_column
|
13
13
|
on_select: @on_tree_item_selected
|
14
|
+
on_tree_change: @on_tree_changed
|
14
15
|
prefix:
|
15
16
|
branch:
|
16
17
|
expanded: '<i class="prefix-expanded fa fa-caret-down"></i>'
|
@@ -30,12 +31,28 @@ class @PaneTree
|
|
30
31
|
footer: @bottom_toolbar()
|
31
32
|
observe: $('.pane-tree .content')
|
32
33
|
|
34
|
+
@pages_reorder_enabled = false
|
35
|
+
$("body").on "click", "A.pages-reorder-link", (e) =>
|
36
|
+
e.preventDefault()
|
37
|
+
pages_widget.on_pages_reorder_started()
|
38
|
+
|
39
|
+
$("body").on "click", ".pages-reorder-save-link", (e) =>
|
40
|
+
e.preventDefault()
|
41
|
+
log "** save reordered pages"
|
42
|
+
for row in @ordered_row_list()
|
43
|
+
log "** #{row.id}: parent:#{row.parent_id}"
|
44
|
+
|
33
45
|
log "initialized"
|
34
46
|
|
35
47
|
# Updates pane tree widget
|
36
48
|
#
|
37
49
|
update: (state) ->
|
50
|
+
log "** update:"
|
38
51
|
@tree_table.select state.page_node_id, false
|
52
|
+
if !!state.pages_reorder_enabled && !@pages_reorder_enabled
|
53
|
+
@tree_table.enable_drag_and_drop()
|
54
|
+
@pages_reorder_enabled = true
|
55
|
+
log "** pages reorder enabled!"
|
39
56
|
@scroll_to_view state.page_node_id
|
40
57
|
@update_bottom_toolbar state
|
41
58
|
@update_top_toolbar state
|
@@ -65,12 +82,29 @@ class @PaneTree
|
|
65
82
|
on_tree_item_selected: (id, object, el) =>
|
66
83
|
pages_widget.on_page_selected id, object
|
67
84
|
|
85
|
+
# Callback to be invoked when pages (tree branches/leaves) are reordered
|
86
|
+
#
|
87
|
+
on_tree_changed: () =>
|
88
|
+
log "** tree changed!"
|
89
|
+
form = @bottom_toolbar('.pages-reorder-actions form').first()
|
90
|
+
form.find("input.page_nodes").remove()
|
91
|
+
for row in @ordered_row_list()
|
92
|
+
parent_id = if row.parent_id? then row.parent_id else ''
|
93
|
+
form.append("<input type='hidden' name='page_nodes[#{row.id}][parent_id]' value='#{parent_id}' class='page_nodes'/>")
|
94
|
+
log "** #{row.id}: parent:#{row.parent_id}"
|
95
|
+
|
68
96
|
|
69
97
|
# Returns row object specified by given +id+
|
70
98
|
#
|
71
99
|
find_row_by_id: (id) ->
|
72
100
|
@tree_table.rows[id]
|
73
101
|
|
102
|
+
# Returns ordered list of rows as objects with +id+, +parent_id+
|
103
|
+
#
|
104
|
+
ordered_row_list: ->
|
105
|
+
{ id: row.id, parent_id: row.parent_id } for row in @tree_table.rows_list()
|
106
|
+
|
107
|
+
|
74
108
|
# Returns action buttons elements, or elements within buttons specified by +selector+
|
75
109
|
#
|
76
110
|
bottom_toolbar: (selector = '') ->
|
@@ -79,15 +113,25 @@ class @PaneTree
|
|
79
113
|
# Updates action buttons state and labels
|
80
114
|
#
|
81
115
|
update_bottom_toolbar: (state) ->
|
82
|
-
unless state.page_node_id?
|
116
|
+
unless state.page_node_id? || @pages_reorder_enabled
|
117
|
+
log "** update_bottom_toolbar: disabling"
|
83
118
|
@bottom_toolbar().hide()
|
84
119
|
return
|
85
120
|
object = @find_row_by_id state.page_node_id
|
86
121
|
@bottom_toolbar().show()
|
87
|
-
@
|
88
|
-
|
89
|
-
|
90
|
-
|
122
|
+
if @pages_reorder_enabled
|
123
|
+
@bottom_toolbar('.pages-reorder-actions').show()
|
124
|
+
@bottom_toolbar('.page-actions').hide()
|
125
|
+
else
|
126
|
+
@bottom_toolbar('.pages-reorder-actions').hide()
|
127
|
+
if state.page_node_id?
|
128
|
+
@bottom_toolbar('.page-actions').show()
|
129
|
+
@bottom_toolbar('.page-append-link').attr 'href', pages_widget.url_to_action 'append'
|
130
|
+
@bottom_toolbar('.page-insert-link').attr 'href', pages_widget.url_to_action 'insert'
|
131
|
+
@bottom_toolbar('.page-delete-link').attr 'href', pages_widget.url_to_action 'delete'
|
132
|
+
@bottom_toolbar(' .page-name').text object.contents
|
133
|
+
else
|
134
|
+
@bottom_toolbar('.page-actions').hide()
|
91
135
|
@attached_footer.update_footer()
|
92
136
|
|
93
137
|
# Returns top toolbar element, or elements within buttons specified by +selector+
|
@@ -102,4 +146,11 @@ class @PaneTree
|
|
102
146
|
lang = $(@).attr 'data-lang-id'
|
103
147
|
$(@).attr 'href', pages_widget.url_to( lang, state.page_node_id )
|
104
148
|
|
149
|
+
if @pages_reorder_enabled
|
150
|
+
@top_toolbar('.pages-reorder-link').addClass "disabled"
|
151
|
+
@top_toolbar('.pages-reorder-link .checkmark').show()
|
152
|
+
else
|
153
|
+
@top_toolbar('.pages-reorder-link').removeClass "disabled"
|
154
|
+
@top_toolbar('.pages-reorder-link .checkmark').hide()
|
155
|
+
|
105
156
|
|
data/db/model/page.rb
CHANGED
@@ -4,6 +4,7 @@ class Page
|
|
4
4
|
|
5
5
|
# embedded_in :page
|
6
6
|
belongs_to :page_node, touch: true
|
7
|
+
field :position, type: Integer # !!! denormalized from PageNode
|
7
8
|
|
8
9
|
PUBLICATION_STATES = [:published, :hidden, :not_published]
|
9
10
|
|
@@ -11,12 +12,11 @@ class Page
|
|
11
12
|
field :published_at, type: Time
|
12
13
|
field :publication_state, type: Symbol, default: :published
|
13
14
|
field :link, type: String
|
14
|
-
field :parent_links, type: Array, default: nil
|
15
15
|
field :title, type: String
|
16
16
|
field :html_description, type: String
|
17
17
|
field :html_keywords, type: String
|
18
18
|
|
19
|
-
|
19
|
+
before_create :denormalize_position
|
20
20
|
before_update :touch_ancestors
|
21
21
|
before_destroy :touch_ancestors
|
22
22
|
|
@@ -45,6 +45,7 @@ class Page
|
|
45
45
|
# Returns url to this page if it is accessible, constructed from the parent links.
|
46
46
|
#
|
47
47
|
def url
|
48
|
+
parent_links = ancestors.sort_by(&:depth).map(&:link)
|
48
49
|
parts = [parent_links, link].flatten
|
49
50
|
parts.shift # skip root page
|
50
51
|
"/"+parts.join("/")
|
@@ -81,6 +82,12 @@ class Page
|
|
81
82
|
Page.where( lang: lang, :page_node_id.in => page_node.ancestors.map(&:_id) )
|
82
83
|
end
|
83
84
|
|
85
|
+
# Returns depth of the page_node
|
86
|
+
#
|
87
|
+
def depth
|
88
|
+
page_node.depth
|
89
|
+
end
|
90
|
+
|
84
91
|
# Returns list of allowed content block types.
|
85
92
|
#
|
86
93
|
def available_block_types
|
@@ -96,35 +103,11 @@ class Page
|
|
96
103
|
|
97
104
|
# private
|
98
105
|
|
99
|
-
def
|
100
|
-
|
101
|
-
|
102
|
-
end
|
103
|
-
|
104
|
-
# Generates default value for parent_links, that is used to populate new Page object.
|
105
|
-
#
|
106
|
-
# NOTE: This is impossible to do as field's default with Proc, because by some reason
|
107
|
-
# Mongoid does not initialize relations at 'assign defaults' stage.
|
108
|
-
#
|
109
|
-
def default_parent_links
|
110
|
-
# puts "** default_parent_links: self.page_node=#{self.page_node.inspect}"
|
111
|
-
# puts "** default_parent_links: self=#{self.inspect}"
|
112
|
-
parent_page = parent
|
113
|
-
if parent_page.present?
|
114
|
-
parent_page.parent_links + [parent_page.link]
|
115
|
-
else
|
116
|
-
[]
|
117
|
-
end
|
106
|
+
def denormalize_position
|
107
|
+
# puts "** denormalizing position from page_node: #{page_node_id} -> #{page_node.inspect}"
|
108
|
+
self.position = page_node.try(:position)
|
118
109
|
end
|
119
110
|
|
120
|
-
def update_children_links
|
121
|
-
return unless link_changed? || parent_links_changed?
|
122
|
-
# puts "** update children links fired"
|
123
|
-
links = parent_links + [link]
|
124
|
-
children.each do |p|
|
125
|
-
p.update_attributes parent_links: links
|
126
|
-
end
|
127
|
-
end
|
128
111
|
|
129
112
|
# Touches parents (if present)
|
130
113
|
#
|
data/db/model/page_node.rb
CHANGED
@@ -16,6 +16,8 @@ class PageNode
|
|
16
16
|
allow_destroy: true
|
17
17
|
|
18
18
|
before_update :touch_ancestors
|
19
|
+
before_update :touch_pages
|
20
|
+
before_update :denormalize_position
|
19
21
|
before_destroy :touch_ancestors
|
20
22
|
|
21
23
|
# scope :with_content, ->(lang) { where( :'pages.lang' => lang ) }
|
@@ -38,6 +40,16 @@ private
|
|
38
40
|
ancestors.update_all updated_at: Time.now
|
39
41
|
end
|
40
42
|
|
43
|
+
# Touches pages (if present)
|
44
|
+
#
|
45
|
+
def touch_pages
|
46
|
+
pages.update_all updated_at: Time.now
|
47
|
+
end
|
41
48
|
|
49
|
+
# Denormalize +position+ to owned Page(s).
|
50
|
+
#
|
51
|
+
def denormalize_position
|
52
|
+
pages.update_all( position: position )
|
53
|
+
end
|
42
54
|
|
43
55
|
end # class Page
|
@@ -18,16 +18,14 @@ module Pages::Blocks
|
|
18
18
|
return [] if target_page_node.nil?
|
19
19
|
listed = target_page_node.page( lang ).children
|
20
20
|
listed = (show_hidden ? listed.published_and_hidden : listed.published )
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
# listed
|
29
|
-
@_listed_pages_cache = listed
|
30
|
-
listed
|
21
|
+
if ordered_asc == :desc
|
22
|
+
listed = listed.desc( ordered_by )
|
23
|
+
else
|
24
|
+
listed = listed.asc( ordered_by )
|
25
|
+
end
|
26
|
+
listed = listed.limit( limit ) if limit.present? && limit > 0
|
27
|
+
@_listed_pages_cache = listed.to_a
|
28
|
+
# listed
|
31
29
|
end
|
32
30
|
|
33
31
|
def listed_pages_DISABLED
|
data/lib/aerogel/pages/core.rb
CHANGED
@@ -1,3 +1,9 @@
|
|
1
|
+
# will define methods in Page class
|
2
|
+
unless defined?(::Page)
|
3
|
+
class ::Page
|
4
|
+
end
|
5
|
+
end
|
6
|
+
|
1
7
|
module Aerogel::Pages
|
2
8
|
|
3
9
|
def self.registered(app)
|
@@ -23,6 +29,13 @@ module Aerogel::Pages
|
|
23
29
|
|
24
30
|
def self.register_page_block_type( type, model )
|
25
31
|
registered_page_block_types[type] = model
|
32
|
+
|
33
|
+
# define multiple objects accessor
|
34
|
+
::Page.send( :define_method, :"#{type}s" ) { page_blocks.where( :_type => model ) }
|
35
|
+
|
36
|
+
# define single (first) object accessor
|
37
|
+
::Page.send( :define_method, type ) { page_blocks.where( :_type => model ).first }
|
38
|
+
|
26
39
|
end
|
27
40
|
|
28
41
|
def self.create_page_block( type, *args )
|
data/locales/actions.en.yml
CHANGED
@@ -4,8 +4,13 @@ en:
|
|
4
4
|
pages:
|
5
5
|
delete: Delete page
|
6
6
|
delete_short: Delete
|
7
|
+
deleted: "Page <b>%{title}</b> deleted"
|
7
8
|
insert: Insert page
|
8
9
|
insert_short: Insert
|
9
10
|
append: Append page
|
10
11
|
append_short: Append
|
11
12
|
edit: Edit page
|
13
|
+
reorder: Re-order pages
|
14
|
+
reorder_cancel: Cancel
|
15
|
+
reorder_save: Save changes
|
16
|
+
reordered: Pages reordered
|
data/locales/actions.ru.yml
CHANGED
@@ -4,8 +4,13 @@ ru:
|
|
4
4
|
pages:
|
5
5
|
delete: Удалить страницу
|
6
6
|
delete_short: Удалить
|
7
|
+
deleted: "Страница <b>%{title}</b> удалена"
|
7
8
|
insert: Вставить новую страницу
|
8
9
|
insert_short: Вставить
|
9
10
|
append: Добавить новую страницу
|
10
11
|
append_short: Добавить
|
11
12
|
edit: Редактировать страницу
|
13
|
+
reorder: Изменить порядок страниц
|
14
|
+
reorder_cancel: Отмена
|
15
|
+
reorder_save: Сохранить изменения
|
16
|
+
reordered: Порядок страниц изменён
|
@@ -23,7 +23,7 @@
|
|
23
23
|
|
24
24
|
<div class="bottom-toolbar">
|
25
25
|
<div class="container">
|
26
|
-
<div class="btn-group">
|
26
|
+
<div class="btn-group page-actions">
|
27
27
|
<% link_to "new",
|
28
28
|
class: "btn btn-default btn-sm page-append-link",
|
29
29
|
title: t.aerogel.admin.pages.append do
|
@@ -39,10 +39,21 @@
|
|
39
39
|
<% end %>
|
40
40
|
</div>
|
41
41
|
|
42
|
-
<% link_to_modal "new", class: "btn btn-default btn-sm page-delete-link" do %>
|
42
|
+
<% link_to_modal "new", class: "btn btn-default btn-sm page-delete-link page-actions" do %>
|
43
43
|
<%= icon 'fa-times' %>
|
44
44
|
<%= t.aerogel.admin.pages.delete %>
|
45
45
|
<% end %>
|
46
|
+
|
47
|
+
<div class="pages-reorder-actions">
|
48
|
+
<% form nil, action: "pages_reorder", html_params: { class: 'pages-reorder-form' } do %>
|
49
|
+
<%= link_to "", t.aerogel.admin.pages.reorder_cancel.to_s,
|
50
|
+
class: "btn btn-default pages-reorder-cancel-link"
|
51
|
+
%>
|
52
|
+
<%= button :submit, label: t.aerogel.admin.pages.reorder_save.to_s,
|
53
|
+
class: "btn btn-primary pages-reorder-save-link"
|
54
|
+
%>
|
55
|
+
<% end %>
|
56
|
+
</div>
|
46
57
|
</div>
|
47
58
|
</div>
|
48
59
|
|
@@ -7,18 +7,23 @@
|
|
7
7
|
%>
|
8
8
|
</li>
|
9
9
|
<% end %>
|
10
|
-
<li class="pull-right dropdown
|
10
|
+
<li class="pull-right dropdown">
|
11
11
|
<a class="dropdown-toggle" data-toggle="dropdown" href="#">
|
12
12
|
<%= icon 'fa-cog' %> <span class="caret"></span>
|
13
13
|
</a>
|
14
14
|
<ul class="dropdown-menu">
|
15
|
+
<!--
|
15
16
|
<li class="disabled">
|
16
17
|
<a href="#">item 1</a>
|
17
18
|
</li>
|
18
19
|
<li class="divider">
|
19
20
|
</li>
|
20
|
-
|
21
|
-
|
21
|
+
-->
|
22
|
+
<li class="pages-reorder-link">
|
23
|
+
<a href="#" class="pages-reorder-link">
|
24
|
+
<span class="checkmark"><%= icon 'fa-check' %></span>
|
25
|
+
<%= t.aerogel.admin.pages.reorder %>
|
26
|
+
</a>
|
22
27
|
</li>
|
23
28
|
</ul>
|
24
29
|
</li>
|
@@ -2,7 +2,9 @@
|
|
2
2
|
<li>
|
3
3
|
<%= link_to "/", icon('fa-home')+" "+Page.root(current_locale).try(:title) %>
|
4
4
|
</li>
|
5
|
-
<%= partial "layouts/pages/menu_item",
|
5
|
+
<%= partial "layouts/pages/menu_item",
|
6
|
+
collection: Page.root(current_locale).try(:children).try(:published).try( :asc, :position )
|
7
|
+
%>
|
6
8
|
|
7
9
|
<li class="divider"></li>
|
8
10
|
<li>
|