diff --git a/app/Helpers/DbHelper.php b/app/Helpers/DbHelper.php index 8c74943..f3b191f 100644 --- a/app/Helpers/DbHelper.php +++ b/app/Helpers/DbHelper.php @@ -60,4 +60,11 @@ class DbHelper ->withCount('photos') ->paginate(UserConfig::get('items_per_page')); } + + public static function getAlbumByAliasForCurrentUser($urlAlias) + { + $album = Album::where('url_alias', $urlAlias)->first(); + + return $album; + } } \ No newline at end of file diff --git a/app/Http/Controllers/Gallery/PhotoController.php b/app/Http/Controllers/Gallery/PhotoController.php index 94708bf..03d8e25 100644 --- a/app/Http/Controllers/Gallery/PhotoController.php +++ b/app/Http/Controllers/Gallery/PhotoController.php @@ -20,7 +20,7 @@ class PhotoController extends Controller { public function download(Request $request, $albumUrlAlias, $photoFilename) { - $album = DbHelper::loadAlbumByUrlAlias($albumUrlAlias); + $album = DbHelper::getAlbumByAliasForCurrentUser($albumUrlAlias); if (is_null($album)) { App::abort(404); @@ -75,7 +75,7 @@ class PhotoController extends Controller public function show(Request $request, $albumUrlAlias, $photoFilename) { - $album = DbHelper::loadAlbumByUrlAlias($albumUrlAlias); + $album = DbHelper::getAlbumByAliasForCurrentUser($albumUrlAlias); if (is_null($album)) { App::abort(404); diff --git a/resources/assets/js/albums.js b/resources/assets/js/albums.js index 74b237a..32f8a2f 100644 --- a/resources/assets/js/albums.js +++ b/resources/assets/js/albums.js @@ -1,3 +1,130 @@ +/** + * This model is used by admin/analyse_album.blade.php, to analyse all images. + * @constructor + */ +function AnalyseAlbumViewModel() { + this.el = '#analyse-album'; + + this.data = { + imagesFailed: [], + imagesToAnalyse: [], + imagesInProgress: [], + imagesRecentlyCompleted: [], + numberSuccessful: 0, + numberFailed: 0 + }; + + this.computed = { + failedPercentage: function () { + var result = 0; + + if (this.numberTotal > 0) + { + result = (this.numberFailed / this.numberTotal) * 100; + } + + return result.toFixed(2) + '%'; + }, + isCompleted: function () { + return this.numberTotal > 0 && (this.numberSuccessful + this.numberFailed >= this.numberTotal); + }, + latestCompletedImages: function() { + return this.imagesRecentlyCompleted.slice( + (this.imagesRecentlyCompleted.length - 3 < 0 + ? 0 + : this.imagesRecentlyCompleted.length - 3) + , 3); + }, + numberTotal: function () { + return this.imagesToAnalyse.length; + }, + successfulPercentage: function () { + var result = 0; + + if (this.numberTotal > 0) + { + result = (this.numberSuccessful / this.numberTotal) * 100; + } + + return result.toFixed(2) + '%'; + } + }; + + this.methods = { + // This method is called when an image is added to the array, automatically issue it for analysis + // item is an instance of AnalyseImageViewModel + analyseImage: function (item) { + var self = this; + this.imagesToAnalyse.push(item); + + $.ajax( + item.url, + { + beforeSend: function() { + self.imagesInProgress.push(item); + }, + dataType: 'json', + error: function (xhr, textStatus, errorThrown) { + self.numberFailed++; + self.imagesFailed.push({ + 'name': item.name, + 'reason': textStatus + }); + item.isSuccessful = false; + item.isPending = false; + }, + method: 'POST', + success: function (data) { + if (data.is_successful) { + self.numberSuccessful++; + item.isSuccessful = true; + item.isPending = false; + + // Push into our "recently completed" array + self.imagesRecentlyCompleted.push(item); + var indexToRemove = self.imagesInProgress.indexOf(item); + if (indexToRemove > -1) + { + self.imagesInProgress.splice(indexToRemove, 1); + } + + // Remove it again after a few seconds + /*window.setTimeout(function() { + var indexToRemove = self.imagesRecentlyCompleted.indexOf(item); + if (indexToRemove > -1) { + self.imagesRecentlyCompleted.splice(indexToRemove, 1); + } + }, 2000);*/ + } + else { + self.numberFailed++; + self.imagesFailed.push({ + 'name': item.name, + 'reason': data.message + }); + item.isSuccessful = false; + item.isPending = false; + } + } + } + ); + } + }; +} + +/** + * This model is used by admin/analyse_album.blade.php, as a sub-model of AnalyseAlbumViewModel. + * @param image_info Array of information about the image + * @constructor + */ +function AnalyseImageViewModel(image_info) { + this.isPending = true; + this.isSuccessful = false; + this.name = image_info.name; + this.photoID = image_info.photo_id; + this.url = image_info.url; +} + /** * This model is used by admin/show_album.blade.php to handle photo uploads. * @param album_id ID of the album the photos are being uploaded to @@ -8,6 +135,7 @@ */ function UploadPhotosViewModel(album_id, queue_token, language, urls) { this.el = '#upload-tab'; + this.data = { currentStatus: '', imagesFailed: 0, @@ -17,6 +145,7 @@ function UploadPhotosViewModel(album_id, queue_token, language, urls) { isUploadInProgress: false, statusMessages: [] }; + this.computed = { failedPercentage: function () { var result = 0; @@ -39,6 +168,7 @@ function UploadPhotosViewModel(album_id, queue_token, language, urls) { return result.toFixed(2) + '%'; } }; + this.methods = { // This method is called when an image is uploaded - regardless if it fails or not onUploadCompleted: function () { diff --git a/resources/views/themes/base/admin/analyse_album.blade.php b/resources/views/themes/base/admin/analyse_album.blade.php index e530ce6..08a460c 100644 --- a/resources/views/themes/base/admin/analyse_album.blade.php +++ b/resources/views/themes/base/admin/analyse_album.blade.php @@ -4,50 +4,53 @@ @section('content')
-
-
-
Analysing...
-
+
+
+
Analysing...
+

Your uploaded photos are now being analysed.

-
- +
-
- +
{{-- We display a queue of 3 recently completed items, and 5 up-next items, as well as a counter saying "... and XYZ more" --}} {{-- That's what the 3's and 5's are in the next couple of blocks --}} -
-

...

+
+

...

-
-

...

+
+

...

-
-

@lang('admin.analyse_and_more.and') @lang('admin.analyse_and_more.others')

+
+

@lang('admin.analyse_and_more.and') @lang('admin.analyse_and_more.others')

+
+ +
+

...

-
-
Upload completed
-
+
+
Upload completed
+

Your upload has completed.

-
+ +

@lang('admin.analyse_photos_failed')

-
    -
  • :
  • +
      +
    • :
-
@@ -59,16 +62,15 @@ @push('scripts') @endpush \ No newline at end of file diff --git a/resources/views/themes/base/partials/single_photo_admin.blade.php b/resources/views/themes/base/partials/single_photo_admin.blade.php index bf97bd1..e3d17b1 100644 --- a/resources/views/themes/base/partials/single_photo_admin.blade.php +++ b/resources/views/themes/base/partials/single_photo_admin.blade.php @@ -1,7 +1,7 @@ @php ($field_prefix = sprintf('photo[%d]', $photo->id))