]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-5718 Handle big files
authorStas Vilchik <vilchiks@gmail.com>
Mon, 24 Nov 2014 12:35:12 +0000 (13:35 +0100)
committerStas Vilchik <vilchiks@gmail.com>
Mon, 24 Nov 2014 13:25:40 +0000 (14:25 +0100)
server/sonar-web/src/main/coffee/issues/component-viewer/main.coffee
server/sonar-web/src/main/less/ui.less
sonar-core/src/main/resources/org/sonar/l10n/core.properties

index ad0506786067fcf20b09853271e5a0a00cc93827..981f29799dc1abd7eba98707e2156e574ba16dc3 100644 (file)
@@ -15,9 +15,10 @@ define [
   $ = jQuery
 
   API_SOURCES = "#{baseUrl}/api/sources/show"
-  LINES_AROUND = 500
+  LINES_AROUND = 200
   TOP_OFFSET = 38
   BOTTOM_OFFSET = 10
+  ISSUES_LIMIT = 100
 
 
   class extends Marionette.ItemView
@@ -41,9 +42,7 @@ define [
         formattedSource: []
       @component = new Backbone.Model()
       @issues = new Issues()
-      @listenTo @issues, 'add', @addIssue
       @listenTo options.app.state, 'change:selectedIndex', @select
-      @bindShortcuts()
       @loadSourceBeforeThrottled = _.throttle @loadSourceBefore, 1000
       @loadSourceAfterThrottled = _.throttle @loadSourceAfter, 1000
       @scrollTimer = null
@@ -154,8 +153,14 @@ define [
 
 
     renderIssues: ->
+      @hiddenIssues = false
       @issues.forEach (issue) =>
         @renderIssue issue
+      if @hiddenIssues
+        issues = @$('.issue').length
+        warn = $('<div class="process-spinner shown">' + tp('issues.issues_limit_reached', issues) + '</div>')
+        $('body').append warn
+        setTimeout (-> warn.remove()), 3000
 
 
     addIssue: (issue) ->
@@ -163,18 +168,21 @@ define [
 
 
     renderIssue: (issue) ->
-      line = issue.get 'line' || 0
+      line = issue.get('line') || 0
       row = @$("[data-line-number=#{line}]")
       issueView = new IssueView app: @options.app, model: issue
-      if row.length == 0
+      if line == 0
         issueView.render().$el.insertBefore @$('.issues-workspace-component-viewer-code')
       else
-        line = row.find '.line'
-        line.addClass 'has-issues'
-        issues = line.find '.issue-list'
-        if issues.length == 0
-          issues = $('<div class="issue-list"></div>').appendTo line
-        issueView.render().$el.appendTo issues
+        showBox = Math.abs(issue.get('index') - @model.get('issueIndex')) < ISSUES_LIMIT / 2
+        @hiddenIssues = true unless showBox
+        if showBox && row.length > 0
+          line = row.find '.line'
+          line.addClass 'has-issues'
+          issues = line.find '.issue-list'
+          if issues.length == 0
+            issues = $('<div class="issue-list"></div>').appendTo line
+          issueView.render().$el.appendTo issues
 
 
     select: ->
@@ -184,6 +192,7 @@ define [
         selectedKey = selectedIssue.get 'key'
         @scrollToIssue selectedKey
       else
+        @unbindShortcuts()
         @options.app.controller.showComponentViewer selectedIssue
 
 
@@ -214,14 +223,18 @@ define [
           $(window).scrollTop viewTop - TOP_OFFSET
         if viewBottom > windowBottom
           $(window).scrollTop $(window).scrollTop() - windowBottom + viewBottom + BOTTOM_OFFSET
+      else
+        @unbindShortcuts()
+        selected = @options.app.state.get 'selectedIndex'
+        selectedIssue = @options.app.issues.at selected
+        @options.app.controller.showComponentViewer selectedIssue
 
 
     openFileByIssue: (issue) ->
       componentKey = issue.get 'component'
-      @issues.reset @options.app.issues.filter (issue) => issue.get('component') == componentKey
 
       line = issue.get('line') || 0
-      @model.set key: componentKey, issueLine: line
+      @model.set key: componentKey, issueLine: line, issueIndex: issue.get('index')
 
       # disable clipping effect of the black header
       @$el.addClass 'full-height'
@@ -237,35 +250,35 @@ define [
         @model.set
           hasSourceBefore: firstLine > 1
           hasSourceAfter: lastLine == line + LINES_AROUND
-        @render()
-        @bindScrollEvents()
-        @requestIssues()
+        @requestIssues().done =>
+          @issues.reset @options.app.issues.filter (issue) => issue.get('component') == componentKey
+          @render()
+          @bindScrollEvents()
+          @bindShortcuts()
+          @$el.removeClass 'full-height'
+          @scrollToLine issue.get 'line'
       .fail =>
         @source.set
           source: []
           formattedSource: []
         @model.set hasSourceBefore: false, hasSourceAfter: false
+        @issues.reset @options.app.issues.filter (issue) => issue.get('component') == componentKey
         @render()
-      .always =>
+        @bindShortcuts()
         @$el.removeClass 'full-height'
         @scrollToLine issue.get 'line'
 
 
+
     requestSources: (lineFrom, lineTo) ->
       lineFrom = Math.max 0, lineFrom
       $.get API_SOURCES, key: @model.get('key'), from: lineFrom, to: lineTo
 
 
     requestIssues: ->
-      lastIssue = @options.app.issues.at @options.app.issues.length - 1
-      lastLine = _.last(@source.get('formattedSource')).lineNumber
-      needMore = !@options.app.state.get('maxResultsReached')
-      needMore = needMore && (lastIssue.get('component') == @model.get 'key')
-      needMore = needMore && (lastIssue.get('line') <= lastLine)
-      if needMore
-        @options.app.controller.fetchNextPage().done =>
-          @addNextIssuesPage()
-          @requestIssues()
+      if @options.app.issues.last().get('component') == @model.get('key')
+        @options.app.controller.fetchNextPage()
+      else $.Deferred().resolve().promise()
 
 
     addNextIssuesPage: ->
index 71c52412a9f083026751f1fca2aeaabcf92ff431..77321ea0e5a6b32e8af90f508066cdc256767e65 100644 (file)
@@ -411,9 +411,12 @@ input[type=button] {
 
 .process-spinner {
   position: fixed;
+  z-index: 2000;
   top: 0; left: 50%;
-  width: 300px;
+  min-width: 300px;
+  max-width: 900px;
   margin-left: -150px;
+  padding: 0 10px;
   line-height: 22px;
   background-color: #f0e8ac;
   border-radius: 0 0 3px 3px;
index 32c52343264c28c213d6335d9f267ca837abc08a..24fd83f4fb7897eec6004ffaef8ff175f0781e7c 100644 (file)
@@ -684,7 +684,8 @@ issue.technical_debt=Technical Debt:
 issue.technical_debt_short=Debt
 issue.technical_debt_deleted=Rule not configured to generate technical debt estimate.
 issue.creation_date=Created
-issues.return_to_list=Return To List
+issues.return_to_list=Return to List
+issues.issues_limit_reached=For usability reasons, only the {0} issues are displayed.
 
 
 #------------------------------------------------------------------------------