Skip to content

Commit

Permalink
Extract the HTML from RteList::get method
Browse files Browse the repository at this point in the history
Signed-off-by: Maurício Meneghini Fauth <mauricio@fauth.dev>
  • Loading branch information
MauricioFauth committed Apr 10, 2020
1 parent 8279afd commit 39e567f
Show file tree
Hide file tree
Showing 7 changed files with 180 additions and 181 deletions.
25 changes: 20 additions & 5 deletions libraries/classes/Rte/Events.php
Expand Up @@ -111,19 +111,34 @@ public function setGlobals()
*/
public function main()
{
global $db, $table;
global $db, $table, $pmaThemeImage, $text_dir;

$this->setGlobals();
/**
* Process all requests
*/
$this->handleEditor();
$this->export->events();
/**
* Display a list of available events
*/

$items = $this->dbi->getEvents($db);
echo $this->rteList->get('event', $items);
$response = Response::getInstance();
$isAjax = $response->isAjax() && empty($_REQUEST['ajax_page_request']);

$rows = '';
foreach ($items as $item) {
$rows .= $this->rteList->getEventRow(
$item,
$isAjax ? 'ajaxInsert hide' : ''
);
}

echo $this->template->render('rte/events/list', [
'db' => $db,
'table' => $table,
'items' => $items,
'rows' => $rows,
'select_all_arrow_src' => $pmaThemeImage . 'arrow_' . $text_dir . '.png',
]);

echo $this->template->render('rte/events/footer', [
'db' => $db,
Expand Down
22 changes: 20 additions & 2 deletions libraries/classes/Rte/Routines.php
Expand Up @@ -115,7 +115,7 @@ public function setGlobals()
*/
public function main($type)
{
global $db, $table;
global $db, $table, $pmaThemeImage, $text_dir;

$this->setGlobals();
/**
Expand All @@ -130,8 +130,26 @@ public function main($type)
if (! Core::isValid($type, ['FUNCTION', 'PROCEDURE'])) {
$type = null;
}

$items = $this->dbi->getRoutines($db, $type);
echo $this->rteList->get('routine', $items);
$response = Response::getInstance();
$isAjax = $response->isAjax() && empty($_REQUEST['ajax_page_request']);

$rows = '';
foreach ($items as $item) {
$rows .= $this->rteList->getRoutineRow(
$item,
$isAjax ? 'ajaxInsert hide' : ''
);
}

echo $this->template->render('rte/routines/list', [
'db' => $db,
'table' => $table,
'items' => $items,
'rows' => $rows,
'select_all_arrow_src' => $pmaThemeImage . 'arrow_' . $text_dir . '.png',
]);

echo $this->template->render('rte/routines/footer', [
'db' => $db,
Expand Down
169 changes: 0 additions & 169 deletions libraries/classes/Rte/RteList.php
Expand Up @@ -7,27 +7,18 @@
namespace PhpMyAdmin\Rte;

use PhpMyAdmin\DatabaseInterface;
use PhpMyAdmin\Html\Generator;
use PhpMyAdmin\Html\MySQLDocumentation;
use PhpMyAdmin\Response;
use PhpMyAdmin\SqlParser\Parser;
use PhpMyAdmin\SqlParser\Statements\CreateStatement;
use PhpMyAdmin\SqlParser\Utils\Routine;
use PhpMyAdmin\Template;
use PhpMyAdmin\Url;
use PhpMyAdmin\Util;
use function count;
use function htmlspecialchars;
use function sprintf;

/**
* PhpMyAdmin\Rte\RteList class
*/
class RteList
{
/** @var Words */
private $words;

/** @var Template */
public $template;

Expand All @@ -40,169 +31,9 @@ class RteList
public function __construct(DatabaseInterface $dbi)
{
$this->dbi = $dbi;
$this->words = new Words();
$this->template = new Template();
}

/**
* Creates a list of items containing the relevant
* information and some action links.
*
* @param string $type One of ['routine'|'trigger'|'event']
* @param array $items An array of items
*
* @return string HTML code of the list of items
*/
public function get($type, array $items)
{
global $table;

/**
* Conditional classes switch the list on or off
*/
$class1 = 'hide';
$class2 = '';
if (! $items) {
$class1 = '';
$class2 = ' hide';
}
/**
* Generate output
*/
$retval = '<!-- LIST OF ' . $this->words->get('docu') . " START -->\n";
$retval .= '<form id="rteListForm" class="ajax" action="';
switch ($type) {
case 'routine':
$retval .= Url::getFromRoute('/database/routines');
break;
case 'trigger':
if (! empty($table)) {
$retval .= Url::getFromRoute('/table/triggers');
} else {
$retval .= Url::getFromRoute('/database/triggers');
}
break;
case 'event':
$retval .= Url::getFromRoute('/database/events');
break;
default:
break;
}
$retval .= '">';
$retval .= Url::getHiddenInputs($GLOBALS['db'], $GLOBALS['table']);
$retval .= "<fieldset>\n";
$retval .= " <legend>\n";
$retval .= ' ' . $this->words->get('title') . "\n";
$retval .= ' '
. MySQLDocumentation::show($this->words->get('docu')) . "\n";
$retval .= " </legend>\n";
$retval .= " <div class='" . $class1 . "' id='nothing2display'>\n";
$retval .= ' ' . $this->words->get('nothing') . "\n";
$retval .= " </div>\n";
$retval .= " <table class='data" . $class2 . "'>\n";
$retval .= " <!-- TABLE HEADERS -->\n";
$retval .= " <tr>\n";
// th cells with a colspan need corresponding td cells, according to W3C
switch ($type) {
case 'routine':
$retval .= " <th></th>\n";
$retval .= ' <th>' . __('Name') . "</th>\n";
$retval .= " <th colspan='4'>" . __('Action') . "</th>\n";
$retval .= ' <th>' . __('Type') . "</th>\n";
$retval .= ' <th>' . __('Returns') . "</th>\n";
$retval .= " </tr>\n";
$retval .= " <tr class='hide'>\n"; // see comment above
for ($i = 0; $i < 7; $i++) {
$retval .= " <td></td>\n";
}
break;
case 'trigger':
$retval .= " <th></th>\n";
$retval .= ' <th>' . __('Name') . "</th>\n";
if (empty($table)) {
$retval .= ' <th>' . __('Table') . "</th>\n";
}
$retval .= " <th colspan='3'>" . __('Action') . "</th>\n";
$retval .= ' <th>' . __('Time') . "</th>\n";
$retval .= ' <th>' . __('Event') . "</th>\n";
$retval .= " </tr>\n";
$retval .= " <tr class='hide'>\n"; // see comment above
for ($i = 0; $i < (empty($table) ? 7 : 6); $i++) {
$retval .= " <td></td>\n";
}
break;
case 'event':
$retval .= " <th></th>\n";
$retval .= ' <th>' . __('Name') . "</th>\n";
$retval .= ' <th>' . __('Status') . "</th>\n";
$retval .= " <th colspan='3'>" . __('Action') . "</th>\n";
$retval .= ' <th>' . __('Type') . "</th>\n";
$retval .= " </tr>\n";
$retval .= " <tr class='hide'>\n"; // see comment above
for ($i = 0; $i < 6; $i++) {
$retval .= " <td></td>\n";
}
break;
default:
break;
}
$retval .= " </tr>\n";
$retval .= " <!-- TABLE DATA -->\n";
$response = Response::getInstance();
foreach ($items as $item) {
if ($response->isAjax() && empty($_REQUEST['ajax_page_request'])) {
$rowclass = 'ajaxInsert hide';
} else {
$rowclass = '';
}
// Get each row from the correct function
switch ($type) {
case 'routine':
$retval .= $this->getRoutineRow($item, $rowclass);
break;
case 'trigger':
$retval .= $this->getTriggerRow($item, $rowclass);
break;
case 'event':
$retval .= $this->getEventRow($item, $rowclass);
break;
default:
break;
}
}
$retval .= " </table>\n";

if (count($items)) {
$retval .= '<div class="withSelected">';
$retval .= $this->template->render('select_all', [
'pma_theme_image' => $GLOBALS['pmaThemeImage'],
'text_dir' => $GLOBALS['text_dir'],
'form_name' => 'rteListForm',
]);
$retval .= Generator::getButtonOrImage(
'submit_mult',
'mult_submit',
__('Export'),
'b_export',
'export'
);
$retval .= Generator::getButtonOrImage(
'submit_mult',
'mult_submit',
__('Drop'),
'b_drop',
'drop'
);
$retval .= '</div>';
}

$retval .= "</fieldset>\n";
$retval .= "</form>\n";
$retval .= '<!-- LIST OF ' . $this->words->get('docu') . " END -->\n";

return $retval;
}

/**
* Creates the contents for a row in the list of routines
*
Expand Down
25 changes: 20 additions & 5 deletions libraries/classes/Rte/Triggers.php
Expand Up @@ -87,19 +87,34 @@ public function setGlobals()
*/
public function main()
{
global $db, $table;
global $db, $table, $pmaThemeImage, $text_dir;

$this->setGlobals();
/**
* Process all requests
*/
$this->handleEditor();
$this->export->triggers();
/**
* Display a list of available triggers
*/

$items = $this->dbi->getTriggers($db, $table);
echo $this->rteList->get('trigger', $items);
$response = Response::getInstance();
$isAjax = $response->isAjax() && empty($_REQUEST['ajax_page_request']);

$rows = '';
foreach ($items as $item) {
$rows .= $this->rteList->getTriggerRow(
$item,
$isAjax ? 'ajaxInsert hide' : ''
);
}

echo $this->template->render('rte/triggers/list', [
'db' => $db,
'table' => $table,
'items' => $items,
'rows' => $rows,
'select_all_arrow_src' => $pmaThemeImage . 'arrow_' . $text_dir . '.png',
]);

echo $this->template->render('rte/triggers/footer', [
'db' => $db,
Expand Down
39 changes: 39 additions & 0 deletions templates/rte/events/list.twig
@@ -0,0 +1,39 @@
<form id="rteListForm" class="ajax" action="{{ url('/database/events') }}">
{{ get_hidden_inputs(db, table) }}

<fieldset>
<legend>
{% trans 'Events' %}
{{ show_mysql_docu('EVENTS') }}
</legend>

<div id="nothing2display"{{ items is not empty ? ' class="hide"' }}>
{% trans 'There are no events to display.' %}
</div>

<table class="data{{ items is empty ? ' hide' }}">
<tr>
<th></th>
<th>{% trans 'Name' %}</th>
<th>{% trans 'Status' %}</th>
<th colspan="3">{% trans 'Action' %}</th>
<th>{% trans 'Type' %}</th>
</tr>
<tr class="hide">{% for i in 0..6 %}<td></td>{% endfor %}</tr>

{{ rows|raw }}
</table>

{% if items is not empty %}
<div class="withSelected">
<img class="selectallarrow" src="{{ select_all_arrow_src }}" width="38" height="22" alt="{% trans 'With selected:' %}">
<input type="checkbox" id="rteListForm_checkall" class="checkall_box" title="{% trans 'Check all' %}">
<label for="rteListForm_checkall">{% trans 'Check all' %}</label>
<em class="with-selected">{% trans 'With selected:' %}</em>

{{ get_button_or_image('submit_mult', 'mult_submit', 'Export'|trans, 'b_export', 'export') }}
{{ get_button_or_image('submit_mult', 'mult_submit', 'Drop'|trans, 'b_drop', 'drop') }}
</div>
{% endif %}
</fieldset>
</form>
39 changes: 39 additions & 0 deletions templates/rte/routines/list.twig
@@ -0,0 +1,39 @@
<form id="rteListForm" class="ajax" action="{{ url('/database/routines') }}">
{{ get_hidden_inputs(db, table) }}

<fieldset>
<legend>
{% trans 'Routines' %}
{{ show_mysql_docu('STORED_ROUTINES') }}
</legend>

<div id="nothing2display"{{ items is not empty ? ' class="hide"' }}>
{% trans 'There are no routines to display.' %}
</div>

<table class="data{{ items is empty ? ' hide' }}">
<tr>
<th></th>
<th>{% trans 'Name' %}</th>
<th colspan="4">{% trans 'Action' %}</th>
<th>{% trans 'Type' %}</th>
<th>{% trans 'Returns' %}</th>
</tr>
<tr class="hide">{% for i in 0..7 %}<td></td>{% endfor %}</tr>

{{ rows|raw }}
</table>

{% if items is not empty %}
<div class="withSelected">
<img class="selectallarrow" src="{{ select_all_arrow_src }}" width="38" height="22" alt="{% trans 'With selected:' %}">
<input type="checkbox" id="rteListForm_checkall" class="checkall_box" title="{% trans 'Check all' %}">
<label for="rteListForm_checkall">{% trans 'Check all' %}</label>
<em class="with-selected">{% trans 'With selected:' %}</em>

{{ get_button_or_image('submit_mult', 'mult_submit', 'Export'|trans, 'b_export', 'export') }}
{{ get_button_or_image('submit_mult', 'mult_submit', 'Drop'|trans, 'b_drop', 'drop') }}
</div>
{% endif %}
</fieldset>
</form>

0 comments on commit 39e567f

Please sign in to comment.