mirror of
https://github.com/wassname/talk.git
synced 2026-07-11 07:31:14 +08:00
Add basic index page for assets
This commit is contained in:
@@ -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
@@ -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);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -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>
|
||||
Reference in New Issue
Block a user