Extract HTML from Index::getHtmlForDisplayIndexes

Signed-off-by: Maurício Meneghini Fauth <mauricio@fauth.dev>
This commit is contained in:
Maurício Meneghini Fauth 2020-03-29 16:09:50 -03:00
parent 1e05faffca
commit eb2804540f
5 changed files with 37 additions and 41 deletions

View File

@ -194,7 +194,7 @@ final class RelationController extends AbstractController
'dbi' => $this->dbi,
'default_sliders_state' => $GLOBALS['cfg']['InitialSlidersState'],
'foreignKeySupported' => $foreignKeySupported,
'displayIndexesHtml' => $foreignKeySupported ? Index::getHtmlForDisplayIndexes() : null,
'indexes_html' => $foreignKeySupported ? Index::getHtmlForIndexes($this->table, $this->db) : null,
'route' => $route,
])
);

View File

@ -1331,7 +1331,7 @@ class StructureController extends AbstractController
],
'collations' => $collations,
'is_foreign_key_supported' => Util::isForeignKeySupported($engine),
'displayIndexesHtml' => Index::getHtmlForDisplayIndexes(),
'indexes_html' => Index::getHtmlForIndexes($this->table, $this->db),
'cfg_relation' => $this->relation->getRelationsParam(),
'hide_structure_actions' => $hideStructureActions,
'db' => $this->db,

View File

@ -561,40 +561,6 @@ class Index
return $this->_columns;
}
/**
* Get HTML for display indexes
*
* @return string
*/
public static function getHtmlForDisplayIndexes()
{
$html_output = '<div id="index_div" class="w-100 ajax" >';
$html_output .= self::getHtmlForIndexes(
$GLOBALS['table'],
$GLOBALS['db']
);
$html_output .= '<fieldset class="tblFooters print_ignore" style="text-align: '
. 'left;"><form action="' . Url::getFromRoute('/table/indexes') . '" method="post">';
$html_output .= Url::getHiddenInputs(
$GLOBALS['db'],
$GLOBALS['table']
);
$html_output .= sprintf(
__('Create an index on &nbsp;%s&nbsp;columns'),
'<input type="number" name="added_fields" value="1" '
. 'min="1" required="required">'
);
$html_output .= '<input type="hidden" name="create_index" value="1">'
. '<input class="btn btn-primary add_index ajax"'
. ' type="submit" value="' . __('Go') . '">';
$html_output .= '</form>'
. '</fieldset>'
. '</div>';
return $html_output;
}
/**
* Show index data
*

View File

@ -217,7 +217,24 @@
<input class="btn btn-primary" type="submit" value="{% trans 'Save' %}">
</fieldset>
</form>
{% if foreignKeySupported %}
{{ displayIndexesHtml|raw }}
<div id="index_div" class="w-100 ajax">
{{ indexes_html|raw }}
<fieldset class="tblFooters print_ignore text-left">
<form action="{{ url('/table/indexes') }}" method="post">
{{ get_hidden_inputs(db, table) }}
<input type="hidden" name="create_index" value="1">
{% apply format('<input class="mx-2" type="number" name="added_fields" value="1" min="1" required>')|raw %}
{% trans %}Create an index on %s columns{% endtrans %}
{% endapply %}
<input class="btn btn-primary add_index ajax" type="submit" value="{% trans 'Go' %}">
</form>
</fieldset>
</div>
{% endif %}
{% endblock %}

View File

@ -443,10 +443,23 @@
</form>
{% endif %}
{# Displays indexes #}
{% if not tbl_is_view and not db_is_system_schema
and 'ARCHIVE' != tbl_storage_engine %}
{{ displayIndexesHtml|raw }}
{% if not tbl_is_view and not db_is_system_schema and tbl_storage_engine != 'ARCHIVE' %}
<div id="index_div" class="w-100 ajax">
{{ indexes_html|raw }}
<fieldset class="tblFooters print_ignore text-left">
<form action="{{ url('/table/indexes') }}" method="post">
{{ get_hidden_inputs(db, table) }}
<input type="hidden" name="create_index" value="1">
{% apply format('<input class="mx-2" type="number" name="added_fields" value="1" min="1" required>')|raw %}
{% trans %}Create an index on %s columns{% endtrans %}
{% endapply %}
<input class="btn btn-primary add_index ajax" type="submit" value="{% trans 'Go' %}">
</form>
</fieldset>
</div>
{% endif %}
{# Display partition details #}