Skip to content

Commit

Permalink
New sortable page tree
Browse files Browse the repository at this point in the history
Backport #2252 from tvdeyen/sortable-page-tree
  • Loading branch information
tvdeyen committed Mar 10, 2022
1 parent 0a54b63 commit 0ea561d
Show file tree
Hide file tree
Showing 25 changed files with 313 additions and 724 deletions.
1 change: 0 additions & 1 deletion app/assets/javascripts/alchemy/admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
//= require alchemy/alchemy.link_dialog
//= require alchemy/alchemy.list_filter
//= require alchemy/alchemy.initializer
//= require alchemy/alchemy.page_sorter
//= require alchemy/alchemy.uploader
//= require alchemy/alchemy.preview_window
//= require alchemy/alchemy.spinner
Expand Down
24 changes: 0 additions & 24 deletions app/assets/javascripts/alchemy/alchemy.page_sorter.js

This file was deleted.

1 change: 1 addition & 0 deletions app/assets/javascripts/alchemy/templates/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
//= require alchemy/templates/page
//= require alchemy/templates/node_folder
//= require alchemy/templates/node
//= require alchemy/templates/page_folder
3 changes: 3 additions & 0 deletions app/assets/javascripts/alchemy/templates/page_folder.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<a class="page_folder" data-page-id="{{ page.id }}">
<i class="far fa-{{#if page.folded }}plus{{else}}minus{{/if}}-square fa-fw"></i>
</a>
8 changes: 2 additions & 6 deletions app/assets/stylesheets/alchemy/sitemap.scss
Original file line number Diff line number Diff line change
Expand Up @@ -142,12 +142,8 @@ $sitemap-url-xlarge-width: 350px;
#sitemap {
padding: 0 0 104px 0;

&.sorting {
padding-top: 100px;

.page_icon {
cursor: move;
}
.handle {
cursor: move;
}

.page_folder {
Expand Down
20 changes: 8 additions & 12 deletions app/controllers/alchemy/admin/pages_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class PagesController < ResourcesController

helper "alchemy/pages"

before_action :load_resource, except: [:index, :flush, :new, :order, :create, :copy_language_tree, :link, :sort]
before_action :load_resource, except: [:index, :flush, :new, :order, :create, :copy_language_tree, :link]

authorize_resource class: Alchemy::Page, except: [:index, :tree]

Expand All @@ -21,7 +21,7 @@ class PagesController < ResourcesController
except: [:show]

before_action :set_root_page,
only: [:index, :show, :sort, :order]
only: [:index, :show, :order]

before_action :run_on_page_layout_callbacks,
if: :run_on_page_layout_callbacks?,
Expand Down Expand Up @@ -173,9 +173,7 @@ def link
def fold
# @page is fetched via before filter
@page.fold!(current_alchemy_user.id, !@page.folded?(current_alchemy_user.id))
respond_to do |format|
format.js
end
render json: serialized_page_tree
end

# Leaves the page editing mode and unlocks the page for other users
Expand Down Expand Up @@ -220,10 +218,6 @@ def copy_language_tree
redirect_to admin_pages_path
end

def sort
@sorting = true
end

# Receives a JSON object representing a language tree to be ordered
# and updates all pages in that language structure to their correct indexes
def order
Expand Down Expand Up @@ -405,9 +399,11 @@ def set_root_page
end

def serialized_page_tree
PageTreeSerializer.new(@page, ability: current_ability,
user: current_alchemy_user,
full: params[:full] == "true")
PageTreeSerializer.new(
@page,
ability: current_ability,
user: current_alchemy_user,
)
end

def load_languages_and_layouts
Expand Down
8 changes: 8 additions & 0 deletions app/controllers/alchemy/api/pages_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,14 @@ def show
respond_with @page
end

def move
@page = Page.find(params[:id])
authorize! :update, @page
target_parent_page = Page.find(params[:target_parent_id])
@page.move_to_child_with_index(target_parent_page, params[:new_position])
render json: @page, serializer: PageSerializer
end

private

def load_page
Expand Down
3 changes: 2 additions & 1 deletion app/serializers/alchemy/page_serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ class PageSerializer < ActiveModel::Serializer
:created_at,
:updated_at,
:status,
:url_path
:url_path,
:parent_id

has_many :elements
end
Expand Down
Loading

0 comments on commit 0ea561d

Please sign in to comment.