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

@@ -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',