This repository has been archived by the owner on Dec 16, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 22
/
top-voted.js
72 lines (65 loc) · 2.47 KB
/
top-voted.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
'use strict';
/*
global $
*/
/**
* @ngdoc function
* @name MSLImageExplorerApp.controller:TopVotedCtrl
* @description
* # TopVotedCtrl
* Controller of the MSLImageExplorerApp
*/
angular.module('MSLImageExplorerApp').
controller('TopVotedCtrl', function ($scope, $routeParams, $timeout, $location, $log, MarsPhotosDBAccess, Blueimp) {
$scope.title = 'Top Voted Mars Images';
$scope.description = 'Photos taken by sorted by # of votes by viewers.';
$scope.photos = [];
/*
* Initializes instrument in the scope according to $routeParams. It
* uses the default instrument if none specified.
*/
if ($routeParams.instrument) {
$scope.instrument = $routeParams.instrument;
} else {
$scope.instrument = MarsPhotosDBAccess.defaultInstrument;
}
$scope.mission = MarsPhotosDBAccess.defaultMission;
$scope.missionInstrument = $scope.mission + '+' + $scope.instrument;
$scope.instrumentList = MarsPhotosDBAccess.instrumentList;
/**
* Updates the location path and reloads the page. Called from the child
* controller, SideMenuCtrl.
*/
$scope.reload = function(){
var path = '/topVoted/' + $scope.instrument;
$log.debug('Updating path to ' + path);
$timeout(function(){
$scope.$apply(function(){
$location.path(path);
});
});
};
/**
* Fetches top voted photos via MarsPhotosDBAccess service and replaces
* $scope.photos with the results. It also triggers Blueimp
* image gallery to prepare for the slideshow.
*/
$scope.updatePhotos = function(){
MarsPhotosDBAccess.queryWithVoteIndex({
hashKey: $scope.missionInstrument,
lastEvaluatedKey: $scope.lastEvaluatedKey
}, function(error, data){
if (!error) {
var photos = data.Items;
$scope.lastEvaluatedKey = data.LastEvaluatedKey;
$scope.$apply(function(){
$scope.photos = photos;
});
} else {
$log.error(error);
}
});
};
$scope.updatePhotos();
Blueimp.Gallery($('#links a'), $('#blueimp-gallery').data());
});