template fixes + bug fixes + style fixes

This commit is contained in:
Dennis Eichhorn 2024-04-02 21:40:47 +00:00
parent 98f33f16c1
commit da0d19c638
7 changed files with 250 additions and 89 deletions

View File

@ -14,6 +14,16 @@ declare(strict_types=1);
namespace Modules\EventManagement\Controller;
use Modules\Admin\Models\NullAccount;
use Modules\EventManagement\Models\Event;
use Modules\EventManagement\Models\EventMapper;
use Modules\EventManagement\Models\ProgressType;
use Modules\Media\Models\NullMedia;
use phpOMS\Message\Http\RequestStatusCode;
use phpOMS\Message\RequestAbstract;
use phpOMS\Message\ResponseAbstract;
use phpOMS\Utils\Parser\Markdown\Markdown;
/**
* EventManagement api controller class.
*
@ -24,4 +34,99 @@ namespace Modules\EventManagement\Controller;
*/
final class ApiController extends Controller
{
/**
* Routing end-point for application behavior.
*
* @param RequestAbstract $request Request
* @param ResponseAbstract $response Response
* @param array $data Generic data
*
* @return void
*
* @api
*
* @since 1.0.0
*/
public function apiEventCreate(RequestAbstract $request, ResponseAbstract $response, array $data = []) : void
{
if (!empty($val = $this->validateEventCreate($request))) {
$response->header->status = RequestStatusCode::R_400;
$this->createInvalidCreateResponse($request, $response, $val);
return;
}
$event = $this->createEventFromRequest($request);
$this->createModel($request->header->account, $event, EventMapper::class, 'card', $request->getOrigin());
$this->createStandardCreateResponse($request, $response, $event);
}
/**
* Method to create card from request.
*
* @param RequestAbstract $request Request
*
* @return Event
*
* @since 1.0.0
*/
public function createEventFromRequest(RequestAbstract $request) : Event
{
$event = new Event();
$event->name = $request->getDataString('name') ?? '';
$event->descriptionRaw = $request->getDataString('plain') ?? '';
$event->description = Markdown::parse($request->getDataString('plain') ?? '');
$event->start = $request->getDataDateTime('start') ?? $event->start;
$event->end = $request->getDataDateTime('end') ?? $event->end;
$event->createdBy = new NullAccount($request->header->account);
$event->progressType = ProgressType::tryFromValue($request->getDataInt('progresstype')) ?? ProgressType::MANUAL;
$event->progress = $request->getDataInt('progress') ?? 0;
$event->budgetCosts->value = $request->getDataInt('budgetcosts') ?? 0;
$event->actualCosts->value = $request->getDataInt('actualcosts') ?? 0;
// @todo implement unit
//$event->unit = $this->app->unitId;
if (!empty($uploadedFiles = $request->files)) {
$uploaded = $this->app->moduleManager->get('Media', 'Api')->uploadFiles(
[],
[],
$uploadedFiles,
$request->header->account,
__DIR__ . '/../../../Modules/Media/Files/Modules/EventManagement',
'/Modules/EventManagement',
);
foreach ($uploaded as $media) {
$event->files[] = $media;
}
}
$mediaFiles = $request->getDataJson('media');
foreach ($mediaFiles as $media) {
$event->files[] = new NullMedia($media);
}
return $event;
}
/**
* Validate card create request
*
* @param RequestAbstract $request Request
*
* @return array<string, bool>
*
* @since 1.0.0
*/
private function validateEventCreate(RequestAbstract $request) : array
{
$val = [];
if (($val['name'] = !$request->hasData('name'))) {
return $val;
}
return [];
}
}

View File

@ -73,7 +73,7 @@ final class BackendController extends Controller
public function viewEventManagementCreate(RequestAbstract $request, ResponseAbstract $response, array $data = []) : RenderableInterface
{
$view = new View($this->app->l11nManager, $request, $response);
$view->setTemplate('/Modules/EventManagement/Theme/Backend/eventmanagement-create');
$view->setTemplate('/Modules/EventManagement/Theme/Backend/eventmanagement-view');
$view->data['nav'] = $this->app->moduleManager->get('Navigation')->createNavigationMid(1004201001, $request, $response);
return $view;

View File

@ -78,6 +78,14 @@ class Event
*/
public string $description = '';
/**
* Project raw description.
*
* @var string
* @since 1.0.0
*/
public string $descriptionRaw = '';
/**
* Calendar.
*

47
Models/NullEvent.php Normal file
View File

@ -0,0 +1,47 @@
<?php
/**
* Jingga
*
* PHP Version 8.2
*
* @package Modules\EventManagement\Models
* @copyright Dennis Eichhorn
* @license OMS License 2.0
* @version 1.0.0
* @link https://jingga.app
*/
declare(strict_types=1);
namespace Modules\EventManagement\Models;
/**
* Null model
*
* @package Modules\EventManagement\Models
* @license OMS License 2.0
* @link https://jingga.app
* @since 1.0.0
*/
final class NullEvent extends Event
{
/**
* Constructor
*
* @param int $id Model id
*
* @since 1.0.0
*/
public function __construct(int $id = 0)
{
parent::__construct();
$this->id = $id;
}
/**
* {@inheritdoc}
*/
public function jsonSerialize() : mixed
{
return ['id' => $this->id];
}
}

View File

@ -1,49 +0,0 @@
<?php
/**
* Jingga
*
* PHP Version 8.2
*
* @package Modules\EventManagement
* @copyright Dennis Eichhorn
* @license OMS License 2.0
* @version 1.0.0
* @link https://jingga.app
*/
declare(strict_types=1);
echo $this->data['nav']->render(); ?>
<div class="row">
<div class="col-xs-12 col-md-6">
<section class="box wf-100">
<header><h1><?= $this->getHtml('Event'); ?></h1></header>
<div class="inner">
<form>
<table class="layout wf-100">
<tr><td colspan="3"><label for="iName"><?= $this->getHtml('Name'); ?></label>
<tr><td colspan="2"><input type="text" id="iName" name="name" required><td>
<tr><td colspan="3"><label for="iDescription"><?= $this->getHtml('Description'); ?></label>
<tr><td colspan="2"><textarea id="iDescription" name="description"></textarea><td>
<tr><td colspan="3"><label for="iStatus"><?= $this->getHtml('Status'); ?></label>
<tr><td colspan="2"><select id="iStatus" name="status">
<option value="">
</select><td>
<tr><td colspan="3"><label for="iFiles"><?= $this->getHtml('Files'); ?></label>
<tr><td colspan="2"><input type="file" id="iFiles" name="file" multiple><td>
<tr><td><label for="iStart"><?= $this->getHtml('Start'); ?><label><td><label for="iEnd"><?= $this->getHtml('End'); ?><label><td>
<tr><td><input type="datetime-local" id="iStart" name="start" required><td><input type="datetime-local" id="iEnd" name="end" required><td>
<tr><td><label for="iResponsibility"><?= $this->getHtml('Responsibility'); ?></label><td><label for="iUser"><?= $this->getHtml('UserGroup'); ?></label><td>
<tr><td><select id="iStatus" name="status">
<option value="">
</select>
<td><span class="input"><button type="button" formaction=""><i class="g-icon">book</i></button><input type="text" id="iUser" name="user"></span><td><button><?= $this->getHtml('Add', '0', '0'); ?></button>
<tr><td colspan="3"><label for="iBudget"><?= $this->getHtml('Budget'); ?></label>
<tr><td colspan="2"><input type="text" id="iBudget" name="budget"><td>
<tr><td colspan="3"><input type="submit" value="<?= $this->getHtml('Create', '0', '0'); ?>" name="create-item">
</table>
</form>
</div>
</section>
</div>
</div>

View File

@ -12,65 +12,115 @@
*/
declare(strict_types=1);
$event = $this->data['event'];
use Modules\EventManagement\Models\NullEvent;
use Modules\EventManagement\Models\ProgressType;
/** \Modules\EventManagement\Models\Event $event */
$event = $this->data['event'] ?? new NullEvent();
$isNew = $event->id === 0;
echo $this->data['nav']->render(); ?>
<div class="row">
<div class="col-xs-12 col-md-6">
<section class="box wf-100">
<header><h1><?= $this->printHtml($event->getName()); ?></h1></header>
<div class="inner">
<form id="fEvent" method="POST" action="<?= \phpOMS\Uri\UriFactory::build('{/api}eventmanagement?{?}&csrf={$CSRF}'); ?>">
<table class="layout wf-100">
<tbody>
<tr><td colspan="2"><label for="iName"><?= $this->getHtml('Name'); ?></label>
<tr><td colspan="2"><input type="text" id="iName" name="name" value="<?= $this->printHtml($event->getName()); ?>" required>
<tr><td><label for="iStart"><?= $this->getHtml('Start'); ?></label>
<td><label for="iEnd"><?= $this->getHtml('End'); ?></label>
<tr><td><input type="datetime-local" id="iStart" name="start" value="<?= $this->printHtml($event->getStart()->format('Y-m-d\TH:i:s')); ?>">
<td><input type="datetime-local" id="iEnd" name="end" value="<?= $this->printHtml($event->getEnd()->format('Y-m-d\TH:i:s')); ?>">
<tr><td colspan="2"><label for="iDescription"><?= $this->getHtml('Description'); ?></label>
<tr><td colspan="2"><textarea id="iDescription" name="desc"><?= $this->printHtml($event->description); ?></textarea>
<tr><td colspan="2"><label for="iProgressType"><?= $this->getHtml('Progress'); ?></label>
<tr><td><select id="iProgressType" name="progressType">
<option value="<?= \Modules\EventManagement\Models\ProgressType::MANUAL; ?>"><?= $this->getHtml('Manual'); ?>
<option value="<?= \Modules\EventManagement\Models\ProgressType::LINEAR; ?>"><?= $this->getHtml('Linear'); ?>
<option value="<?= \Modules\EventManagement\Models\ProgressType::EXPONENTIAL; ?>"><?= $this->getHtml('Exponential'); ?>
<option value="<?= \Modules\EventManagement\Models\ProgressType::LOG; ?>"><?= $this->getHtml('Log'); ?>
<option value="<?= \Modules\EventManagement\Models\ProgressType::TASKS; ?>"><?= $this->getHtml('Tasks'); ?>
</select>
<td><input type="text" id="iProgress" name="progress" value="<?= $event->getProgress(); ?>"<?= $event->getProgressType() !== \Modules\EventManagement\Models\ProgressType::MANUAL ? ' disabled' : ''; ?>>
<tr><td><label for="iBudget"><?= $this->getHtml('Budget'); ?></label><td><label for="iActual"><?= $this->getHtml('Actual'); ?></label>
<tr><td><input type="text" id="iBudget" name="budget"><td><input type="text" id="iActual" name="actual">
<tr><td colspan="2"><input type="submit" value="<?= $this->getHtml('Save', '0', '0'); ?>" name="save-eventmanagement-profile">
</table>
</form>
<section class="portlet">
<form id="fEvent" method="<?= $isNew ? 'PUT' : 'POST'; ?>" action="<?= \phpOMS\Uri\UriFactory::build('{/api}eventmanagement?{?}&csrf={$CSRF}'); ?>">
<div class="portlet-head"><?= $this->getHtml('Event'); ?></div>
<div class="portlet-body">
<div class="form-group">
<label for="iId"><?= $this->getHtml('ID', '0', '0'); ?></label>
<input type="text" name="id" id="iId" value="<?= $event->id; ?>" disabled>
</div>
<div class="form-group">
<label for="iName"><?= $this->getHtml('Name'); ?></label>
<input type="text" id="iName" name="name" value="<?= $this->printHtml($event->name); ?>" required>
</div>
<div class="flex-line">
<div>
<div class="form-group">
<label for="iStart"><?= $this->getHtml('Start'); ?></label>
<input type="datetime-local" id="iStart" name="start" value="<?= $this->printHtml($event->start->format('Y-m-d\TH:i:s')); ?>">
</div>
</div>
<div>
<div class="form-group">
<label for="iEnd"><?= $this->getHtml('End'); ?></label>
<input type="datetime-local" id="iEnd" name="end" value="<?= $this->printHtml($event->end->format('Y-m-d\TH:i:s')); ?>">
</div>
</div>
</div>
<div class="form-group">
<label for="iDescription"><?= $this->getHtml('Description'); ?></label>
<textarea id="iDescription" name="desc"><?= $this->printHtml($event->description); ?></textarea>
</div>
<div class="form-group">
<label for="iProgressType"><?= $this->getHtml('Progress'); ?></label>
<div class="flex-line wf-100">
<div>
<select id="iProgressType" name="progressType">
<option value="<?= ProgressType::MANUAL; ?>"><?= $this->getHtml('Manual'); ?>
<option value="<?= ProgressType::LINEAR; ?>"><?= $this->getHtml('Linear'); ?>
<option value="<?= ProgressType::EXPONENTIAL; ?>"><?= $this->getHtml('Exponential'); ?>
<option value="<?= ProgressType::LOG; ?>"><?= $this->getHtml('Log'); ?>
<option value="<?= ProgressType::TASKS; ?>"><?= $this->getHtml('Tasks'); ?>
</select>
</div>
<div>
<input type="text" id="iProgress" name="progress" value="<?= $event->progress; ?>"<?= $event->progressType !== ProgressType::MANUAL ? ' disabled' : ''; ?>>
</div>
</div>
</div>
<div class="flex-line">
<div>
<div class="form-group">
<label for="iBudget"><?= $this->getHtml('Budget'); ?></label><td>
<input type="text" id="iBudget" name="budget">
</div>
</div>
<div>
<div class="form-group">
<label for="iActual"><?= $this->getHtml('Actual'); ?></label>
<input type="text" id="iActual" name="actual">
</div>
</div>
</div>
</div>
<div class="portlet-foot">
<?php if ($isNew) : ?>
<input id="iCreateSubmit" type="Submit" value="<?= $this->getHtml('Create', '0', '0'); ?>">
<?php else : ?>
<input id="iSaveSubmit" type="Submit" value="<?= $this->getHtml('Save', '0', '0'); ?>">
<?php endif; ?>
</div>
</form>
</section>
</div>
<?php if (!$isNew) : ?>
<div class="col-xs-12 col-md-6">
<div class="box wf-100">
<?= $this->getData('tasklist')->render($event->tasks); ?>
</div>
</div>
<?php endif; ?>
</div>
<?php if (!$isNew) : ?>
<div class="row">
<div class="col-xs-12 col-md-6">
<?= $this->getData('calendar')->render($event->getCalendar()); ?>
</div>
<div class="col-xs-12 col-md-6">
<?= $this->getData('medialist')->render($event->files); ?>
<?= $this->getData('medialist')->render($event->files); ?>
</div>
</div>
<div class="row">
<div class="col-xs-12 col-md-6">
<section class="box wf-100">
<header><h1>Finances</h1></header>
</section>
</div>
</div>
<?php endif; ?>

View File

@ -100,7 +100,7 @@ final class EventMapperTest extends \PHPUnit\Framework\TestCase
#[\PHPUnit\Framework\Attributes\Group('module')]
public function testNewest() : void
{
$newest = EventMapper::getAll()->sort('id', OrderType::DESC)->limit(1)->execute();
$newest = EventMapper::getAll()->sort('id', OrderType::DESC)->limit(1)->executeGetArray();
self::assertCount(1, $newest);
}