File size: 2,535 Bytes
5893f8f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
/**
 * Each section of the site has its own module. It probably also has
 * submodules, though this boilerplate is too simple to demonstrate it. Within
 * `src/app/gallery`, however, could exist several additional folders representing
 * additional modules that would then be listed as dependencies of this one.
 * For example, a `note` section could have the submodules `note.create`,
 * `note.delete`, `note.edit`, etc.
 *
 * Regardless, so long as dependencies are managed correctly, the build process
 * will automatically take take of the rest.
 *
 * The dependencies block here is also where component dependencies should be
 * specified, as shown below.
 */
angular.module( 'dash.gallery', [
		'ui.router',
		'angular-hal'
])

/**
 * Each section or module of the site can also have its own routes. AngularJS
 * will handle ensuring they are all available at run-time, but splitting it
 * this way makes each module more "self-contained".
 */
.config(function config( $stateProvider ) {
	$stateProvider.state( 'gallery', {
		url: '/gallery',
		views: {
			"main": {
				controller: 'GalleryCtrl',
				templateUrl: 'gallery/gallery.tpl.html'
			}
		},
		data:{ pageTitle: 'Gallery' }
	});
})

/**
 * And of course we define a controller for our route.
 */
.controller( 'GalleryCtrl', function GalleryController( $scope, GalleryApi, $q, $modal ) {

	GalleryApi.albums()
		.then( function( albums ) {
//			console.log(GalleryApi);
//			console.log(albums);
			$scope.albums = albums;
		})
	;

	$scope.loadAlbum = function(album) {
		$scope.selected = album;
		album.$get('images')
			.then(function(images) {
				$scope.images = images.map( function( image ) {
					image.href = image.$href('medium');
					image.thumb = image.$href('thumb');
					return image; 
				});
			});

	};

	$scope.open = function (image, images) {

		var modalInstance = $modal.open({
			resolve: { 
				images: function() { 
					return images.map(function(img) { 
						img.active = img === image ? true : false;
						return img;
					});
				}
			},
			templateUrl: 'lightbox-modal.html',
			controller: 'ModalInstanceCtrl'
		}); 
	};

}).controller( 'ModalInstanceCtrl', function ( $scope, images ) {
	$scope.images = images;
})


.factory( 'GalleryApi', function ( $http, halClient ) {

//	console.log(halClient);

	var apiFactory = 
	{

		load: function() { return halClient.$get('/gallery/api'); },

		albums: function() {
			return apiFactory.load()
				.then(function(api) { return api.$get('albums'); });
		}

	};

	return apiFactory;
})

;