mirror of
https://github.com/Karaka-Management/oms-Draw.git
synced 2026-01-11 14:28:40 +00:00
Fixing draw and drafting create
This commit is contained in:
parent
3f6672eb42
commit
6bdc90c65e
12
Admin/Routes/Web/Api.php
Normal file
12
Admin/Routes/Web/Api.php
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
<?php
|
||||
|
||||
use phpOMS\Router\RouteVerb;
|
||||
|
||||
return [
|
||||
'^.*/backend/draw.*$' => [
|
||||
[
|
||||
'dest' => '\Modules\Draw\Controller:apiDrawCreate',
|
||||
'verb' => RouteVerb::SET,
|
||||
],
|
||||
],
|
||||
];
|
||||
|
|
@ -1,5 +1,8 @@
|
|||
(function (jsOMS) {
|
||||
"use strict";
|
||||
|
||||
/** @namespace jsOMS.Uri.UriFactory */
|
||||
jsOMS.Autoloader.defineNamespace('jsOMS.Modules.Draw');
|
||||
|
||||
jsOMS.Modules.Draw = function (app) {
|
||||
this.app = app;
|
||||
|
|
|
|||
|
|
@ -92,7 +92,9 @@ class Controller extends ModuleAbstract implements WebInterface
|
|||
{
|
||||
/** @var Head $head */
|
||||
$head = $response->get('Content')->getData('head');
|
||||
$head->addAsset(AssetType::JS, $request->getUri()->getBase() . 'Modules/Draw/ModuleDraw.js');
|
||||
$head->addAsset(AssetType::JSLATE, $request->getUri()->getBase() . 'Modules/Draw/Controller.js');
|
||||
$head->addAsset(AssetType::JSLATE, $request->getUri()->getBase() . 'Modules/Draw/Models/DrawType.enum.js');
|
||||
$head->addAsset(AssetType::JSLATE, $request->getUri()->getBase() . 'Modules/Draw/Models/Editor.js');
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -133,4 +135,77 @@ class Controller extends ModuleAbstract implements WebInterface
|
|||
return $view;
|
||||
}
|
||||
|
||||
private function validateDrawCreate(RequestAbstract $request) : array
|
||||
{
|
||||
$val = [];
|
||||
if (
|
||||
($val['title'] = empty($request->getData('title')))
|
||||
|| ($val['image'] = empty($request->getData('plain')))
|
||||
|| ($val['status'] = (
|
||||
$request->getData('status') === null
|
||||
|| !NewsStatus::isValidValue((int) $request->getData('status'))
|
||||
))
|
||||
) {
|
||||
return $val;
|
||||
}
|
||||
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param RequestAbstract $request Request
|
||||
* @param ResponseAbstract $response Response
|
||||
* @param mixed $data Generic data
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public function apiDrawCreate(RequestAbstract $request, ResponseAbstract $response, $data = null)
|
||||
{
|
||||
if (!empty($val = $this->validateDrawCreate($request))) {
|
||||
$response->set('draw_create', new FormValidation($val));
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$path = MediaController::createMediaPath();
|
||||
$extension = 'png';
|
||||
$filename = '';
|
||||
$rnd = '';
|
||||
|
||||
// todo: implement limit since this could get exploited
|
||||
do {
|
||||
$filename = sha1($request->getData('image') . $rnd);
|
||||
$filename .= '.' . $extension;
|
||||
|
||||
$rnd = mt_rand();
|
||||
} while (file_exists($path . '/' . $filename));
|
||||
|
||||
$fullPath = $path . '/' . $filename;
|
||||
|
||||
$this->createLocalFile($fullPath, $request->getData('image'));
|
||||
|
||||
$status = [
|
||||
'path' => $path,
|
||||
'filename' => $filename,
|
||||
'size' => File::size($fullPath),
|
||||
'extension' => $extension,
|
||||
];
|
||||
|
||||
$media = MediaController::createDbEntries($status, $request->getAccount());
|
||||
$draw = Draw::fromMedia(end($media));
|
||||
|
||||
DrawMapper::create($draw);
|
||||
|
||||
$response->set('image', $draw->jsonSerialize());
|
||||
}
|
||||
|
||||
private function createLocalFile(string $outputPath, string $raw) : bool
|
||||
{
|
||||
$imageData = ImageUtils::decodeBase64Image($raw);
|
||||
File::put($outputPath, $imageData);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,6 +10,9 @@
|
|||
(function (jsOMS)
|
||||
{
|
||||
"use strict";
|
||||
|
||||
/** @namespace jsOMS.Uri.UriFactory */
|
||||
jsOMS.Autoloader.defineNamespace('jsOMS.Modules.Draw');
|
||||
|
||||
jsOMS.Modules.Draw.DrawTypeEnum = Object.freeze({
|
||||
DRAW: 0,
|
||||
|
|
|
|||
|
|
@ -1,6 +1,9 @@
|
|||
(function (jsOMS)
|
||||
{
|
||||
"use strict";
|
||||
|
||||
/** @namespace jsOMS.Uri.UriFactory */
|
||||
jsOMS.Autoloader.defineNamespace('jsOMS.Modules.Draw');
|
||||
|
||||
jsOMS.Modules.Draw.Editor = function (editor)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -21,8 +21,8 @@ echo $this->getData('nav')->render(); ?>
|
|||
|
||||
<section class="box w-100">
|
||||
<div class="inner">
|
||||
<form>
|
||||
<input type="text" class="wf-100">
|
||||
<form id="drawForm" action="<?= \phpOMS\Uri\UriFactory::build('/{/lang}/api/draw?csrf={$CSRF}'); ?>" method="POST">
|
||||
<input type="text" class="wf-100"><input type="submit" value="<?= $this->getText('Create', 0, 0); ?>">
|
||||
</form>
|
||||
</div>
|
||||
</section>
|
||||
|
|
@ -63,7 +63,7 @@ echo $this->getData('nav')->render(); ?>
|
|||
<div class="m-draw">
|
||||
<section class="box w-100" style="height: 30%;">
|
||||
<div class="inner">
|
||||
<canvas></canvas>
|
||||
<canvas id="canvasImage" name="image" form="drawForm"></canvas>
|
||||
</div>
|
||||
</section>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -21,8 +21,8 @@ echo $this->getData('nav')->render(); ?>
|
|||
|
||||
<section class="box w-100">
|
||||
<div class="inner">
|
||||
<form>
|
||||
<input type="text" class="wf-100">
|
||||
<form id="drawForm" action="<?= \phpOMS\Uri\UriFactory::build('/{/lang}/api/draw?csrf={$CSRF}'); ?>" method="POST">
|
||||
<input type="text" class="wf-100"><input type="submit" value="<?= $this->getText('Create', 0, 0); ?>">
|
||||
</form>
|
||||
</div>
|
||||
</section>
|
||||
|
|
@ -63,7 +63,7 @@ echo $this->getData('nav')->render(); ?>
|
|||
<div class="m-draw">
|
||||
<section class="box w-100" style="height: 30%;">
|
||||
<div class="inner">
|
||||
<canvas></canvas>
|
||||
<canvas id="canvasImage" name="image" form="drawForm"></canvas>
|
||||
</div>
|
||||
</section>
|
||||
</div>
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user