draft navigation hotkeys

This commit is contained in:
Dennis Eichhorn 2020-05-31 18:02:31 +02:00
parent 5670fcc3c0
commit 9bae506c77
4 changed files with 185 additions and 1 deletions

43
Admin/Install/Search.php Normal file
View File

@ -0,0 +1,43 @@
<?php
/**
* Orange Management
*
* PHP Version 7.4
*
* @package Modules\Navigation\Admin\Install
* @copyright Dennis Eichhorn
* @license OMS License 1.0
* @version 1.0.0
* @link https://orange-management.org
*/
declare(strict_types=1);
namespace Modules\Navigation\Admin\Install;
use phpOMS\DataStorage\Database\DatabasePool;
/**
* Search class.
*
* @package Modules\Navigation\Admin\Install
* @license OMS License 1.0
* @link https://orange-management.org
* @since 1.0.0
*/
final class Search
{
/**
* Install navigation providing
*
* @param string $path Module path
* @param DatabasePool $dbPool Database pool for database interaction
*
* @return void
*
* @since 1.0.0
*/
public static function install(string $path, DatabasePool $dbPool) : void
{
\Modules\Search\Admin\Installer::installExternal($dbPool, ['path' => __DIR__ . '/SearchCommands.php']);
}
}

View File

@ -0,0 +1,30 @@
<?php
/**
* Orange Management
*
* PHP Version 7.4
*
* @package Modules\Navigation
* @copyright Dennis Eichhorn
* @license OMS License 1.0
* @version 1.0.0
* @link https://orange-management.org
*/
declare(strict_types=1);
use Modules\Navigation\Controller\SearchController;
use phpOMS\Account\PermissionType;
use phpOMS\Router\RouteVerb;
return [
'^:goto .*$' => [
[
'dest' => '\Modules\Navigation\Controller\SearchController:searchGoto',
'verb' => RouteVerb::ANY,
'permission' => [
'module' => SearchController::MODULE_NAME,
'type' => PermissionType::READ,
],
],
],
];

View File

@ -0,0 +1,111 @@
<?php
/**
* Orange Management
*
* PHP Version 7.4
*
* @package Modules\Navigation
* @copyright Dennis Eichhorn
* @license OMS License 1.0
* @version 1.0.0
* @link https://orange-management.org
*/
declare(strict_types=1);
namespace Modules\Navigation\Controller;
use Modules\Navigation\Models\NavElementMapper;
use phpOMS\Message\RequestAbstract;
use phpOMS\Message\ResponseAbstract;
use Modules\Navigation\Models\Navigation;
use phpOMS\Model\Message\Redirect;
use phpOMS\Uri\UriFactory;
use phpOMS\System\MimeType;
/**
* Search class.
*
* @package Modules\Navigation
* @license OMS License 1.0
* @link https://orange-management.org
* @since 1.0.0
*/
final class SearchController extends Controller
{
/**
* Api method to create a task
*
* @param RequestAbstract $request Request
* @param ResponseAbstract $response Response
* @param mixed $data Generic data
*
* @return void
*
* @api
*
* @since 1.0.0
*/
public function searchGoto(RequestAbstract $request, ResponseAbstract $response, $data = null) : void
{
$this->loadLanguage($request, $response, $request->getData('app'));
$elements = NavElementMapper::getAll();
$search = \explode(' ', $request->getData('search'))[1];
$found = null;
foreach ($elements as $element) {
if (empty($element->uri)) {
continue;
}
$name = $this->app->l11nManager->getText(
$response->getHeader()->getL11n()->getLanguage() ?? 'en',
'Navigation', '0',
$element->name,
);
if ($name === $search) {
$found = $element;
break;
}
}
$response->getHeader()->set('Content-Type', MimeType::M_JSON . '; charset=utf-8', true);
$response->set($request->getUri()->__toString(), new Redirect(UriFactory::build($found->uri)));
}
/**
* Load navigation language
*
* @param RequestAbstract $request Request
* @param ResponseAbstract $response Response
* @param string $app App name
*
* @return void
*
* @todo Orange-Management/Modules#190 & Orange-Management/Modules#181
* The loading of the language file is slow since every module is loaded separately.
* This should either get cached per user or maybe put into one large language file per language (like the routes).
*
* @since 1.0.0
* @codeCoverageIgnore
*/
private function loadLanguage(RequestAbstract $request, ResponseAbstract $response, string $app) : void
{
$languages = $this->app->moduleManager->getLanguageFiles($request, $app);
$langCode = $response->getHeader()->getL11n()->getLanguage();
foreach ($languages as $path) {
$path = __DIR__ . '/../../..' . $path . '.' . $langCode . '.lang.php';
if (!\file_exists($path)) {
continue;
}
/** @noinspection PhpIncludeInspection */
$lang = include $path;
$this->app->l11nManager->loadLanguage($langCode, 'Navigation', $lang);
}
}
}

View File

@ -29,7 +29,7 @@ if (isset($this->nav[\Modules\Navigation\Models\NavigationType::CONTENT])
$uri = \phpOMS\Uri\UriFactory::build($link['nav_uri']);
echo '<li'
. (\stripos($uri, $uriPath) !== false ? ' class="active"' : '')
. '><a href="' . $uri . '">'
. '><a tabindex="0" href="' . $uri . '">'
. $this->getHtml($link['nav_name'], 'Navigation') . '</a>';
}
}