diff --git a/app/Http/Controllers/ImageController.php b/app/Http/Controllers/ImageController.php
index bf7f3bb82..eb92ae9a8 100644
--- a/app/Http/Controllers/ImageController.php
+++ b/app/Http/Controllers/ImageController.php
@@ -164,32 +164,6 @@ class ImageController extends Controller
return response()->json($image);
}
- /**
- * Replace the data content of a drawing.
- * @param string $id
- * @param Request $request
- * @return \Illuminate\Contracts\Routing\ResponseFactory|\Illuminate\Http\JsonResponse|\Symfony\Component\HttpFoundation\Response
- */
- public function updateDrawing(string $id, Request $request)
- {
- $this->validate($request, [
- 'image' => 'required|string'
- ]);
- $this->checkPermission('image-create-all');
-
- $imageBase64Data = $request->get('image');
- $image = $this->imageRepo->getById($id);
- $this->checkOwnablePermission('image-update', $image);
-
- try {
- $image = $this->imageRepo->updateDrawing($image, $imageBase64Data);
- } catch (ImageUploadException $e) {
- return response($e->getMessage(), 500);
- }
-
- return response()->json($image);
- }
-
/**
* Get the content of an image based64 encoded.
* @param $id
@@ -257,22 +231,11 @@ class ImageController extends Controller
return response()->json($pageSearch);
}
- /**
- * Get the revisions for an image.
- * @param $id
- * @return \Illuminate\Http\JsonResponse
- */
- public function getRevisions($id)
- {
- $image = $this->imageRepo->getById($id);
- $revisions = $image->revisions()->orderBy('id', 'desc')->get();
- return response()->json($revisions);
- }
-
/**
* Deletes an image and all thumbnail/image files
* @param int $id
* @return \Illuminate\Http\JsonResponse
+ * @throws \Exception
*/
public function destroy($id)
{
diff --git a/app/Image.php b/app/Image.php
index ac94d9bf0..412beea90 100644
--- a/app/Image.php
+++ b/app/Image.php
@@ -20,23 +20,4 @@ class Image extends Ownable
return Images::getThumbnail($this, $width, $height, $keepRatio);
}
- /**
- * Get the revisions for this image.
- * @return \Illuminate\Database\Eloquent\Relations\HasMany
- */
- public function revisions()
- {
- return $this->hasMany(ImageRevision::class);
- }
-
- /**
- * Get the count of revisions made to this image.
- * Based off numbers on revisions rather than raw count of attached revisions
- * as they may be cleared up or revisions deleted at some point.
- * @return int
- */
- public function revisionCount()
- {
- return intval($this->revisions()->max('revision'));
- }
}
diff --git a/app/ImageRevision.php b/app/ImageRevision.php
deleted file mode 100644
index fde232867..000000000
--- a/app/ImageRevision.php
+++ /dev/null
@@ -1,26 +0,0 @@
-belongsTo(User::class, 'created_by');
- }
-
- /**
- * Get the image that this is a revision of.
- * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
- */
- public function image()
- {
- return $this->belongsTo(Image::class);
- }
-}
diff --git a/app/Repos/ImageRepo.php b/app/Repos/ImageRepo.php
index 384ea5454..4ccd719ad 100644
--- a/app/Repos/ImageRepo.php
+++ b/app/Repos/ImageRepo.php
@@ -153,17 +153,6 @@ class ImageRepo
return $image;
}
- /**
- * Replace the image content of a drawing.
- * @param Image $image
- * @param string $base64Uri
- * @return Image
- * @throws \BookStack\Exceptions\ImageUploadException
- */
- public function updateDrawing(Image $image, string $base64Uri)
- {
- return $this->imageService->updateImageFromBase64Uri($image, $base64Uri);
- }
/**
* Update the details of an image via an array of properties.
@@ -251,7 +240,7 @@ class ImageRepo
*/
public function isValidType($type)
{
- $validTypes = ['drawing', 'gallery', 'cover', 'system', 'user'];
+ $validTypes = ['gallery', 'cover', 'system', 'user'];
return in_array($type, $validTypes);
}
}
diff --git a/app/Services/ImageService.php b/app/Services/ImageService.php
index e83c1860b..736b30705 100644
--- a/app/Services/ImageService.php
+++ b/app/Services/ImageService.php
@@ -2,7 +2,6 @@
use BookStack\Exceptions\ImageUploadException;
use BookStack\Image;
-use BookStack\ImageRevision;
use BookStack\User;
use Exception;
use Intervention\Image\Exception\NotSupportedException;
@@ -82,22 +81,6 @@ class ImageService extends UploadService
return $this->saveNew($name, $data, $type, $uploadedTo);
}
- /**
- * @param Image $image
- * @param string $base64Uri
- * @return Image
- * @throws ImageUploadException
- */
- public function updateImageFromBase64Uri(Image $image, string $base64Uri)
- {
- $splitData = explode(';base64,', $base64Uri);
- if (count($splitData) < 2) {
- throw new ImageUploadException("Invalid base64 image data provided");
- }
- $data = base64_decode($splitData[1]);
- return $this->update($image, $data);
- }
-
/**
* Gets an image from url and saves it to the database.
* @param $url
@@ -168,59 +151,6 @@ class ImageService extends UploadService
return $image;
}
- /**
- * Update the content of an existing image.
- * Uploaded the new image content and creates a revision for the old image content.
- * @param Image $image
- * @param $imageData
- * @return Image
- * @throws ImageUploadException
- */
- private function update(Image $image, $imageData)
- {
- // Save image revision if not previously exists to ensure we always have
- // a reference to the image files being uploaded.
- if ($image->revisions()->count() === 0) {
- $this->saveImageRevision($image);
- }
-
- $pathInfo = pathinfo($image->path);
- $revisionCount = $image->revisionCount() + 1;
- $newFileName = preg_replace('/^(.+?)(-v\d+)?$/', '$1-v' . $revisionCount, $pathInfo['filename']);
-
- $image->path = str_replace_last($pathInfo['filename'], $newFileName, $image->path);
- $image->url = $this->getPublicUrl($image->path);
- $image->updated_by = user()->id;
-
- $storage = $this->getStorage();
-
- try {
- $storage->put($image->path, $imageData);
- $storage->setVisibility($image->path, 'public');
- $image->save();
- $this->saveImageRevision($image);
- } catch (Exception $e) {
- throw new ImageUploadException(trans('errors.path_not_writable', ['filePath' => $image->path]));
- }
- return $image;
- }
-
- /**
- * Save a new revision for an image.
- * @param Image $image
- * @return ImageRevision
- */
- protected function saveImageRevision(Image $image)
- {
- $revision = new ImageRevision();
- $revision->image_id = $image->id;
- $revision->path = $image->path;
- $revision->url = $image->url;
- $revision->created_by = user()->id;
- $revision->revision = $image->revisionCount() + 1;
- $revision->save();
- return $revision;
- }
/**
* Checks if the image is a gif. Returns true if it is, else false.
@@ -309,13 +239,6 @@ class ImageService extends UploadService
*/
public function destroy(Image $image)
{
- // Destroy image revisions
- foreach ($image->revisions as $revision) {
- $this->destroyImagesFromPath($revision->path);
- $revision->delete();
- }
-
- // Destroy main image
$this->destroyImagesFromPath($image->path);
$image->delete();
}
diff --git a/database/migrations/2018_05_13_090521_create_image_revisions_table.php b/database/migrations/2018_05_13_090521_create_image_revisions_table.php
deleted file mode 100644
index d3032258f..000000000
--- a/database/migrations/2018_05_13_090521_create_image_revisions_table.php
+++ /dev/null
@@ -1,38 +0,0 @@
-increments('id');
- $table->integer('image_id');
- $table->integer('revision');
- $table->string('path');
- $table->string('url');
- $table->integer('created_by');
-
- $table->index('image_id');
- $table->timestamps();
- });
- }
-
- /**
- * Reverse the migrations.
- *
- * @return void
- */
- public function down()
- {
- Schema::dropIfExists('image_revisions');
- }
-}
diff --git a/resources/assets/js/components/wysiwyg-editor.js b/resources/assets/js/components/wysiwyg-editor.js
index 03d73d2b5..764b0a929 100644
--- a/resources/assets/js/components/wysiwyg-editor.js
+++ b/resources/assets/js/components/wysiwyg-editor.js
@@ -229,16 +229,18 @@ function drawIoPlugin() {
}
function showDrawingManager(mceEditor, selectedNode = null) {
- // TODO - Handle how image manager links in.
+ pageEditor = mceEditor;
+ currentNode = selectedNode;
// Show image manager
window.ImageManager.show(function (image) {
-
-
- // // Replace the actively selected content with the linked image
- // let html = ``;
- // html += ``;
- // html += '';
- // win.tinyMCE.activeEditor.execCommand('mceInsertContent', false, html);
+ if (selectedNode) {
+ let imgElem = selectedNode.querySelector('img');
+ pageEditor.dom.setAttrib(imgElem, 'src', image.url);
+ pageEditor.dom.setAttrib(selectedNode, 'drawio-diagram', image.id);
+ } else {
+ let imgHTML = `