commit ba625b42b7bf1dc7d549a7702b8c806f5d5c8891 Author: Iain R. Learmonth irl@fsfe.org Date: Fri Jan 12 02:35:50 2018 +0000
Adds aggregation search by version number (Fixes: #6855) --- js/collections/aggregates.js | 9 ++++++++- js/models/aggregate.js | 3 ++- js/views/aggregate/search.js | 4 ++-- js/views/search/main.js | 4 ++++ templates/aggregate/search.html | 24 +++++++++++++++--------- templates/search/main.html | 1 + 6 files changed, 32 insertions(+), 13 deletions(-)
diff --git a/js/collections/aggregates.js b/js/collections/aggregates.js index b7354f4..9ddce23 100644 --- a/js/collections/aggregates.js +++ b/js/collections/aggregates.js @@ -7,7 +7,7 @@ define([ ], function($, _, Backbone, aggregateModel){ var aggregatesCollection = Backbone.Collection.extend({ model: aggregateModel, - baseurl: 'https://onionoo.torproject.org/details?running=true&type=relay&field...', + baseurl: 'https://onionoo.torproject.org/details?running=true&type=relay&field...', url: '', aType: 'cc', lookup: function(options) { @@ -35,6 +35,7 @@ define([
var ccAggregate = false; var asAggregate = false; + var versionAggregate = false;
if (collection.aType == "all") { aggregateKey = "zz"; // A user-assigned ISO 3166-1 code, but really just a static key @@ -44,6 +45,9 @@ define([ } else if (collection.aType == "as") { aggregateKey = relay.as_number; asAggregate = true; + } else if (collection.aType == "version") { + aggregateKey = relay.version.split(".").slice(0, 3).join(".") + "."; + versionAggregate = true; } else { aggregateKey = relay.country + "/" + relay.as_number; ccAggregate = asAggregate = true; @@ -61,6 +65,9 @@ define([ } else { aggregates[aggregateKey].as = new Set(); } + if (versionAggregate) { + aggregates[aggregateKey].version = aggregateKey; + } aggregates[aggregateKey].as_name = relay.as_name; }
diff --git a/js/models/aggregate.js b/js/models/aggregate.js index 50740df..6c2a059 100644 --- a/js/models/aggregate.js +++ b/js/models/aggregate.js @@ -19,7 +19,8 @@ define([ consensus_weight_to_bandwidth_count: 0, relays: 0, guards: 0, - exits: 0 + exits: 0, + version: null }); return aggregateModel; }); diff --git a/js/views/aggregate/search.js b/js/views/aggregate/search.js index b3eeaeb..5cb8c82 100644 --- a/js/views/aggregate/search.js +++ b/js/views/aggregate/search.js @@ -21,17 +21,17 @@ define([ var compiledTemplate = _.template(aggregateSearchTemplate) this.$el.html(compiledTemplate({query: query, aggregates: this.collection.models, + aType: this.collection.aType, countries: CountryCodes, error: this.error, relaysPublished: this.relaysPublished, bridgesPublished: this.bridgesPublished}));
// This creates the table using DataTables - //loadSortingExtensions(); var oTable = $('#torstatus_results').dataTable({ "sDom": "<"top"l>rt<"bottom"ip><"clear">", "bStateSave": false, - "aaSorting": [[2, "desc"]], + "aaSorting": [[(this.collection.aType == "version") ? 3 : 2, "desc"]], "fnDrawCallback": function( oSettings ) { $(".tip").tooltip({'html': true}); } diff --git a/js/views/search/main.js b/js/views/search/main.js index 58d6401..23b0240 100644 --- a/js/views/search/main.js +++ b/js/views/search/main.js @@ -94,6 +94,10 @@ define([ return goAggregate("ascc") });
+ $("#do-advanced-aggregation-version").bind('click', function(){ + return goAggregate("version") + }); + $("#home-advanced-search").bind('submit', function(){ var query = buildAdvancedQuery(); document.location = "#search/"+encodeURI(query); diff --git a/templates/aggregate/search.html b/templates/aggregate/search.html index f8f364e..d71f6e4 100644 --- a/templates/aggregate/search.html +++ b/templates/aggregate/search.html @@ -40,6 +40,7 @@ <table class="table table-hover table-striped" id="torstatus_results"> <thead> <tr> + <% if (aType == "version") { %><th>Version</th><% } %> <th>Country</sup></th> <th>Autonomous System</th> <th>Consensus Weight</th> @@ -56,25 +57,30 @@
<% _.each(aggregates, function(aggregate) { %> <tr> + <% if (aType == "version") { %> + <td> + <%= aggregate.version %> + </td> + <% } %> <td> <% if ((typeof aggregate.country) == "string") { %> - <a href="#search/<%= (query) ? query + " " : "" %><% if (query.indexOf("country:") == -1) { %>country:<%= aggregate.country %><% } %>"><img class="inline country" src="img/cc/<%= aggregate.country %>.png"> <%= countries[aggregate.country] %></a> + <a href="#search/<%= (query) ? query + " " : "" %><%= (aggregate.version) ? "version:" + aggregate.version + " " : "" %><% if (query.indexOf("country:") == -1) { %>country:<%= aggregate.country %><% } %>"><img class="inline country" src="img/cc/<%= aggregate.country %>.png"> <%= countries[aggregate.country] %></a> <% } else { %> <% if ((typeof aggregate.as) == "string") { %> - (<a href="#aggregate/ascc/<%= (query) ? query + " " : "" %><% if (query.indexOf("as:") == -1) { %>as:<%= aggregate.as %><% } %>"><%= aggregate.country.size %> distinct</a>) + (<a href="#aggregate/ascc/<%= (query) ? query + " " : "" %><%= (aggregate.version) ? "version:" + aggregate.version + " " : "" %><% if (query.indexOf("as:") == -1) { %>as:<%= aggregate.as %><% } %>"><%= aggregate.country.size %> distinct</a>) <% } else { %> - (<a href="#aggregate/cc<%= (query) ? "/" + query : "" %>"><%= aggregate.country.size %> distinct</a>) + (<a href="#aggregate/cc<%= (query || aggregate.version) ? "/" : "" %><% (query) ? query + " " : "" %><%= (aggregate.version) ? "version:" + aggregate.version + " " : "" %>"><%= aggregate.country.size %> distinct</a>) <% } %> <% } %> </td> <td> <% if ((typeof aggregate.as) == "string") { %> - <a href="#search/<%= (query) ? query + " " : "" %><% if (query.indexOf("as:") == -1) { %>as:<%= aggregate.as %><% } %>"><%= aggregate.as_name %> (<%= aggregate.as %>)</a> + <a href="#search/<%= (query) ? query + " " : "" %><%= (aggregate.version) ? "version:" + aggregate.version + " " : "" %><% if (query.indexOf("as:") == -1) { %>as:<%= aggregate.as %><% } %>"><%= aggregate.as_name %> (<%= aggregate.as %>)</a> <% } else { %> <% if ((typeof aggregate.country) == "string") { %> - (<a href="#aggregate/ascc/<%= (query) ? query + " " : "" %><% if (query.indexOf("country:") == -1) { %>country:<%= aggregate.country %><% } %>"><%= aggregate.as.size %> distinct</a>) + (<a href="#aggregate/ascc/<%= (query) ? query + " " : "" %><%= (aggregate.version) ? "version:" + aggregate.version + " " : "" %><% if (query.indexOf("country:") == -1) { %>country:<%= aggregate.country %><% } %>"><%= aggregate.as.size %> distinct</a>) <% } else { %> - (<a href="#aggregate/as<%= (query) ? "/" + query : "" %>"><%= aggregate.as.size %> distinct</a>) + (<a href="#aggregate/as<%= (query || aggregate.version) ? "/" : "" %><% (query) ? query + " " : "" %><%= (aggregate.version) ? "version:" + aggregate.version + " " : "" %>"><%= aggregate.as.size %> distinct</a>) <% } %> <% } %> </td> @@ -85,21 +91,21 @@ <td data-order="<%= aggregate.exit_probability %>"><%= (aggregate.exit_probability * 100).toFixed(4) %>%</td> <td> <% if ((typeof aggregate.as) == "string" || (typeof aggregate.country) == "string") { %> - <a href="#search/<% if ((typeof aggregate.as) == "string" && query.indexOf("as:") == -1) { %>as:<%= aggregate.as %> <% } if ((typeof aggregate.country) == "string" && query.indexOf("country:") == -1) { %>country:<%= aggregate.country %> <% } %><%= (query) ? query + " " : "" %>"><%= aggregate.relays %></a> + <a href="#search/<% if ((typeof aggregate.as) == "string" && query.indexOf("as:") == -1) { %>as:<%= aggregate.as %> <% } if ((typeof aggregate.country) == "string" && query.indexOf("country:") == -1) { %>country:<%= aggregate.country %> <% } %><%= (query) ? query + " " : "" %><%= (aggregate.version) ? "version:" + aggregate.version + " " : "" %>"><%= aggregate.relays %></a> <% } else { %> <%= aggregate.relays %> <% } %> </td> <td> <% if (aggregate.guards > 0) { %> - <a href="#search/<% if ((typeof aggregate.as) == "string" && query.indexOf("as:") == -1) { %>as:<%= aggregate.as %> <% } if ((typeof aggregate.country) == "string" && query.indexOf("country:") == -1) { %>country:<%= aggregate.country %> <% } %><%= (query) ? query + " " : "" %><% if (query.indexOf("flag:") == -1) { %>flag:guard<% } %>"><%= aggregate.guards %></a></td> + <a href="#search/<% if ((typeof aggregate.as) == "string" && query.indexOf("as:") == -1) { %>as:<%= aggregate.as %> <% } if ((typeof aggregate.country) == "string" && query.indexOf("country:") == -1) { %>country:<%= aggregate.country %> <% } %><%= (query) ? query + " " : "" %><% if (query.indexOf("flag:") == -1) { %>flag:guard <% } %><%= (aggregate.version) ? "version:" + aggregate.version + " " : "" %>"><%= aggregate.guards %></a></td> <% } else { %> 0 <% } %> </td> <td> <% if (aggregate.exits > 0) { %> - <a href="#search/<% if ((typeof aggregate.as) == "string" && query.indexOf("as:") == -1) { %>as:<%= aggregate.as %> <% } if ((typeof aggregate.country) == "string" && query.indexOf("country:") == -1) { %>country:<%= aggregate.country %> <% } %><%= (query) ? query + " " : "" %><% if (query.indexOf("flag:") == -1) { %>flag:exit<% } %>"><%= aggregate.exits %></a></td> + <a href="#search/<% if ((typeof aggregate.as) == "string" && query.indexOf("as:") == -1) { %>as:<%= aggregate.as %> <% } if ((typeof aggregate.country) == "string" && query.indexOf("country:") == -1) { %>country:<%= aggregate.country %> <% } %><%= (query) ? query + " " : "" %><% if (query.indexOf("flag:") == -1) { %>flag:exit <% } %><%= (aggregate.version) ? "version:" + aggregate.version + " " : "" %>"><%= aggregate.exits %></a></td> <% } else { %> 0 <% } %> diff --git a/templates/search/main.html b/templates/search/main.html index ee0a0ff..b69612c 100644 --- a/templates/search/main.html +++ b/templates/search/main.html @@ -133,6 +133,7 @@ or exit relay filtered by the search parameters.</p> <button id="do-advanced-aggregation-as" class="btn btn-secondary tip" type="button" title="Aggregate by Autonomous System">by AS</button> <button id="do-advanced-aggregation-cc" class="btn btn-secondary tip" type="button" title="Aggregate by Country">by CC</button> <button id="do-advanced-aggregation-ascc" class="btn btn-secondary tip" type="button" title="Aggregate by both Autonomous System and Country">by AS+CC</button> + <button id="do-advanced-aggregation-version" class="btn btn-secondary tip" type="button" title="Aggregate by Version">by Version</button> </p> </form> <p><sup>†</sup> These options are ignored when performing an aggregation as the aggregated searches are restricted to only currently running relays.</p>
tor-commits@lists.torproject.org