aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-web
diff options
context:
space:
mode:
authorJean-Baptiste Lievremont <jean-baptiste.lievremont@sonarsource.com>2014-10-06 15:44:22 +0200
committerJean-Baptiste Lievremont <jean-baptiste.lievremont@sonarsource.com>2014-10-06 15:44:33 +0200
commit57688b561ad220b039822e49096a1e679af07c1d (patch)
tree40d44de74036c25a507ad9a49ac3177e76fe5942 /server/sonar-web
parentcf9fd46d7c5dd3c658508930c5065e8d6fc2c644 (diff)
downloadsonarqube-57688b561ad220b039822e49096a1e679af07c1d.tar.gz
sonarqube-57688b561ad220b039822e49096a1e679af07c1d.zip
SONAR-5634 Keep facets and filters in sync, use sticky facets
Diffstat (limited to 'server/sonar-web')
-rw-r--r--server/sonar-web/src/main/coffee/coding-rules/app.coffee35
-rw-r--r--server/sonar-web/src/main/coffee/coding-rules/router.coffee2
-rw-r--r--server/sonar-web/src/main/coffee/coding-rules/views/coding-rules-facets-view.coffee21
-rw-r--r--server/sonar-web/src/main/coffee/coding-rules/views/filter-bar-view.coffee18
4 files changed, 48 insertions, 28 deletions
diff --git a/server/sonar-web/src/main/coffee/coding-rules/app.coffee b/server/sonar-web/src/main/coffee/coding-rules/app.coffee
index 14ab0d938c5..953c0091080 100644
--- a/server/sonar-web/src/main/coffee/coding-rules/app.coffee
+++ b/server/sonar-web/src/main/coffee/coding-rules/app.coffee
@@ -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 = ->
diff --git a/server/sonar-web/src/main/coffee/coding-rules/router.coffee b/server/sonar-web/src/main/coffee/coding-rules/router.coffee
index a6f73769b20..fe49b73dbbd 100644
--- a/server/sonar-web/src/main/coffee/coding-rules/router.coffee
+++ b/server/sonar-web/src/main/coffee/coding-rules/router.coffee
@@ -33,5 +33,7 @@ define [
loadResults: (params) ->
@app.filterBarView.restoreFromQuery(params)
+ if @app.codingRulesFacetsView
+ @app.codingRulesFacetsView.restoreFromQuery(params)
@app.restoreSorting(params)
@app.fetchFirstPage()
diff --git a/server/sonar-web/src/main/coffee/coding-rules/views/coding-rules-facets-view.coffee b/server/sonar-web/src/main/coffee/coding-rules/views/coding-rules-facets-view.coffee
index b0bc3653b67..55b3f0b5720 100644
--- a/server/sonar-web/src/main/coffee/coding-rules/views/coding-rules-facets-view.coffee
+++ b/server/sonar-web/src/main/coffee/coding-rules/views/coding-rules-facets-view.coffee
@@ -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'
diff --git a/server/sonar-web/src/main/coffee/coding-rules/views/filter-bar-view.coffee b/server/sonar-web/src/main/coffee/coding-rules/views/filter-bar-view.coffee
index 4c9c455f2ca..b01ee86ab85 100644
--- a/server/sonar-web/src/main/coffee/coding-rules/views/filter-bar-view.coffee
+++ b/server/sonar-web/src/main/coffee/coding-rules/views/filter-bar-view.coffee
@@ -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()