From 8bc1b5991db768797bfd758265d925b9063fc065 Mon Sep 17 00:00:00 2001 From: inna-r Date: Wed, 24 May 2017 15:59:37 +0300 Subject: [PATCH] Use image_url from API response issue #351 --- index.html | 1 + .../main/src/controllers/galleryModalCtrl.js | 24 +++-------- js/modules/main/src/controllers/itemCtrl.js | 41 +++++++++---------- .../src/directives/fallbackSrcDirective.js | 18 ++++++++ templates/item/photoUnits.html | 28 +++++-------- templates/item/text_item.html | 8 ++-- templates/main/gallery-modal.html | 23 ++++++----- 7 files changed, 69 insertions(+), 74 deletions(-) create mode 100644 js/modules/main/src/directives/fallbackSrcDirective.js diff --git a/index.html b/index.html index 77c9a6a8..be2d55d9 100644 --- a/index.html +++ b/index.html @@ -108,6 +108,7 @@ + diff --git a/js/modules/main/src/controllers/galleryModalCtrl.js b/js/modules/main/src/controllers/galleryModalCtrl.js index ac30d676..1c48eaed 100644 --- a/js/modules/main/src/controllers/galleryModalCtrl.js +++ b/js/modules/main/src/controllers/galleryModalCtrl.js @@ -1,5 +1,6 @@ -var GalleryModalCtrl = function($scope, langManager, gallery, index, $uibModalInstance) { +var GalleryModalCtrl = function($scope, langManager, gallery, index, $uibModalInstance, sorted_pictures) { $scope.gallery = gallery; + $scope.sorted_pictures = sorted_pictures; $scope.index = index; $scope.lang = langManager.lang; @@ -7,11 +8,11 @@ var GalleryModalCtrl = function($scope, langManager, gallery, index, $uibModalIn return $scope.index === index; }; $scope.showPrev = function () { - $scope.index = ($scope.index > 0) ? --$scope.index : $scope.gallery.Pictures.length - 1; + $scope.index = ($scope.index > 0) ? --$scope.index : $scope.sorted_pictures.length - 1; }; $scope.showNext = function () { - $scope.index = ($scope.index < $scope.gallery.Pictures.length - 1) ? ++$scope.index : 0; + $scope.index = ($scope.index < $scope.sorted_pictures.length - 1) ? ++$scope.index : 0; }; $scope.showPhoto = function (index) { $scope.index = index; @@ -22,21 +23,6 @@ var GalleryModalCtrl = function($scope, langManager, gallery, index, $uibModalIn $scope.print = function () { window.print(); }; - $scope.sort_pictures = function() { - var digitized = [], - nondigitized = []; - for (var i = 0; i < gallery.Pictures.length; i++) { - var pic = gallery.Pictures[i]; - if(pic.PictureId !== '') { - digitized.push(pic); - } - else { - nondigitized.push(pic); - } - } - digitized.push.apply(digitized, nondigitized); - return digitized; - } }; -angular.module('main').controller('GalleryModalCtrl', ['$scope', 'langManager', 'gallery', 'index', '$uibModalInstance', GalleryModalCtrl]); +angular.module('main').controller('GalleryModalCtrl', ['$scope', 'langManager', 'gallery', 'index', '$uibModalInstance', 'sorted_pictures', GalleryModalCtrl]); diff --git a/js/modules/main/src/controllers/itemCtrl.js b/js/modules/main/src/controllers/itemCtrl.js index 8ff7681e..4d45bf75 100644 --- a/js/modules/main/src/controllers/itemCtrl.js +++ b/js/modules/main/src/controllers/itemCtrl.js @@ -31,6 +31,7 @@ function ItemCtrl($scope, $state, $stateParams, item, notification, itemTypeMap, this.active_font = 's'; this.font_sizes = {'s':18, 'm':20, 'l':22}; this.get_item(); + this.sorted_pictures = []; this.public_url = $state.href(($rootScope.lang=='en'?'item-view': 'he.he_item-view'), {collection: $stateParams.collection, local_slug: $stateParams.local_slug}, {absolute: true}); @@ -147,6 +148,7 @@ ItemCtrl.prototype = { thumbnail_url: item_data.thumbnail_url }); self.item_data = item_data; + self.sorted_pictures = self.sort_pictures(self.item_data); self.proper_link = self.item.get_url(self.item_data); self.content_loaded = true; self.refresh_root_scope(); @@ -203,11 +205,11 @@ ItemCtrl.prototype = { }, showPrev: function () { - this._Index = (this._Index > 0) ? --this._Index : this.item_data.Pictures.length - 1; + this._Index = (this._Index > 0) ? --this._Index : this.sorted_pictures.length - 1; }, showNext: function () { - this._Index = (this._Index < this.item_data.Pictures.length - 1) ? ++this._Index : 0; + this._Index = (this._Index < this.sorted_pictures.length - 1) ? ++this._Index : 0; }, isActive: function (index) { @@ -223,6 +225,7 @@ ItemCtrl.prototype = { index = this._Index; } var gallery = this.item_data; + var sorted_pictures = this.sorted_pictures; this.$uibModal.open({ templateUrl: 'templates/main/gallery-modal.html', @@ -231,7 +234,10 @@ ItemCtrl.prototype = { resolve : { gallery: function () { return gallery - }, + }, + sorted_pictures: function () { + return sorted_pictures; + }, index: function () { return index } @@ -262,35 +268,26 @@ ItemCtrl.prototype = { } }, - get_additional_pic_index: function() { + get_additional_pic_url: function() { for (var i = 0; i < this.item_data.Pictures.length; i++) { var pic = this.item_data.Pictures[i]; if (pic.IsPreview == "0") { - return i; + return pic.PictureUrl; } } }, - get_additional_pic_url: function () { - return "https://storage.googleapis.com/bhs-flat-pics/" + this.item_data.Pictures[this.get_additional_pic_index()].PictureId + ".jpg"; - }, - - sort_pictures: function() { - if (this.item_data.Pictures) { - var digitized = [], - nondigitized = []; - for (var i = 0; i < this.item_data.Pictures.length; i++) { - var pic = this.item_data.Pictures[i]; - if(pic.PictureId !== '') { - digitized.push(pic); - } - else { - nondigitized.push(pic); + sort_pictures: function(data) { + if (data.Pictures) { + var digitized = []; + for (var i = 0; i < data.Pictures.length; i++) { + var pic = data.Pictures[i]; + if(pic.PictureUrl) { + digitized.push(pic); + } } } - digitized.push.apply(digitized, nondigitized); return digitized; - } }, uc_first: function() { diff --git a/js/modules/main/src/directives/fallbackSrcDirective.js b/js/modules/main/src/directives/fallbackSrcDirective.js new file mode 100644 index 00000000..0b95f0e2 --- /dev/null +++ b/js/modules/main/src/directives/fallbackSrcDirective.js @@ -0,0 +1,18 @@ +angular.module('main'). + directive('fallbackSrc', function () { + return { + link: function(scope, element, attrs) { + element.bind('error', function() { + if (attrs.src != attrs.fallbackSrc) { + attrs.$set('src', attrs.fallbackSrc); + } + }); + + attrs.$observe('ngSrc', function(value) { + if (!value && attrs.fallbackSrc) { + attrs.$set('src', attrs.fallbackSrc); + } + }); + } + } +}); diff --git a/templates/item/photoUnits.html b/templates/item/photoUnits.html index 366ee783..d034a195 100644 --- a/templates/item/photoUnits.html +++ b/templates/item/photoUnits.html @@ -29,25 +29,16 @@
-
- + - - - - + fit-thumb/>
-
+
@@ -120,9 +111,10 @@

{{itemController.item_data.Header.He}} Pictures ({{itemController.item_data.Pictures.length}} found)

diff --git a/templates/item/text_item.html b/templates/item/text_item.html index 54df24e9..67178fa5 100644 --- a/templates/item/text_item.html +++ b/templates/item/text_item.html @@ -30,17 +30,17 @@
-
+
Item Image
-
+
diff --git a/templates/main/gallery-modal.html b/templates/main/gallery-modal.html index e0ff7d61..a0dafb2f 100644 --- a/templates/main/gallery-modal.html +++ b/templates/main/gallery-modal.html @@ -5,24 +5,25 @@