浏览代码

[search] Generic URL to browse any collection

Open the collection in a gridlayout.
e.g.
${ reverse('search:browse', kwargs={'name': 'yelp_demo'}) }
Romain Rigaux 11 年之前
父节点
当前提交
e339079
共有 3 个文件被更改,包括 43 次插入10 次删除
  1. 1 0
      apps/search/src/search/urls.py
  2. 26 0
      apps/search/src/search/views.py
  3. 16 10
      apps/search/static/js/search.ko.js

+ 1 - 0
apps/search/src/search/urls.py

@@ -22,6 +22,7 @@ urlpatterns = patterns('search.views',
   url(r'^search$', 'search', name='search'),
   url(r'^save$', 'save', name='save'),
   url(r'^new_search', 'new_search', name='new_search'),
+  url(r'^browse/(?P<name>\w+)', 'browse', name='browse'),
   url(r'^download$', 'download', name='download'),
   
   url(r'^dashboard$', 'dashboard', name='dashboard'),

+ 26 - 0
apps/search/src/search/views.py

@@ -75,6 +75,7 @@ def index(request):
   })
 
 
+# TODO security
 def new_search(request):
   collections = SearchController(request.user).get_solr_collection().keys()
   if not collections:
@@ -99,6 +100,31 @@ def new_search(request):
   })
 
 
+# TODO security
+def browse(request, name):
+  collections = SearchController(request.user).get_solr_collection().keys()
+  if not collections:
+    return no_collections(request)
+
+  collection = Collection(name=name, label=name)
+  query = {'qs': [{'q': ''}], 'fqs': [], 'start': 0}
+
+  return render('search2.mako', request, {
+    'collection': collection,
+    'query': query,
+    'initial': json.dumps({
+         'autoLoad': True,
+         'collections': collections,
+         'layout': [
+              {"size":12,"rows":[{"widgets":[
+                  {"size":12,"name":"Grid Results","id":"52f07188-f30f-1296-2450-f77e02e1a5c0","widgetType":"resultset-widget",
+                   "properties":{},"offset":0,"isLoading":True,"klass":"card card-widget span12"}]}],
+              "drops":["temp"],"klass":"card card-home card-column span10"}
+         ] 
+     }),
+  })
+
+
 def search(request):
   response = {}  
   

+ 16 - 10
apps/search/static/js/search.ko.js

@@ -733,8 +733,22 @@ var NewTemplate = function (vm, initial) {
   var self = this;
 
   self.collections = ko.mapping.fromJS(initial.collections);
-  
   self.layout = initial.layout;
+
+  if (self.collections) {
+    vm.collection.name.subscribe(function (newValue) {
+	  vm.collection.label(newValue);
+	  vm.collection.switchCollection();
+	  vm.changeCollection(false);
+	  vm.search();
+    });
+  }
+  
+  self.init = function() {
+    if (initial.autoLoad) {
+	  magicLayout(vm);
+    }
+  };
 };
 
 
@@ -748,15 +762,6 @@ var SearchViewModel = function (collection_json, query_json, initial_json) {
   self.query = new Query(self, query_json);
   self.initial = new NewTemplate(self, initial_json);
 
-  if (initial_json.collections) {
-    self.collection.name.subscribe(function (newValue) {
-	  self.collection.label(newValue);
-	  self.collection.switchCollection();
-	  self.changeCollection(false);
-	  self.search();
-    });
-  }
-  
   // UI
   self.response = ko.observable({});
   self.results = ko.observableArray([]);
@@ -827,6 +832,7 @@ var SearchViewModel = function (collection_json, query_json, initial_json) {
   });
   
   self.init = function (callback) {
+	self.initial.init();
 	self.collection.syncFields();
     self.isEditing(true);
     self.search(callback);