Add basic index page for assets

This commit is contained in:
David Erwin
2017-01-25 15:23:02 -05:00
parent ad9684acd9
commit 29e69a66bb
3 changed files with 43 additions and 4 deletions
+16
View File
@@ -9,6 +9,9 @@ router.get('/id/:asset_id', (req, res, next) => {
return Assets.findById(req.params.asset_id)
.then(asset => {
if (asset === null) {
return res.json({'message': 'Asset not found'});
}
res.render('article', {
title: asset.title,
asset_url: asset.url,
@@ -28,4 +31,17 @@ router.get('/title/:asset_title', (req, res) => {
});
});
router.get('/', (req, res, next) => {
let skip = req.query.skip ? parseInt(req.query.skip) : 0;
let limit = req.query.limit ? parseInt(req.query.limit) : 25;
return Assets.all(skip, limit)
.then(assets => {
res.render('articles', {
assets: assets
});
})
.catch(err => next(err));
});
module.exports = router;
+7 -4
View File
@@ -88,9 +88,9 @@ module.exports = class AssetsService {
* @param {String} value string to search by.
* @return {Promise}
*/
static search(value) {
static search(value = '', skip = null, limit = null) {
if (value.length === 0) {
return AssetsService.all();
return AssetsService.all(skip, limit);
} else {
return AssetModel.find({
$text: {
@@ -110,7 +110,10 @@ module.exports = class AssetsService {
return AssetModel.find(query);
}
static all() {
return AssetModel.find({});
static all(skip = null, limit = null) {
return AssetModel
.find({})
.skip(skip)
.limit(limit);
}
};
+20
View File
@@ -0,0 +1,20 @@
<html>
<head>
Asset list
</head>
<body>
<p>
Clicking on an asset below will bring you to its comment stream.
</p>
<p>
You may paginate manually using skip and limit query params. (aka, ?skip=100&limit=25)
</p>
<p>
This is intended for developer use only.
</p>
<% assets.forEach(function (asset) { %>
<a href="/assets/id/<%= asset.id %>"><%= asset.url %></a><br />
<% }) %>
</body>
</html>