diff --git a/client/api/api.js b/client/api/api.js index 18d7fc3f..c51f7292 100644 --- a/client/api/api.js +++ b/client/api/api.js @@ -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; }); diff --git a/client/api/gallery.js b/client/api/gallery.js new file mode 100644 index 00000000..12d90903 --- /dev/null +++ b/client/api/gallery.js @@ -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; \ No newline at end of file diff --git a/client/pages/gallery.js b/client/pages/gallery.js index a8942158..1221da84 100644 --- a/client/pages/gallery.js +++ b/client/pages/gallery.js @@ -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; });