+api gallery + gallery caching;

This commit is contained in:
tmshv committed 2015-07-08 22:06:15 +03:00
1 parent 97966817ea
commit a9a0b2c6b8
3 files changed
+38 -21

No files matched your search

+7 -2
View File
@@ -2,11 +2,16 @@
* Created by tmshv on 22/11/14.
*/
var APINews = require("./news");
var APIGallery = require("./gallery");
module.exports = function(app) {
var minute = 1000 * 60;
app.factory("api", function ($http) {
var api = {};
var Endpoint = require("./news");
api.news = new Endpoint($http);
api.news = new APINews($http);
api.gallery = new APIGallery($http, minute);
return api;
});
+22
View File
@@ -0,0 +1,22 @@
/**
* Created by tmshv on 22/11/14.
*/
function APIGallery(http){
this.request = http;
}
APIGallery.prototype.year = function(year) {
return this.request.get("/gallery/" + year, {cache: true});
};
APIGallery.prototype.album = function(year, course, album) {
var url = '/album/{year}/{course}/{album}'
.replace('{year}', year)
.replace('{course}', course)
.replace('{album}', album);
return this.request.get(url, {cache: true});
};
module.exports = APIGallery;
+9 -19
View File
@@ -28,11 +28,11 @@ module.exports = function (app) {
}
});
app.controller("GalleryPageController", function ($scope, $http) {
app.controller("GalleryPageController", function ($scope, api) {
$scope.years = [];
var years = [2015, 2014, 2013, 2012, 2011, 2010];
years.forEach(function (year, year_index) {
$http.get("/gallery/" + year)
api.gallery.year(year)
.success(function (albums) {
if(albums.length) {
$scope.years[year_index] = {
@@ -48,29 +48,19 @@ module.exports = function (app) {
}
})
});
//$http.get("/gallery")
// .success(function (albums) {
// $scope.albums = albums.map(function (album) {
// var preview = album.content[0];
// album.preview_url = preview.content.medium.url;
// album.fotorama = album.content.map(productToFotorama);
//
// return album;
// });
// });
}
);
app.controller("AlbumPageController", function ($scope, $http, $routeParams, $compile) {
var url = '/album/{year}/{course}/{album}'
.replace('{year}', $routeParams.year)
.replace('{course}', $routeParams.course)
.replace('{album}', $routeParams.album);
$http.get(url)
app.controller("AlbumPageController", function ($scope, $http, $routeParams, api) {
api.gallery.album(
$routeParams.year,
$routeParams.course,
$routeParams.album
)
.success(function (album) {
var preview = album.content[0];
album.preview_url = preview.content.medium.url;
album.fotorama = album.content.map(productToFotorama);
//album.fotorama = album.content.map(productToFotorama);
$scope.album = album;
});