1
0
mirror of https://github.com/BookStackApp/BookStack.git synced 2024-11-24 11:52:34 +01:00

Merge branch 'bug/image-upload' of git://github.com/Abijeet/BookStack into Abijeet-bug/image-upload

This commit is contained in:
Dan Brown 2018-03-24 14:39:57 +00:00
commit 746684ec8c
No known key found for this signature in database
GPG Key ID: 46D9F943C24A2EF9
10 changed files with 48 additions and 27 deletions

View File

@ -120,7 +120,7 @@ class ImageController extends Controller
{ {
$this->checkPermission('image-create-all'); $this->checkPermission('image-create-all');
$this->validate($request, [ $this->validate($request, [
'file' => 'required|is_image' 'file' => 'required|image'
]); ]);
if (!$this->imageRepo->isValidType($type)) { if (!$this->imageRepo->isValidType($type)) {

View File

@ -15,7 +15,7 @@ class AppServiceProvider extends ServiceProvider
public function boot() public function boot()
{ {
// Custom validation methods // Custom validation methods
Validator::extend('is_image', function ($attribute, $value, $parameters, $validator) { Validator::extend('image', function ($attribute, $value, $parameters, $validator) {
$imageMimes = ['image/png', 'image/bmp', 'image/gif', 'image/jpeg', 'image/jpg', 'image/tiff', 'image/webp']; $imageMimes = ['image/png', 'image/bmp', 'image/gif', 'image/jpeg', 'image/jpg', 'image/tiff', 'image/webp'];
return in_array($value->getMimeType(), $imageMimes); return in_array($value->getMimeType(), $imageMimes);
}); });

View File

@ -12,7 +12,9 @@ const props = ['placeholder', 'uploadUrl', 'uploadedTo'];
function mounted() { function mounted() {
let container = this.$el; let container = this.$el;
let _this = this; let _this = this;
new DropZone(container, { this._dz = new DropZone(container, {
addRemoveLinks: true,
dictRemoveFile: trans('components.image_upload_remove'),
url: function() { url: function() {
return _this.uploadUrl; return _this.uploadUrl;
}, },
@ -41,7 +43,7 @@ function mounted() {
$(file.previewElement).find('[data-dz-errormessage]').text(message); $(file.previewElement).find('[data-dz-errormessage]').text(message);
} }
if (xhr.status === 413) setMessage(trans('errors.server_upload_limit')); if (xhr && xhr.status === 413) setMessage(trans('errors.server_upload_limit'));
if (errorMessage.file) setMessage(errorMessage.file[0]); if (errorMessage.file) setMessage(errorMessage.file[0]);
}); });
} }
@ -49,12 +51,19 @@ function mounted() {
} }
function data() { function data() {
return {} return {};
} }
const methods = {
onClose: function () {
this._dz.removeAllFiles(true);
}
};
module.exports = { module.exports = {
template, template,
props, props,
mounted, mounted,
data, data,
}; methods
};

View File

@ -43,6 +43,8 @@ const methods = {
hide() { hide() {
this.showing = false; this.showing = false;
this.selectedImage = false;
this.$refs.dropzone.onClose();
this.$el.children[0].components.overlay.hide(); this.$el.children[0].components.overlay.hide();
}, },
@ -175,4 +177,4 @@ module.exports = {
data, data,
computed, computed,
components: {dropzone}, components: {dropzone},
}; };

View File

@ -224,15 +224,15 @@
padding: 0; padding: 0;
align-items: center; align-items: center;
text-align: center; text-align: center;
justify-content: center;
width: 28px; width: 28px;
padding-left: $-xs; padding-left: $-xs;
padding-right: $-xs; padding-right: $-xs;
&:hover { &:hover {
background-color: #EEE; background-color: #EEE;
} }
i { .svg-icon {
flex: 1; margin-right: 0px;
padding: 0;
} }
} }
> div .outline input { > div .outline input {
@ -258,4 +258,4 @@
background-color: #F8F8F8; background-color: #F8F8F8;
padding: $-m; padding: $-m;
border: 1px solid #DDD; border: 1px solid #DDD;
} }

View File

@ -211,6 +211,7 @@ body.flexbox-support #entity-selector-wrap .popup-body .form-group {
margin-left: 1px; margin-left: 1px;
padding: $-m $-l; padding: $-m $-l;
overflow-y: auto; overflow-y: auto;
overflow-x: hidden;
border-left: 1px solid #DDD; border-left: 1px solid #DDD;
.dropzone-container { .dropzone-container {
margin-top: $-m; margin-top: $-m;
@ -315,8 +316,7 @@ body.flexbox-support #entity-selector-wrap .popup-body .form-group {
.dz-preview.dz-file-preview .dz-image { .dz-preview.dz-file-preview .dz-image {
border-radius: 4px; border-radius: 4px;
background: #999; background: #e9e9e9;
background: linear-gradient(to bottom, #eee, #ddd);
} }
.dz-preview.dz-file-preview .dz-details { .dz-preview.dz-file-preview .dz-details {
@ -332,11 +332,12 @@ body.flexbox-support #entity-selector-wrap .popup-body .form-group {
} }
.dz-preview .dz-remove { .dz-preview .dz-remove {
font-size: 14px; font-size: 13px;
text-align: center; text-align: center;
display: block; display: block;
cursor: pointer; cursor: pointer;
border: none; border: none;
margin-top: 3px;
} }
.dz-preview .dz-remove:hover { .dz-preview .dz-remove:hover {
@ -385,7 +386,7 @@ body.flexbox-support #entity-selector-wrap .popup-body .form-group {
border: 1px solid transparent; border: 1px solid transparent;
} }
.dz-preview .dz-details .dz-filename span, .dz-preview .dz-details .dz-size span { .dz-preview .dz-details .dz-filename span {
background-color: rgba(255, 255, 255, 0.4); background-color: rgba(255, 255, 255, 0.4);
padding: 0 0.4em; padding: 0 0.4em;
border-radius: 3px; border-radius: 3px;
@ -421,13 +422,13 @@ body.flexbox-support #entity-selector-wrap .popup-body .form-group {
.dz-preview .dz-success-mark, .dz-preview .dz-error-mark { .dz-preview .dz-success-mark, .dz-preview .dz-error-mark {
pointer-events: none; pointer-events: none;
opacity: 0; opacity: 0;
z-index: 500; z-index: 1001;
position: absolute; position: absolute;
display: block; display: block;
top: 50%; top: 50%;
left: 50%; left: 50%;
margin-left: -27px; margin-left: -27px;
margin-top: -27px; margin-top: -35px;
} }
.dz-preview .dz-success-mark svg, .dz-preview .dz-error-mark svg { .dz-preview .dz-success-mark svg, .dz-preview .dz-error-mark svg {
@ -482,9 +483,13 @@ body.flexbox-support #entity-selector-wrap .popup-body .form-group {
display: block; display: block;
} }
.dz-preview.dz-error:hover .dz-error-message { .dz-preview.dz-error {
opacity: 1; .dz-image, .dz-details {
pointer-events: auto; &:hover ~ .dz-error-message {
opacity: 1;
pointer-events: auto;
}
}
} }
.dz-preview .dz-error-message { .dz-preview .dz-error-message {
@ -496,7 +501,7 @@ body.flexbox-support #entity-selector-wrap .popup-body .form-group {
opacity: 0; opacity: 0;
transition: opacity 0.3s ease; transition: opacity 0.3s ease;
border-radius: 4px; border-radius: 4px;
font-size: 11.5px; font-size: 12px;
line-height: 1.2; line-height: 1.2;
top: 88px; top: 88px;
left: -26px; left: -26px;
@ -597,4 +602,4 @@ body.flexbox-support #entity-selector-wrap .popup-body .form-group {
.text-muted { .text-muted {
color: #999; color: #999;
} }
} }

View File

@ -210,6 +210,9 @@
flex: 1; flex: 1;
padding-top: 0; padding-top: 0;
} }
div[toolbox-tab-content] .padded.files {
overflow-x: hidden;
}
h4 { h4 {
font-size: 24px; font-size: 24px;
margin: $-m 0 0 0; margin: $-m 0 0 0;

View File

@ -21,6 +21,7 @@ return [
'image_upload_success' => 'Image uploaded successfully', 'image_upload_success' => 'Image uploaded successfully',
'image_update_success' => 'Image details successfully updated', 'image_update_success' => 'Image details successfully updated',
'image_delete_success' => 'Image successfully deleted', 'image_delete_success' => 'Image successfully deleted',
'image_upload_remove' => 'Remove',
/** /**
* Code editor * Code editor
@ -29,4 +30,4 @@ return [
'code_language' => 'Code Language', 'code_language' => 'Code Language',
'code_content' => 'Code Content', 'code_content' => 'Code Content',
'code_save' => 'Save Code', 'code_save' => 'Save Code',
]; ];

View File

@ -35,6 +35,7 @@ return [
'cannot_get_image_from_url' => 'Cannot get image from :url', 'cannot_get_image_from_url' => 'Cannot get image from :url',
'cannot_create_thumbs' => 'The server cannot create thumbnails. Please check you have the GD PHP extension installed.', 'cannot_create_thumbs' => 'The server cannot create thumbnails. Please check you have the GD PHP extension installed.',
'server_upload_limit' => 'The server does not allow uploads of this size. Please try a smaller file size.', 'server_upload_limit' => 'The server does not allow uploads of this size. Please try a smaller file size.',
'uploaded' => 'The server does not allow uploads of this size. Please try a smaller file size.',
'image_upload_error' => 'An error occurred uploading the image', 'image_upload_error' => 'An error occurred uploading the image',
'image_upload_type_error' => 'The image type being uploaded is invalid', 'image_upload_type_error' => 'The image type being uploaded is invalid',
@ -78,4 +79,4 @@ return [
'error_occurred' => 'An Error Occurred', 'error_occurred' => 'An Error Occurred',
'app_down' => ':appName is down right now', 'app_down' => ':appName is down right now',
'back_soon' => 'It will be back up soon.', 'back_soon' => 'It will be back up soon.',
]; ];

View File

@ -1,10 +1,10 @@
<div id="image-manager" image-type="{{ $imageType }}" uploaded-to="{{ $uploaded_to or 0 }}"> <div id="image-manager" image-type="{{ $imageType }}" uploaded-to="{{ $uploaded_to or 0 }}">
<div overlay v-cloak> <div overlay v-cloak @click="hide()">
<div class="popup-body" @click.stop=""> <div class="popup-body" @click.stop="">
<div class="popup-header primary-background"> <div class="popup-header primary-background">
<div class="popup-title">{{ trans('components.image_select') }}</div> <div class="popup-title">{{ trans('components.image_select') }}</div>
<button class="overlay-close neg corner-button button">x</button> <button class="overlay-close neg corner-button button" @click="hide()">x</button>
</div> </div>
<div class="flex-fill image-manager-body"> <div class="flex-fill image-manager-body">
@ -79,7 +79,7 @@
</div> </div>
<dropzone placeholder="{{ trans('components.image_dropzone') }}" :upload-url="uploadUrl" :uploaded-to="uploadedTo" @success="uploadSuccess"></dropzone> <dropzone ref="dropzone" placeholder="{{ trans('components.image_dropzone') }}" :upload-url="uploadUrl" :uploaded-to="uploadedTo" @success="uploadSuccess"></dropzone>
</div> </div>
</div> </div>