diff --git a/src/client/api/APIGallery.js b/src/client/api/APIGallery.js index 262edecc..e124cfe9 100644 --- a/src/client/api/APIGallery.js +++ b/src/client/api/APIGallery.js @@ -1,7 +1,3 @@ -/** - * Created by tmshv on 22/11/14. - */ - import EndPoint from './EndPoint'; export default class APIGallery extends EndPoint { @@ -9,8 +5,8 @@ export default class APIGallery extends EndPoint { return this.request.get(`/gallery/${year}`, {cache: true}); } - album(year, course, album) { - let url = `/gallery/${year}/${course}/${album}`; + album(year, course, album, doPopulate) { + let url = `/gallery/${year}/${course}/${album}?populate=${doPopulate}`; return this.request.get(url, {cache: true}); } } diff --git a/src/client/controllers/AlbumController.js b/src/client/controllers/AlbumController.js index 30980dcb..c34c6a5e 100644 --- a/src/client/controllers/AlbumController.js +++ b/src/client/controllers/AlbumController.js @@ -1,5 +1,5 @@ export default function (app) { - app.controller('AlbumController', ($scope, $rootScope, $http, $routeParams, team, api, menu) => { + app.controller('AlbumController', ($scope, $rootScope, $http, $routeParams, api, menu) => { menu.activate('/gallery'); let year_uri = $routeParams.year; @@ -8,7 +8,8 @@ export default function (app) { api.gallery.album(year_uri, course_uri, album_uri) .success(album => { - album.teacherName = team.name(album['teacher']); + //album.teacherName = team.name(album['teacher']); + album.teacherName = album['teacher']; $scope.album = album; $scope.crumbs = [ diff --git a/src/routes/gallery.js b/src/routes/gallery.js index 544e8d88..78a659c6 100644 --- a/src/routes/gallery.js +++ b/src/routes/gallery.js @@ -1,83 +1,72 @@ -/** - * Created by tmshv on 22/11/14. - */ +import co from 'co'; +import route from 'koa-route'; +import {c} from '../core/db'; +import {json} from './'; -var co = require("co"); -var route = require("koa-route"); -var router = require("./"); -var db = require("../core/db"); - -module.exports = function (app) { - app.use(route.get("/gallery", router.accepts({ - "text/html": router.index(), - "text/plain": router.index(), - "application/json": function *() { +export default function (app) { + app.use(route.get('/gallery', json( + function *() { var query = {}; - var albums = yield db.c("albums") + var albums = yield c('albums') .find(query) .toArray(); albums = yield albums.map(processAlbum); this.body = albums; } - }))); + ))); - app.use(route.get("/gallery/:year", router.accepts({ - "text/html": router.index(), - "text/plain": router.index(), - "application/json": function *(year) { + app.use(route.get('/gallery/:year', json( + function *(year) { year = parseInt(year); - var start = new Date(year, 0, 1); - var end = new Date(year, 11, 31); - var query = { + let start = new Date(year, 0, 1); + let end = new Date(year, 11, 31); + let query = { date: {$gte: start, $lt: end} }; - var albums = yield db.c("albums") + let albums = yield c('albums') .find(query) .toArray(); albums = yield albums.map(processAlbum); this.body = albums; } - }))); + ))); - app.use(route.get("/gallery/:year/:course/:album", router.accepts({ - "text/html": router.index(), - "text/plain": router.index(), - "application/json": function *(year, course, album) { + app.use(route.get('/gallery/:year/:course/:album', json( + function *(year, course, album) { year = parseInt(year); course = '/' + course; album = '/' + album; - var start = new Date(year, 0, 1); - var end = new Date(year, 11, 31); - var query = { + let start = new Date(year, 0, 1); + let end = new Date(year, 11, 31); + let query = { date: {$gte: start, $lt: end}, course_uri: course, uri: album }; - var a = yield db.c("albums").findOne(query); - a = yield processAlbum(a); - this.body = a; + let record = yield c('albums').findOne(query); + record = yield processAlbum(record); + this.body = record; } - }))); + ))); }; -function processAlbum(album) { - return co(function *() { - album.url = '/gallery/{year}{course}{album}' - .replace('{year}', album.date.getFullYear()) - .replace('{course}', album.course_uri) - .replace('{album}', album.uri); +let processAlbum = album => co(function *() { + album.url = `/gallery/{year}{course}{album}` + .replace('{year}', album.date.getFullYear()) + .replace('{course}', album.course_uri) + .replace('{album}', album.uri); - album.content = yield album.content.map(function (product_id) { - return co(function *() { - var product = yield db.c("products").findOne({_id: product_id}); - if (product) return product; - else return null; - }); - }); + album.content = yield album.content.map(product_id => co(function *() { + let product = yield c('products').findOne({_id: product_id}); + if (product) return product; + else return null; + })); - return album; - }); -} \ No newline at end of file + let teacher = yield c('collective').findOne({id: album.teacher}); + album.teacher = teacher.name; + + return album; +}); \ No newline at end of file