[tor-commits] [compass/master] Added functionality to bookmark searches.

karsten at torproject.org karsten at torproject.org
Mon Jan 7 07:09:40 UTC 2013


commit ab2769a7a9c454d5e6ecc0ce0be52d6ea673c9c7
Author: Chris Wacek <cwacek at cs.georgetown.edu>
Date:   Fri Dec 28 00:59:25 2012 -0500

    Added functionality to bookmark searches.
    
    Queries now update the location bar. This allows users to save the
    url as a saved query. The app also now watches for changes to the
    location bar query parameters, and uses those to load a saved search.
    
    Fixed a minor bug around country list parsing.
---
 static/js/angularize.js |   21 +++++++++++++++------
 util.py                 |    5 ++++-
 2 files changed, 19 insertions(+), 7 deletions(-)

diff --git a/static/js/angularize.js b/static/js/angularize.js
index 35c7f5e..81b7c27 100644
--- a/static/js/angularize.js
+++ b/static/js/angularize.js
@@ -7,20 +7,23 @@ compassModule.value('ui.config', {
    }
 });
 
-compassModule.controller('CompassCtrl',function CompassCtrl($scope,$http) {
+compassModule.controller('CompassCtrl',function CompassCtrl($scope,$http,$location) {
 
   $scope.state = "hidden"
   $scope.query = {
     exit_filter:"all_relays",
     links:true,
     sort:'cw',
-    sort_reverse:true,
     country: null
   }
-  $scope.table = {
-    sort: 'cw',
-    reverse: true
-  }
+
+  /** Watch the location bar to allow us to load saved searches **/
+  $scope.$watch($location.search(), function(newv, oldv, scope) {
+    if ($location.search().top) {
+      $scope.query=$location.search()
+      $scope.request()
+    }
+  })
 
   /** Make a sorting request
    *
@@ -30,6 +33,9 @@ compassModule.controller('CompassCtrl',function CompassCtrl($scope,$http) {
     $scope.query.sort = sortBy
     $scope.query.sort_reverse = invert
 
+    //Update the location bar to track sorting
+    $location.search($scope.query)
+
     $http.get('result.json',{"params":$scope.query})
       .success(function(data) {
         if (data.results.length > 0) {
@@ -55,6 +61,9 @@ compassModule.controller('CompassCtrl',function CompassCtrl($scope,$http) {
   $scope.request = function(success_cb) {
     $scope.state = 'loading'
 
+    //Set the location bar for this search
+    $location.search($scope.query)
+
     $http.get('result.json',{"params":$scope.query})
       .success(function(data) {
         if (data.results.length > 0) {
diff --git a/util.py b/util.py
index 7dfc543..2ae6a37 100644
--- a/util.py
+++ b/util.py
@@ -1,7 +1,10 @@
 import json
 
 def Container(val):
-  return json.loads(val)
+  try:
+    return json.loads(val)
+  except ValueError:
+    return []
 
 def NullFn(val):
   return val





More information about the tor-commits mailing list