[yocto] [[RRS]] rrs/recipes: Add support for persist search and filters.

Aníbal Limón anibal.limon at linux.intel.com
Tue Dec 1 16:04:20 PST 2015


Now when search something the URL is modified and you can
share the URL for access to the data.

[YOCTO #7809]

Signed-off-by: Aníbal Limón <anibal.limon at linux.intel.com>
---
 rrs/views.py               | 11 +++++++++++
 templates/rrs/recipes.html | 35 +++++++++++++++++++++++++++++++++--
 2 files changed, 44 insertions(+), 2 deletions(-)

diff --git a/rrs/views.py b/rrs/views.py
index 8cbbe49..957529c 100644
--- a/rrs/views.py
+++ b/rrs/views.py
@@ -253,6 +253,15 @@ class RecipeListView(ListView):
         else:
             self.maintainer_name = 'All'
 
+        if 'search' in self.request.GET.keys():
+            self.search = self.request.GET['search']
+
+            # only allow one type of filter search or upstream_status/maintainer
+            self.upstream_status = 'All'
+            self.maintainer_name = 'All'
+        else:
+            self.search = ''
+
         _check_url_params(self.upstream_status, self.maintainer_name)
 
         self.milestone_statistics = _get_milestone_statistics(milestone)
@@ -309,6 +318,8 @@ class RecipeListView(ListView):
             all_maintainers.append(rm['maintainer__name'])
         context['all_maintainers'] = all_maintainers
 
+        context['search'] = self.search
+
         return context
 
 def recipes_report(request, release_name, milestone_name):
diff --git a/templates/rrs/recipes.html b/templates/rrs/recipes.html
index 3ec980b..be2a3a5 100644
--- a/templates/rrs/recipes.html
+++ b/templates/rrs/recipes.html
@@ -167,6 +167,16 @@ $(document).ready(function() {
     recipesTable = $('#recipestable')
     upstreamStatus = $("<div/>").html('{{ upstream_status }}').text()
     maintainer = $("<div/>").html('{{ maintainer_name }}').text()
+    search = '{{ search }}'
+
+    function updateQueryString(queryString) {
+        if (window.history.pushState) {
+            var newurl = window.location.protocol + "//" +
+                window.location.host + window.location.pathname +
+                queryString
+            window.history.pushState({path:newurl}, '', newurl);
+        }
+    }
 
     function updateRecipeCount() {
         $('#recipestable').show()
@@ -243,21 +253,38 @@ $(document).ready(function() {
 
         updateStatusSelected()
         updateMaintainerSelected()
+
+        queryString = ''
+        if (search != '') {
+            $.uiTableFilter(recipesTable, search);
+            queryString = '?search=' + search
+        } else {
+            if (upstreamStatus != 'All' && maintainer != 'All') {
+                queryString = '?upstream_status=' + upstreamStatus +
+                    '&maintainer_name=' + maintainer
+            } else if (upstreamStatus != 'All') {
+                queryString = '?upstream_status=' + upstreamStatus
+            } else if (maintainer != 'All') {
+                queryString = '?maintainer_name=' + maintainer
+            }
+        }
+        updateQueryString(queryString)
     }
 
     $("#form-search").submit(function( event ) {
         upstreamStatus = 'All' 
         maintainer = 'All'
-        search_text = $("#filter").val()
+        search = $("#filter").val()
         $("#clear-search-btn").show()
         applyFilters()
-        $.uiTableFilter(recipesTable, search_text);
         updateRecipeCount()
+
         event.preventDefault();
     });
 
     function clearSearch() {
         $("#filter").val('')
+        search = $("#filter").val()
         $("#clear-search-btn").hide()
         applyFilters()
         updateRecipeCount()
@@ -299,6 +326,10 @@ $(document).ready(function() {
     }); 
 {% endif %}
 
+    if (search != '') {
+        $("#filter").val(search)
+        $("#clear-search-btn").show()
+    }
     applyFilters()
     updateRecipeCount()
 });
-- 
2.1.4




More information about the yocto mailing list