+ Articles

This commit is contained in:
tmshv committed 2016-03-18 01:55:33 +03:00
1 parent ac99501dad
commit 636de8e37a
10 files changed
+104 -35

No files matched your search

+3 -1
View File
@@ -4,6 +4,7 @@ import APIDocument from './APIDocument';
import APITeacher from './APITeacher';
import APISchedule from './APISchedule';
import APIEvent from './APIEvent';
import APIArticle from './APIArticle';
export default class API {
constructor(request) {
@@ -13,5 +14,6 @@ export default class API {
this.teacher = new APITeacher(request);
this.schedule = new APISchedule(request);
this.event = new APIEvent(request);
this.article = new APIArticle(request);
}
}
}
+8
View File
@@ -0,0 +1,8 @@
import EndPoint from './EndPoint';
export default class APIArticle extends EndPoint {
id(id) {
let url = `/article/${id}`;
return this.get(url);
}
}
-5
View File
@@ -8,9 +8,4 @@ export default class APIEvent extends EndPoint {
let url = `/events?skip=${skip}&limit=${limit}`;
return this.get(url);
}
post(id) {
let url = `/event/${id}`;
return this.get(url);
}
}
+18 -4
View File
@@ -24,7 +24,7 @@ import Parallax from './components/Parallax';
import PageSchool from './components/PageSchool';
import PageEvents from './components/PageEvents';
import PageEvent from './components/PageEvent';
import PageArticle from './components/PageArticle';
import PageSchedule from './components/PageSchedule';
import PageCollective from './components/PageCollective';
import PageTeacher from './components/PageTeacher';
@@ -93,8 +93,17 @@ app.config(($locationProvider, $routeProvider) => {
}
},
{
name: '/article/:event',
template: '<page-event></page-event>'
name: '/article/:id',
template: '<page-article article="$.data"></page-article>',
resolveAs: '$',
resolve:{
data: ($route, api) => {
let id = $route.current.params.id;
if(!id) return null;
return api.article.id(id)
.then(i => i.data)
}
}
},
{
name: '/schedule/:period?/:semester?',
@@ -194,6 +203,11 @@ app.run(($location, $rootScope, $http) => {
if (title) $rootScope.title = title;
});
$rootScope.$on('$routeChangeError', (event, current) => {
//let title = current['$$route'].title;
//if (title) $rootScope.title = title;
});
$http.defaults.headers.common['Accept'] = 'application/json';
});
@@ -224,7 +238,7 @@ app.run(($location, $rootScope, $http) => {
AlbumCollection,
TeacherProfile,
PageSchool,
PageEvent,
PageArticle,
PageEvents,
PageSchedule,
PageCollective,
+30
View File
@@ -0,0 +1,30 @@
import template from '../../templates/components/page-article.html';
export default function (app) {
app.component('pageArticle', {
bindings: {
article: '<'
},
template: template,
controllerAs: '$',
controller: function ($rootScope, $routeParams, api, menu) {
menu.activate('/events');
if(this.article){
$rootScope.title = this.article.title;
}
//this.posts = [this.article];
//let id = $routeParams.id;
//if(!id) return;
//
//api.article.id(id)
// .then(i => i.data)
// .then(post => {
// $rootScope.title = post.title;
// this.posts = [post];
// });
}
});
};
-21
View File
@@ -1,21 +0,0 @@
import template from '../../templates/components/page-event.html';
export default function (app) {
app.component('pageEvent', {
template: template,
controllerAs: '$',
controller: function ($rootScope, $routeParams, api, menu) {
this.pageClass = 'page-event';
menu.activate('/events');
let id = $routeParams.event;
if(!id) return;
api.event.post(id)
.success(post => {
$rootScope.title = post.title;
this.posts = [post];
});
}
});
};
+38
View File
@@ -0,0 +1,38 @@
import route from 'koa-route';
import {c} from '../core/db';
import {accepts, index} from './';
import {sortBy} from '../utils/sort';
export default function (app) {
function* exists(id) {
let i = yield c('events').findOne({id: id});
if (!i) {
i = yield c('timeline').findOne({id: id});
}
return i ? true : false;
}
app.use(route.get('/article/:id', accepts({
//'text/html': function* (id){
// let test = yield exists(id);
// if(test){
// return yield index();
// }else{
// this.status = 404;
// return yield index();
// }
//},
'text/html': index(exists),
'text/plain': index(exists),
'application/json': function* (id) {
let i = yield c('events').findOne({id: id});
if (!i) {
i = yield c('timeline').findOne({id: id});
}
if (!i) this.status = 404;
else this.body = i;
}
})));
};
+3 -1
View File
@@ -24,6 +24,7 @@ import error404 from './routes/404';
import documents from './routes/documents';
import teachers from './routes/teachers';
import events from './routes/events';
import articles from './routes/articles';
export const app = koa();
app.proxy = true;
@@ -58,5 +59,6 @@ instagram(app);
instagramIO(app);
documents(app);
events(app);
articles(app);
teachers(app);
app.use(error404());
app.use(error404());
@@ -0,0 +1,4 @@
<section class="content content_thin content--padding-top--menu">
<!--<h-article ng-repeat="i in $.posts" post="i"></h-article>-->
<h-article post="$.article"></h-article>
</section>
-3
View File
@@ -1,3 +0,0 @@
<section class="content content_thin content--padding-top--menu">
<h-article ng-repeat="i in $.posts" post="i"></h-article>
</section>