use 100% Html\Form\Components

This commit is contained in:
Jean-Christian Denis 2023-04-29 21:52:44 +02:00
parent dbc8541d59
commit 15d7248db5
Signed by: JcDenis
GPG key ID: 1B5B8C5B90B6C951

View file

@ -19,7 +19,13 @@ use adminGenericListV2;
use dcPager; use dcPager;
use Dotclear\Helper\Date; use Dotclear\Helper\Date;
use Dotclear\Helper\Html\Html; use Dotclear\Helper\Html\Html;
use Dotclear\Helper\Html\Form\Checkbox; use Dotclear\Helper\Html\Form\{
Component,
Div,
Checkbox,
Para,
Text
};
/** /**
* Backend logs list helper. * Backend logs list helper.
@ -34,95 +40,100 @@ class BackendList extends adminGenericListV2
* @param string $enclose_block The enclose block * @param string $enclose_block The enclose block
* @param bool $filter Filter is applied * @param bool $filter Filter is applied
*/ */
public function display(int $page, int $nb_per_page, string $enclose_block = '', bool $filter = false): void public function display(int $page, int $nb_per_page, string $enclose_block = '%s', bool $filter = false): void
{ {
if ($this->rs->isEmpty()) { if ($this->rs->isEmpty()) {
echo $filter ? echo
'<p><strong>' . __('No log matches the filter') . '</strong></p>' : (new Text('p', $filter ? __('No log matches the filter') : __('No log')))
'<p><strong>' . __('No log') . '</strong></p>'; ->class('info')
->render();
} else { } else {
$pager = new dcPager($page, $this->rs_count, $nb_per_page, 10); $pager = new dcPager($page, $this->rs_count, $nb_per_page, 10);
$entries = [];
if (isset($_REQUEST['entries'])) {
foreach ($_REQUEST['entries'] as $v) {
$entries[(int) $v] = true;
}
}
$cols = [ $cols = [
'date' => '<th colspan="2" class="first">' . __('Date') . '</th>', 'date' => (new Text('th', __('Date')))
'msg' => '<th scope="col">' . __('Message') . '</th>', ->class('first')
'blog' => '<th scope="col">' . __('Blog') . '</th>', ->extra('colspan="2"'),
'table' => '<th scope="col">' . __('Component') . '</th>', 'msg' => (new Text('th', __('Message')))
'user' => '<th scope="col">' . __('User') . '</th>', ->extra('scope="col"'),
'ip' => '<th scope="col">' . __('IP') . '</th>', 'blog' => (new Text('th', __('Blog')))
->extra('scope="col"'),
'table' => (new Text('th', __('Component')))
->extra('scope="col"'),
'user' => (new Text('th', __('User')))
->extra('scope="col"'),
'ip' => (new Text('th', __('IP')))
->extra('scope="col"'),
]; ];
$cols = new ArrayObject($cols); $cols = new ArrayObject($cols);
$this->userColumns(My::BACKEND_LIST_ID, $cols); $this->userColumns(My::BACKEND_LIST_ID, $cols);
$html_block = '<div class="table-outer"><table><caption>' . $lines = [];
( while ($this->rs->fetch()) {
$lines[] = $this->line(isset($_POST['entries']) && in_array($this->rs->log_id, $_POST['entries']));
}
echo
$pager->getLinks() .
sprintf(
$enclose_block,
(new Div())
->class('table-outer')
->items([
(new Para(null, 'table'))
->items([
(new Text(
'caption',
$filter ? $filter ?
sprintf(__('List of %s logs matching the filter.'), $this->rs_count) : sprintf(__('List of %s logs matching the filter.'), $this->rs_count) :
sprintf(__('List of logs. (%s)'), $this->rs_count) sprintf(__('List of logs. (%s)'), $this->rs_count)
)),
(new Para(null, 'tr'))
->items(iterator_to_array($cols)),
(new Para(null, 'tbody'))
->items($lines),
]),
])
->render()
) . ) .
'</caption><tr>' . implode(iterator_to_array($cols)) . '</tr>%s</table>%s</div>'; $pager->getLinks();
if ($enclose_block) {
$html_block = sprintf($enclose_block, $html_block);
}
$blocks = explode('%s', $html_block);
echo $pager->getLinks() . $blocks[0];
while ($this->rs->fetch()) {
$this->logLine(isset($entries[$this->rs->log_id]));
}
echo $blocks[1] . $blocks[2] . $pager->getLinks();
} }
} }
/** /**
* Display a records line. * Get a records line.
* *
* @param bool $checked Selected line * @param bool $checked Selected line
*/ */
private function logLine(bool $checked): void private function line(bool $checked): Component
{ {
$cols = [ $cols = [
'check' => '<td class="nowrap minimal">' . 'check' => (new Para(null, 'td'))
(new Checkbox(['entries[]'], $checked))->value($this->rs->log_id)->render() . ->class('nowrap minimal')
'</td>', ->items([
'date' => '<td class="nowrap minimal">' . (new Checkbox(['entries[]'], $checked))->value($this->rs->log_id),
Html::escapeHTML(Date::dt2str( ]),
'date' => (new Text('td', Html::escapeHTML(Date::dt2str(
__('%Y-%m-%d %H:%M'), __('%Y-%m-%d %H:%M'),
$this->rs->log_dt $this->rs->log_dt
)) . ))))
'</td>', ->class('nowrap minimal'),
'msg' => '<td class="maximal">' . 'msg' => (new Text('td', nl2br(Html::escapeHTML($this->rs->log_msg))))
nl2br(Html::escapeHTML($this->rs->log_msg)) . ->class('maximal'),
'</td>', 'blog' => (new Text('td', Html::escapeHTML($this->rs->blog_id)))
'blog' => '<td class="minimal nowrap">' . ->class('nowrap minimal'),
Html::escapeHTML($this->rs->blog_id) . 'table' => (new Text('td', Html::escapeHTML($this->rs->log_table)))
'</td>', ->class('nowrap minimal'),
'table' => '<td class="minimal nowrap">' . 'user' => (new Text('td', Html::escapeHTML($this->rs->getUserCN())))
Html::escapeHTML($this->rs->log_table) . ->class('nowrap minimal'),
'</td>', 'ip' => (new Text('td', Html::escapeHTML($this->rs->log_ip)))
'user' => '<td class="minimal nowrap">' . ->class('nowrap minimal'),
Html::escapeHTML($this->rs->getUserCN()) .
'</td>',
'ip' => '<td class="minimal nowrap">' .
Html::escapeHTML($this->rs->log_ip) .
'</td>',
]; ];
$cols = new ArrayObject($cols); $cols = new ArrayObject($cols);
$this->userColumns(My::BACKEND_LIST_ID, $cols); $this->userColumns(My::BACKEND_LIST_ID, $cols);
echo return
'<tr class="line" id="p' . $this->rs->log_id . '">' . (new Para('p' . $this->rs->log_id, 'tr'))
implode(iterator_to_array($cols)) . ->items(iterator_to_array($cols));
'</tr>';
} }
} }