documents update

This commit is contained in:
tmshv committed 2016-02-27 18:13:24 +03:00
1 parent 7b6559e57d
commit 10008a323a
7 files changed
+65 -25

No files matched your search

+6 -1
View File
@@ -1,8 +1,13 @@
import EndPoint from './EndPoint'; import EndPoint from './EndPoint';
export default class APIDocument extends EndPoint { export default class APIDocument extends EndPoint {
documents(){
let url = '/documents/type/document';
return this.request.get(url, {cache: true});
}
awards() { awards() {
let url = '/documents/awards'; let url = '/documents/type/award';
return this.request.get(url, {cache: true}); return this.request.get(url, {cache: true});
} }
} }
+4 -2
View File
@@ -3,10 +3,12 @@ import template from '../../templates/components/document.html';
export default function (app) { export default function (app) {
app.component('document', { app.component('document', {
bindings: { bindings: {
document: '=' document: '<'
}, },
controllerAs: '$',
controller: function () { controller: function () {
//this.testing = 123; this.previewUrl = this.document.preview.data.medium.url;
this.file = this.document.file;
}, },
template: template template: template
}); });
+4 -2
View File
@@ -1,5 +1,4 @@
import template from '../../templates/components/page-documents.html'; import template from '../../templates/components/page-documents.html';
import {docs} from '../../models/document';
export default function (app) { export default function (app) {
app.component('pageDocuments', { app.component('pageDocuments', {
@@ -7,7 +6,10 @@ export default function (app) {
controller: function (api) { controller: function (api) {
this.pageClass = 'page-documents'; this.pageClass = 'page-documents';
this.documents = docs; api.document.documents()
.success(data => {
this.documents = data;
});
api.document.awards() api.document.awards()
.success(data => { .success(data => {
+28 -12
View File
@@ -1,7 +1,7 @@
import co from 'co'; import co from 'co';
import route from 'koa-route'; import route from 'koa-route';
import {index, json} from './'; import {index, json} from './';
import db from '../core/db'; import {c} from '../core/db';
export default function (app) { export default function (app) {
[ [
@@ -9,25 +9,41 @@ export default function (app) {
'/documents', '/documents',
json(function *() { json(function *() {
let query = {}; let query = {};
this.body = yield db.c('documents') this.body = yield c('documents')
.find(query) .find(query)
.toArray(); .toArray();
}) })
], ],
[ [
'/documents/:type', '/documents/type/:type',
json(function *(type) { function *(type) {
this.body = yield db.c(type) let types = {
.find() 'document': ['documents', {type: 'document'}, populateDocPreview],
.toArray(); 'award': ['awards', {}]
}) };
],
[ if (type in types) {
'/document/:doc', let [collection, query, mapFn] = types[type];
index('../templates/document.html')
let docs = yield c(collection)
.find(query)
.toArray();
if (mapFn) docs = yield docs.map(mapFn);
this.body = docs;
} else {
this.status = 404;
}
}
] ]
].forEach(item => { ].forEach(item => {
let [path, fn] = item; let [path, fn] = item;
app.use(route.get(path, fn)); app.use(route.get(path, fn));
}); });
}; };
function* populateDocPreview(doc) {
doc.preview = yield c('images').findOne({_id: doc.preview});
return doc;
}
+12 -2
View File
@@ -1,13 +1,23 @@
@import "../variables"; @import "../variables";
.document { .document {
margin: 0 1.2em $single-margin; display: flex;
flex-direction: column;
align-items: center;
padding: 0;
margin: 0 $single-margin $double-margin;
p { p {
text-align: center; text-align: center;
} }
}
.document__image{
max-width: 7.5em;
img { img {
max-width: 100%; width: 100%;
box-shadow: $white-shadow;
} }
} }
+1 -1
View File
@@ -1,7 +1,7 @@
.documents-container { .documents-container {
display: flex; display: flex;
flex-wrap: wrap; flex-wrap: wrap;
justify-content: space-around; justify-content: center;
align-items: baseline; align-items: baseline;
} }
+10 -5
View File
@@ -1,8 +1,13 @@
<div class="document"> <div class="document">
<a href="{{$ctrl.document.url}}" target="_blank" class="invisible"> <div class="document__image">
<img ng-src="{{$ctrl.document.preview}}"> <a href="{{$.document.url}}" target="_blank" class="invisible">
</a> <img ng-src="{{$.previewUrl}}">
<p> </a>
<a href="{{$ctrl.document.url}}" target="_blank">{{$ctrl.document.title | uppercaseFirst}}</a> </div>
<p class="document__file">{{$.document.title | uppercaseFirst}}</p>
<!--<a href="{{$.document.url}}" target="_blank">{{$.document.title | uppercaseFirst}}</a>-->
<p class="document__file-info">
<a href="{{$.document.url}}" target="_blank">{{$.file.name | ext}} ({{$.file.size | bytes}})</a>
</p> </p>
</div> </div>