FUCKING BIG UPDATE: server, parallax, apis, new data models, style, layout, other
This commit is contained in:
1 parent
e0f54171a9
commit
359cc430f5
78 files changed
+1063
-445
No files matched your search
@@ -19,7 +19,7 @@ export default function (app) {
|
||||
function *(type) {
|
||||
let types = {
|
||||
'document': ['documents', {type: 'document'}, populateDocPreview],
|
||||
'award': ['awards', {}]
|
||||
'award': ['awards', {}, populateDocPreview]
|
||||
};
|
||||
|
||||
if (type in types) {
|
||||
|
||||
+10
-1
@@ -1,14 +1,23 @@
|
||||
import route from 'koa-route';
|
||||
import {c} from '../core/db';
|
||||
import {json} from './';
|
||||
import {sortBy} from '../utils/sort';
|
||||
|
||||
export default function (app) {
|
||||
let sortByDate = sortBy(
|
||||
i => (new Date(i.date))
|
||||
.getTime()
|
||||
);
|
||||
|
||||
app.use(route.get('/events', json(
|
||||
function *() {
|
||||
let query = {};
|
||||
this.body = yield c('events')
|
||||
let events = yield c('events')
|
||||
.find(query)
|
||||
.toArray();
|
||||
|
||||
this.body = events
|
||||
.sort(sortByDate);
|
||||
}
|
||||
)));
|
||||
|
||||
|
||||
+61
-41
@@ -6,47 +6,62 @@ import {json} from './';
|
||||
export default function (app) {
|
||||
app.use(route.get('/gallery', json(
|
||||
function *() {
|
||||
var query = {};
|
||||
var albums = yield c('albums')
|
||||
.find(query)
|
||||
.toArray();
|
||||
let query = {};
|
||||
let fields = ['_id', 'id', 'title', 'date'];
|
||||
//.reduce((f, i) => {
|
||||
// f[i] = 1;
|
||||
// return f;
|
||||
//}, {});
|
||||
|
||||
albums = yield albums.map(processAlbum);
|
||||
this.body = albums;
|
||||
}
|
||||
)));
|
||||
|
||||
app.use(route.get('/gallery/:year', json(
|
||||
function *(year) {
|
||||
year = parseInt(year);
|
||||
let start = new Date(year, 0, 1);
|
||||
let end = new Date(year, 11, 31);
|
||||
let query = {
|
||||
date: {$gte: start, $lt: end}
|
||||
};
|
||||
let albums = yield c('albums')
|
||||
.find(query)
|
||||
.toArray();
|
||||
|
||||
//albums = albums.map(i => {
|
||||
// return fields.reduce((a, key)=> {
|
||||
// a[key] = i[key];
|
||||
// return a;
|
||||
// }, {});
|
||||
//});
|
||||
|
||||
albums = yield albums.map(processAlbum);
|
||||
this.body = albums;
|
||||
}
|
||||
)));
|
||||
|
||||
app.use(route.get('/gallery/:year/:course/:album', json(
|
||||
function *(year, course, album) {
|
||||
year = parseInt(year);
|
||||
course = '/' + course;
|
||||
album = '/' + album;
|
||||
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
|
||||
};
|
||||
//app.use(route.get('/gallery/:year', json(
|
||||
// function *(year) {
|
||||
// year = parseInt(year);
|
||||
// let start = new Date(year, 0, 1);
|
||||
// let end = new Date(year, 11, 31);
|
||||
// let query = {
|
||||
// date: {$gte: start, $lt: end}
|
||||
// };
|
||||
// let albums = yield c('albums')
|
||||
// .find(query)
|
||||
// .toArray();
|
||||
//
|
||||
// albums = yield albums.map(processAlbum);
|
||||
// this.body = albums;
|
||||
// }
|
||||
//)));
|
||||
|
||||
let record = yield c('albums').findOne(query);
|
||||
app.use(route.get('/album/:id', json(
|
||||
function *(id) {
|
||||
//year = parseInt(year);
|
||||
//course = '/' + course;
|
||||
//album = '/' + album;
|
||||
//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
|
||||
//};
|
||||
|
||||
let record = yield c('albums').findOne({
|
||||
id: id
|
||||
});
|
||||
record = yield processAlbum(record);
|
||||
this.body = record;
|
||||
}
|
||||
@@ -54,19 +69,24 @@ export default function (app) {
|
||||
};
|
||||
|
||||
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.url = `/gallery/{year}{course}{album}`
|
||||
// .replace('{year}', album.date.getFullYear())
|
||||
// .replace('{course}', album.course_uri)
|
||||
// .replace('{album}', album.uri);
|
||||
album.url = `/album/${album.id}`;
|
||||
|
||||
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;
|
||||
}));
|
||||
//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;
|
||||
//}));
|
||||
|
||||
let teacher = yield c('collective').findOne({id: album.teacher});
|
||||
album.teacher = teacher.name;
|
||||
//let teacher = yield c('collective').findOne({id: album.teacher});
|
||||
//album.teacher = teacher.name;
|
||||
|
||||
let previewImageId = album.images[0];
|
||||
let image = yield c('images').findOne({_id: previewImageId});
|
||||
album.preview = image.data.medium;
|
||||
|
||||
return album;
|
||||
});
|
||||
+2
-7
@@ -2,14 +2,9 @@ import path from 'path';
|
||||
import fs from 'mz/fs';
|
||||
import config from '../config';
|
||||
|
||||
export function queryObject(){
|
||||
let assign = (dict, key, value) => {
|
||||
dict[key] = value;
|
||||
return dict;
|
||||
};
|
||||
let map = (v, fn) =>
|
||||
value => fn(value) ? v : value;
|
||||
import {map, assign} from '../utils/common';
|
||||
|
||||
export function queryObject() {
|
||||
let toTrue = map(true, i => i === 'true');
|
||||
let toFalse = map(false, i => i === 'false');
|
||||
const processors = [toTrue, toFalse];
|
||||
|
||||
+50
-62
@@ -1,78 +1,75 @@
|
||||
/**
|
||||
* Created by tmshv on 22/11/14.
|
||||
*/
|
||||
import route from 'koa-route';
|
||||
import {accepts, index} from './';
|
||||
import {c} from '../core/db';
|
||||
import {sortBy} from '../utils/sort';
|
||||
|
||||
var route = require("koa-route");
|
||||
var router = require("./");
|
||||
var db = require("../core/db");
|
||||
export default function (app) {
|
||||
let sortNewsByDate = sortBy(
|
||||
i => (new Date(i.date))
|
||||
.getTime()
|
||||
);
|
||||
|
||||
module.exports = function (app) {
|
||||
app.use(route.get("/news", router.accepts({
|
||||
"text/html": function *() {
|
||||
this.redirect("/");
|
||||
app.use(route.get('/news', accepts({
|
||||
'text/html': function *() {
|
||||
this.redirect('/');
|
||||
},
|
||||
"text/plain": function *() {
|
||||
this.redirect("/");
|
||||
'text/plain': function *() {
|
||||
this.redirect('/');
|
||||
},
|
||||
"application/json": function *() {
|
||||
var count = parseInt(this.query["count"]) || 10;
|
||||
var portion = parseInt(this.query["portion"]) || 0;
|
||||
var skip = portion * count;
|
||||
'application/json': function *() {
|
||||
let limit = parseInt(this.query['limit']) || 10;
|
||||
let skip = parseInt(this.query['skip']) || 0;
|
||||
|
||||
var query = {};
|
||||
let query = {};
|
||||
if (this.query.type) query.type = this.query.type;
|
||||
|
||||
var pinned = [];
|
||||
if(portion == 0) {
|
||||
var now = new Date();
|
||||
pinned = yield db.c("posts").find({until: {$gte: now}}).toArray()
|
||||
.then(function (items) {
|
||||
return items.sort(sortNewsByDate);
|
||||
});
|
||||
let pinned = [];
|
||||
if(skip == 0) {
|
||||
const now = new Date();
|
||||
pinned = yield c('timeline')
|
||||
.find({until: {$gte: now}})
|
||||
.toArray()
|
||||
.then(i => i.sort(sortNewsByDate));
|
||||
}
|
||||
var pinned_ids = pinned.map(function (p) {
|
||||
return p["_id"]+"";
|
||||
});
|
||||
|
||||
var posts = yield db.c("posts").find(query)
|
||||
let sid = id => id + '';
|
||||
let pinnedIds = pinned.map(p => sid(p['_id']));
|
||||
|
||||
let posts = yield c('timeline')
|
||||
.find(query)
|
||||
.sort({date: -1})
|
||||
.skip(skip)
|
||||
.limit(count)
|
||||
.limit(limit)
|
||||
.toArray()
|
||||
.then(function (items) {
|
||||
return items.filter(function (i) {
|
||||
var id = i["_id"]+"";
|
||||
return pinned_ids.indexOf(id) < 0;
|
||||
});
|
||||
});
|
||||
.then(items => items.filter(
|
||||
i => pinnedIds.indexOf(sid(i['_id'])) < 0
|
||||
));
|
||||
|
||||
this.body = pinned.concat(posts);
|
||||
//this.body = pinned_ids
|
||||
}
|
||||
})));
|
||||
|
||||
app.use(route.get("/news/pinned", router.accepts({
|
||||
"text/html": function *() {
|
||||
this.redirect("/");
|
||||
app.use(route.get('/news/pinned', accepts({
|
||||
'text/html': function *() {
|
||||
this.redirect('/');
|
||||
},
|
||||
"text/plain": function *() {
|
||||
this.redirect("/");
|
||||
'text/plain': function *() {
|
||||
this.redirect('/');
|
||||
},
|
||||
"application/json": function *() {
|
||||
var now = new Date();
|
||||
var pinned = yield db.c("posts").find({until: {$gte: now}}).toArray()
|
||||
.then(function (items) {
|
||||
return items.sort(sortNewsByDate);
|
||||
});
|
||||
this.body = pinned;
|
||||
'application/json': function *() {
|
||||
let now = new Date();
|
||||
this.body = yield c('timeline')
|
||||
.find({until: {$gte: now}})
|
||||
.toArray()
|
||||
.then(i => i.sort(sortNewsByDate));
|
||||
}
|
||||
})));
|
||||
|
||||
app.use(route.get("/news/:uri", router.accepts({
|
||||
"text/html": router.index(),
|
||||
"text/plain": router.index(),
|
||||
"application/json": function *(uri) {
|
||||
var item = yield db.c("posts").findOne({uri: uri});
|
||||
app.use(route.get('/news/:id', accepts({
|
||||
'text/html': index(),
|
||||
'text/plain': index(),
|
||||
'application/json': function *(id) {
|
||||
let item = yield c('timeline').findOne({uri: id});
|
||||
if (item) {
|
||||
this.body = item;
|
||||
} else {
|
||||
@@ -81,12 +78,3 @@ module.exports = function (app) {
|
||||
}
|
||||
})));
|
||||
};
|
||||
|
||||
function sortNewsByDate(i1, i2) {
|
||||
var t1 = new Date(i1.date).getTime();
|
||||
var t2 = new Date(i2.date).getTime();
|
||||
|
||||
if (t1 < t2) return 1;
|
||||
if (t1 > t2) return -1;
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
import co from 'co';
|
||||
import route from 'koa-route';
|
||||
import {index, json} from './';
|
||||
import {sortByPattern} from '../utils/sort';
|
||||
import {c} from '../core/db';
|
||||
|
||||
let split = d => s => s.split(d);
|
||||
let toArray = split(',');
|
||||
|
||||
export default function (app) {
|
||||
app.use(route.get('/collective', index()));
|
||||
|
||||
app.use(route.get('/teacher/list', json(
|
||||
function *() {
|
||||
this.type = 'application/json';
|
||||
let pattern = toArray(this.query.sort || '');
|
||||
|
||||
let data = yield c('collective').find();
|
||||
if (!data) {
|
||||
this.status = 404;
|
||||
return;
|
||||
}
|
||||
|
||||
let collective = yield data
|
||||
.map(processProfile);
|
||||
|
||||
this.body = sortByPattern(collective, pattern, i => i.id);
|
||||
}
|
||||
)));
|
||||
|
||||
app.use(route.get('/teacher/:id', json(
|
||||
function *(id) {
|
||||
this.type = 'application/json';
|
||||
|
||||
let data = yield c('collective').findOne({id: id});
|
||||
if (!data) {
|
||||
this.status = 404;
|
||||
return;
|
||||
}
|
||||
|
||||
this.body = yield processProfile(data);
|
||||
}
|
||||
)))
|
||||
};
|
||||
|
||||
let processProfile = profile => co(function *() {
|
||||
let imageId = profile.picture;
|
||||
profile.picture = yield c('images').findOne({_id: imageId});
|
||||
profile.url = `/teacher/${profile.id}`;
|
||||
return profile;
|
||||
});
|
||||
Reference in new issue
Block a user