mirror of
https://github.com/Karaka-Management/oms-Draw.git
synced 2026-02-14 22:28:41 +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,6 +1,9 @@
|
||||||
(function (jsOMS) {
|
(function (jsOMS) {
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
|
/** @namespace jsOMS.Uri.UriFactory */
|
||||||
|
jsOMS.Autoloader.defineNamespace('jsOMS.Modules.Draw');
|
||||||
|
|
||||||
jsOMS.Modules.Draw = function (app) {
|
jsOMS.Modules.Draw = function (app) {
|
||||||
this.app = app;
|
this.app = app;
|
||||||
this.editors = [];
|
this.editors = [];
|
||||||
|
|
|
||||||
|
|
@ -92,7 +92,9 @@ class Controller extends ModuleAbstract implements WebInterface
|
||||||
{
|
{
|
||||||
/** @var Head $head */
|
/** @var Head $head */
|
||||||
$head = $response->get('Content')->getData('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;
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,9 @@
|
||||||
{
|
{
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
|
/** @namespace jsOMS.Uri.UriFactory */
|
||||||
|
jsOMS.Autoloader.defineNamespace('jsOMS.Modules.Draw');
|
||||||
|
|
||||||
jsOMS.Modules.Draw.DrawTypeEnum = Object.freeze({
|
jsOMS.Modules.Draw.DrawTypeEnum = Object.freeze({
|
||||||
DRAW: 0,
|
DRAW: 0,
|
||||||
LINE: 1,
|
LINE: 1,
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,9 @@
|
||||||
{
|
{
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
|
/** @namespace jsOMS.Uri.UriFactory */
|
||||||
|
jsOMS.Autoloader.defineNamespace('jsOMS.Modules.Draw');
|
||||||
|
|
||||||
jsOMS.Modules.Draw.Editor = function (editor)
|
jsOMS.Modules.Draw.Editor = function (editor)
|
||||||
{
|
{
|
||||||
this.editor = editor;
|
this.editor = editor;
|
||||||
|
|
|
||||||
|
|
@ -21,8 +21,8 @@ echo $this->getData('nav')->render(); ?>
|
||||||
|
|
||||||
<section class="box w-100">
|
<section class="box w-100">
|
||||||
<div class="inner">
|
<div class="inner">
|
||||||
<form>
|
<form id="drawForm" action="<?= \phpOMS\Uri\UriFactory::build('/{/lang}/api/draw?csrf={$CSRF}'); ?>" method="POST">
|
||||||
<input type="text" class="wf-100">
|
<input type="text" class="wf-100"><input type="submit" value="<?= $this->getText('Create', 0, 0); ?>">
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
</section>
|
</section>
|
||||||
|
|
@ -63,7 +63,7 @@ echo $this->getData('nav')->render(); ?>
|
||||||
<div class="m-draw">
|
<div class="m-draw">
|
||||||
<section class="box w-100" style="height: 30%;">
|
<section class="box w-100" style="height: 30%;">
|
||||||
<div class="inner">
|
<div class="inner">
|
||||||
<canvas></canvas>
|
<canvas id="canvasImage" name="image" form="drawForm"></canvas>
|
||||||
</div>
|
</div>
|
||||||
</section>
|
</section>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
|
|
@ -21,8 +21,8 @@ echo $this->getData('nav')->render(); ?>
|
||||||
|
|
||||||
<section class="box w-100">
|
<section class="box w-100">
|
||||||
<div class="inner">
|
<div class="inner">
|
||||||
<form>
|
<form id="drawForm" action="<?= \phpOMS\Uri\UriFactory::build('/{/lang}/api/draw?csrf={$CSRF}'); ?>" method="POST">
|
||||||
<input type="text" class="wf-100">
|
<input type="text" class="wf-100"><input type="submit" value="<?= $this->getText('Create', 0, 0); ?>">
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
</section>
|
</section>
|
||||||
|
|
@ -63,7 +63,7 @@ echo $this->getData('nav')->render(); ?>
|
||||||
<div class="m-draw">
|
<div class="m-draw">
|
||||||
<section class="box w-100" style="height: 30%;">
|
<section class="box w-100" style="height: 30%;">
|
||||||
<div class="inner">
|
<div class="inner">
|
||||||
<canvas></canvas>
|
<canvas id="canvasImage" name="image" form="drawForm"></canvas>
|
||||||
</div>
|
</div>
|
||||||
</section>
|
</section>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user