From 4cff4597819a93412d2db14dd6f6cc7625009aa6 Mon Sep 17 00:00:00 2001
From: "Iain R. Learmonth" <irl@debian.org>
Date: Sun, 19 Jun 2016 18:48:01 +0100
Subject: [PATCH] Adds a list of the top 10 relays by consensus weight (Fixes:
 #5430)

 * Adds a navbar to the top of the page for Home, About and Top 10
   Relays.
 * Re-uses the search results view using a hardcoded Onionoo URL (taken
   from Globe) to show a list of the top 10 relays by consensus weight.
 * Disables sorting by default of the datatables, and disables saving of
   state for sorting options. This allows the list of the top 10 to be
   sorted by consensus weight as reported by Onionoo, though manual
   sorting is still possible as before.
---
 index.html            |  7 ++++++-
 js/router.js          | 24 ++++++++++++++++++++++++
 js/views/search/do.js |  3 ++-
 3 files changed, 32 insertions(+), 2 deletions(-)

diff --git a/index.html b/index.html
index b3297a1..5588c23 100644
--- a/index.html
+++ b/index.html
@@ -36,7 +36,12 @@
       <div class="navbar-inner">
         <div class="container">
           <a class="brand" href="#"><img src="img/atlas.png"/></a>
-            <form id="nav-search" class="navbar-search pull-left" action>
+          <ul class="nav navbar-nav">
+            <li><a href="#/">Home</a></li>
+            <li><a href="#/about">About</a></li>
+            <li><a href="#/top10">Top 10 Relays</a></li>
+          </ul>
+            <form id="nav-search" class="navbar-search pull-right" action>
                 <input type="text" class="search-query" placeholder="Search">
             </form>
         </div>
diff --git a/js/router.js b/js/router.js
index 92b2647..f79e933 100644
--- a/js/router.js
+++ b/js/router.js
@@ -14,6 +14,7 @@ define([
        // Define the routes for the actions in Atlas
     	'details/:fingerprint': 'mainDetails',
     	'search/:query': 'doSearch',
+	'top10': 'showTop10',
     	'about': 'showAbout',
     	// Default
     	'*actions': 'defaultAction'
@@ -81,6 +82,29 @@ define([
             });
         }
     },
+    showTop10: function(){
+        $("#home").removeClass("active");
+        $("#about").removeClass("active");
+
+        $("#loading").show();
+        $("#content").hide();
+
+        doSearchView.collection.url = "https://onionoo.torproject.org/summary?type=relay&order=-consensus_weight&limit=10&running=true";
+            doSearchView.collection.lookup({
+                success: function(relays){
+                    $("#content").show();
+                    doSearchView.relays = doSearchView.collection.models;
+                    doSearchView.render("");
+                    $("#loading").hide();
+                },
+
+                error: function(erno){
+                    $("#content").show();
+                    doSearchView.error(erno);
+                    $("#loading").hide();
+                }
+            });
+    },
     // Display the Atlas about page
     showAbout: function(){
         $("#home").removeClass("active");
diff --git a/js/views/search/do.js b/js/views/search/do.js
index 5e077ec..77a6b02 100644
--- a/js/views/search/do.js
+++ b/js/views/search/do.js
@@ -156,7 +156,8 @@ define([
 			var oTable = $('#torstatus_results').dataTable({
 				// Save the state of the tables
                 "sDom": "<'row'<'span6'l><'span6 hide'f>r>t<'row'<'span6'i><'span6'p>>",
-				"bStateSave": true
+				"bStateSave": false,
+				"aaSorting": []
 			});
             // Make the tooltips
             $(".flags").tooltip();
-- 
GitLab