diff --git a/assets/style/gallery.scss b/assets/style/gallery.scss new file mode 100644 index 00000000..a43f0262 --- /dev/null +++ b/assets/style/gallery.scss @@ -0,0 +1,21 @@ +.gallery-block { + width: 90%; + margin: 0 auto; + display: flex; + justify-content: center; + flex-wrap: wrap; + align-items: flex-start; +} + +.gallery-album { + margin: 0 20px 30px; +} + +.gallery-album img { + max-width: 400px; +} + +.album-block { + width: 70%; + margin: 0 auto; +} \ No newline at end of file diff --git a/assets/style/main.scss b/assets/style/main.scss index 5116106d..b5cef3b6 100644 --- a/assets/style/main.scss +++ b/assets/style/main.scss @@ -20,6 +20,24 @@ a:active { border-bottom: 1px solid rgb(63, 156, 234); } +h3 a{ + color: black; + text-decoration: none; + border-bottom: 1px solid #ddd; + + &:hover { + border-bottom: 1px solid #484848; + } + + &:active { + border-bottom: 1px solid #000000; + } +} + +a.invisible { + border-bottom: none; +} + ul.submenu { list-style: none; display: inline-block; diff --git a/assets/style/menu.scss b/assets/style/menu.scss index c7056c27..34ec70d8 100644 --- a/assets/style/menu.scss +++ b/assets/style/menu.scss @@ -59,6 +59,10 @@ &.pink { border-top: 4px solid #f655a0; } + + &.red { + border-top: 4px solid #f61b14; + } } } diff --git a/client/app.js b/client/app.js index e76ad482..8f18b89e 100644 --- a/client/app.js +++ b/client/app.js @@ -33,6 +33,18 @@ app.config(function ($locationProvider, $routeProvider) { controller: "TeamPageController", title:"Преподаватели" }, + { + name: "/gallery", + templateUrl: "/views/gallery.html", + controller: "GalleryPageController", + title:"Работы учащихся" + }, + { + name: "/gallery/:year/:course/:album", + templateUrl: "/views/gallery-album.html", + controller: "AlbumPageController", + title:"Работы учащихся" + }, { name: "/docs", templateUrl: "/views/docs.html", @@ -76,6 +88,7 @@ require("./filters/uppercase-first")(app); require("./pages/home")(app); require("./pages/schedule")(app); require("./pages/team")(app); +require("./pages/gallery")(app); require("./pages/docs")(app); app.controller("SchedulePageController", function ($scope) { diff --git a/client/pages/gallery.js b/client/pages/gallery.js new file mode 100644 index 00000000..8466275d --- /dev/null +++ b/client/pages/gallery.js @@ -0,0 +1,58 @@ +module.exports = function (app) { + app.directive("gFotorama", function(){ + return { + restrict: "A", + link: function(scope, element, attrs){ + element.addClass('fotorama'); + var fotorama = $(element.fotorama()).data('fotorama'); + fotorama.setOptions({ + width: "100%", + maxheight: 500, + loop: true, + nav: "thumbs" + }); + + scope.$watch(attrs.gFotorama, function (value){ + console.log(value); + fotorama.load(value); + }); + } + } + }); + + 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); + + return album; + }); + }); + }); + + app.controller("AlbumPageController", function ($scope, $http, $routeParams) { + var url = '/gallery/{year}/{course}/{album}' + .replace('{year}', $routeParams.year) + .replace('{course}', $routeParams.course) + .replace('{album}', $routeParams.album); + $http.get(url) + .success(function (album) { + var preview = album.content[0]; + album.preview_url = preview.content.medium.url; + album.fotorama = album.content.map(productToFotorama); + + $scope.album = album; + }); + }); +}; + +function productToFotorama(product) { + return { + img: product.content["big"].url, + thumb: product.content["small"].url, + full: product.content["original"].url + } +} \ No newline at end of file diff --git a/gulpfile.js b/gulpfile.js index 88b5a916..d588184f 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -34,7 +34,7 @@ gulp.task("compile", function(){ .pipe(browserify({ transform: [annotate] })) - .pipe(uglify()) + //.pipe(uglify()) .pipe(gulp.dest("public")); gulp.src("client/document.js") diff --git a/models/menu.json b/models/menu.json index a9ce2451..00b49f0b 100644 --- a/models/menu.json +++ b/models/menu.json @@ -21,7 +21,8 @@ }, { "text": "Галерея", - "color": "" + "url": "/gallery", + "color": "red" }, { "text": "Документы", diff --git a/routes/gallery.js b/routes/gallery.js new file mode 100644 index 00000000..58531f84 --- /dev/null +++ b/routes/gallery.js @@ -0,0 +1,64 @@ +/** + * Created by tmshv on 22/11/14. + */ + +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 *() { + var query = {}; + var albums = yield db.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) { + year = parseInt(year); + course = '/' + course; + album = '/' + album; + var start = new Date(year, 0, 1); + var end = new Date(year, 11, 31); + var 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; + } + }))); +}; + +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); + + 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; + }); + }); + + return album; + }); +} \ No newline at end of file diff --git a/server.js b/server.js index 0402d8ee..152df729 100644 --- a/server.js +++ b/server.js @@ -54,6 +54,7 @@ app.use(route.get("/document/:doc", routes.index( require("./routes/schedule")(app); require("./routes/news")(app); +require("./routes/gallery")(app); require("./routes/404")(app); diff --git a/templates/views/gallery-album.html b/templates/views/gallery-album.html new file mode 100644 index 00000000..3d7dfc0f --- /dev/null +++ b/templates/views/gallery-album.html @@ -0,0 +1,4 @@ +
+

{{album.title}}

+
+
diff --git a/templates/views/gallery.html b/templates/views/gallery.html new file mode 100644 index 00000000..1ac1a2d7 --- /dev/null +++ b/templates/views/gallery.html @@ -0,0 +1,9 @@ +