This commit is contained in:
Dennis Eichhorn 2018-02-03 13:09:09 +01:00
parent ffe24deb90
commit b35353e731
5 changed files with 34 additions and 36 deletions

View File

@ -19,7 +19,6 @@ use phpOMS\Module\UpdateAbstract;
use phpOMS\System\File\Directory; use phpOMS\System\File\Directory;
use phpOMS\Module\InfoManager; use phpOMS\Module\InfoManager;
/** /**
* Navigation class. * Navigation class.
* *

View File

@ -4,7 +4,7 @@
jsOMS.Autoloader.defineNamespace('jsOMS.Modules'); jsOMS.Autoloader.defineNamespace('jsOMS.Modules');
jsOMS.Modules.Draw = function (app) { jsOMS.Modules.Draw = function (app) {
this.app = app; this.app = app;
this.editors = []; this.editors = [];
}; };
@ -19,7 +19,7 @@
this.editors.push(temp); this.editors.push(temp);
} else { } else {
const canvas = document.getElementsByClassName('m-draw'), const canvas = document.getElementsByClassName('m-draw'),
length = canvas.length; length = canvas.length;
this.editors = []; this.editors = [];

View File

@ -207,8 +207,7 @@ class Controller extends ModuleAbstract implements WebInterface
private function validateDrawCreate(RequestAbstract $request) : array private function validateDrawCreate(RequestAbstract $request) : array
{ {
$val = []; $val = [];
if ( if (($val['title'] = empty($request->getData('title')))
($val['title'] = empty($request->getData('title')))
|| ($val['image'] = empty($request->getData('image'))) || ($val['image'] = empty($request->getData('image')))
) { ) {
return $val; return $val;
@ -240,17 +239,17 @@ class Controller extends ModuleAbstract implements WebInterface
return; return;
} }
$path = MediaController::createMediaPath(); $path = MediaController::createMediaPath();
$extension = 'png'; $extension = 'png';
$filename = ''; $filename = '';
$rnd = ''; $rnd = '';
// todo: implement limit since this could get exploited // todo: implement limit since this could get exploited
do { do {
$filename = sha1(((string) $request->getData('image')) . $rnd); $filename = sha1(((string) $request->getData('image')) . $rnd);
$filename .= '.' . $extension; $filename .= '.' . $extension;
$rnd = mt_rand(); $rnd = mt_rand();
} while (file_exists($path . '/' . $filename)); } while (file_exists($path . '/' . $filename));
$fullPath = __DIR__ . '/../../' . $path . '/' . $filename; $fullPath = __DIR__ . '/../../' . $path . '/' . $filename;
@ -267,7 +266,7 @@ class Controller extends ModuleAbstract implements WebInterface
]; ];
$media = MediaController::createDbEntry($status, $request->getHeader()->getAccount()); $media = MediaController::createDbEntry($status, $request->getHeader()->getAccount());
$draw = DrawImage::fromMedia($media); $draw = DrawImage::fromMedia($media);
DrawImageMapper::create($draw); DrawImageMapper::create($draw);

View File

@ -6,13 +6,13 @@
jsOMS.Modules.Draw.Editor = function (editor, app) jsOMS.Modules.Draw.Editor = function (editor, app)
{ {
this.editor = editor; this.editor = editor;
this.app = app; this.app = app;
this.canvas = document.getElementsByTagName('canvas')[0]; this.canvas = document.getElementsByTagName('canvas')[0];
this.canvasContainer = this.canvas.parentElement; this.canvasContainer = this.canvas.parentElement;
this.ctx = this.canvas.getContext("2d"); this.ctx = this.canvas.getContext("2d");
let canvasStyle = window.getComputedStyle(this.canvas, null), let canvasStyle = window.getComputedStyle(this.canvas, null),
canvasContainerStyle = window.getComputedStyle(this.canvasContainer, null); canvasContainerStyle = window.getComputedStyle(this.canvasContainer, null);
this.resize({ this.resize({
@ -22,14 +22,14 @@
// Backup for undo. // Backup for undo.
this.canvasBackup = document.createElement('canvas'); this.canvasBackup = document.createElement('canvas');
this.ctxBackup = this.canvasBackup.getContext("2d"); this.ctxBackup = this.canvasBackup.getContext("2d");
this.size = 1; this.size = 1;
this.type = jsOMS.Modules.Draw.DrawTypeEnum.DRAW; this.type = jsOMS.Modules.Draw.DrawTypeEnum.DRAW;
this.color = '#000000'; this.color = '#000000';
this.drawFlag = false; this.drawFlag = false;
this.oldPos = {x: 0, y: 0}; this.oldPos = {x: 0, y: 0};
this.newPos = {x: 0, y: 0}; this.newPos = {x: 0, y: 0};
// All backup steps need to be stored here (draw, resize etc.) // All backup steps need to be stored here (draw, resize etc.)
// Undo means the whole canvas will be redrawn on the canvasBackup without the last step // Undo means the whole canvas will be redrawn on the canvasBackup without the last step
@ -44,7 +44,7 @@
this.initCanvas(); this.initCanvas();
this.app.eventManager.attach(this.canvasContainer.id, function(evt) { this.app.eventManager.attach(this.canvasContainer.id, function(evt) {
self.canvasStyle = window.getComputedStyle(self.canvas, null); self.canvasStyle = window.getComputedStyle(self.canvas, null);
self.canvasContainerStyle = window.getComputedStyle(self.canvasContainer, null); self.canvasContainerStyle = window.getComputedStyle(self.canvasContainer, null);
this.resize({ this.resize({
@ -70,8 +70,8 @@
this.canvas.addEventListener("mousedown", function (evt) this.canvas.addEventListener("mousedown", function (evt)
{ {
self.drawFlag = true; self.drawFlag = true;
self.oldPos = self.newPos; self.oldPos = self.newPos;
self.newPos = self.mousePosition(evt); self.newPos = self.mousePosition(evt);
if (self.drawFlag && self.type === jsOMS.Modules.Draw.DrawTypeEnum.DRAW) { if (self.drawFlag && self.type === jsOMS.Modules.Draw.DrawTypeEnum.DRAW) {
self.draw(self.newPos, self.newPos); self.draw(self.newPos, self.newPos);
@ -99,7 +99,7 @@
self.newPos = self.mousePosition(evt); self.newPos = self.mousePosition(evt);
self.draw(self.oldPos, self.newPos); self.draw(self.oldPos, self.newPos);
self.drawFlag = false; self.drawFlag = false;
document.body.style.cursor = 'default'; document.body.style.cursor = 'default';
}, false); }, false);
}; };
@ -107,14 +107,14 @@
jsOMS.Modules.Draw.Editor.prototype.initCanvas = function() jsOMS.Modules.Draw.Editor.prototype.initCanvas = function()
{ {
const img = this.canvas.getAttribute('data-src'), const img = this.canvas.getAttribute('data-src'),
self = this; self = this;
if(img !== null && typeof img !== 'undefined' && img.length > 0) { if(img !== null && typeof img !== 'undefined' && img.length > 0) {
/** global: Image */ /** global: Image */
let imgObj = new Image(); let imgObj = new Image();
imgObj.addEventListener('load', function() { imgObj.addEventListener('load', function() {
self.canvas.width = imgObj.width; self.canvas.width = imgObj.width;
self.canvas.height = imgObj.height; self.canvas.height = imgObj.height;
self.canvas.getContext("2d").drawImage(imgObj, 0, 0); self.canvas.getContext("2d").drawImage(imgObj, 0, 0);
}); });
@ -128,7 +128,7 @@
if (this.drawFlag) { if (this.drawFlag) {
this.ctx.beginPath(); this.ctx.beginPath();
this.ctx.strokeStyle = this.color; this.ctx.strokeStyle = this.color;
this.ctx.lineWidth = this.size; this.ctx.lineWidth = this.size;
if (this.type === jsOMS.Modules.Draw.DrawTypeEnum.DRAW) { if (this.type === jsOMS.Modules.Draw.DrawTypeEnum.DRAW) {
this.ctx.moveTo(start.x, start.y); this.ctx.moveTo(start.x, start.y);
@ -169,7 +169,7 @@
jsOMS.Modules.Draw.Editor.prototype.toImage = function (callback) jsOMS.Modules.Draw.Editor.prototype.toImage = function (callback)
{ {
const image = new Image(); const image = new Image();
image.onload = function () image.onload = function ()
{ {
callback(image); callback(image);
@ -191,13 +191,13 @@
jsOMS.Modules.Draw.Editor.prototype.resize = function (size) jsOMS.Modules.Draw.Editor.prototype.resize = function (size)
{ {
const tmpCanvas = document.createElement('canvas'); const tmpCanvas = document.createElement('canvas');
tmpCanvas.width = this.canvas.width; tmpCanvas.width = this.canvas.width;
tmpCanvas.height = this.canvas.height; tmpCanvas.height = this.canvas.height;
tmpCanvas.getContext('2d').drawImage(this.canvas, 0, 0); tmpCanvas.getContext('2d').drawImage(this.canvas, 0, 0);
this.canvas.width = size.width; this.canvas.width = size.width;
this.canvas.height = size.height; this.canvas.height = size.height;
this.canvas.getContext('2d').drawImage(tmpCanvas, 0, 0, tmpCanvas.width, tmpCanvas.height, 0, 0, this.canvas.width, this.canvas.height); this.canvas.getContext('2d').drawImage(tmpCanvas, 0, 0, tmpCanvas.width, tmpCanvas.height, 0, 0, this.canvas.width, this.canvas.height);
@ -205,8 +205,8 @@
jsOMS.Modules.Draw.Editor.prototype.scale = function (scale) jsOMS.Modules.Draw.Editor.prototype.scale = function (scale)
{ {
const tmpCanvas = document.createElement('canvas'); const tmpCanvas = document.createElement('canvas');
tmpCanvas.width = this.canvas.width; tmpCanvas.width = this.canvas.width;
tmpCanvas.height = this.canvas.height; tmpCanvas.height = this.canvas.height;
tmpCanvas.getContext('2d').drawImage(this.canvas, 0, 0); tmpCanvas.getContext('2d').drawImage(this.canvas, 0, 0);

View File

@ -27,5 +27,5 @@ use phpOMS\Stdlib\Base\Enum;
abstract class PermissionState extends Enum abstract class PermissionState extends Enum
{ {
/* public */ const DASHBOARD = 1; /* public */ const DASHBOARD = 1;
/* public */ const DRAW = 2; /* public */ const DRAW = 2;
} }