Skip to content

Commit

Permalink
Merge database events templates
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 14, 2020
1 parent 367df7b commit ec3047e
Show file tree
Hide file tree
Showing 4 changed files with 123 additions and 101 deletions.
42 changes: 5 additions & 37 deletions libraries/classes/Database/Events.php
Expand Up @@ -76,54 +76,22 @@ public function __construct(DatabaseInterface $dbi, Template $template, $respons
$this->response = $response;
}

/**
* Main function for the events functionality
*
* @return void
*/
public function main()
public function main(): void
{
global $db, $table, $pmaThemeImage, $text_dir;
global $db, $pmaThemeImage, $text_dir;

/**
* Process all requests
*/
$this->handleEditor();
$this->export();

$items = $this->dbi->getEvents($db);
$hasPrivilege = Util::currentUserHasPrivilege('EVENT', $db);
$isAjax = $this->response->isAjax() && empty($_REQUEST['ajax_page_request']);

$rows = '';
foreach ($items as $item) {
$sqlDrop = sprintf(
'DROP EVENT IF EXISTS %s',
Util::backquote($item['name'])
);
$rows .= $this->template->render('database/events/row', [
'db' => $db,
'table' => $table,
'event' => $item,
'has_privilege' => $hasPrivilege,
'sql_drop' => $sqlDrop,
'row_class' => $isAjax ? 'ajaxInsert hide' : '',
]);
}

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

echo $this->template->render('database/events/footer', [
'db' => $db,
'table' => $table,
'has_privilege' => Util::currentUserHasPrivilege('EVENT', $db, $table),
'has_privilege' => Util::currentUserHasPrivilege('EVENT', $db),
'toggle_button' => $this->getFooterToggleButton(),
'is_ajax' => $this->response->isAjax() && empty($_REQUEST['ajax_page_request']),
]);
}

Expand Down
25 changes: 0 additions & 25 deletions templates/database/events/footer.twig

This file was deleted.

118 changes: 118 additions & 0 deletions templates/database/events/index.twig
@@ -0,0 +1,118 @@
<form id="rteListForm" class="ajax" action="{{ url('/database/events') }}">
{{ get_hidden_inputs(db) }}

<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>

{% for event in items %}
<tr{{ is_ajax ? ' class="ajaxInsert hide"' }}>
<td>
<input type="checkbox" class="checkall" name="item_name[]" value="{{ event.name }}">
</td>
<td>
<span class="drop_sql hide">{{ 'DROP EVENT IF EXISTS %s'|format(backquote(event.name)) }}</span>
<strong>{{ event.name }}</strong>
</td>
<td>
{{ event.status }}
</td>
<td>
{% if has_privilege %}
<a class="ajax edit_anchor" href="{{ url('/database/events', {
'db': db,
'edit_item': true,
'item_name': event.name
}) }}">
{{ get_icon('b_edit', 'Edit'|trans) }}
</a>
{% else %}
{{ get_icon('bd_edit', 'Edit'|trans) }}
{% endif %}
</td>
<td>
<a class="ajax export_anchor" href="{{ url('/database/events', {
'db': db,
'export_item': true,
'item_name': event.name
}) }}">
{{ get_icon('b_export', 'Export'|trans) }}
</a>
</td>
<td>
{% if has_privilege %}
{{ link_or_button(
url('/sql', {
'db': db,
'sql_query': 'DROP EVENT IF EXISTS %s'|format(backquote(event.name)),
'goto': url('/database/events', {'db': db})
}),
get_icon('b_drop', 'Drop'|trans),
{'class': 'ajax drop_anchor'}
) }}
{% else %}
{{ get_icon('bd_drop', 'Drop'|trans) }}
{% endif %}
</td>
<td>
{{ event.type }}
</td>
</tr>
{% endfor %}
</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>

<div class="doubleFieldset">
<fieldset class="left">
<legend>{% trans %}New{% context %}Create new event{% endtrans %}</legend>
<div class="wrap">
{% if has_privilege %}
<a class="ajax add_anchor" href="{{ url('/database/events', {'db': db, 'add_item': true}) }}" onclick="$.datepicker.initialized = false;">
{{ get_icon('b_event_add') }}
{% trans 'Add event' %}
</a>
{% else %}
{{ get_icon('bd_event_add') }}
{% trans 'Add event' %}
{% endif %}
{{ show_mysql_docu('CREATE_EVENT') }}
</div>
</fieldset>

<fieldset class="right">
<legend>{% trans 'Event scheduler status' %}</legend>
<div class="wrap">
{{ toggle_button|raw }}
</div>
</fieldset>
<div class="clearfloat"></div>
</div>
39 changes: 0 additions & 39 deletions templates/database/events/list.twig

This file was deleted.

0 comments on commit ec3047e

Please sign in to comment.