]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-5718 Add permalinks for saved filters
authorStas Vilchik <vilchiks@gmail.com>
Fri, 31 Oct 2014 08:48:46 +0000 (09:48 +0100)
committerStas Vilchik <vilchiks@gmail.com>
Fri, 31 Oct 2014 09:06:42 +0000 (10:06 +0100)
server/sonar-web/src/main/coffee/issues/app.coffee
server/sonar-web/src/main/coffee/issues/controller.coffee
server/sonar-web/src/main/coffee/issues/models/state.coffee
server/sonar-web/src/main/coffee/issues/router.coffee

index 29bcf6fee9aae4d1ddaec8903eb61536be062161..775b26a4d9a0035f22da5cf46c889f44e9872170 100644 (file)
@@ -74,10 +74,6 @@ requirejs [
     @controller = new Controller app: @
 
 
-  App.addInitializer ->
-    @controller.fetchFilters()
-
-
   App.addInitializer ->
     @issuesView = new WorkspaceListView
       app: @
@@ -108,9 +104,10 @@ requirejs [
 
 
   App.addInitializer ->
-    key.setScope 'list'
-    @router = new Router app: @
-    Backbone.history.start()
+    @controller.fetchFilters().done =>
+      key.setScope 'list'
+      @router = new Router app: @
+      Backbone.history.start()
 
 
   l10nXHR = window.requestMessages()
index a5424edb81bb25eef457b54f1ade08c75ed739d6..56ddd0b4309e2e71366f9f609682928499d174c5 100644 (file)
@@ -137,9 +137,10 @@ define [
       @options.app.state.setQuery resolved: 'false'
 
 
-    applyFilter: (filter) ->
-      query = @parseQuery filter.get 'query'
-      @options.app.state.setQuery query
+    applyFilter: (filter, ignoreQuery = false) ->
+      unless ignoreQuery
+        filterQuery = @parseQuery filter.get 'query'
+        @options.app.state.setQuery filterQuery
       @options.app.state.set filter: filter, changed: false
 
 
@@ -160,6 +161,17 @@ define [
       route.join separator
 
 
+    getRoute: (separator = '|') ->
+      filter = @options.app.state.get 'filter'
+      query = @getQuery separator
+      if filter?
+        if @options.app.state.get('changed') && query.length > 0
+          query = "id=#{filter.id}|#{query}"
+        else
+          query = "id=#{filter.id}"
+      query
+
+
     _prepareComponent: (issue) ->
       key: issue.get 'component'
       name: issue.get 'componentLongName'
index 264e81ad2e1cd2da1f74f8dd2b0582bb3294eaa5..49040ea3c79d7c31fc093916146d48adc70ea706 100644 (file)
@@ -43,6 +43,6 @@ define [
 
     setQuery: (query) ->
       @set { query: query }, { silent: true }
-      @trigger 'change:query'
       @set changed: true
+      @trigger 'change:query'
 
index b89b9e5ace3ef5e89f5938a34ab0ca5fba397cfb..b85773f6c4343170dae2ec82b958cb3feced6234 100644 (file)
@@ -15,6 +15,7 @@ define [
     initialize: (options) ->
       @options = options
       @listenTo @options.app.state, 'change:query', @updateRoute
+      @listenTo @options.app.state, 'change:filter', @updateRoute
 
 
     emptyQuery: ->
@@ -22,11 +23,22 @@ define [
 
 
     index: (query) ->
-      filter = @options.app.controller.parseQuery query
-      @options.app.state.setQuery filter
+      query = @options.app.controller.parseQuery query
+      if query.id?
+        filter = @options.app.filters.get query.id
+        delete query.id
+        filter.fetch().done =>
+          if Object.keys(query).length > 0
+            @options.app.controller.applyFilter filter, true
+            @options.app.state.setQuery query
+            @options.app.state.set changed: true
+          else
+            @options.app.controller.applyFilter filter
+      else
+        @options.app.state.setQuery query
 
 
     updateRoute: ->
-      route = @options.app.controller.getQuery()
+      route = @options.app.controller.getRoute()
       @navigate route