Explorar o código

[search] Copy a selection of search dashboards

Romain Rigaux %!s(int64=10) %!d(string=hai) anos
pai
achega
518cc4b922

+ 23 - 22
apps/search/src/search/search_controller.py

@@ -17,6 +17,7 @@
 # limitations under the License.
 
 import logging
+import uuid
 
 from django.contrib.auth.models import User
 from django.db.models import Q
@@ -26,6 +27,7 @@ from desktop.models import Document2
 from libsolr.api import SolrApi
 
 from search.conf import SOLR_URL
+from search.models import Collection2
 
 
 LOG = logging.getLogger(__name__)
@@ -79,28 +81,27 @@ class SearchController(object):
     result = {'status': -1, 'message': ''}
     try:
       for collection in self.get_shared_search_collections().filter(id__in=collection_ids):
-        copy = collection
-        copy.label += _(' (Copy)')
-        copy.id = copy.pk = None
-
-        # todo
-
-        facets = copy.facets
-        facets.id = None
-        facets.save()
-        copy.facets = facets
-
-        result_ = copy.result
-        result_.id = None
-        result_.save()
-        copy.result = result_
-
-        sorting = copy.sorting
-        sorting.id = None
-        sorting.save()
-        copy.sorting = sorting
-
-        copy.save()
+        doc2 = Document2.objects.get(type='search-dashboard', id=collection.id)
+    
+        name = doc2.name + '-copy'
+        copy_doc = doc2.doc.get().copy(name=name, owner=self.user)
+    
+        doc2.pk = None
+        doc2.id = None
+        doc2.uuid = str(uuid.uuid4())
+        doc2.name = name
+        doc2.owner = self.user
+        doc2.save()
+    
+        doc2.doc.all().delete()
+        doc2.doc.add(copy_doc)
+        doc2.save()
+    
+        copy = Collection2(document=doc2)
+        copy['collection']['name'] = name
+    
+        doc2.update_data({'collection': copy['collection']})
+        doc2.save()
       result['status'] = 0
     except Exception, e:
       LOG.warn('Error copying collection: %s' % e)

+ 2 - 5
apps/search/src/search/static/search/js/collections.ko.js

@@ -29,7 +29,7 @@ var Collection = function (coll) {
 
   self.id = ko.observable(coll.id);
   self.name = ko.observable(coll.name);
-  self.label = ko.observable(coll.label);
+  self.description = ko.observable(coll.description);
   self.enabled = ko.observable(coll.enabled);
   self.isCoreOnly = ko.observable(coll.isCoreOnly);
   self.absoluteUrl = ko.observable(coll.absoluteUrl);
@@ -80,6 +80,7 @@ var SearchCollectionsModel = function (props) {
       return coll.selected();
     });
   }, self);
+
   self.selectedOwnerCollections = ko.computed(function () {
     return ko.utils.arrayFilter(self.selectedCollections(), function (coll) {
       return coll.isOwner();
@@ -121,10 +122,6 @@ var SearchCollectionsModel = function (props) {
     location.href = collection.absoluteUrl();
   };
 
-  self.editIndex = function (collection) {
-    location.href = self.INDEXER_URL + collection.name();
-  };
-
   self.markManyForDeletion = function (collections) {
     if (self.atLeastOneSelected()){
       self.collectionToDelete = collections;

+ 3 - 3
apps/search/src/search/templates/admin_collections.mako

@@ -79,7 +79,7 @@ ${ commonheader(_('Search'), "search", user, "29px") | n,unicode }
                 <span data-bind="click: toggleSelectAll, css: {'fa-check': ! ko.utils.arrayFilter(filteredCollections(), function(collection) {return !collection.selected()}).length}" class="hueCheckbox fa"></span>
               </th>
               <th>${ _('Name') }</th>
-              <th>${ _('Solr Index') }</th>
+              <th>${ _('Description') }</th>
               <th width="15%">${ _('Owner') }</th>
             </tr>
           </thead>
@@ -88,8 +88,8 @@ ${ commonheader(_('Search'), "search", user, "29px") | n,unicode }
               <td data-bind="click: $root.toggleCollectionSelect.bind($root), clickBubble: false">
                 <span data-bind="css: {'fa-check': $root.filteredCollections()[$index()].selected()}" class="hueCheckbox fa"></span>
               </td>
-              <td><a data-bind="text: label, click: $root.editCollection" title="${ _('Click to edit') }" class="pointer"></a></td>
-              <td><a data-bind="text: name, click: $root.editIndex" title="${ _('Click to edit the index') }" class="pointer"></a></td>
+              <td><a data-bind="text: name, click: $root.editCollection" title="${ _('Click to edit') }" class="pointer"></a></td>
+              <td><span data-bind="text: description"></span></td>
               <td><span data-bind="text: owner"></span></td>
             </tr>
           </tbody>

+ 1 - 1
apps/search/src/search/views.py

@@ -212,7 +212,7 @@ def admin_collections(request, is_redirect=False):
       massaged_collection = {
         'id': collection.id,
         'name': collection.name,
-        'label': collection.description,
+        'description': collection.description,
         'absoluteUrl': collection.get_absolute_url(),
         'owner': collection.owner and collection.owner.username,
         'isOwner': collection.owner == request.user or request.user.is_superuser