Browse Source

Started implementing ordering

Leaving this for now as Onionoo doesn't currently support ordering by anything other than consensus_weight.
Submitted a ticket: https://bugs.torproject.org/21095
order
Luke Childs 8 years ago
parent
commit
961a3c418b
  1. 11
      controllers/listing.js
  2. 9
      views/listing.html

11
controllers/listing.js

@ -1,5 +1,10 @@
const tor = require('../lib/tor');
const orderValues = [
'consensus_weight',
'first_seen'
];
module.exports = (req, res, next) => {
let title = 'Top nodes by consensus weight';
@ -16,13 +21,17 @@ module.exports = (req, res, next) => {
if(req.query.p) {
query.offset = (query.limit * req.query.p) - query.limit;
}
if(req.query.order && orderValues.includes(req.query.order)) {
query.order = req.query.order;
}
tor.listNodes(query)
.then(nodes => res.render('listing.html', {
pageTitle: req.query.s ? `Search: ${req.query.s}` : false,
title: title,
nodes: nodes,
numOfNodes: query.limit
numOfNodes: query.limit,
orderValues: orderValues
}))
.catch(err => {
if(err.statusCode == 400 && req.query.s) {

9
views/listing.html

@ -3,6 +3,15 @@
{% block main %}
<h2>{{ title }}</h2>
<form action="/">
<input type="hidden" name="s" value="{{ req.query.s }}" />
<input type="hidden" name="p" value="{{ req.query.p }}" />
<select name="order">
{% for order in orderValues %}
<option value="{{ order }}">{{ order }}</option>
{% endfor %}
</select>
<input type="submit" />
{% if nodes.length %}
<table>
<thead>

Loading…
Cancel
Save