add default-sorting of listings in frontend

Signed-off-by: Michael Kaufmann <d00p@froxlor.org>
This commit is contained in:
Michael Kaufmann
2022-09-30 09:44:11 +02:00
parent fa826aa87e
commit e944a886b6
40 changed files with 51 additions and 26 deletions

View File

@@ -109,7 +109,7 @@ class Collection
return $this;
}
public function withPagination(array $columns): Collection
public function withPagination(array $columns, array $default_sorting = []): Collection
{
// Get only searchable columns
/*
@@ -122,7 +122,7 @@ class Collection
*/
// Prepare pagination
$this->pagination = new Pagination($columns, $this->count(), (int)Settings::Get('panel.paging'));
$this->pagination = new Pagination($columns, $this->count(), (int)Settings::Get('panel.paging'), $default_sorting);
$this->params = array_merge($this->params, $this->pagination->getApiCommandParams());
return $this;

View File

@@ -54,8 +54,9 @@ class Pagination
* @param array $fields
* @param int $total_entries
* @param int $perPage
* @param array $default_sorting array of key=sortfield,value=sortorder for default sorting
*/
public function __construct(array $fields = [], int $total_entries = 0, int $perPage = 20)
public function __construct(array $fields = [], int $total_entries = 0, int $perPage = 20, array $default_sorting = [])
{
$this->fields = $fields;
$this->entries = $total_entries;
@@ -87,8 +88,14 @@ class Pagination
$this->sortfield = $_REQUEST['sortfield'];
$this->addOrderBy($this->sortfield, $this->sortorder);
} else {
// add default ordering by given order
if (!empty($default_sorting)) {
$this->sortfield = array_key_first($default_sorting);
$this->sortorder = array_shift($default_sorting) ?? $this->sortorder;
$this->addOrderBy($this->sortfield, $this->sortorder);
}
// add default ordering by given fields
if (count($fields) > 0) {
if (count($fields) > 0 && empty($this->sortfield)) {
$orderfields = array_keys($fields);
$this->sortfield = $orderfields[0];
$this->addOrderBy($orderfields[0], $this->sortorder);

View File

@@ -36,6 +36,7 @@ return [
'title' => lng('admin.admin'),
'icon' => 'fa-solid fa-user',
'self_overview' => ['section' => 'admins', 'page' => 'admins'],
'default_sorting' => ['loginname' => 'asc'],
'columns' => [
'adminid' => [
'label' => 'ID',

View File

@@ -30,6 +30,7 @@ return [
'cron_list' => [
'title' => lng('admin.cron.cronsettings'),
'icon' => 'fa-solid fa-clock-rotate-left',
'default_sorting' => ['c.id' => 'asc'],
'columns' => [
'c.desc_lng_key' => [
'label' => lng('cron.description'),

View File

@@ -36,6 +36,7 @@ return [
'description' => lng('admin.customers_list_desc'),
'icon' => 'fa-solid fa-user',
'self_overview' => ['section' => 'customers', 'page' => 'customers'],
'default_sorting' => ['c.name' => 'asc'],
'columns' => [
'c.customerid' => [
'label' => 'ID',

View File

@@ -35,6 +35,7 @@ return [
'icon' => 'fa-solid fa-globe',
'empty_msg' => $customerCollection->count() == 0 ? lng('admin.domain_nocustomeraddingavailable') : '',
'self_overview' => ['section' => 'domains', 'page' => 'domains'],
'default_sorting' => ['d.domain_ace' => 'asc'],
'columns' => [
'd.id' => [
'label' => 'ID',

View File

@@ -30,6 +30,7 @@ return [
'title' => lng('admin.templates.filetemplates'),
'icon' => 'fa-solid fa-file-lines',
'self_overview' => ['section' => 'templates', 'page' => 'email'],
'default_sorting' => ['template' => 'asc'],
'columns' => [
'template' => [
'label' => lng('admin.templates.action'),

View File

@@ -32,6 +32,7 @@ return [
'title' => lng('menue.phpsettings.fpmdaemons'),
'icon' => 'fa-brands fa-php',
'self_overview' => ['section' => 'phpsettings', 'page' => 'fpmdaemons'],
'default_sorting' => ['description' => 'asc'],
'columns' => [
'id' => [
'label' => 'ID',

View File

@@ -32,6 +32,7 @@ return [
'title' => lng('admin.integritycheck'),
'icon' => 'fa-solid fa-circle-check',
'self_overview' => ['section' => 'settings', 'page' => 'integritycheck'],
'default_sorting' => ['displayid' => 'asc'],
'columns' => [
'displayid' => [
'label' => 'ID',

View File

@@ -32,6 +32,7 @@ return [
'title' => lng('admin.ipsandports.ipsandports'),
'icon' => 'fa-solid fa-ethernet',
'self_overview' => ['section' => 'ipsandports', 'page' => 'ipsandports'],
'default_sorting' => ['ip' => 'asc'],
'columns' => [
'ip' => [
'label' => lng('admin.ipsandports.ip'),

View File

@@ -30,6 +30,7 @@ return [
'title' => lng('admin.templates.templates'),
'icon' => 'fa-solid fa-envelope',
'self_overview' => ['section' => 'templates', 'page' => 'email'],
'default_sorting' => ['template' => 'asc'],
'columns' => [
'language' => [
'label' => lng('login.language'),

View File

@@ -31,6 +31,7 @@ return [
'title' => lng('admin.mysqlserver.mysqlserver'),
'icon' => 'fa-solid fa-server',
'self_overview' => ['section' => 'mysqlserver', 'page' => 'mysqlserver'],
'default_sorting' => ['caption' => 'asc'],
'columns' => [
'id' => [
'label' => lng('admin.mysqlserver.dbserver'),

View File

@@ -33,6 +33,7 @@ return [
'title' => lng('menue.phpsettings.maintitle'),
'icon' => 'fa-brands fa-php',
'self_overview' => ['section' => 'phpsettings', 'page' => 'overview'],
'default_sorting' => ['c.description' => 'asc'],
'columns' => [
'c.id' => [
'label' => 'ID',

View File

@@ -31,6 +31,7 @@ return [
'title' => lng('admin.plans.plans'),
'icon' => 'fa-solid fa-clipboard-list',
'self_overview' => ['section' => 'plans', 'page' => 'overview'],
'default_sorting' => ['p.name' => 'asc'],
'columns' => [
'p.id' => [
'label' => 'ID',

View File

@@ -32,6 +32,7 @@ return [
'title' => lng('error.customerhasongoingbackupjob'),
'icon' => 'fa-solid fa-server',
'self_overview' => ['section' => 'extras', 'page' => 'backup'],
'default_sorting' => ['destdir' => 'asc'],
'columns' => [
'destdir' => [
'label' => lng('panel.path'),

View File

@@ -33,6 +33,7 @@ return [
'title' => lng('admin.domains'),
'icon' => 'fa-solid fa-globe',
'self_overview' => ['section' => 'domains', 'page' => 'domains'],
'default_sorting' => ['d.domain_ace' => 'asc'],
'columns' => [
'd.domain_ace' => [
'label' => lng('domains.domainname'),

View File

@@ -33,6 +33,7 @@ return [
'title' => lng('menue.email.emails'),
'icon' => 'fa-solid fa-envelope',
'self_overview' => ['section' => 'email', 'page' => 'emails'],
'default_sorting' => ['m.email_full' => 'asc'],
'columns' => [
'm.email_full' => [
'label' => lng('emails.emailaddress'),

View File

@@ -32,6 +32,7 @@ return [
'title' => lng('menue.ftp.accounts'),
'icon' => 'fa-solid fa-users',
'self_overview' => ['section' => 'ftp', 'page' => 'accounts'],
'default_sorting' => ['username' => 'asc'],
'columns' => [
'username' => [
'label' => lng('login.username'),

View File

@@ -32,6 +32,7 @@ return [
'title' => lng('menue.extras.pathoptions'),
'icon' => 'fa-solid fa-folder',
'self_overview' => ['section' => 'extras', 'page' => 'htaccess'],
'default_sorting' => ['path' => 'asc'],
'columns' => [
'path' => [
'label' => lng('panel.path'),

View File

@@ -31,6 +31,7 @@ return [
'title' => lng('menue.extras.directoryprotection'),
'icon' => 'fa-solid fa-lock',
'self_overview' => ['section' => 'extras', 'page' => 'htpasswds'],
'default_sorting' => ['path' => 'asc'],
'columns' => [
'username' => [
'label' => lng('login.username'),

View File

@@ -32,6 +32,7 @@ return [
'title' => lng('menue.mysql.databases'),
'icon' => 'fa-solid fa-database',
'self_overview' => ['section' => 'mysql', 'page' => 'mysqls'],
'default_sorting' => ['databasename' => 'asc'],
'columns' => [
'databasename' => [
'label' => lng('mysql.databasename'),

View File

@@ -32,6 +32,7 @@ return [
'title' => lng('domains.ssl_certificates'),
'icon' => 'fa-solid fa-shield',
'self_overview' => ['section' => 'domains', 'page' => 'sslcertificates'],
'default_sorting' => ['domains.domain_ace' => 'asc'],
'columns' => [
'd.domain' => [
'label' => lng('domains.domainname'),

View File

@@ -32,6 +32,7 @@ return [
'title' => lng('menue.logger.logger'),
'icon' => 'fa-solid fa-file-lines',
'self_overview' => ['section' => 'logger', 'page' => 'log'],
'default_sorting' => ['date' => 'desc'],
'columns' => [
'date' => [
'label' => lng('logger.date'),