Author: sevein
Date: Wed Aug 8 18:08:13 2012
New Revision: 12055
Log:
Simplify logic of the more button in the treeview, drop sorting logic because I
just added to a specific class (see previous commit)
Modified:
trunk/apps/qubit/modules/informationobject/actions/treeViewAction.class.php
trunk/apps/qubit/modules/informationobject/actions/treeViewComponent.class.php
trunk/apps/qubit/modules/informationobject/templates/_treeView.php
trunk/apps/qubit/modules/informationobject/templates/treeViewSuccess.php
Modified:
trunk/apps/qubit/modules/informationobject/actions/treeViewAction.class.php
==============================================================================
--- trunk/apps/qubit/modules/informationobject/actions/treeViewAction.class.php
Wed Aug 8 18:06:15 2012 (r12054)
+++ trunk/apps/qubit/modules/informationobject/actions/treeViewAction.class.php
Wed Aug 8 18:08:13 2012 (r12055)
@@ -30,42 +30,37 @@
$this->resource = $this->getRoute()->resource;
}
- // Sorting action
- // This should probably be in a separate action
- if (in_array($request->show, array('moveAfter', 'moveBefore')))
+ // Number of siblings that we are showing above and below the current node
+ // It's good to keep this number small since getTreeViewSiblings can be
very
+ // slow (when sorting by title or identifierTitle)
+ $numberOfPreviousOrNextSiblings = 4;
+
+ switch ($request->show)
{
- // Check authorization
- if (QubitInformationObject::ROOT_ID == $this->resource->id ||
!QubitAcl::check($this->resource, 'update'))
- {
- QubitAcl::forwardUnauthorized();
- }
-
- // Parse $request->target
- $params =
$this->context->routing->parse(Qubit::pathInfo($request->target));
- if (!isset($params['_sf_route']))
- {
- $this->forward404();
- }
- $target = $params['_sf_route']->resource;
-
- switch ($request->show)
- {
- case 'moveAfter':
- $this->resource->moveToNextSiblingOf($target);
-
- break;
+ case 'prevSiblings':
- case 'moveBefore':
- $this->resource->moveToPrevSiblingOf($target);
+ $this->items =
array_reverse($this->resource->getTreeViewSiblings(array('limit' =>
$numberOfPreviousOrNextSiblings + 1, 'position' => 'previous')));
- break;
- }
+ $this->hasPrevSiblings = count($this->items) >
$numberOfPreviousOrNextSiblings;
+ if ($this->hasPrevSiblings)
+ {
+ array_pop($this->items);
+ }
- return sfView::NONE;
- }
+ break;
+
+ case 'nextSiblings':
+
+ $this->items = $this->resource->getTreeViewSiblings(array('limit' =>
$numberOfPreviousOrNextSiblings + 1, 'position' => 'next'));
+
+ $this->hasNextSiblings = count($this->items) >
$numberOfPreviousOrNextSiblings;
+ if ($this->hasNextSiblings)
+ {
+ array_pop($this->items);
+ }
+
+ break;
- switch ($request->show)
- {
case 'all':
case 'item':
default:
@@ -79,18 +74,6 @@
$this->items = QubitInformationObject::get($criteria);
break;
-
- case 'prevSiblings':
-
- $this->items =
array_reverse($this->resource->getTreeViewSiblings(array('limit' => 5,
'position' => 'previous')));
-
- break;
-
- case 'nextSiblings':
-
- $this->items = $this->resource->getTreeViewSiblings(array('limit' =>
5, 'position' => 'next'));
-
- break;
}
}
}
Modified:
trunk/apps/qubit/modules/informationobject/actions/treeViewComponent.class.php
==============================================================================
---
trunk/apps/qubit/modules/informationobject/actions/treeViewComponent.class.php
Wed Aug 8 18:06:15 2012 (r12054)
+++
trunk/apps/qubit/modules/informationobject/actions/treeViewComponent.class.php
Wed Aug 8 18:08:13 2012 (r12055)
@@ -30,8 +30,26 @@
// At this point we don't need to do any ACL check on ancestors
$this->ancestors = $this->resource->getAncestors()->orderBy('lft');
- // Get a list of siblings doing ACL checks
- $this->prevSiblings =
array_reverse($this->resource->getTreeViewSiblings(array('limit' => 5,
'position' => 'previous')));
+ // Number of siblings that we are showing above and below the current node
+ // It's good to keep this number small since getTreeViewSiblings can be
very
+ // slow (when sorting by title or identifierTitle)
+ $numberOfPreviousOrNextSiblings = 4;
+
+ // Previous siblings
+ // Get an extra sibling just to know if the + button is necessary
+ $this->prevSiblings =
array_reverse($this->resource->getTreeViewSiblings(array('limit' =>
$numberOfPreviousOrNextSiblings + 1, 'position' => 'previous')));
+ $this->hasPrevSiblings = count($this->prevSiblings) >
$numberOfPreviousOrNextSiblings;
+ if ($this->hasPrevSiblings)
+ {
+ array_pop($this->prevSiblings);
+ }
+
+ // Next siblings, same logic than above with the + button
$this->nextSiblings = $this->resource->getTreeViewSiblings(array('limit'
=> 5, 'position' => 'next'));
+ $this->hasNextSiblings = count($this->nextSiblings) >
$numberOfPreviousOrNextSiblings;
+ if ($this->hasNextSiblings)
+ {
+ array_pop($this->nextSiblings);
+ }
}
}
Modified: trunk/apps/qubit/modules/informationobject/templates/_treeView.php
==============================================================================
--- trunk/apps/qubit/modules/informationobject/templates/_treeView.php Wed Aug
8 18:06:15 2012 (r12054)
+++ trunk/apps/qubit/modules/informationobject/templates/_treeView.php Wed Aug
8 18:08:13 2012 (r12055)
@@ -17,13 +17,11 @@
<?php endforeach; ?>
<?php // More button ?>
- <?php if (isset($prevSiblings) && 0 < count($prevSiblings)): ?>
- <?php if (1 < $prevSiblings[0]->lft - $parent->lft): ?>
- <?php echo render_treeview_node(
- null,
- array('more' => true),
- array('xhr-location' => url_for(array('module' =>
'informationobject', 'action' => 'treeView', 'slug' =>
$prevSiblings[0]->slug)))); ?>
- <?php endif; ?>
+ <?php if ($hasPrevSiblings): ?>
+ <?php echo render_treeview_node(
+ null,
+ array('more' => true),
+ array('xhr-location' => url_for(array('module' => 'informationobject',
'action' => 'treeView', 'slug' => $prevSiblings[0]->slug)))); ?>
<?php endif; ?>
<?php // N prev items ?>
@@ -50,7 +48,7 @@
<?php // More button ?>
<?php $last = isset($next) ? $next : $resource ?>
- <?php if ($parent->rgt - $last->rgt > 1): ?>
+ <?php if ($hasNextSiblings): ?>
<?php echo render_treeview_node(
null,
array('more' => true),
Modified:
trunk/apps/qubit/modules/informationobject/templates/treeViewSuccess.php
==============================================================================
--- trunk/apps/qubit/modules/informationobject/templates/treeViewSuccess.php
Wed Aug 8 18:06:15 2012 (r12054)
+++ trunk/apps/qubit/modules/informationobject/templates/treeViewSuccess.php
Wed Aug 8 18:08:13 2012 (r12055)
@@ -1,4 +1,4 @@
-<?php if ('prevSiblings' == $sf_request->show && 0 < count($items) && 1 <
($items[0]->lft - $resource->parent->lft)): ?>
+<?php if (isset($hasPrevSiblings) && $hasPrevSiblings): ?>
<?php echo render_treeview_node(
null,
array('more' => true),
@@ -12,12 +12,9 @@
array('xhr-location' => url_for(array($item, 'module' =>
'informationobject', 'action' => 'treeView')))); ?>
<?php endforeach; ?>
-<?php if ('prevSiblings' != $sf_request->show): ?>
- <?php $parent = 'item' == $sf_request->show ||
QubitInformationObject::ROOT_ID == $resource->id ? $resource :
$resource->parent ?>
- <?php if ($parent->rgt - $item->rgt > 1): ?>
- <?php echo render_treeview_node(
- null,
- array('more' => true),
- array('xhr-location' => url_for(array($item, 'module' =>
'informationobject', 'action' => 'treeView')))); ?>
- <?php endif; ?>
+<?php if (isset($hasNextSiblings) && $hasNextSiblings): ?>
+ <?php echo render_treeview_node(
+ null,
+ array('more' => true),
+ array('xhr-location' => url_for(array($item, 'module' =>
'informationobject', 'action' => 'treeView')))); ?>
<?php endif; ?>
--
You received this message because you are subscribed to the Google Groups
"Qubit Toolkit Commits" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/qubit-commits?hl=en.