Skip to content

Commit

Permalink
Use image_url from API response
Browse files Browse the repository at this point in the history
  • Loading branch information
Inna-r committed May 24, 2017
1 parent 90c6b14 commit 8bc1b59
Show file tree
Hide file tree
Showing 7 changed files with 69 additions and 74 deletions.
1 change: 1 addition & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@
<script src="/js/modules/main/src/directives/fudgedYearDirective.js"></script>
<script src="/js/modules/main/src/directives/fitThumbDirective.js"></script>
<script src="/js/modules/main/src/directives/filtersFieldDirective.js"></script>
<script src="/js/modules/main/src/directives/fallbackSrcDirective.js"></script>
<script src="/js/modules/main/src/directives/draggableDirective.js"></script>
<script src="/js/modules/main/src/directives/defaultFocusDirective.js"></script>
<script src="/js/modules/main/src/directives/alterUsernameDirective.js"></script>
Expand Down
24 changes: 5 additions & 19 deletions js/modules/main/src/controllers/galleryModalCtrl.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
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;

$scope.isActive = function (index) {
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;
Expand All @@ -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]);
41 changes: 19 additions & 22 deletions js/modules/main/src/controllers/itemCtrl.js
Original file line number Diff line number Diff line change
Expand Up @@ -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});
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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) {
Expand All @@ -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',
Expand All @@ -231,7 +234,10 @@ ItemCtrl.prototype = {
resolve : {
gallery: function () {
return gallery
},
},
sorted_pictures: function () {
return sorted_pictures;
},
index: function () {
return index
}
Expand Down Expand Up @@ -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() {
Expand Down
18 changes: 18 additions & 0 deletions js/modules/main/src/directives/fallbackSrcDirective.js
Original file line number Diff line number Diff line change
@@ -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);
}
});
}
}
});
28 changes: 10 additions & 18 deletions templates/item/photoUnits.html
Original file line number Diff line number Diff line change
Expand Up @@ -29,25 +29,16 @@
<div printSection class="item__content">
<div class="item__content__media-container"
ng-class="{'item__content__media-container--photoUnit': itemController.item_type === 'photoUnits'}">
<div ng-repeat="pic in itemController.sort_pictures()" ng-switch on="pic.PictureId != undefined">
<img ng-switch-when="true"
class="picture"
<div ng-repeat="pic in itemController.sorted_pictures">
<img class="picture"
fallback-src="images/digitization-{{itemController.lang}}.jpg"
ng-show="itemController.isActive($index)"
ng-src="https://storage.googleapis.com/bhs-flat-pics/{{pic.PictureId}}.jpg"
ng-src="{{pic.PictureUrl}}"
ng-click="itemController.open_gallery()"
prevent-rightclick
fit-thumb>

<a ng-switch-when="false"
ng-href="{{itemController.lang=='en'?'http://www.bh.org.il/about-us/volunteering/':'http://www.bh.org.il/he/%D7%90%D7%95%D7%93%D7%95%D7%AA%D7%99%D7%A0%D7%95/%D7%94%D7%AA%D7%A0%D7%93%D7%91%D7%95%D7%AA-2/'}}"
target="blank">
<img class="picture notdigitized"
ng-show="itemController.isActive($index)"
ng-src="images/digitization-{{itemController.lang}}.jpg"
prevent-rightclick>
</a>
fit-thumb/>
</div>
<div class="arrows" ng-if="itemController.item_data.Pictures.length > 1">
<div class="arrows" ng-if="itemController.sorted_pictures.length > 1">
<div class="arrow-left" ng-click="itemController.showPrev()"></div>
<div class="arrow-right" ng-click="itemController.showNext()"></div>
</div>
Expand Down Expand Up @@ -120,9 +111,10 @@ <h1 class="item__article-header">
<he>{{itemController.item_data.Header.He}} Pictures ({{itemController.item_data.Pictures.length}} found)</he>
</div>
<ul class="gallery-modal__info__gallery-preview__minified-picture">
<li ng-repeat="pic in itemController.sort_pictures()" ng-class="{'active':itemController.isActive($index)}" ng-hide="isHidden($index)">
<img ng-src="{{pic.PictureId == undefined ? 'images/digitization-sm-'+itemController.lang+'.jpg' : 'https://storage.googleapis.com/bhs-flat-pics/'+pic.PictureId+'.jpg' }}"
ng-click="itemController.showPhoto($index)"/>
<li ng-repeat="pic in itemController.sorted_pictures" ng-class="{'active':itemController.isActive($index)}" ng-hide="isHidden($index)">
<img fallback-src="images/digitization-sm-{{itemController.lang}}.jpg"
ng-src="{{pic.PictureUrl}}"
ng-click="itemController.showPhoto($index)"/>
</li>
</ul>
</div>
Expand Down
8 changes: 4 additions & 4 deletions templates/item/text_item.html
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,17 @@
<div id="printSection" class="item__content">
<div class="item__content__media-container"
ng-if="itemController.item_data.main_image_url">
<div class="main-img-wrapper" ng-class="{'main-img-wrapper--display-more': itemController.item_data.Pictures.length > 1}">
<div class="main-img-wrapper" ng-class="{'main-img-wrapper--display-more': itemController.sorted_pictures.length > 1}">
<img class="picture"
ng-class="{'picture--display-more': itemController.item_data.Pictures.length > 1}"
ng-class="{'picture--display-more': itemController.sorted_pictures.length > 1}"
ng-src="{{itemController.item_data.main_image_url}}"
alt="Item Image"
ng-click="itemController.open_gallery(itemController.get_main_pic_index())"
prevent-rightclick/>
</div>
<div class="add-img-wrapper" ng-if="itemController.item_data.Pictures.length > 1">
<div class="add-img-wrapper" ng-if="itemController.sorted_pictures.length > 1">
<img class="picture"
ng-class="{'picture--display-more': itemController.item_data.Pictures.length > 1}"
ng-class="{'picture--display-more': itemController.sorted_pictures.length > 1}"
ng-click="itemController.open_gallery(itemController.get_additional_pic_index())"
ng-src="{{itemController.get_additional_pic_url()}}"
prevent-rightclick>
Expand Down
23 changes: 12 additions & 11 deletions templates/main/gallery-modal.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,25 @@
<icon class="xsign" position="[-224, -333]" ng-click="dismiss()"></icon>
</div>
<div class="gallery-modal__stage noselect">
<div ng-repeat="pic in sort_pictures()" ng-switch on="pic.PictureId != undefined">
<img ng-switch-when="true"
ng-show="isActive($index)"
ng-src="https://storage.googleapis.com/bhs-flat-pics/{{pic.PictureId}}.jpg"
<div ng-repeat="pic in sorted_pictures">
<img ng-show="isActive($index)"
fallback-src="images/digitization-{{lang}}.jpg"
ng-src="{{pic.PictureUrl}}"
alt="More Images"
fit-thumb
prevent-rightclick/>
<a ng-switch-default
<!-- TODO : add link to fallback image
<a ng-switch-default
ng-href="{{lang=='en'?'http://www.bh.org.il/about-us/volunteering/':'http://www.bh.org.il/he/%D7%90%D7%95%D7%93%D7%95%D7%AA%D7%99%D7%A0%D7%95/%D7%94%D7%AA%D7%A0%D7%93%D7%91%D7%95%D7%AA-2/'}}"
target="blank">
<img class="picture notdigitized"
ng-show="isActive($index)"
ng-src="images/digitization-{{lang}}.jpg"
prevent-rightclick>
</a>
</a> -->
</div>

<div class="arrows" ng-if="gallery.Pictures.length > 1">
<div class="arrows" ng-if="sorted_pictures.length > 1">
<div class="arrow-left" ng-click="showPrev()"></div>
<div class="arrow-right" ng-click="showNext()"></div>
</div>
Expand All @@ -47,12 +48,12 @@
</div>
<div class="gallery-modal__info__gallery-preview">
<div class="gallery-modal__info__gallery-preview__title">
<en>{{gallery.Header.En}} ({{gallery.Pictures.length}} Pictures found)</en>
<he>{{gallery.Header.He}} ({{gallery.Pictures.length}} תמונות נמצאו)</he>
<en>{{gallery.Header.En}} ({{sorted_pictures.length}} Pictures found)</en>
<he>{{gallery.Header.He}} ({{sorted_pictures.length}} תמונות נמצאו)</he>
</div>
<ul class="gallery-modal__info__gallery-preview__minified-picture">
<li ng-repeat="pic in sort_pictures()" ng-class="{'active':isActive($index)}">
<img ng-src="{{pic.PictureId == undefined ? 'images/digitization-sm-'+lang+'.jpg' : 'https://storage.googleapis.com/bhs-flat-pics/'+pic.PictureId+'.jpg' }}"
<li ng-repeat="pic in sorted_pictures" ng-class="{'active':isActive($index)}">
<img fallback-src="images/digitization-sm-{{lang}}.jpg" ng-src="{{pic.PictureUrl}}"
ng-click="showPhoto($index)"/>
</li>
</ul>
Expand Down

0 comments on commit 8bc1b59

Please sign in to comment.