]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-5634 Keep facets and filters in sync, use sticky facets
authorJean-Baptiste Lievremont <jean-baptiste.lievremont@sonarsource.com>
Mon, 6 Oct 2014 13:44:22 +0000 (15:44 +0200)
committerJean-Baptiste Lievremont <jean-baptiste.lievremont@sonarsource.com>
Mon, 6 Oct 2014 13:44:33 +0000 (15:44 +0200)
server/sonar-web/src/main/coffee/coding-rules/app.coffee
server/sonar-web/src/main/coffee/coding-rules/router.coffee
server/sonar-web/src/main/coffee/coding-rules/views/coding-rules-facets-view.coffee
server/sonar-web/src/main/coffee/coding-rules/views/filter-bar-view.coffee

index 14ab0d938c55d8495fd5f94e994d566a61318b85..953c00910805a1385ef1bd9ede8c66dfb94ff2b6 100644 (file)
@@ -111,11 +111,8 @@ requirejs [
   App = new Marionette.Application
 
 
-  App.getQuery = (includeFacetsQuery = true) ->
-    query = @filterBarView.getQuery()
-    if includeFacetsQuery and @codingRulesFacetsView
-      _.extend query, @codingRulesFacetsView.getQuery()
-    query
+  App.getQuery = ->
+    @filterBarView.getQuery()
 
 
   App.restoreSorting = (params) ->
@@ -145,18 +142,17 @@ requirejs [
 
 
 
-  App.fetchList = (firstPage, fromFacets = false) ->
-    pristineQuery = @getQuery(false)
-    query = @getQuery(fromFacets)
+  App.fetchList = (firstPage) ->
+    query = @getQuery()
 
-    fetchQuery = _.extend { p: @pageIndex, ps: 25, facets: not fromFacets }, query
+    fetchQuery = _.extend { p: @pageIndex, ps: 25, facets: firstPage }, query
 
     if @codingRules.sorting && @codingRules.sorting.sort
       _.extend fetchQuery,
           s: @codingRules.sorting.sort,
           asc: @codingRules.sorting.asc
 
-    @storeQuery pristineQuery, @codingRules.sorting
+    @storeQuery query, @codingRules.sorting
 
     # Optimize requested fields
     _.extend fetchQuery, f: 'name,lang,status,tags,sysTags'
@@ -167,7 +163,7 @@ requirejs [
       scrollOffset = 0
 
     @layout.showSpinner 'resultsRegion'
-    @layout.showSpinner 'facetsRegion' unless fromFacets || !firstPage
+    @layout.showSpinner 'facetsRegion' if firstPage
 
 
     jQuery.ajax
@@ -206,14 +202,15 @@ requirejs [
       else
         @codingRulesListView.selectCurrent()
 
-      unless firstPage
-        jQuery('.navigator-results')[0].scrollTop = scrollOffset
-
-      unless fromFacets
+      if firstPage
         @codingRulesFacetsView = new CodingRulesFacetsView
           app: @
           collection: new Backbone.Collection r.facets, comparator: 'property'
         @layout.facetsRegion.show @codingRulesFacetsView
+        @filterBarView.restoreFromWsQuery query
+        @codingRulesFacetsView.restoreFromQuery query
+      else
+        jQuery('.navigator-results')[0].scrollTop = scrollOffset
 
       @layout.onResize()
 
@@ -224,15 +221,15 @@ requirejs [
     App.facetPropertyToLabels[property](value)
 
 
-  App.fetchFirstPage = (fromFacets = false) ->
+  App.fetchFirstPage = ->
     @pageIndex = 1
-    App.fetchList true, fromFacets
+    App.fetchList true
 
 
-  App.fetchNextPage = (fromFacets = true) ->
+  App.fetchNextPage = ->
     if @pageIndex < @codingRules.paging.pages
       @pageIndex++
-      App.fetchList false, fromFacets
+      App.fetchList false
 
 
   App.getQualityProfile = ->
index a6f73769b205000a511dc65db6a1545d38a00cce..fe49b73dbbdaeb931dffb396a91c7adfe66988b6 100644 (file)
@@ -33,5 +33,7 @@ define [
 
     loadResults: (params) ->
       @app.filterBarView.restoreFromQuery(params)
+      if @app.codingRulesFacetsView
+        @app.codingRulesFacetsView.restoreFromQuery(params)
       @app.restoreSorting(params)
       @app.fetchFirstPage()
index b0bc3653b67b7ec1aa28b140f9baf6a1d05ce24f..55b3f0b57201e0531faa5d9104df8542b4a04196 100644 (file)
@@ -33,18 +33,21 @@ define [
     selectOption: (e) ->
       option = jQuery(e.currentTarget)
       option.toggleClass 'active'
+      property = option.closest('.navigator-facets-list-item').data('property')
+      value = option.data('key')
+      @options.app.filterBarView.toggle(property, value)
       @applyOptions()
 
 
     applyOptions: ->
-      @options.app.fetchFirstPage true
+      @options.app.fetchFirstPage()
 
 
-    getQuery: ->
-      q = {}
-      if @ui.facets.each
-        @ui.facets.each ->
-          property = jQuery(@).data 'property'
-          activeOptions = jQuery(@).find('.active').map(-> jQuery(@).data 'key').get()
-          q[property] = activeOptions.join ',' if activeOptions.length > 0
-      q
+    restoreFromQuery: (params) ->
+      @ui.options.each ->
+        jQuery(@).removeClass('active')
+      @ui.facets.each ->
+        property = jQuery(@).data 'property'
+        if !!params[property]
+          _(params[property].split(',')).map (value) ->
+            jQuery('.navigator-facets-list-item[data-property="' + property + '"] .navigator-facets-list-item-option[data-key="' + value + '"]').addClass 'active'
index 4c9c455f2ca20ba1a3b22196b69a9a3da60cc25a..b01ee86ab85837afed5d75cac86c5b32737f3e92 100644 (file)
@@ -77,3 +77,21 @@ define [
 
     fetchNextPage: ->
       @options.app.fetchNextPage()
+
+
+    restoreFromWsQuery: (query) ->
+      params = _.map(query, (value, key) ->
+        'key': key
+        'value': value
+      )
+      @restoreFromQuery params
+
+
+    toggle: (property, value) ->
+      filter = @collection.findWhere(property: property)
+      unless filter.view.isActive()
+        @moreCriteriaFilter.view.detailsView.enableByProperty(property)
+      choice = filter.view.choices.get(value)
+      choice.set 'checked', !choice.get('checked')
+      filter.view.detailsView.updateValue()
+      filter.view.detailsView.updateLists()