]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-5718 Navigation of issues inside different files
authorStas Vilchik <vilchiks@gmail.com>
Fri, 31 Oct 2014 12:45:30 +0000 (13:45 +0100)
committerStas Vilchik <vilchiks@gmail.com>
Fri, 31 Oct 2014 12:45:39 +0000 (13:45 +0100)
server/sonar-web/src/main/coffee/issues/component-viewer/main.coffee

index 6573d999d919d26b992519d9b510a61dd77b9ce8..dc618fcdf29c2028053b0b7cb11cb35cc8c55096 100644 (file)
@@ -16,6 +16,8 @@ define [
 
   API_SOURCES = "#{baseUrl}/api/sources/show"
   LINES_AROUND = 500
+  TOP_OFFSET = 38
+  BOTTOM_OFFSET = 10
 
 
   class extends Marionette.ItemView
@@ -126,8 +128,26 @@ define [
 
     select: ->
       selected = @options.app.state.get 'selectedIndex'
-      selectedKey = @options.app.issues.at(selected).get 'key'
-      @highlightIssue selectedKey
+      selectedIssue = @options.app.issues.at selected
+      if selectedIssue.get('component') == @model.get('key')
+        selectedKey = selectedIssue.get 'key'
+        @scrollToIssue selectedKey
+        @highlightIssue selectedKey
+      else
+        @options.app.controller.showComponentViewer selectedIssue
+
+
+    scrollToIssue: (key) ->
+      el = @$("[data-issue-key='#{key}']")
+      if el.length > 0
+        viewTop = el.offset().top
+        viewBottom = viewTop + el.outerHeight()
+        windowTop = $(window).scrollTop()
+        windowBottom = windowTop + $(window).height()
+        if viewTop < windowTop
+          $(window).scrollTop viewTop - TOP_OFFSET
+        if viewBottom > windowBottom
+          $(window).scrollTop $(window).scrollTop() - windowBottom + viewBottom + BOTTOM_OFFSET
 
 
     highlightIssue: (key) ->