From 04d6d5ca99ebfd1cebb8ce06618fb3811fc1a8aa Mon Sep 17 00:00:00 2001 From: Charles Date: Thu, 9 Jan 2020 10:55:03 +0100 Subject: phpmyadmin working --- .../templates/table/relation/common_form.twig | 223 +++++++++++++++++++++ .../table/relation/dropdown_generate.twig | 9 + .../templates/table/relation/foreign_key_row.twig | 136 +++++++++++++ .../table/relation/relational_dropdown.twig | 18 ++ 4 files changed, 386 insertions(+) create mode 100644 srcs/phpmyadmin/templates/table/relation/common_form.twig create mode 100644 srcs/phpmyadmin/templates/table/relation/dropdown_generate.twig create mode 100644 srcs/phpmyadmin/templates/table/relation/foreign_key_row.twig create mode 100644 srcs/phpmyadmin/templates/table/relation/relational_dropdown.twig (limited to 'srcs/phpmyadmin/templates/table/relation') diff --git a/srcs/phpmyadmin/templates/table/relation/common_form.twig b/srcs/phpmyadmin/templates/table/relation/common_form.twig new file mode 100644 index 0000000..e85c6ce --- /dev/null +++ b/srcs/phpmyadmin/templates/table/relation/common_form.twig @@ -0,0 +1,223 @@ +{% extends 'table/page_with_secondary_tabs.twig' %} + +{% block content %} +
+ {{ get_hidden_inputs(db, table) }} + {# InnoDB #} + {% if is_foreign_key_supported(tbl_storage_engine) %} +
+ {% trans 'Foreign key constraints' %} +
+ + + + + {% if tbl_storage_engine|upper == 'INNODB' %} + + {% else %} + + {% endif %} + + + + + + + + + + + {% set i = 0 %} + {% if existrel_foreign is not empty %} + {% for key, one_key in existrel_foreign %} + {# Foreign database dropdown #} + {% set foreign_db = one_key['ref_db_name'] is defined + and one_key['ref_db_name'] is not null + ? one_key['ref_db_name'] : db %} + {% set foreign_table = false %} + {% if foreign_db %} + {% set foreign_table = one_key['ref_table_name'] is defined + and one_key['ref_table_name'] is not null + ? one_key['ref_table_name'] : false %} + {% endif %} + {% set unique_columns = [] %} + {% if foreign_db and foreign_table %} + {% set table_obj = table_get(foreign_table, foreign_db) %} + {% set unique_columns = table_obj.getUniqueColumns(false, false) %} + {% endif %} + {% include 'table/relation/foreign_key_row.twig' with { + 'i': i, + 'one_key': one_key, + 'column_array': column_array, + 'options_array': options_array, + 'tbl_storage_engine': tbl_storage_engine, + 'db': db, + 'table': table, + 'url_params': url_params, + 'databases': databases, + 'foreign_db': foreign_db, + 'foreign_table': foreign_table, + 'unique_columns': unique_columns + } only %} + {% set i = i + 1 %} + {% endfor %} + {% endif %} + {% include 'table/relation/foreign_key_row.twig' with { + 'i': i, + 'one_key': [], + 'column_array': column_array, + 'options_array': options_array, + 'tbl_storage_engine': tbl_storage_engine, + 'db': db, + 'table': table, + 'url_params': url_params, + 'databases': databases, + 'foreign_db': foreign_db, + 'foreign_table': foreign_table, + 'unique_columns': unique_columns + } only %} + {% set i = i + 1 %} + + + +
{% trans 'Actions' %}{% trans 'Constraint properties' %} + {% trans 'Column' %} + {{ show_hint('Creating a foreign key over a non-indexed column would automatically create an index on it. Alternatively, you can define an index below, before creating the foreign key.'|trans) }} + + {% trans 'Column' %} + {{ show_hint('Only columns with index will be displayed. You can define an index below.'|trans) }} + + {% trans 'Foreign key constraint' %} + ({{ tbl_storage_engine }}) +
{% trans 'Database' %}{% trans 'Table' %}{% trans 'Column' %}
+ + {% trans '+ Add constraint' %} + +
+
+
+ {% endif %} + + {% if cfg_relation['relwork'] %} + {% if is_foreign_key_supported(tbl_storage_engine) %} + {% include 'div_for_slider_effect.twig' with { + 'id': 'ir_div', + 'message': 'Internal relationships'|trans, + 'initial_sliders_state': default_sliders_state + } only %} + {% endif %} + +
+ + {% trans 'Internal relationships' %} + {{ show_docu('config', 'cfg_Servers_relation') }} + + + + + + {% set saved_row_cnt = save_row|length - 1 %} + {% for i in 0..saved_row_cnt %} + {% set myfield = save_row[i]['Field'] %} + {# Use an md5 as array index to avoid having special characters + in the name attribute (see bug #1746964 ) #} + {% set myfield_md5 = column_hash_array[myfield] %} + + {% set foreign_table = false %} + {% set foreign_column = false %} + + {# Database dropdown #} + {% if existrel[myfield] is defined %} + {% set foreign_db = existrel[myfield]['foreign_db'] %} + {% else %} + {% set foreign_db = db %} + {% endif %} + + {# Table dropdown #} + {% set tables = [] %} + {% if foreign_db %} + {% if existrel[myfield] is defined %} + {% set foreign_table = existrel[myfield]['foreign_table'] %} + {% endif %} + {% set tables = dbi.getTables(foreign_db) %} + {% endif %} + + {# Column dropdown #} + {% set unique_columns = [] %} + {% if foreign_db and foreign_table %} + {% if existrel[myfield] is defined %} + {% set foreign_column = existrel[myfield]['foreign_field'] %} + {% endif %} + {% set table_obj = table_get(foreign_table, foreign_db) %} + {% set unique_columns = table_obj.getUniqueColumns(false, false) %} + {% endif %} + + + + + + + {% endfor %} +
{% trans 'Column' %}{% trans 'Internal relation' %} + {% if is_foreign_key_supported(tbl_storage_engine) %} + {{ show_hint('An internal relation is not necessary when a corresponding FOREIGN KEY relation exists.'|trans) }} + {% endif %} +
+ {{ myfield }} + + + {% include 'table/relation/relational_dropdown.twig' with { + 'name': 'destination_db[' ~ myfield_md5 ~ ']', + 'title': 'Database'|trans, + 'values': databases, + 'foreign': foreign_db + } only %} + + {% include 'table/relation/relational_dropdown.twig' with { + 'name': 'destination_table[' ~ myfield_md5 ~ ']', + 'title': 'Table'|trans, + 'values': tables, + 'foreign': foreign_table + } only %} + + {% include 'table/relation/relational_dropdown.twig' with { + 'name': 'destination_column[' ~ myfield_md5 ~ ']', + 'title': 'Column'|trans, + 'values': unique_columns, + 'foreign': foreign_column + } only %} +
+
+ {% if is_foreign_key_supported(tbl_storage_engine) %} + + {% endif %} + {% endif %} + + {% if cfg_relation['displaywork'] %} + {% set disp = get_display_field(db, table) %} +
+ + +
+ {% endif %} + +
+ + +
+
+{% if foreignKeySupported %} + {{ displayIndexesHtml|raw }} +{% endif %} +{% endblock %} diff --git a/srcs/phpmyadmin/templates/table/relation/dropdown_generate.twig b/srcs/phpmyadmin/templates/table/relation/dropdown_generate.twig new file mode 100644 index 0000000..ff179bc --- /dev/null +++ b/srcs/phpmyadmin/templates/table/relation/dropdown_generate.twig @@ -0,0 +1,9 @@ +{{ dropdown_question is not empty ? dropdown_question -}} + diff --git a/srcs/phpmyadmin/templates/table/relation/foreign_key_row.twig b/srcs/phpmyadmin/templates/table/relation/foreign_key_row.twig new file mode 100644 index 0000000..3df6c34 --- /dev/null +++ b/srcs/phpmyadmin/templates/table/relation/foreign_key_row.twig @@ -0,0 +1,136 @@ + + {# Drop key anchor #} + + {% set js_msg = '' %} + {% set this_params = null %} + {% if one_key['constraint'] is defined %} + {% set drop_fk_query = 'ALTER TABLE ' ~ backquote(db) ~ '.' ~ backquote(table) + ~ ' DROP FOREIGN KEY ' + ~ backquote(one_key['constraint']) ~ ';' + %} + {% set this_params = url_params %} + {% set this_params = { + 'goto': 'tbl_relation.php', + 'back': 'tbl_relation.php', + 'sql_query': drop_fk_query, + 'message_to_show': 'Foreign key constraint %s has been dropped'|trans|format( + one_key['constraint'] + ) + } %} + {% set js_msg = 'ALTER TABLE ' ~ db ~ '.' ~ table ~ ' DROP FOREIGN KEY ' ~ one_key['constraint'] ~ ';'|js_format %} + {% endif %} + {% if one_key['constraint'] is defined %} + + {% set drop_url = 'sql.php' ~ get_common(this_params) %} + {% set drop_str = get_icon('b_drop', 'Drop'|trans) %} + {{ link_or_button(drop_url, drop_str, {'class': 'drop_foreign_key_anchor ajax'}) }} + {% endif %} + + + + + +
+ {# For ON DELETE and ON UPDATE, the default action + is RESTRICT as per MySQL doc; however, a SHOW CREATE TABLE + won't display the clause if it's set as RESTRICT. #} + {% set on_delete = one_key['on_delete'] is defined + ? one_key['on_delete'] : 'RESTRICT' %} + {% set on_update = one_key['on_update'] is defined + ? one_key['on_update'] : 'RESTRICT' %} + + {% include 'table/relation/dropdown_generate.twig' with { + 'dropdown_question': 'ON DELETE', + 'select_name': 'on_delete[' ~ i ~ ']', + 'choices': options_array, + 'selected_value': on_delete + } only %} + + + {% include 'table/relation/dropdown_generate.twig' with { + 'dropdown_question': 'ON UPDATE', + 'select_name': 'on_update[' ~ i ~ ']', + 'choices': options_array, + 'selected_value': on_update + } only %} + +
+ + + {% if one_key['index_list'] is defined %} + {% for key, column in one_key['index_list'] %} + + {% include 'table/relation/dropdown_generate.twig' with { + 'dropdown_question': '', + 'select_name': 'foreign_key_fields_name[' ~ i ~ '][]', + 'choices': column_array, + 'selected_value': column + } only %} + + {% endfor %} + {% else %} + + {% include 'table/relation/dropdown_generate.twig' with { + 'dropdown_question': '', + 'select_name': 'foreign_key_fields_name[' ~ i ~ '][]', + 'choices': column_array, + 'selected_value': '' + } only %} + + {% endif %} + + {% trans '+ Add column' %} + + + {% set tables = [] %} + {% if foreign_db %} + {% set tables = get_tables(foreign_db, tbl_storage_engine) %} + {% endif %} + + + {% include 'table/relation/relational_dropdown.twig' with { + 'name': 'destination_foreign_db[' ~ i ~ ']', + 'title': 'Database'|trans, + 'values': databases, + 'foreign': foreign_db + } only %} + + + + + {% include 'table/relation/relational_dropdown.twig' with { + 'name': 'destination_foreign_table[' ~ i ~ ']', + 'title': 'Table'|trans, + 'values': tables, + 'foreign': foreign_table + } only %} + + + + {% if foreign_db and foreign_table %} + {% for foreign_column in one_key['ref_index_list'] %} + + {% include 'table/relation/relational_dropdown.twig' with { + 'name': 'destination_foreign_column[' ~ i ~ '][]', + 'title': 'Column'|trans, + 'values': unique_columns, + 'foreign': foreign_column + } only %} + + {% endfor %} + {% else %} + + {% include 'table/relation/relational_dropdown.twig' with { + 'name': 'destination_foreign_column[' ~ i ~ '][]', + 'title': 'Column'|trans, + 'values': [], + 'foreign': '' + } only %} + + {% endif %} + + diff --git a/srcs/phpmyadmin/templates/table/relation/relational_dropdown.twig b/srcs/phpmyadmin/templates/table/relation/relational_dropdown.twig new file mode 100644 index 0000000..9d5f3c9 --- /dev/null +++ b/srcs/phpmyadmin/templates/table/relation/relational_dropdown.twig @@ -0,0 +1,18 @@ + -- cgit