+ document page

This commit is contained in:
tmshv committed 2016-03-18 05:38:27 +03:00
1 parent d3e6eb2659
commit 2dc366c9ba
9 files changed
+78 -10

No files matched your search

+5
View File
@@ -10,4 +10,9 @@ export default class APIDocument extends EndPoint {
let url = '/documents/type/award'; let url = '/documents/type/award';
return this.get(url); return this.get(url);
} }
id(id){
let url = `/documents/${id}`;
return this.get(url);
}
} }
+15
View File
@@ -31,6 +31,7 @@ import PageTeacher from './components/PageTeacher';
import PageGallery from './components/PageGallery'; import PageGallery from './components/PageGallery';
import PageAlbum from './components/PageAlbum'; import PageAlbum from './components/PageAlbum';
import PageDocuments from './components/PageDocuments'; import PageDocuments from './components/PageDocuments';
import PageDocument from './components/PageDocument';
import AppController from './controllers/AppController'; import AppController from './controllers/AppController';
import CopyrightController from './controllers/CopyrightController'; import CopyrightController from './controllers/CopyrightController';
@@ -177,6 +178,19 @@ app.config(($locationProvider, $routeProvider) => {
return sortByPattern(i, documentsSortPattern, i => i.category); return sortByPattern(i, documentsSortPattern, i => i.category);
}) })
} }
},
{
name: '/documents/:id',
template: '<page-document item="$resolve.document"></page-document>',
resolve: {
document: ($route, api) => {
let id = $route.current.params.id;
return api.document
.id(id)
.then(i => i.data)
}
}
} }
] ]
.map(i => { .map(i => {
@@ -246,6 +260,7 @@ app.run(($location, $rootScope, $http) => {
PageGallery, PageGallery,
PageAlbum, PageAlbum,
PageDocuments, PageDocuments,
PageDocument,
AppController, AppController,
CopyrightController, CopyrightController,
ContactsController, ContactsController,
+6 -2
View File
@@ -3,11 +3,15 @@ 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: '<',
preview: '@'
}, },
controllerAs: '$', controllerAs: '$',
controller: function () { controller: function () {
this.previewUrl = this.document.preview.data.medium.url; const size = this.preview || 'medium';
this.imageClass = `document__image--${size}`;
this.previewUrl = this.document.preview.data[size].url;
this.file = this.document.file; this.file = this.document.file;
}, },
template: template template: template
+12
View File
@@ -0,0 +1,12 @@
import template from '../../templates/components/page-document.html';
import {unique} from '../../utils/common';
export default function (app) {
app.component('pageDocument', {
bindings: {
item: '<'
},
template: template,
controllerAs: '$'
});
};
-1
View File
@@ -10,7 +10,6 @@ export default function (app) {
template: template, template: template,
controllerAs: '$', controllerAs: '$',
controller: function () { controller: function () {
this.pageClass = 'page-documents';
let categories = unique(i => i.category); let categories = unique(i => i.category);
this.collections = []; this.collections = [];
+21 -2
View File
@@ -1,8 +1,12 @@
import co from 'co';
import route from 'koa-route'; import route from 'koa-route';
import {json} from './'; import {index, json, accepts} from './';
import {c} from '../core/db'; import {c} from '../core/db';
function* exists(id) {
let i = yield c('documents').findOne({id: id});
return i ? true : false;
}
export default function (app) { export default function (app) {
[ [
[ [
@@ -36,6 +40,21 @@ export default function (app) {
this.status = 404; this.status = 404;
} }
} }
],
[
'/documents/:id',
accepts({
'text/html': index(exists),
'text/plain': index(exists),
'application/json': function* (id) {
let i = yield c('documents').findOne({id: id});
if (!i) this.status = 404;
else {
i = yield populateDocPreview(i);
this.body = i;
}
}
})
] ]
].forEach(item => { ].forEach(item => {
let [path, fn] = item; let [path, fn] = item;
+8 -2
View File
@@ -13,14 +13,20 @@
} }
.document__image{ .document__image{
max-width: 7.5em;
img { img {
width: 100%; width: 100%;
box-shadow: $white-shadow; box-shadow: $white-shadow;
} }
} }
.document__image--medium{
max-width: 7.5em;
}
.document__image--big{
max-width: 20em;
}
@media (max-width: $mobile-width) { @media (max-width: $mobile-width) {
.document { .document {
margin: 0 $single-margin/2 $single-margin; margin: 0 $single-margin/2 $single-margin;
+2 -3
View File
@@ -1,12 +1,11 @@
<div class="document"> <div class="document">
<div class="document__image"> <div class="document__image {{$.imageClass}}">
<a href="{{$.document.url}}" target="_blank" class="invisible"> <a href="{{$.document.url}}" target="_blank" class="invisible">
<img ng-src="{{$.previewUrl}}"> <img ng-src="{{$.previewUrl}}" alt="{{$.document.title}}">
</a> </a>
</div> </div>
<p class="document__file">{{$.document.title | uppercaseFirst}}</p> <p class="document__file">{{$.document.title | uppercaseFirst}}</p>
<!--<a href="{{$.document.url}}" target="_blank">{{$.document.title | uppercaseFirst}}</a>-->
<p class="document__file-info"> <p class="document__file-info">
<a href="{{$.document.url}}" target="_blank">{{$.file.name | ext}} ({{$.file.size | bytes}})</a> <a href="{{$.document.url}}" target="_blank">{{$.file.name | ext}} ({{$.file.size | bytes}})</a>
</p> </p>
@@ -0,0 +1,9 @@
<div class="content content_wide content--padding-top--menu">
<div>
<h2>{{$.item.name}}</h2>
<div class="documents-container">
<document document="$.item" preview="big"></document>
</div>
</div>
</div>