Skip to content

Commit

Permalink
Add /list to show non-editably
Browse files Browse the repository at this point in the history
  • Loading branch information
cchan committed Sep 14, 2019
1 parent 22c858e commit 5fc0c2c
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 0 deletions.
2 changes: 2 additions & 0 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ var redirectController = require('./controllers/RedirectController')(redis);
//Initialize routes
var admin = require('./routes/admin.js')(frontendController, apiController);
app.use('/admin', admin);
var list = require('./routes/list.js')(frontendController, apiController);
app.use('/list', list);
var main = require('./routes/main.js')(rootRedirect, redirectController);
app.use('/', main);
app.use(function(req, res, next) {
Expand Down
10 changes: 10 additions & 0 deletions controllers/admin/FrontendController.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,16 @@ module.exports = function(redis, passport) {
});
};

FrontendController.list = function(req, res) {
Redirect.getAll(function(err, redirects) {
if (err)
res.status(500).send(err);
else {
res.status(200).render('admin/list', { redirects: redirects });
}
});
};

FrontendController.createRedirect = function(req, res) {
var key = req.body.key;
var url = req.body.url;
Expand Down
7 changes: 7 additions & 0 deletions routes/list.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
var express = require('express');

module.exports = function(frontend, api) {
var router = express.Router();
router.get('/', frontend.list);
return router;
};
20 changes: 20 additions & 0 deletions views/admin/list.jade
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
html
head
title redisred list
link(rel="stylesheet", href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css")
meta(name="viewport",content="width=device-width, initial-scale=1")
body
div.container-fluid(style="max-width: 1000px;")
h1 redisred list
table.table.table-striped(style="table-layout: fixed;")
tr
th.col-sm-2 Key
th.col-sm-7 URL
th.col-sm-3(colspan=3) Clicks
each redirect in redirects
tr
td.col-sm-2(style="overflow: hidden; text-overflow: ellipsis; word-break: keep-all;")
a(href=("/"+redirect.key))=redirect.key
td.col-sm-7(style="overflow: hidden; text-overflow: ellipsis; word-break: keep-all;")
a(href=redirect.url)= redirect.url
td.col-sm-1= redirect.clicks

0 comments on commit 5fc0c2c

Please sign in to comment.