diff --git a/assets/style/gallery.scss b/assets/style/gallery.scss index 84486fd7..cc7fb114 100644 --- a/assets/style/gallery.scss +++ b/assets/style/gallery.scss @@ -1,9 +1,32 @@ +//.gallery-block { +// margin: 2em 0 0; +// display: flex; +// justify-content: center; +// flex-wrap: wrap; +// align-items: flex-start; +//} + .gallery-block { margin: 2em 0 0; - display: flex; - justify-content: center; - flex-wrap: wrap; - align-items: flex-start; + display: block; +} + +.gallery-period{ + margin-bottom: 2em; + + & > div{ + margin: 1.5em 0 0; + display: flex; + justify-content: center; + flex-wrap: wrap; + align-items: flex-start; + } + + p.period{ + text-align: center; + font-size: 1.5em; + font-weight: bold; + } } .gallery-album { diff --git a/client/app.js b/client/app.js index 8f18b89e..c87266cd 100644 --- a/client/app.js +++ b/client/app.js @@ -40,7 +40,7 @@ app.config(function ($locationProvider, $routeProvider) { title:"Работы учащихся" }, { - name: "/gallery/:year/:course/:album", + name: "/album/:year/:course/:album", templateUrl: "/views/gallery-album.html", controller: "AlbumPageController", title:"Работы учащихся" diff --git a/client/pages/gallery.js b/client/pages/gallery.js index 8466275d..a10be5d4 100644 --- a/client/pages/gallery.js +++ b/client/pages/gallery.js @@ -1,8 +1,8 @@ module.exports = function (app) { - app.directive("gFotorama", function(){ + app.directive("gFotorama", function () { return { restrict: "A", - link: function(scope, element, attrs){ + link: function (scope, element, attrs) { element.addClass('fotorama'); var fotorama = $(element.fotorama()).data('fotorama'); fotorama.setOptions({ @@ -12,7 +12,7 @@ module.exports = function (app) { nav: "thumbs" }); - scope.$watch(attrs.gFotorama, function (value){ + scope.$watch(attrs.gFotorama, function (value) { console.log(value); fotorama.load(value); }); @@ -21,20 +21,40 @@ module.exports = function (app) { }); app.controller("GalleryPageController", function ($scope, $http) { - $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); + $scope.years = []; + var years = [2015, 2014, 2013, 2012, 2011, 2010]; + years.forEach(function (year, year_index) { + $http.get("/gallery/" + year) + .success(function (albums) { + if(albums.length) { + $scope.years[year_index] = { + year: year, + 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; - }); + return album; + }) + }; + } + }) }); - }); + //$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) { - var url = '/gallery/{year}/{course}/{album}' + var url = '/album/{year}/{course}/{album}' .replace('{year}', $routeParams.year) .replace('{course}', $routeParams.course) .replace('{album}', $routeParams.album); @@ -47,7 +67,8 @@ module.exports = function (app) { $scope.album = album; }); }); -}; +} +; function productToFotorama(product) { return { diff --git a/routes/gallery.js b/routes/gallery.js index 58531f84..2c764ef9 100644 --- a/routes/gallery.js +++ b/routes/gallery.js @@ -22,7 +22,26 @@ module.exports = function (app) { } }))); - app.use(route.get("/gallery/:year/:course/:album", router.accepts({ + app.use(route.get("/gallery/:year", router.accepts({ + "text/html": router.index(), + "text/plain": router.index(), + "application/json": function *(year) { + year = parseInt(year); + var start = new Date(year, 0, 1); + var end = new Date(year, 11, 31); + var query = { + date: {$gte: start, $lt: end} + }; + var albums = yield db.c("albums") + .find(query) + .toArray(); + + albums = yield albums.map(processAlbum); + this.body = albums; + } + }))); + + app.use(route.get("/album/:year/:course/:album", router.accepts({ "text/html": router.index(), "text/plain": router.index(), "application/json": function *(year, course, album) { @@ -46,7 +65,7 @@ module.exports = function (app) { function processAlbum(album) { return co(function *() { - album.url = '/gallery/{year}{course}{album}' + album.url = '/album/{year}{course}{album}' .replace('{year}', album.date.getFullYear()) .replace('{course}', album.course_uri) .replace('{album}', album.uri); diff --git a/templates/views/gallery.html b/templates/views/gallery.html index 50888c09..c51a8056 100644 --- a/templates/views/gallery.html +++ b/templates/views/gallery.html @@ -1,10 +1,22 @@