Restore deferred cms tree loading

This commit is contained in:
Damian Mooyman 2017-08-21 12:45:56 +12:00
parent 2bbb21a450
commit e078e6623d
No known key found for this signature in database
GPG Key ID: 78B823A10DE27D1A
6 changed files with 93 additions and 68 deletions

View File

@ -2,15 +2,12 @@
namespace SilverStripe\CMS\Controllers; namespace SilverStripe\CMS\Controllers;
use InvalidArgumentException;
use Psr\SimpleCache\CacheInterface;
use SilverStripe\Admin\AdminRootController; use SilverStripe\Admin\AdminRootController;
use SilverStripe\Admin\CMSBatchActionHandler; use SilverStripe\Admin\CMSBatchActionHandler;
use SilverStripe\Admin\LeftAndMain_SearchFilter;
use SilverStripe\Admin\LeftAndMainFormRequestHandler;
use SilverStripe\CMS\Model\VirtualPage;
use SilverStripe\Core\Environment;
use SilverStripe\Forms\Tab;
use SilverStripe\ORM\CMSPreviewable;
use SilverStripe\Admin\LeftAndMain; use SilverStripe\Admin\LeftAndMain;
use SilverStripe\Admin\LeftAndMainFormRequestHandler;
use SilverStripe\CMS\BatchActions\CMSBatchAction_Archive; use SilverStripe\CMS\BatchActions\CMSBatchAction_Archive;
use SilverStripe\CMS\BatchActions\CMSBatchAction_Publish; use SilverStripe\CMS\BatchActions\CMSBatchAction_Publish;
use SilverStripe\CMS\BatchActions\CMSBatchAction_Restore; use SilverStripe\CMS\BatchActions\CMSBatchAction_Restore;
@ -18,16 +15,16 @@ use SilverStripe\CMS\BatchActions\CMSBatchAction_Unpublish;
use SilverStripe\CMS\Model\CurrentPageIdentifier; use SilverStripe\CMS\Model\CurrentPageIdentifier;
use SilverStripe\CMS\Model\RedirectorPage; use SilverStripe\CMS\Model\RedirectorPage;
use SilverStripe\CMS\Model\SiteTree; use SilverStripe\CMS\Model\SiteTree;
use SilverStripe\CMS\Model\VirtualPage;
use SilverStripe\Control\Controller; use SilverStripe\Control\Controller;
use SilverStripe\Control\Director; use SilverStripe\Control\Director;
use SilverStripe\Control\Session;
use SilverStripe\Control\HTTPRequest; use SilverStripe\Control\HTTPRequest;
use SilverStripe\Control\HTTPResponse; use SilverStripe\Control\HTTPResponse;
use SilverStripe\Control\HTTPResponse_Exception; use SilverStripe\Control\HTTPResponse_Exception;
use SilverStripe\Core\Convert; use SilverStripe\Core\Convert;
use SilverStripe\Core\Environment;
use SilverStripe\Core\Injector\Injector; use SilverStripe\Core\Injector\Injector;
use SilverStripe\Core\Manifest\ModuleLoader; use SilverStripe\Core\Manifest\ModuleLoader;
use Psr\SimpleCache\CacheInterface;
use SilverStripe\Forms\DateField; use SilverStripe\Forms\DateField;
use SilverStripe\Forms\DropdownField; use SilverStripe\Forms\DropdownField;
use SilverStripe\Forms\FieldGroup; use SilverStripe\Forms\FieldGroup;
@ -44,9 +41,11 @@ use SilverStripe\Forms\GridField\GridFieldSortableHeader;
use SilverStripe\Forms\HiddenField; use SilverStripe\Forms\HiddenField;
use SilverStripe\Forms\LabelField; use SilverStripe\Forms\LabelField;
use SilverStripe\Forms\LiteralField; use SilverStripe\Forms\LiteralField;
use SilverStripe\Forms\Tab;
use SilverStripe\Forms\TabSet; use SilverStripe\Forms\TabSet;
use SilverStripe\Forms\TextField; use SilverStripe\Forms\TextField;
use SilverStripe\ORM\ArrayList; use SilverStripe\ORM\ArrayList;
use SilverStripe\ORM\CMSPreviewable;
use SilverStripe\ORM\DataList; use SilverStripe\ORM\DataList;
use SilverStripe\ORM\DataObject; use SilverStripe\ORM\DataObject;
use SilverStripe\ORM\DB; use SilverStripe\ORM\DB;
@ -56,19 +55,18 @@ use SilverStripe\ORM\Hierarchy\MarkedSet;
use SilverStripe\ORM\SS_List; use SilverStripe\ORM\SS_List;
use SilverStripe\ORM\ValidationResult; use SilverStripe\ORM\ValidationResult;
use SilverStripe\Security\InheritedPermissions; use SilverStripe\Security\InheritedPermissions;
use SilverStripe\SiteConfig\SiteConfig;
use SilverStripe\Versioned\Versioned;
use SilverStripe\Security\Member; use SilverStripe\Security\Member;
use SilverStripe\Security\Permission; use SilverStripe\Security\Permission;
use SilverStripe\Security\PermissionProvider; use SilverStripe\Security\PermissionProvider;
use SilverStripe\Security\Security; use SilverStripe\Security\Security;
use SilverStripe\Security\SecurityToken; use SilverStripe\Security\SecurityToken;
use SilverStripe\SiteConfig\SiteConfig;
use SilverStripe\Versioned\ChangeSet;
use SilverStripe\Versioned\ChangeSetItem;
use SilverStripe\Versioned\Versioned;
use SilverStripe\View\ArrayData; use SilverStripe\View\ArrayData;
use SilverStripe\View\Requirements; use SilverStripe\View\Requirements;
use Translatable; use Translatable;
use InvalidArgumentException;
use SilverStripe\Versioned\ChangeSet;
use SilverStripe\Versioned\ChangeSetItem;
/** /**
* The main "content" area of the CMS. * The main "content" area of the CMS.
@ -140,6 +138,8 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr
private static $url_handlers = [ private static $url_handlers = [
'EditForm/$ID' => 'EditForm', 'EditForm/$ID' => 'EditForm',
'treeview/$ID' => 'treeview',
'listview/$ParentID' => 'listview',
]; ];
private static $casting = array( private static $casting = array(
@ -199,16 +199,6 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr
return $this->ListViewForm()->forTemplate(); return $this->ListViewForm()->forTemplate();
}); });
// PageList view
$negotiator->setCallback('Content-PageList', function () {
return $this->PageList()->forTemplate();
});
// PageList view for edit controller
$negotiator->setCallback('Content-PageList-Sidebar', function () {
return $this->PageListSidebar()->forTemplate();
});
return $negotiator; return $negotiator;
} }
@ -314,10 +304,41 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr
*/ */
public function LinkListView() public function LinkListView()
{ {
// Note : Force redirect to top level page controller // Note : Force redirect to top level page controller (no parentid)
return $this->LinkWithSearch(CMSMain::singleton()->Link('listview')); return $this->LinkWithSearch(CMSMain::singleton()->Link('listview'));
} }
/**
* Link to list view for children of a parent page
*
* @param int|string $parentID Literal parentID, or placeholder (e.g. '%d') for
* client side substitution
* @return string
*/
public function LinkListViewChildren($parentID)
{
return $this->LinkWithSearch(Controller::join_links(
CMSMain::singleton()->Link('listview'),
$parentID
));
}
/**
* Link to lazy-load deferred tree view
*
* @return string
*/
public function LinkTreeViewDeferred()
{
$link = $this->Link('treeview');
// Ensure selected page is encoded into URL
$selectedID = $this->currentPageID();
if ($selectedID) {
$link = Controller::join_links($link, $selectedID);
}
return $this->LinkWithSearch($link);
}
public function LinkPageEdit($id = null) public function LinkPageEdit($id = null)
{ {
if (!$id) { if (!$id) {
@ -506,13 +527,9 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr
protected function getTreeNodeCustomisations() protected function getTreeNodeCustomisations()
{ {
$rootTitle = $this->getCMSTreeTitle(); $rootTitle = $this->getCMSTreeTitle();
$linkWithSearch = $this->LinkWithSearch($this->Link()); return function (SiteTree $node) use ($rootTitle) {
return function (SiteTree $node) use ($linkWithSearch, $rootTitle) {
return [ return [
'listViewLink' => Controller::join_links( 'listViewLink' => $this->LinkListViewChildren($node->ID),
$linkWithSearch,
'?view=listview&ParentID=' . $node->ID
),
'rootTitle' => $rootTitle, 'rootTitle' => $rootTitle,
'extraClass' => $this->getTreeNodeClasses($node), 'extraClass' => $this->getTreeNodeClasses($node),
]; ];
@ -1289,20 +1306,31 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr
} }
/** /**
* This method exclusively handles deferred ajax requests to render the
* pages tree deferred handler (no pjax-fragment)
*
* @param HTTPRequest $request * @param HTTPRequest $request
* @return string HTML * @return string HTML
*/ */
public function treeview($request) public function treeview($request)
{ {
return $this->getResponseNegotiator()->respond($request); // Ensure selected page ID is highlighted
$pageID = $request->param('ID') ?: 0;
$this->setCurrentPageID($pageID);
return $this->renderWith($this->getTemplatesWithSuffix('_TreeView'));
} }
/** /**
* Note: This method exclusively handles top level view of list view
*
* @param HTTPRequest $request * @param HTTPRequest $request
* @return string HTML * @return string HTML
*/ */
public function listview($request) public function listview($request)
{ {
// Ensure selected page ID is highlighted
$pageID = $request->param('ParentID') ?: 0;
$this->setCurrentPageID($pageID);
return $this->getResponseNegotiator()->respond($request); return $this->getResponseNegotiator()->respond($request);
} }
@ -1407,15 +1435,15 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr
public function ListViewForm() public function ListViewForm()
{ {
$params = $this->getRequest()->requestVar('q'); $params = $this->getRequest()->requestVar('q');
$list = $this->getList($params, $parentID = $this->getRequest()->requestVar('ParentID')); $parentID = $this->getRequest()->param('ParentID');
$list = $this->getList($params, $parentID);
$gridFieldConfig = GridFieldConfig::create()->addComponents( $gridFieldConfig = GridFieldConfig::create()->addComponents(
new GridFieldSortableHeader(), new GridFieldSortableHeader(),
new GridFieldDataColumns(), new GridFieldDataColumns(),
new GridFieldPaginator($this->config()->get('page_length')) new GridFieldPaginator($this->config()->get('page_length'))
); );
if ($parentID) { if ($parentID) {
$linkSpec = $this->Link(); $linkSpec = $this->LinkListViewChildren('%d');
$linkSpec = $linkSpec . (strstr($linkSpec, '?') ? '&' : '?') . 'ParentID=%d&view=listview';
$gridFieldConfig->addComponent( $gridFieldConfig->addComponent(
GridFieldLevelup::create($parentID) GridFieldLevelup::create($parentID)
->setLinkSpec($linkSpec) ->setLinkSpec($linkSpec)
@ -1456,10 +1484,7 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr
if ($num) { if ($num) {
return sprintf( return sprintf(
'<a class="btn btn-secondary btn--no-text btn--icon-large font-icon-right-dir cms-panel-link list-children-link" data-pjax-target="ListViewForm,Breadcrumbs" href="%s"><span class="sr-only">%s child pages</span></a>', '<a class="btn btn-secondary btn--no-text btn--icon-large font-icon-right-dir cms-panel-link list-children-link" data-pjax-target="ListViewForm,Breadcrumbs" href="%s"><span class="sr-only">%s child pages</span></a>',
Controller::join_links( $this->LinkListViewChildren((int)$item->ID),
$controller->Link(),
sprintf("?ParentID=%d&view=listview", (int)$item->ID)
),
$num $num
); );
} }

View File

@ -1,18 +1,18 @@
<% include SilverStripe\\CMS\\Controllers\\CMSPagesController_ContentToolActions %> <% include SilverStripe\\CMS\\Controllers\\CMSPagesController_ContentToolActions %>
<div class="ss-dialog cms-page-add-form-dialog cms-dialog-content" id="cms-page-add-form" title="<%t SilverStripe\CMS\Controllers\CMSMain.AddNew 'Add new page' %>"> <div class="ss-dialog cms-page-add-form-dialog cms-dialog-content" id="cms-page-add-form" title="<%t SilverStripe\\CMS\\Controllers\\CMSMain.AddNew 'Add new page' %>">
$AddForm $AddForm
</div> </div>
<div class="cms-panel-content center"> <div class="cms-panel-content center">
<% if $TreeIsFiltered %> <% if $TreeIsFiltered %>
<div class="cms-notice cms-tree-filtered"> <div class="cms-notice cms-tree-filtered">
<strong><%t SilverStripe\CMS\Controllers\CMSMain.ListFiltered 'Showing search results.' %></strong> <strong><%t SilverStripe\\CMS\\Controllers\\CMSMain.ListFiltered 'Showing search results.' %></strong>
<a href="$LinkPages.ATT" class="cms-panel-link"> <a href="$LinkPages.ATT" class="cms-panel-link">
<%t SilverStripe\CMS\Controllers\CMSMain.TreeFilteredClear 'Clear' %> <%t SilverStripe\\CMS\\Controllers\\CMSMain.TreeFilteredClear 'Clear' %>
</a> </a>
<div class="cms-list" data-url-list="$Link(getListViewHTML)"> <div class="cms-list" data-url-list="$Link('getListViewHTML')">
$ListViewForm $ListViewForm
</div> </div>
</div> </div>

View File

@ -1,7 +1,7 @@
<div class="flexbox-area-grow cms-content-view" data-pjax-fragment="Content-PageList">
<% if $ViewState == 'listview' %> <% if $ViewState == 'listview' %>
<div class="flexbox-area-grow cms-content-view">
<% include SilverStripe\\CMS\\Controllers\\CMSMain_ListView %> <% include SilverStripe\\CMS\\Controllers\\CMSMain_ListView %>
<% else %>
<% include SilverStripe\\CMS\\Controllers\\CMSMain_TreeView %>
<% end_if %>
</div> </div>
<% else %>
<% include SilverStripe\\CMS\\Controllers\\CMSMain_TreeView_Deferred %>
<% end_if %>

View File

@ -1,3 +1 @@
<div class="panel panel--padded panel--scrollable flexbox-area-grow fill-height flexbox-display cms-content-view cms-tree-view-sidebar" data-pjax-fragment="Content-PageList-Sidebar"> <% include SilverStripe\\CMS\\Controllers\\CMSMain_TreeView_Deferred %>
<% include SilverStripe\\CMS\\Controllers\\CMSMain_TreeView %>
</div>

View File

@ -14,9 +14,9 @@ $ExtraTreeTools
</a> </a>
<div class="cms-tree <% if $TreeIsFiltered %>filtered-list<% end_if %>" <div class="cms-tree <% if $TreeIsFiltered %>filtered-list<% end_if %>"
data-url-tree="$LinkWithSearch($Link(getsubtree)).ATT" data-url-tree="$LinkWithSearch($Link('getsubtree')).ATT"
data-url-savetreenode="$Link(savetreenode).ATT" data-url-savetreenode="$Link('savetreenode').ATT"
data-url-updatetreenodes="$Link(updatetreenodes).ATT" data-url-updatetreenodes="$Link('updatetreenodes').ATT"
data-url-addpage="{$LinkPageAdd('AddForm/?action_doAdd=1', 'ParentID=%s&PageType=%s').ATT}" data-url-addpage="{$LinkPageAdd('AddForm/?action_doAdd=1', 'ParentID=%s&PageType=%s').ATT}"
data-url-editpage="$LinkPageEdit('%s').ATT" data-url-editpage="$LinkPageEdit('%s').ATT"
data-url-duplicate="{$Link('duplicate/%s').ATT}" data-url-duplicate="{$Link('duplicate/%s').ATT}"
@ -28,13 +28,11 @@ $ExtraTreeTools
$SiteTreeAsUL $SiteTreeAsUL
</div> </div>
</div> </div>
<% else %> <% else %>
<div class="cms-tree flexbox-area-grow <% if $TreeIsFiltered %>filtered-list<% end_if %>" <div class="cms-tree flexbox-area-grow <% if $TreeIsFiltered %>filtered-list<% end_if %>"
data-url-tree="$LinkWithSearch($Link(getsubtree)).ATT" data-url-tree="$LinkWithSearch($Link('getsubtree')).ATT"
data-url-savetreenode="$Link(savetreenode).ATT" data-url-savetreenode="$Link('savetreenode').ATT"
data-url-updatetreenodes="$Link(updatetreenodes).ATT" data-url-updatetreenodes="$Link('updatetreenodes').ATT"
data-url-addpage="{$LinkPageAdd('AddForm/?action_doAdd=1', 'ParentID=%s&PageType=%s').ATT}" data-url-addpage="{$LinkPageAdd('AddForm/?action_doAdd=1', 'ParentID=%s&PageType=%s').ATT}"
data-url-editpage="$LinkPageEdit('%s').ATT" data-url-editpage="$LinkPageEdit('%s').ATT"
data-url-duplicate="{$Link('duplicate/%s').ATT}" data-url-duplicate="{$Link('duplicate/%s').ATT}"
@ -45,5 +43,4 @@ $ExtraTreeTools
data-extra-params="SecurityID=$SecurityID.ATT"> data-extra-params="SecurityID=$SecurityID.ATT">
$SiteTreeAsUL $SiteTreeAsUL
</div> </div>
<% end_if %> <% end_if %>

View File

@ -0,0 +1,5 @@
<div class="panel panel--padded panel--scrollable flexbox-area-grow fill-height flexbox-display cms-content-view cms-tree-view-sidebar cms-panel-deferred"
data-url="$LinkTreeViewDeferred"
>
<%-- Lazy-loaded via ajax --%>
</div>