Added mulit image-type compatability to manager & app and added scaled image selection
Showing
9 changed files
with
78 additions
and
25 deletions
| ... | @@ -33,23 +33,24 @@ class ImageController extends Controller | ... | @@ -33,23 +33,24 @@ class ImageController extends Controller |
| 33 | 33 | ||
| 34 | 34 | ||
| 35 | /** | 35 | /** |
| 36 | - * Get all images, Paginated | 36 | + * Get all gallery images, Paginated |
| 37 | * @param int $page | 37 | * @param int $page |
| 38 | * @return \Illuminate\Http\JsonResponse | 38 | * @return \Illuminate\Http\JsonResponse |
| 39 | */ | 39 | */ |
| 40 | - public function getAllGallery($page = 0) | 40 | + public function getAllByType($type, $page = 0) |
| 41 | { | 41 | { |
| 42 | - $imgData = $this->imageRepo->getAllGallery($page); | 42 | + $imgData = $this->imageRepo->getPaginatedByType($type, $page); |
| 43 | return response()->json($imgData); | 43 | return response()->json($imgData); |
| 44 | } | 44 | } |
| 45 | 45 | ||
| 46 | 46 | ||
| 47 | /** | 47 | /** |
| 48 | * Handles image uploads for use on pages. | 48 | * Handles image uploads for use on pages. |
| 49 | + * @param string $type | ||
| 49 | * @param Request $request | 50 | * @param Request $request |
| 50 | * @return \Illuminate\Http\JsonResponse | 51 | * @return \Illuminate\Http\JsonResponse |
| 51 | */ | 52 | */ |
| 52 | - public function uploadGallery(Request $request) | 53 | + public function uploadByType($type, Request $request) |
| 53 | { | 54 | { |
| 54 | $this->checkPermission('image-create'); | 55 | $this->checkPermission('image-create'); |
| 55 | $this->validate($request, [ | 56 | $this->validate($request, [ |
| ... | @@ -57,10 +58,25 @@ class ImageController extends Controller | ... | @@ -57,10 +58,25 @@ class ImageController extends Controller |
| 57 | ]); | 58 | ]); |
| 58 | 59 | ||
| 59 | $imageUpload = $request->file('file'); | 60 | $imageUpload = $request->file('file'); |
| 60 | - $image = $this->imageRepo->saveNew($imageUpload, 'gallery'); | 61 | + $image = $this->imageRepo->saveNew($imageUpload, $type); |
| 61 | return response()->json($image); | 62 | return response()->json($image); |
| 62 | } | 63 | } |
| 63 | 64 | ||
| 65 | + /** | ||
| 66 | + * Generate a sized thumbnail for an image. | ||
| 67 | + * @param $id | ||
| 68 | + * @param $width | ||
| 69 | + * @param $height | ||
| 70 | + * @param $crop | ||
| 71 | + * @return \Illuminate\Http\JsonResponse | ||
| 72 | + */ | ||
| 73 | + public function getThumbnail($id, $width, $height, $crop) | ||
| 74 | + { | ||
| 75 | + $this->checkPermission('image-create'); | ||
| 76 | + $image = $this->imageRepo->getById($id); | ||
| 77 | + $thumbnailUrl = $this->imageRepo->getThumbnail($image, $width, $height, $crop == 'false'); | ||
| 78 | + return response()->json(['url' => $thumbnailUrl]); | ||
| 79 | + } | ||
| 64 | 80 | ||
| 65 | /** | 81 | /** |
| 66 | * Update image details | 82 | * Update image details | ... | ... |
| ... | @@ -18,7 +18,8 @@ class UserController extends Controller | ... | @@ -18,7 +18,8 @@ class UserController extends Controller |
| 18 | 18 | ||
| 19 | /** | 19 | /** |
| 20 | * UserController constructor. | 20 | * UserController constructor. |
| 21 | - * @param $user | 21 | + * @param User $user |
| 22 | + * @param UserRepo $userRepo | ||
| 22 | */ | 23 | */ |
| 23 | public function __construct(User $user, UserRepo $userRepo) | 24 | public function __construct(User $user, UserRepo $userRepo) |
| 24 | { | 25 | { | ... | ... |
| ... | @@ -57,10 +57,12 @@ Route::group(['middleware' => 'auth'], function () { | ... | @@ -57,10 +57,12 @@ Route::group(['middleware' => 'auth'], function () { |
| 57 | 57 | ||
| 58 | // Image routes | 58 | // Image routes |
| 59 | Route::group(['prefix' => 'images'], function() { | 59 | Route::group(['prefix' => 'images'], function() { |
| 60 | - Route::get('/gallery/all', 'ImageController@getAllGallery'); | 60 | + // Standard get, update and deletion for all types |
| 61 | - Route::get('/gallery/all/{page}', 'ImageController@getAllGallery'); | 61 | + Route::get('/thumb/{id}/{width}/{height}/{crop}', 'ImageController@getThumbnail'); |
| 62 | - Route::post('/gallery/upload', 'ImageController@uploadGallery'); | ||
| 63 | Route::put('/update/{imageId}', 'ImageController@update'); | 62 | Route::put('/update/{imageId}', 'ImageController@update'); |
| 63 | + Route::post('/{type}/upload', 'ImageController@uploadByType'); | ||
| 64 | + Route::get('/{type}/all', 'ImageController@getAllByType'); | ||
| 65 | + Route::get('/{type}/all/{page}', 'ImageController@getAllByType'); | ||
| 64 | Route::delete('/{imageId}', 'ImageController@destroy'); | 66 | Route::delete('/{imageId}', 'ImageController@destroy'); |
| 65 | }); | 67 | }); |
| 66 | 68 | ... | ... |
| ... | @@ -52,15 +52,15 @@ class ImageRepo | ... | @@ -52,15 +52,15 @@ class ImageRepo |
| 52 | 52 | ||
| 53 | 53 | ||
| 54 | /** | 54 | /** |
| 55 | - * Get all images for the standard gallery view that's used for | 55 | + * Gets a load images paginated, filtered by image type. |
| 56 | - * adding images to shared content such as pages. | 56 | + * @param string $type |
| 57 | - * @param int $page | 57 | + * @param int $page |
| 58 | - * @param int $pageSize | 58 | + * @param int $pageSize |
| 59 | * @return array | 59 | * @return array |
| 60 | */ | 60 | */ |
| 61 | - public function getAllGallery($page = 0, $pageSize = 24) | 61 | + public function getPaginatedByType($type, $page = 0, $pageSize = 24) |
| 62 | { | 62 | { |
| 63 | - $images = $this->image->where('type', '=', 'gallery') | 63 | + $images = $this->image->where('type', '=', strtolower($type)) |
| 64 | ->orderBy('created_at', 'desc')->skip($pageSize * $page)->take($pageSize + 1)->get(); | 64 | ->orderBy('created_at', 'desc')->skip($pageSize * $page)->take($pageSize + 1)->get(); |
| 65 | $hasMore = count($images) > $pageSize; | 65 | $hasMore = count($images) > $pageSize; |
| 66 | 66 | ||
| ... | @@ -191,7 +191,7 @@ class ImageRepo | ... | @@ -191,7 +191,7 @@ class ImageRepo |
| 191 | * @param bool $keepRatio | 191 | * @param bool $keepRatio |
| 192 | * @return string | 192 | * @return string |
| 193 | */ | 193 | */ |
| 194 | - private function getThumbnail(Image $image, $width = 220, $height = 220, $keepRatio = false) | 194 | + public function getThumbnail(Image $image, $width = 220, $height = 220, $keepRatio = false) |
| 195 | { | 195 | { |
| 196 | $thumbDirName = '/' . ($keepRatio ? 'scaled-' : 'thumbs-') . $width . '-' . $height . '/'; | 196 | $thumbDirName = '/' . ($keepRatio ? 'scaled-' : 'thumbs-') . $width . '-' . $height . '/'; |
| 197 | $thumbFilePath = dirname($image->path) . $thumbDirName . basename($image->path); | 197 | $thumbFilePath = dirname($image->path) . $thumbDirName . basename($image->path); | ... | ... |
| ... | @@ -76,6 +76,22 @@ | ... | @@ -76,6 +76,22 @@ |
| 76 | } | 76 | } |
| 77 | }, | 77 | }, |
| 78 | 78 | ||
| 79 | + props: { | ||
| 80 | + imageType: { | ||
| 81 | + type: String, | ||
| 82 | + required: true | ||
| 83 | + }, | ||
| 84 | + resizeWidth: { | ||
| 85 | + type: String | ||
| 86 | + }, | ||
| 87 | + resizeHeight: { | ||
| 88 | + type: String | ||
| 89 | + }, | ||
| 90 | + resizeCrop: { | ||
| 91 | + type: Boolean | ||
| 92 | + } | ||
| 93 | + }, | ||
| 94 | + | ||
| 79 | created: function () { | 95 | created: function () { |
| 80 | window.ImageManager = this; | 96 | window.ImageManager = this; |
| 81 | }, | 97 | }, |
| ... | @@ -88,7 +104,7 @@ | ... | @@ -88,7 +104,7 @@ |
| 88 | methods: { | 104 | methods: { |
| 89 | fetchData: function () { | 105 | fetchData: function () { |
| 90 | var _this = this; | 106 | var _this = this; |
| 91 | - this.$http.get('/images/gallery/all/' + _this.page, function (data) { | 107 | + this.$http.get('/images/' + _this.imageType + '/all/' + _this.page, function (data) { |
| 92 | _this.images = _this.images.concat(data.images); | 108 | _this.images = _this.images.concat(data.images); |
| 93 | _this.hasMore = data.hasMore; | 109 | _this.hasMore = data.hasMore; |
| 94 | _this.page++; | 110 | _this.page++; |
| ... | @@ -98,7 +114,7 @@ | ... | @@ -98,7 +114,7 @@ |
| 98 | setupDropZone: function () { | 114 | setupDropZone: function () { |
| 99 | var _this = this; | 115 | var _this = this; |
| 100 | var dropZone = new Dropzone(_this.$els.dropZone, { | 116 | var dropZone = new Dropzone(_this.$els.dropZone, { |
| 101 | - url: '/images/gallery/upload', | 117 | + url: '/images/' + _this.imageType + '/upload', |
| 102 | init: function () { | 118 | init: function () { |
| 103 | var dz = this; | 119 | var dz = this; |
| 104 | this.on("sending", function (file, xhr, data) { | 120 | this.on("sending", function (file, xhr, data) { |
| ... | @@ -120,6 +136,24 @@ | ... | @@ -120,6 +136,24 @@ |
| 120 | }); | 136 | }); |
| 121 | }, | 137 | }, |
| 122 | 138 | ||
| 139 | + returnCallback: function (image) { | ||
| 140 | + var _this = this; | ||
| 141 | + var isResized = _this.resizeWidth && _this.resizeHeight; | ||
| 142 | + | ||
| 143 | + if (!isResized) { | ||
| 144 | + _this.callback(image); | ||
| 145 | + return; | ||
| 146 | + } | ||
| 147 | + | ||
| 148 | + var cropped = _this.resizeCrop ? 'true' : 'false'; | ||
| 149 | + var requestString = '/images/thumb/' + image.id + '/' + _this.resizeWidth + '/' + _this.resizeHeight + '/' + cropped; | ||
| 150 | + _this.$http.get(requestString, function(data) { | ||
| 151 | + image.thumbs.custom = data.url; | ||
| 152 | + _this.callback(image); | ||
| 153 | + }); | ||
| 154 | + | ||
| 155 | + }, | ||
| 156 | + | ||
| 123 | imageClick: function (image) { | 157 | imageClick: function (image) { |
| 124 | var dblClickTime = 380; | 158 | var dblClickTime = 380; |
| 125 | var cTime = (new Date()).getTime(); | 159 | var cTime = (new Date()).getTime(); |
| ... | @@ -127,7 +161,7 @@ | ... | @@ -127,7 +161,7 @@ |
| 127 | if (this.cClickTime !== 0 && timeDiff < dblClickTime && this.selectedImage === image) { | 161 | if (this.cClickTime !== 0 && timeDiff < dblClickTime && this.selectedImage === image) { |
| 128 | // DoubleClick | 162 | // DoubleClick |
| 129 | if (this.callback) { | 163 | if (this.callback) { |
| 130 | - this.callback(image); | 164 | + this.returnCallback(image); |
| 131 | } | 165 | } |
| 132 | this.hide(); | 166 | this.hide(); |
| 133 | } else { | 167 | } else { |
| ... | @@ -139,7 +173,7 @@ | ... | @@ -139,7 +173,7 @@ |
| 139 | 173 | ||
| 140 | selectButtonClick: function () { | 174 | selectButtonClick: function () { |
| 141 | if (this.callback) { | 175 | if (this.callback) { |
| 142 | - this.callback(this.selectedImage); | 176 | + this.returnCallback(this.selectedImage); |
| 143 | } | 177 | } |
| 144 | this.hide(); | 178 | this.hide(); |
| 145 | }, | 179 | }, | ... | ... |
| ... | @@ -24,7 +24,7 @@ | ... | @@ -24,7 +24,7 @@ |
| 24 | showImageManager: function(e) { | 24 | showImageManager: function(e) { |
| 25 | var _this = this; | 25 | var _this = this; |
| 26 | ImageManager.show(function(image) { | 26 | ImageManager.show(function(image) { |
| 27 | - _this.image = image.url; | 27 | + _this.image = image.thumbs.custom || image.url; |
| 28 | }); | 28 | }); |
| 29 | }, | 29 | }, |
| 30 | reset: function() { | 30 | reset: function() { | ... | ... |
| ... | @@ -14,6 +14,6 @@ | ... | @@ -14,6 +14,6 @@ |
| 14 | @include('pages/form', ['model' => $page]) | 14 | @include('pages/form', ['model' => $page]) |
| 15 | </form> | 15 | </form> |
| 16 | </div> | 16 | </div> |
| 17 | - <image-manager></image-manager> | 17 | + <image-manager image-type="gallery"></image-manager> |
| 18 | 18 | ||
| 19 | @stop | 19 | @stop |
| ... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
| ... | @@ -32,7 +32,7 @@ | ... | @@ -32,7 +32,7 @@ |
| 32 | <div class="col-md-6"> | 32 | <div class="col-md-6"> |
| 33 | <div class="form-group" id="logo-control"> | 33 | <div class="form-group" id="logo-control"> |
| 34 | <label for="setting-app-logo">Application Logo</label> | 34 | <label for="setting-app-logo">Application Logo</label> |
| 35 | - <p class="small">This image should be 43px in height. </p> | 35 | + <p class="small">This image should be 43px in height. <br>Large images will be scaled down.</p> |
| 36 | <image-picker current-image="{{ Setting::get('app-logo', '') }}" default-image="/logo.png" name="setting-app-logo" image-class="logo-image"></image-picker> | 36 | <image-picker current-image="{{ Setting::get('app-logo', '') }}" default-image="/logo.png" name="setting-app-logo" image-class="logo-image"></image-picker> |
| 37 | </div> | 37 | </div> |
| 38 | </div> | 38 | </div> |
| ... | @@ -86,6 +86,6 @@ | ... | @@ -86,6 +86,6 @@ |
| 86 | 86 | ||
| 87 | </div> | 87 | </div> |
| 88 | 88 | ||
| 89 | -<image-manager></image-manager> | 89 | +<image-manager image-type="system" resize-height="43" resize-width="200"></image-manager> |
| 90 | 90 | ||
| 91 | @stop | 91 | @stop | ... | ... |
-
Please register or sign in to post a comment