mirror of
https://github.com/Karaka-Management/oms-Dashboard.git
synced 2026-02-18 11:08:42 +00:00
always use and many other todo implementations
This commit is contained in:
parent
4a22b13afa
commit
71340d6226
|
|
@ -29,14 +29,14 @@ class Navigation
|
||||||
/**
|
/**
|
||||||
* Install navigation providing
|
* Install navigation providing
|
||||||
*
|
*
|
||||||
* @param string $path Module path
|
|
||||||
* @param ApplicationAbstract $app Application
|
* @param ApplicationAbstract $app Application
|
||||||
|
* @param string $path Module path
|
||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*
|
*
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
*/
|
*/
|
||||||
public static function install(string $path, ApplicationAbstract $app) : void
|
public static function install(ApplicationAbstract $app, string $path) : void
|
||||||
{
|
{
|
||||||
\Modules\Navigation\Admin\Installer::installExternal($app, ['path' => __DIR__ . '/Navigation.install.json']);
|
\Modules\Navigation\Admin\Installer::installExternal($app, ['path' => __DIR__ . '/Navigation.install.json']);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -14,12 +14,18 @@ declare(strict_types=1);
|
||||||
|
|
||||||
namespace Modules\Dashboard\Admin;
|
namespace Modules\Dashboard\Admin;
|
||||||
|
|
||||||
|
use Modules\Admin\Models\NullAccount;
|
||||||
use Modules\Dashboard\Models\DashboardBoard;
|
use Modules\Dashboard\Models\DashboardBoard;
|
||||||
use Modules\Dashboard\Models\DashboardBoardMapper;
|
use Modules\Dashboard\Models\DashboardBoardMapper;
|
||||||
|
use Modules\Dashboard\Models\DashboardBoardStatus;
|
||||||
|
use Modules\Dashboard\Models\DashboardComponent;
|
||||||
|
use Modules\Dashboard\Models\DashboardComponentMapper;
|
||||||
|
use phpOMS\Application\ApplicationAbstract;
|
||||||
use phpOMS\Config\SettingsInterface;
|
use phpOMS\Config\SettingsInterface;
|
||||||
use phpOMS\DataStorage\Database\DatabasePool;
|
use phpOMS\DataStorage\Database\DatabasePool;
|
||||||
use phpOMS\Module\InstallerAbstract;
|
use phpOMS\Module\InstallerAbstract;
|
||||||
use phpOMS\Module\ModuleInfo;
|
use phpOMS\Module\ModuleInfo;
|
||||||
|
use phpOMS\System\File\PathException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Installer class.
|
* Installer class.
|
||||||
|
|
@ -42,11 +48,89 @@ final class Installer extends InstallerAbstract
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public static function install(DatabasePool $dbPool, ModuleInfo $info, SettingsInterface $cfgHandler) : void
|
public static function install(ApplicationAbstract $app, ModuleInfo $info, SettingsInterface $cfgHandler) : void
|
||||||
{
|
{
|
||||||
parent::install($dbPool, $info, $cfgHandler);
|
parent::install($app, $info, $cfgHandler);
|
||||||
|
|
||||||
|
self::installDefault();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static function installDefault() : void
|
||||||
|
{
|
||||||
$board = new DashboardBoard();
|
$board = new DashboardBoard();
|
||||||
|
$board->title = 'Default Board';
|
||||||
|
$board->account = new NullAccount(1);
|
||||||
|
$board->setStatus(DashboardBoardStatus::ACTIVE);
|
||||||
|
|
||||||
DashboardBoardMapper::create()->execute($board);
|
DashboardBoardMapper::create()->execute($board);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Install data from providing modules.
|
||||||
|
*
|
||||||
|
* The data can be either directories which should be created or files which should be "uploaded"
|
||||||
|
*
|
||||||
|
* @param ApplicationAbstract $app Application
|
||||||
|
* @param array $data Additional data
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*
|
||||||
|
* @throws PathException
|
||||||
|
* @throws \Exception
|
||||||
|
*
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
|
public static function installExternal(ApplicationAbstract $app, array $data) : array
|
||||||
|
{
|
||||||
|
if (!\is_file($data['path'] ?? '')) {
|
||||||
|
throw new PathException($data['path'] ?? '');
|
||||||
|
}
|
||||||
|
|
||||||
|
$dashboardFile = \file_get_contents($data['path'] ?? '');
|
||||||
|
if ($dashboardFile === false) {
|
||||||
|
throw new PathException($data['path'] ?? ''); // @codeCoverageIgnore
|
||||||
|
}
|
||||||
|
|
||||||
|
$dashboardData = \json_decode($dashboardFile, true) ?? [];
|
||||||
|
if ($dashboardData === false) {
|
||||||
|
throw new \Exception(); // @codeCoverageIgnore
|
||||||
|
}
|
||||||
|
|
||||||
|
$result = [
|
||||||
|
'component' => [],
|
||||||
|
];
|
||||||
|
|
||||||
|
foreach ($dashboardData as $dashboard) {
|
||||||
|
switch ($dashboard['component']) {
|
||||||
|
case 'component':
|
||||||
|
$result['component'][] = self::createComponent($app->dbPool, $dashboard);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create board component.
|
||||||
|
*
|
||||||
|
* @param DatabasePool $dbPool Database instance
|
||||||
|
* @param array $data Type info
|
||||||
|
*
|
||||||
|
* @return EditorDocType
|
||||||
|
*
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
|
private static function createComponent(DatabasePool $dbPool, array $data) : DashboardComponent
|
||||||
|
{
|
||||||
|
$component = new DashboardComponent();
|
||||||
|
$component->board = (int) ($data['board'] ?? 0);
|
||||||
|
$component->order = (int) ($data['order'] ?? 0);
|
||||||
|
$component->module = (string) ($data['module'] ?? '');
|
||||||
|
|
||||||
|
DashboardComponentMapper::create()->execute($component);
|
||||||
|
|
||||||
|
return $component;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -100,7 +100,7 @@ final class ApiControllerTest extends \PHPUnit\Framework\TestCase
|
||||||
$request = new HttpRequest(new HttpUri(''));
|
$request = new HttpRequest(new HttpUri(''));
|
||||||
|
|
||||||
$request->header->account = 1;
|
$request->header->account = 1;
|
||||||
$request->setData('title', 'TestBoard');
|
$request->setData('title', 'Default Board');
|
||||||
|
|
||||||
$this->module->apiBoardCreate($request, $response);
|
$this->module->apiBoardCreate($request, $response);
|
||||||
self::assertGreaterThan(0, $response->get('')['response']->getId());
|
self::assertGreaterThan(0, $response->get('')['response']->getId());
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user