show apikey details in modal-overlay; todo: edit allowed_from and valid_until

Signed-off-by: Michael Kaufmann <d00p@froxlor.org>
This commit is contained in:
Michael Kaufmann
2022-04-09 13:32:08 +02:00
parent 9272c15706
commit 7f0eb97f9b
11 changed files with 143 additions and 44 deletions

View File

@@ -30,7 +30,6 @@ use Froxlor\UI\Request;
$del_stmt = Database::prepare("DELETE FROM `" . TABLE_API_KEYS . "` WHERE id = :id");
$success_message = "";
$id = (int) Request::get('id');
$area = AREA;
// do the delete and then just show a success-message and the apikeys list again
if ($action == 'delete') {

View File

@@ -864,7 +864,7 @@ CREATE TABLE `panel_fpmdaemons` (
INSERT INTO `panel_fpmdaemons` (`id`, `description`, `reload_cmd`, `config_dir`) VALUES
(1, 'System default', 'service php7.3-fpm restart', '/etc/php/7.3/fpm/pool.d/');
(1, 'System default', 'service php7.4-fpm restart', '/etc/php/7.4/fpm/pool.d/');

View File

@@ -4,6 +4,7 @@ namespace Froxlor\UI\Callbacks;
use Froxlor\PhpHelper;
use Froxlor\UI\Panel\UI;
use Froxlor\Froxlor;
use Froxlor\User;
/**
@@ -65,4 +66,22 @@ class Text
{
return wordwrap($attributes['data'], 100, '<br>', true);
}
public static function apikeyDetailModal(array $attributes): array
{
$linker = UI::getLinker();
$result = $attributes['fields'];
$apikey_data = include Froxlor::getInstallDir() . '/lib/formfields/formfield.api_key.php';
$body = UI::twig()->render(UI::getTheme().'/user/inline-form.html.twig', [
'formaction' => $linker->getLink(array('section' => 'index', 'page' => 'apikeys')),
'formdata' => $apikey_data['apikey'],
'editid' => $attributes['fields']['id']
]);
return [
'id' => 'akModal' . $attributes['fields']['id'],
'title' => 'API-key ' . ($attributes['fields']['loginname'] ?? $attributes['fields']['adminname']),
'body' => $body
];
}
}

View File

@@ -171,6 +171,11 @@ class Listing
// Set actual link from linker
$actions[$key]['href'] = $linker->getLink($action['href']);
}
// modal trigger - always require a valid callback
if (isset($action['modal']) && !empty($action['modal'])) {
$actions[$key]['modal'] = call_user_func($action['modal'], ['fields' => $item]);
}
}
return $actions;

View File

@@ -0,0 +1,57 @@
<?php
use Froxlor\UI\Panel\UI;
/**
* This file is part of the Froxlor project.
* Copyright (c) 2010 the Froxlor Team (see authors).
*
* For the full copyright and license information, please view the COPYING
* file that was distributed with this source code. You can also view the
* COPYING file online at http://files.froxlor.org/misc/COPYING.txt
*
* @copyright (c) the authors
* @author Froxlor team <team@froxlor.org> (2010-)
* @license GPLv2 http://files.froxlor.org/misc/COPYING.txt
* @package Formfields
*
*/
return [
'apikey' => [
'title' => UI::getLng('menue.main.apikeys'),
'sections' => [
'section_a' => [
'fields' => [
'loginname' => [
'label' => UI::getLng('login.username'),
'type' => 'label',
'value' => $result['loginname'] ?? $result['adminname']
],
'apikey' => [
'label' => 'API key',
'type' => 'text',
'readonly' => true,
'value' => $result['apikey']
],
'secret' => [
'label' => 'Secret',
'type' => 'text',
'readonly' => true,
'value' => $result['secret']
],
'allowed_from' => [
'label' => UI::getLng('apikeys.allowed_from'),
'type' => 'text',
'value' => $result['allowed_from'],
],
'valid_until' => [
'label' => UI::getLng('apikeys.valid_until'),
'type' => 'text',
'value' => $result['valid_until'],
'format_callback' => [Text::class, 'timestampUntil'],
]
]
]
]
]
];

View File

@@ -61,12 +61,7 @@ return [
'show' => [
'icon' => 'fa fa-eye',
'title' => $lng['apikeys']['clicktoview'],
'href' => [
'section' => 'index',
'page' => 'apikeys',
'action' => '#',
'id' => ':id'
],
'modal' => [Text::class, 'apikeyDetailModal'],
],
'delete' => [
'icon' => 'fa fa-trash',

View File

@@ -2164,4 +2164,5 @@ $lng['panel']['backtooverview'] = 'Back to overview';
$lng['panel']['settingsmode'] = 'Mode';
$lng['panel']['settingsmodebasic'] = 'Basic';
$lng['panel']['settingsmodeadvanced'] = 'Advanced';
$lng['panel']['settingsmodetoggle'] = 'Click to toggle mode';
$lng['panel']['settingsmodetoggle'] = 'Click to toggle mode';
$lng['panel']['modalclose'] = 'Close';

View File

@@ -1803,3 +1803,4 @@ $lng['panel']['settingsmode'] = 'Modus';
$lng['panel']['settingsmodebasic'] = 'Einfach';
$lng['panel']['settingsmodeadvanced'] = 'Erweitert';
$lng['panel']['settingsmodetoggle'] = 'Modus umschalten';
$lng['panel']['modalclose'] = 'Schließen';

View File

@@ -1,4 +1,4 @@
{% macro form(form_data, formaction, title = "", hiddenid = "") %}
{% macro form(form_data, formaction, title = "", hiddenid = "", nosubmit = false) %}
{% import "Froxlor/form/formfields.html.twig" as formfields %}
@@ -21,25 +21,27 @@
</div>
{% endfor %}
<!-- submit buttons -->
<div>
{% if hiddenid is not empty %}
<input type="hidden" name="id" value="{{ hiddenid }}"/>
{% endif %}
<input type="hidden" name="page" value="{{ page }}"/>
<input type="hidden" name="action" value="{{ action }}"/>
<input type="hidden" name="send" value="send"/>
<div class="col-12 text-end">
{% if form_data.buttons is defined and form_data.buttons is iterable %}
{% for btn in form_data.buttons %}
<button type="{{ btn.type|default("submit") }}" class="btn {{ btn.class|default(" btn-primary") }}">{{ btn.label }}</button>
{% endfor %}
{% else %}
<button type="reset" class="btn btn-outline-secondary">{{ lng('panel.cancel') }}</button>
<button type="submit" class="btn btn-primary">{{ lng('panel.save') }}</button>
{% if nosubmit == false %}
<!-- submit buttons -->
<div>
{% if hiddenid is not empty %}
<input type="hidden" name="id" value="{{ hiddenid }}"/>
{% endif %}
<input type="hidden" name="page" value="{{ page }}"/>
<input type="hidden" name="action" value="{{ action }}"/>
<input type="hidden" name="send" value="send"/>
<div class="col-12 text-end">
{% if form_data.buttons is defined and form_data.buttons is iterable %}
{% for btn in form_data.buttons %}
<button type="{{ btn.type|default("submit") }}" class="btn {{ btn.class|default(" btn-primary") }}">{{ btn.label }}</button>
{% endfor %}
{% else %}
<button type="reset" class="btn btn-outline-secondary">{{ lng('panel.cancel') }}</button>
<button type="submit" class="btn btn-primary">{{ lng('panel.save') }}</button>
{% endif %}
</div>
</div>
</div>
{% endif %}
</form>
{% endmacro %}

View File

@@ -31,27 +31,45 @@
{% macro link(data) %}
{% apply spaceless %}
<a href="{{ data.href }}" {% if data.class is defined %} class="{{ data.class }}" {% endif %} {% if data.target is defined %} target="{{ data.target }}" {% endif %}{% if data.title is defined %} title="{{ data.title }}" {% endif %}>
{% if data.icon is defined %}
<i class="{{ data.icon }}"></i>
{% endif %}
{% if data.text is defined %}
{{ data.text }}
{% endif %}
</a>
<a href="{{ data.href }}" {% if data.class is defined %} class="{{ data.class }}" {% endif %} {% if data.target is defined %} target="{{ data.target }}" {% endif %} {% if data.title is defined %} title="{{ data.title }}" {% endif %}>
{% if data.icon is defined %}
<i class="{{ data.icon }}"></i>
{% endif %}
{% if data.text is defined %}
{{ data.text }}
{% endif %}
</a>
{% endapply %}
{% endmacro %}
{% macro button(data) %}
{% apply spaceless %}
<a class="{% if data.class is defined %}btn btn-sm {{ data.class }}{% else %}btn btn-sm btn-outline-secondary{% endif %}" href="{{ data.href }}" {% if data.target is defined %} target="{{ data.target }}" {% endif %}{% if data.title is defined %} title="{{ data.title }}" {% endif %}>
{% if data.icon is defined %}
<i class="{{ data.icon }}"></i>
{% endif %}
{% if data.text is defined %}
{{ data.text }}
{% endif %}
</a>
<a class="{% if data.class is defined %}btn btn-sm {{ data.class }}{% else %}btn btn-sm btn-outline-secondary{% endif %}" {% if data.modal is defined and data.modal is iterable %} data-bs-toggle="modal" role="button" href="#{{ data.modal.id }}" {% else %} href="{{ data.href }}" {% endif %} {% if data.target is defined %} target="{{ data.target }}" {% endif %} {% if data.title is defined %} title="{{ data.title }}" {% endif %}>
{% if data.icon is defined %}
<i class="{{ data.icon }}"></i>
{% endif %}
{% if data.text is defined %}
{{ data.text }}
{% endif %}
</a>
{% if data.modal is defined and data.modal is iterable %}
<div class="modal fade" id="{{ data.modal.id }}" aria-hidden="true" aria-labelledby="{{ data.modal.id }}Label" tabindex="-1">
<div class="modal-dialog {{ data.modal.size|default('modal-xl') }} modal-dialog-centered">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="{{ data.modal.id }}Label">{{ data.modal.title }}</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="{{ lng('panel.modalclose') }}"></button>
</div>
<div class="modal-body text-start">
{{ data.modal.body|raw }}
</div>
<div class="modal-footer">
<button class="btn btn-primary" data-bs-dismiss="modal">{{ lng('panel.modalclose') }}</button>
</div>
</div>
</div>
</div>
{% endif %}
{% endapply %}
{% endmacro %}

View File

@@ -0,0 +1,2 @@
{% import "Froxlor/form/form.html.twig" as form %}
{{ form.form(formdata, formaction|default('#'), formdata.title, editid|default(''), true) }}