Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New sortable page tree #2252

Merged
merged 8 commits into from
Mar 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ spec/dummy/uploads/
.ruby-gemset
.ruby-version
.env
.rspec
node_modules
yarn-error.log
yarn-debug.log*
Expand Down
1 change: 1 addition & 0 deletions .rspec
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
--require spec_helper
3 changes: 3 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,15 @@ namespace :alchemy do
task :prepare do
system(
<<~BASH
yarn install && \
yarn link && \
cd spec/dummy && \
export RAILS_ENV=test && \
bin/rake db:create && \
bin/rake db:environment:set && \
bin/rake db:migrate:reset && \
bin/rails g alchemy:install --skip --skip-demo-files --auto-accept && \
yarn link @alchemy_cms/admin && \
RAILS_ENV=test bin/webpack && \
cd -
BASH
Expand Down
1 change: 0 additions & 1 deletion app/assets/javascripts/alchemy/admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,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 @@ -168,9 +168,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 @@ -203,10 +201,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 @@ -388,9 +382,11 @@ def set_page_version
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
6 changes: 3 additions & 3 deletions app/serializers/alchemy/page_tree_serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
module Alchemy
class PageTreeSerializer < BaseSerializer
def attributes
{"pages" => nil}
{ "pages" => nil }
end

def pages
tree = []
path = [{id: object.parent_id, children: tree}]
page_list = object.self_and_descendants
path = [{ id: object.parent_id, children: tree }]
page_list = object.self_and_descendants.includes(:public_version, { language: :site })
base_level = object.level - 1
# Load folded pages in advance
folded_user_pages = FoldedPage.folded_for_user(opts[:user]).pluck(:page_id)
Expand Down
Loading