diff --git a/administrator/components/com_admin/sql/updates/mysql/5.0.0-2023-07-12.sql b/administrator/components/com_admin/sql/updates/mysql/5.0.0-2023-07-12.sql new file mode 100644 index 0000000000000..3e80b56b76e31 --- /dev/null +++ b/administrator/components/com_admin/sql/updates/mysql/5.0.0-2023-07-12.sql @@ -0,0 +1,2 @@ +ALTER TABLE `#__menu_types` ADD COLUMN `ordering` int NOT NULL DEFAULT 0 AFTER `client_id`; +UPDATE `#__menu_types` SET `ordering` = `id` WHERE `client_id` = 0; diff --git a/administrator/components/com_admin/sql/updates/postgresql/5.0.0-2023-07-12.sql b/administrator/components/com_admin/sql/updates/postgresql/5.0.0-2023-07-12.sql new file mode 100644 index 0000000000000..632a55a87bcd7 --- /dev/null +++ b/administrator/components/com_admin/sql/updates/postgresql/5.0.0-2023-07-12.sql @@ -0,0 +1,2 @@ +ALTER TABLE "#__menu_types" ADD COLUMN "ordering" int NOT NULL DEFAULT 0 AFTER "client_id"; +UPDATE "#__menu_types" SET "ordering" = "id" WHERE "client_id" = 0; diff --git a/administrator/components/com_menus/forms/filter_menus.xml b/administrator/components/com_menus/forms/filter_menus.xml index 3f65394583e5f..ed68dd76aa15b 100644 --- a/administrator/components/com_menus/forms/filter_menus.xml +++ b/administrator/components/com_menus/forms/filter_menus.xml @@ -31,6 +31,8 @@ validate="options" > + + diff --git a/administrator/components/com_menus/presets/default.xml b/administrator/components/com_menus/presets/default.xml index 7e8252caf344a..d67d96b4cebbd 100644 --- a/administrator/components/com_menus/presets/default.xml +++ b/administrator/components/com_menus/presets/default.xml @@ -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" > getTable(); diff --git a/administrator/components/com_menus/src/Model/MenusModel.php b/administrator/components/com_menus/src/Model/MenusModel.php index 08b2a6cce528e..b8fa0e8c8e608 100644 --- a/administrator/components/com_menus/src/Model/MenusModel.php +++ b/administrator/components/com_menus/src/Model/MenusModel.php @@ -45,6 +45,7 @@ public function __construct($config = [], MVCFactoryInterface $factory = null) 'title', 'a.title', 'menutype', 'a.menutype', 'client_id', 'a.client_id', + 'ordering', 'a.ordering', ]; } @@ -165,6 +166,7 @@ protected function getListQuery() $db->quoteName('a.title'), $db->quoteName('a.description'), $db->quoteName('a.client_id'), + $db->quoteName('a.ordering'), ] ) ) @@ -209,7 +211,7 @@ protected function getListQuery() * * @since 1.6 */ - protected function populateState($ordering = 'a.title', $direction = 'asc') + protected function populateState($ordering = 'a.ordering', $direction = 'asc') { $search = $this->getUserStateFromRequest($this->context . '.search', 'filter_search'); $this->setState('filter.search', $search); diff --git a/administrator/components/com_menus/src/View/Menus/HtmlView.php b/administrator/components/com_menus/src/View/Menus/HtmlView.php index 924eae48f89b9..4882e76b95db2 100644 --- a/administrator/components/com_menus/src/View/Menus/HtmlView.php +++ b/administrator/components/com_menus/src/View/Menus/HtmlView.php @@ -73,6 +73,14 @@ class HtmlView extends BaseHtmlView */ public $activeFilters; + /** + * Ordering of the items + * + * @var array + * @since __DEPLOY_SINCE__ + */ + protected $ordering; + /** * Display the view * diff --git a/administrator/components/com_menus/tmpl/menus/default.php b/administrator/components/com_menus/tmpl/menus/default.php index 33cbb9c29c77f..808a6a6661c4f 100644 --- a/administrator/components/com_menus/tmpl/menus/default.php +++ b/administrator/components/com_menus/tmpl/menus/default.php @@ -14,6 +14,7 @@ use Joomla\CMS\Language\Text; use Joomla\CMS\Layout\LayoutHelper; use Joomla\CMS\Router\Route; +use Joomla\CMS\Session\Session; use Joomla\CMS\Uri\Uri; /** @var \Joomla\CMS\WebAsset\WebAssetManager $wa */ @@ -36,6 +37,13 @@ } } +$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]); ?>
@@ -60,6 +68,9 @@ + + + @@ -87,15 +98,35 @@ - + class="js-draggable" data-url="" data-direction="" data-nested="false"> items as $i => $item) : + $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); ?> - + id, false, 'cid', 'cb', $item->title); ?> + + + + + + + + +
diff --git a/installation/sql/mysql/base.sql b/installation/sql/mysql/base.sql index d215cb55cfd09..0514a4977d0e6 100644 --- a/installation/sql/mysql/base.sql +++ b/installation/sql/mysql/base.sql @@ -552,6 +552,7 @@ CREATE TABLE IF NOT EXISTS `#__menu_types` ( `title` varchar(48) NOT NULL, `description` varchar(255) NOT NULL DEFAULT '', `client_id` int NOT NULL DEFAULT 0, + `ordering` int NOT NULL DEFAULT 0, PRIMARY KEY (`id`), UNIQUE KEY `idx_menutype` (`menutype`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 DEFAULT COLLATE=utf8mb4_unicode_ci; @@ -560,8 +561,8 @@ CREATE TABLE IF NOT EXISTS `#__menu_types` ( -- Dumping data for table `#__menu_types` -- -INSERT IGNORE INTO `#__menu_types` (`id`, `asset_id`, `menutype`, `title`, `description`, `client_id`) VALUES -(1, 0, 'mainmenu', 'Main Menu', 'The main menu for the site', 0); +INSERT IGNORE INTO `#__menu_types` (`id`, `asset_id`, `menutype`, `title`, `description`, `client_id`, `ordering`) VALUES +(1, 0, 'mainmenu', 'Main Menu', 'The main menu for the site', 0, 1); -- -------------------------------------------------------- diff --git a/installation/sql/postgresql/base.sql b/installation/sql/postgresql/base.sql index bc6f36bcd900c..4e37522385fcc 100644 --- a/installation/sql/postgresql/base.sql +++ b/installation/sql/postgresql/base.sql @@ -576,6 +576,7 @@ CREATE TABLE IF NOT EXISTS "#__menu_types" ( "title" varchar(48) NOT NULL, "description" varchar(255) DEFAULT '' NOT NULL, "client_id" int DEFAULT 0 NOT NULL, + "ordering" int NOT NULL DEFAULT 0, PRIMARY KEY ("id"), CONSTRAINT "#__menu_types_idx_menutype" UNIQUE ("menutype") ); @@ -584,8 +585,8 @@ CREATE TABLE IF NOT EXISTS "#__menu_types" ( -- Dumping data for table `#__menu_types` -- -INSERT INTO "#__menu_types" ("id", "asset_id", "menutype", "title", "description", "client_id") VALUES -(1, 0, 'mainmenu', 'Main Menu', 'The main menu for the site', 0); +INSERT INTO "#__menu_types" ("id", "asset_id", "menutype", "title", "description", "client_id", "ordering") VALUES +(1, 0, 'mainmenu', 'Main Menu', 'The main menu for the site', 0, 1); SELECT setval('#__menu_types_id_seq', 2, false);