Skip to content

Commit

Permalink
[wip] order site menus in admin ui
Browse files Browse the repository at this point in the history
currently they are hard coded to be displayed by id desc

this pr will (when finished) allows the order to be set using drag and drop from com_menus&view=menus

This is for the display of the menus in the sidebar and the menus dashboard

todo
- [ ] sql update
- [ ] sql installation
- [ ] saveorderingajax
- [ ] add ordering to menu creation
  • Loading branch information
brianteeman committed Jun 26, 2022
1 parent b12020a commit 2150ffa
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 7 deletions.
2 changes: 2 additions & 0 deletions administrator/components/com_menus/forms/filter_menus.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
validate="options"
>
<option value="">JGLOBAL_SORT_BY</option>
<option value="a.ordering ASC">JGRID_HEADING_ORDERING_ASC</option>
<option value="a.ordering DESC">JGRID_HEADING_ORDERING_DESC</option>
<option value="a.title ASC">JGLOBAL_TITLE_ASC</option>
<option value="a.title DESC">JGLOBAL_TITLE_DESC</option>
<option value="a.id ASC">JGRID_HEADING_ID_ASC</option>
Expand Down
2 changes: 1 addition & 1 deletion administrator/components/com_menus/presets/default.xml
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@
sql_where="a.client_id = 0"
sql_leftjoin="#__menu AS m ON m.menutype = a.menutype AND m.home = 1 LEFT JOIN #__languages AS l ON l.lang_code = m.language"
sql_group="a.id, a.title, a.menutype, m.language, l.lang_code"
sql_order="a.id DESC"
sql_order="a.ordering ASC"
>
<menuitem
title="{sql:title}"
Expand Down
2 changes: 1 addition & 1 deletion administrator/components/com_menus/presets/menus.xml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
sql_where="a.client_id = 0"
sql_leftjoin="#__menu AS m ON m.menutype = a.menutype AND m.home = 1 LEFT JOIN #__languages AS l ON l.lang_code = m.language"
sql_group="a.id, a.title, a.menutype, m.language, l.lang_code"
sql_order="a.id DESC"
sql_order="a.ordering ASC"
sql_target="self"
>
<menuitem
Expand Down
2 changes: 2 additions & 0 deletions administrator/components/com_menus/src/Model/MenusModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public function __construct($config = array(), MVCFactoryInterface $factory = nu
'title', 'a.title',
'menutype', 'a.menutype',
'client_id', 'a.client_id',
'ordering', 'a.ordering',
);
}

Expand Down Expand Up @@ -174,6 +175,7 @@ protected function getListQuery()
$db->quoteName('a.title'),
$db->quoteName('a.description'),
$db->quoteName('a.client_id'),
$db->quoteName('a.ordering'),
]
)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,14 @@ class HtmlView extends BaseHtmlView
*/
public $activeFilters;

/**
* Ordering of the items
*
* @var array
* @since __DEPLOY_SINCE__
*/
protected $ordering;

/**
* Display the view
*
Expand Down
43 changes: 38 additions & 5 deletions administrator/components/com_menus/tmpl/menus/default.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use Joomla\CMS\Layout\LayoutHelper;
use Joomla\CMS\Router\Route;
use Joomla\CMS\Uri\Uri;
use Joomla\CMS\Session\Session;

/** @var \Joomla\CMS\WebAsset\WebAssetManager $wa */
$wa = $this->document->getWebAssetManager();
Expand All @@ -37,6 +38,14 @@
}
}

$saveOrder = $listOrder == 'a.ordering';

if ($saveOrder)
{
$saveOrderingUrl = 'index.php?option=com_menus&task=menus.saveOrderAjax&tmpl=component&' . Session::getFormToken() . '=1';
HTMLHelper::_('draggablelist.draggable');
}

$this->document->addScriptOptions('menus-default', ['items' => $itemIds]);
?>
<form action="<?php echo Route::_('index.php?option=com_menus&view=menus'); ?>" method="post" name="adminForm" id="adminForm">
Expand All @@ -61,6 +70,9 @@
<td class="w-1 text-center">
<?php echo HTMLHelper::_('grid.checkall'); ?>
</td>
<th scope="col" class="w-1 text-center d-none d-md-table-cell">
<?php echo HTMLHelper::_('searchtools.sort', '', 'a.ordering', $listDirn, $listOrder, null, 'asc', 'JGRID_HEADING_ORDERING', 'icon-sort'); ?>
</th>
<th scope="col">
<?php echo HTMLHelper::_('searchtools.sort', 'JGLOBAL_TITLE', 'a.title', $listDirn, $listOrder); ?>
</th>
Expand Down Expand Up @@ -88,15 +100,36 @@
</th>
</tr>
</thead>
<tbody>
<tbody <?php if ($saveOrder) :?> class="js-draggable" data-url="<?php echo $saveOrderingUrl; ?>" data-direction="<?php echo strtolower($listDirn); ?>" data-nested="false"<?php endif; ?>>
<?php foreach ($this->items as $i => $item) :
$canEdit = $user->authorise('core.edit', 'com_menus.menu.' . (int) $item->id);
$canManageItems = $user->authorise('core.manage', 'com_menus.menu.' . (int) $item->id);
?>
<tr class="row<?php echo $i % 2; ?>">
$ordering = ($listOrder == 'a.ordering');
$canEdit = $user->authorise('core.edit', 'com_menus.menu.' . (int) $item->id);
$canManageItems = $user->authorise('core.manage', 'com_menus.menu.' . (int) $item->id);
$canChange = $user->authorise('core.edit.state', 'com_menus.menu.' . (int) $item->id);
?>
<tr class="row<?php echo $i % 2; ?>" data-draggable-group="0">
<td class="text-center">
<?php echo HTMLHelper::_('grid.id', $i, $item->id, false, 'cid', 'cb', $item->title); ?>
</td>
<td class="text-center d-none d-md-table-cell">
<?php
$iconClass = '';
if (!$canChange)
{
$iconClass = ' inactive';
}
elseif (!$saveOrder)
{
$iconClass = ' inactive" title="' . Text::_('JORDERINGDISABLED');
}
?>
<span class="sortable-handler<?php echo $iconClass; ?>">
<span class="icon-ellipsis-v" aria-hidden="true"></span>
</span>
<?php if ($canChange && $saveOrder) : ?>
<input type="text" name="order[]" size="5" value="<?php echo $item->ordering; ?>" class="width-20 text-area-order hidden">
<?php endif; ?>
</td>
<th scope="row">
<div class="name break-word">
<?php if ($canEdit) : ?>
Expand Down

0 comments on commit 2150ffa

Please sign in to comment.