From 57688b561ad220b039822e49096a1e679af07c1d Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Lievremont Date: Mon, 6 Oct 2014 15:44:22 +0200 Subject: [PATCH] SONAR-5634 Keep facets and filters in sync, use sticky facets --- .../src/main/coffee/coding-rules/app.coffee | 35 +++++++++---------- .../main/coffee/coding-rules/router.coffee | 2 ++ .../views/coding-rules-facets-view.coffee | 21 ++++++----- .../coding-rules/views/filter-bar-view.coffee | 18 ++++++++++ 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() -- 2.39.5