add options to sort modules and show distributed modules

This commit is contained in:
Jean-Christian Denis 2023-04-06 23:27:30 +02:00
parent 52b16c0e3f
commit 7bc5d8989f
Signed by: JcDenis
GPG key ID: 1B5B8C5B90B6C951
2 changed files with 23 additions and 3 deletions

View file

@ -24,6 +24,7 @@ use Dotclear\Helper\Html\Form\{
Label, Label,
Legend, Legend,
Para, Para,
Select,
Text Text
}; };
use Exception; use Exception;
@ -61,6 +62,8 @@ class Config extends dcNsProcess
} }
dcCore::app()->blog->settings->get(My::id())->put('disabled', $pdisabled); dcCore::app()->blog->settings->get(My::id())->put('disabled', $pdisabled);
dcCore::app()->blog->settings->get(My::id())->put('nodetails', !empty($_POST['nodetails'])); dcCore::app()->blog->settings->get(My::id())->put('nodetails', !empty($_POST['nodetails']));
dcCore::app()->blog->settings->get(My::id())->put('allow_distrib', !empty($_POST['allow_distrib']));
dcCore::app()->blog->settings->get(My::id())->put('combosortby', $_POST['combosortby'] ?: 'name');
dcPage::addSuccessNotice(__('Configuration successfully updated')); dcPage::addSuccessNotice(__('Configuration successfully updated'));
@ -103,6 +106,14 @@ class Config extends dcNsProcess
(new Checkbox('nodetails', (bool) dcCore::app()->blog->settings->get(My::id())->get('nodetails')))->value('1'), (new Checkbox('nodetails', (bool) dcCore::app()->blog->settings->get(My::id())->get('nodetails')))->value('1'),
(new Label(__('Hide details of rendered actions'), Label::OUTSIDE_LABEL_AFTER))->class('classic')->for('nodetails'), (new Label(__('Hide details of rendered actions'), Label::OUTSIDE_LABEL_AFTER))->class('classic')->for('nodetails'),
]), ]),
(new Para())->items([
(new Checkbox('allow_distrib', (bool) dcCore::app()->blog->settings->get(My::id())->get('allow_distrib')))->value('1'),
(new Label(__('Show dotclear distributed modules'), Label::OUTSIDE_LABEL_AFTER))->class('classic')->for('allow_distrib'),
]),
(new Para())->items([
(new Label(__('Sort modules seletion by:')))->for('combosortby'),
(new Select('combosortby'))->items([__('Name') => 'name', __('Id') => 'id'])->default(dcCore::app()->blog->settings->get(My::id())->get('combosortby')),
]),
]), ]),
])->render(); ])->render();
} }

View file

@ -129,13 +129,22 @@ class Manage extends dcNsProcess
} }
$combo_modules = []; $combo_modules = [];
foreach (self::$type == 'plugin' ? dcCore::app()->plugins->getDefines() : dcCore::app()->themes->getDefines() as $module) { $modules = self::$type == 'plugin' ? dcCore::app()->plugins->getDefines() : dcCore::app()->themes->getDefines();
if (dcCore::app()->blog->settings->get(My::id())->get('combosortby') == 'id') {
uasort($modules, fn ($a, $b) => strtolower($a->getId()) <=> strtolower($b->getId()));
} else {
uasort($modules, fn ($a, $b) => strtolower(dcUtils::removeDiacritics($a->get('name'))) <=> strtolower(dcUtils::removeDiacritics($b->get('name'))));
}
foreach ($modules as $module) {
if (!$module->get('root_writable') || !dcCore::app()->blog->settings->get(My::id())->get('allow_distrib') && $module->get('distributed')) { if (!$module->get('root_writable') || !dcCore::app()->blog->settings->get(My::id())->get('allow_distrib') && $module->get('distributed')) {
continue; continue;
} }
$combo_modules[sprintf(__('%s (%s)'), __($module->get('name')), $module->getId())] = $module->getId(); if (dcCore::app()->blog->settings->get(My::id())->get('combosortby') == 'id') {
$combo_modules[sprintf(__('%s (%s)'), $module->getId(), __($module->get('name')))] = $module->getId();
} else {
$combo_modules[sprintf(__('%s (%s)'), __($module->get('name')), $module->getId())] = $module->getId();
}
} }
dcUtils::lexicalKeySort($combo_modules);
return array_merge([__('Select a module') => '-'], $combo_modules); return array_merge([__('Select a module') => '-'], $combo_modules);
} }