Skip to content

Commit

Permalink
Extract HTML from Rte\Routines::getParameterRow
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 Jun 24, 2019
1 parent bc585d9 commit b409c83
Show file tree
Hide file tree
Showing 3 changed files with 93 additions and 81 deletions.
100 changes: 29 additions & 71 deletions libraries/classes/Rte/Routines.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,15 @@
namespace PhpMyAdmin\Rte;

use PhpMyAdmin\Charsets;
use PhpMyAdmin\Charsets\Charset;
use PhpMyAdmin\Core;
use PhpMyAdmin\DatabaseInterface;
use PhpMyAdmin\Message;
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;

Expand Down Expand Up @@ -758,7 +760,7 @@ public function getDataFromName($name, $type, $all = true)
*/
public function getParameterRow(array $routine = [], $index = null, $class = '')
{
global $param_directions, $param_opts_num, $titles;
global $param_directions, $param_opts_num;

if ($index === null) {
// template row for AJAX request
Expand All @@ -783,78 +785,34 @@ public function getParameterRow(array $routine = [], $index = null, $class = '')
return '';
}

// Create the output
$retval = "";
$retval .= " <tr>\n";
$retval .= " <td class='dragHandle'>"
. "<span class='ui-icon ui-icon-arrowthick-2-n-s'></span>"
. "</td>\n";
$retval .= " <td class='routine_direction_cell$class'>\n";
$retval .= " <select name='item_param_dir[$index]'>\n";
foreach ($param_directions as $key => $value) {
$selected = "";
if (! empty($routine['item_param_dir'][$i])
&& $routine['item_param_dir'][$i] == $value
) {
$selected = " selected='selected'";
}
$retval .= " <option$selected>$value</option>\n";
}
$retval .= " </select>\n";
$retval .= " </td>\n";
$retval .= " <td><input name='item_param_name[$index]' type='text'\n"
. " value='{$routine['item_param_name'][$i]}'></td>\n";
$retval .= " <td><select name='item_param_type[$index]'>";
$retval .= Util::getSupportedDatatypes(
true,
$routine['item_param_type'][$i]
) . "\n";
$retval .= " </select></td>\n";
$retval .= " <td>\n";
$retval .= " <input id='item_param_length_$index'\n"
. " name='item_param_length[$index]' type='text'\n"
. " value='{$routine['item_param_length'][$i]}'>\n";
$retval .= " <div class='enum_hint'>\n";
$retval .= " <a href='#' class='open_enum_editor'>\n";
$retval .= " "
. Util::getImage('b_edit', '', ['title' => __('ENUM/SET editor')])
. "\n";
$retval .= " </a>\n";
$retval .= " </div>\n";
$retval .= " </td>\n";
$retval .= " <td class='hide no_len'>---</td>\n";
$retval .= " <td class='routine_param_opts_text'>\n";
$retval .= Charsets::getCharsetDropdownBox(
$this->dbi,
$GLOBALS['cfg']['Server']['DisableIS'],
"item_param_opts_text[$index]",
null,
$routine['item_param_opts_text'][$i]
);
$retval .= " </td>\n";
$retval .= " <td class='hide no_opts'>---</td>\n";
$retval .= " <td class='routine_param_opts_num'>\n";
$retval .= " <select name='item_param_opts_num[$index]'>\n";
$retval .= " <option value=''></option>";
foreach ($param_opts_num as $key => $value) {
$selected = "";
if (! empty($routine['item_param_opts_num'][$i])
&& $routine['item_param_opts_num'][$i] == $value
) {
$selected = " selected='selected'";
}
$retval .= "<option$selected>$value</option>";
$allCharsets = Charsets::getCharsets($this->dbi, $GLOBALS['cfg']['Server']['DisableIS']);
$charsets = [];
/** @var Charset $charset */
foreach ($allCharsets as $charset) {
$charsets[] = [
'name' => $charset->getName(),
'description' => $charset->getDescription(),
'is_selected' => $charset->getName() === $routine['item_param_opts_text'][$i],
];
}
$retval .= "\n </select>\n";
$retval .= " </td>\n";
$retval .= " <td class='routine_param_remove$drop_class'>\n";
$retval .= " <a href='#' class='routine_param_remove_anchor'>\n";
$retval .= " {$titles['Drop']}\n";
$retval .= " </a>\n";
$retval .= " </td>\n";
$retval .= " </tr>\n";

return $retval;
$template = new Template();
return $template->render('rte/routines/parameter_row', [
'class' => $class,
'index' => $index,
'param_directions' => $param_directions,
'param_opts_num' => $param_opts_num,
'item_param_dir' => $routine['item_param_dir'][$i] ?? '',
'item_param_name' => $routine['item_param_name'][$i] ?? '',
'item_param_length' => $routine['item_param_length'][$i] ?? '',
'item_param_opts_num' => $routine['item_param_opts_num'][$i] ?? '',
'supported_datatypes' => Util::getSupportedDatatypes(
true,
$routine['item_param_type'][$i]
),
'charsets' => $charsets,
'drop_class' => $drop_class,
]);
}

/**
Expand Down
54 changes: 54 additions & 0 deletions templates/rte/routines/parameter_row.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<tr>
<td class="dragHandle">
<span class="ui-icon ui-icon-arrowthick-2-n-s"></span>
</td>
<td class="routine_direction_cell{{ class }}">
<select name="item_param_dir[{{ index }}]">
{% for value in param_directions %}
<option value="{{ value }}"{{ item_param_dir == value ? ' selected' }}>{{ value }}</option>
{% endfor %}
</select>
</td>
<td>
<input name="item_param_name[{{ index }}]" type="text" value="{{ item_param_name }}">
</td>
<td>
<select name="item_param_type[{{ index }}]">
{{ supported_datatypes|raw }}
</select>
</td>
<td>
<input id="item_param_length_{{ index }}" name="item_param_length[{{ index }}]" type="text" value="{{ item_param_length }}">
<div class="enum_hint">
<a href="#" class="open_enum_editor">
{{ get_image('b_edit', '', {'title': 'ENUM/SET editor'|trans}) }}
</a>
</div>
</td>
<td class="hide no_len">---</td>
<td class="routine_param_opts_text">
<select lang="en" dir="ltr" name="item_param_opts_text[{{ index }}]">
<option value="">{% trans 'Charset' %}</option>
<option value=""></option>
{% for charset in charsets %}
<option value="{{ charset.name }}" title="{{ charset.description }}"{{ charset.is_selected ? ' selected' }}>
{{- charset.name -}}
</option>
{% endfor %}
</select>
</td>
<td class="hide no_opts">---</td>
<td class="routine_param_opts_num">
<select name="item_param_opts_num[{{ index }}]">
<option value=""></option>
{% for value in param_opts_num %}
<option value="{{ value }}"{{ item_param_opts_num == value ? ' selected' }}>{{ value }}</option>
{% endfor %}
</select>
</td>
<td class="routine_param_remove{{ drop_class }}">
<a href="#" class="routine_param_remove_anchor">
{{ get_icon('b_drop', 'Drop'|trans) }}
</a>
</td>
</tr>
20 changes: 10 additions & 10 deletions test/classes/Rte/RoutinesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -369,27 +369,27 @@ public function providerGetParameterRow()
[
$data,
0,
"<select name='item_param_dir[0]'",
'<select name="item_param_dir[0]"',
],
[
$data,
0,
"<input name='item_param_name[0]'",
'<input name="item_param_name[0]"',
],
[
$data,
0,
"<select name='item_param_type[0]'",
'<select name="item_param_type[0]"',
],
[
$data,
0,
"<select name='item_param_opts_num[0]'",
'<select name="item_param_opts_num[0]"',
],
[
$data,
0,
"<a href='#' class='routine_param_remove_anchor'",
'<a href="#" class="routine_param_remove_anchor"',
],
];
}
Expand Down Expand Up @@ -452,23 +452,23 @@ public function providerGetParameterRowAjax()
return [
[
$data,
"<select name='item_param_dir[%s]'",
'<select name="item_param_dir[%s]"',
],
[
$data,
"<input name='item_param_name[%s]'",
'<input name="item_param_name[%s]"',
],
[
$data,
"<select name='item_param_dir[%s]'",
'<select name="item_param_dir[%s]"',
],
[
$data,
"<select name='item_param_opts_num[%s]'",
'<select name="item_param_opts_num[%s]"',
],
[
$data,
"<a href='#' class='routine_param_remove_anchor'",
'<a href="#" class="routine_param_remove_anchor"',
],
];
}
Expand Down

0 comments on commit b409c83

Please sign in to comment.