]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-5627 Feedback applied
authorStas Vilchik <vilchiks@gmail.com>
Fri, 24 Oct 2014 15:23:43 +0000 (17:23 +0200)
committerStas Vilchik <vilchiks@gmail.com>
Fri, 24 Oct 2014 15:28:53 +0000 (17:28 +0200)
12 files changed:
server/sonar-web/src/main/coffee/analysis-reports/app.coffee
server/sonar-web/src/main/coffee/analysis-reports/layout.coffee
server/sonar-web/src/main/coffee/analysis-reports/models/reports.coffee
server/sonar-web/src/main/coffee/analysis-reports/router.coffee [new file with mode: 0644]
server/sonar-web/src/main/coffee/analysis-reports/views/actions-view.coffee
server/sonar-web/src/main/coffee/analysis-reports/views/report-view.coffee
server/sonar-web/src/main/coffee/analysis-reports/views/reports-empty-view.coffee [new file with mode: 0644]
server/sonar-web/src/main/coffee/analysis-reports/views/reports-view.coffee
server/sonar-web/src/main/hbs/analysis-reports/analysis-reports-empty.hbs [new file with mode: 0644]
server/sonar-web/src/main/hbs/analysis-reports/analysis-reports-header.hbs
server/sonar-web/src/main/hbs/analysis-reports/analysis-reports-report.hbs
server/sonar-web/src/main/less/navigator/base.less

index 4a82e4479ca78bdb9204690a3ea4127c7eec9094..f0c19a1d9f6bdbd27f8d82771eb35eb3ce4ad5da 100644 (file)
@@ -19,6 +19,7 @@ requirejs.config
 requirejs [
   'backbone', 'backbone.marionette'
 
+  'analysis-reports/router'
   'analysis-reports/layout'
   'analysis-reports/models/reports'
   'analysis-reports/views/reports-view'
@@ -28,6 +29,7 @@ requirejs [
   'common/handlebars-extensions'
 ], (
   Backbone, Marionette
+  Router
   Layout
   Reports
   ReportsView
@@ -44,36 +46,47 @@ requirejs [
 
 
   App.fetchReports = ->
+    process = window.process.addBackgroundProcess()
     fetch = if @state.get 'active' then @reports.fetchActive() else @reports.fetchHistory()
     @layout.showSpinner 'actionsRegion'
     @layout.resultsRegion.reset()
     fetch.done =>
+      @state.set page: @reports.paging.page
       @reportsView = new ReportsView
         app: @
         collection: @reports
       @layout.resultsRegion.show @reportsView
+      @reportsView.bindScrollEvents() unless @state.get 'active'
 
       @actionsView = new ActionsView
         app: @
         collection: @reports
       @layout.actionsRegion.show @actionsView
 
+      @layout.onResize()
+
+      window.process.finishBackgroundProcess process
+
+
+  App.fetchNextPage = ->
+    process = window.process.addBackgroundProcess()
+    @reports.fetchHistory
+      data:
+        p: @state.get('page') + 1
+      remove: false
+    .done =>
+      @state.set page: @reports.paging.page
+      window.process.finishBackgroundProcess process
+
 
   App.addInitializer ->
-    @state = new Backbone.Model active: true
+    @state = new Backbone.Model()
     @state.on 'change:active', => @fetchReports()
 
 
   App.addInitializer ->
     @layout = new Layout app: @
     jQuery('#analysis-reports').empty().append @layout.render().el
-    @layout.onResize()
-
-
-  App.addInitializer ->
-    @reports = new Reports()
-    @fetchReports()
-    setInterval (=> @fetchReports()), 30000 # Once every 30s
 
 
   App.addInitializer ->
@@ -81,6 +94,11 @@ requirejs [
     @layout.headerRegion.show @headerView
 
 
+  App.addInitializer ->
+    @reports = new Reports()
+    @router = new Router app: @
+    Backbone.history.start()
+
 
   l10nXHR = window.requestMessages()
   jQuery.when(l10nXHR).done -> App.start()
index 2ce017d04d77a677e3e23d55883a1fa1db42d9aa..147522cd7bb24f9f2d95365d34bd855ee9db7f4c 100644 (file)
@@ -31,8 +31,7 @@ define [
       footerHeight = footerEl.outerHeight true
 
       resultsEl = @ui.results
-      resultsHeight = jQuery(window).height() - resultsEl.offset().top -
-        parseInt(resultsEl.css('margin-bottom'), 10) - footerHeight
+      resultsHeight = jQuery(window).height() - resultsEl.offset().top - footerHeight
       resultsEl.height resultsHeight
 
 
index fd0ef350cfd2ffef00fc255c859d704043101794..cbaeec3df68bcda0841553ae2f505d74e16a290c 100644 (file)
@@ -12,7 +12,11 @@ define [
 
 
     parse: (r) ->
-      @paging = r.paging
+      @paging =
+        page: r.p
+        pageSize: r.ps
+        total: r.total
+        maxResultsReached: r.p * r.ps >= r.total
       r.reports
 
 
@@ -20,5 +24,7 @@ define [
       @fetch { url: "#{baseUrl}/api/analysis_reports/active" }, { reset: true }
 
 
-    fetchHistory: ->
-      @fetch { url: "#{baseUrl}/api/analysis_reports/history" }, { reset: true }
+    fetchHistory: (options = {  }) ->
+      _.extend options,
+        url: "#{baseUrl}/api/analysis_reports/history"
+      @fetch options, { reset: true }
diff --git a/server/sonar-web/src/main/coffee/analysis-reports/router.coffee b/server/sonar-web/src/main/coffee/analysis-reports/router.coffee
new file mode 100644 (file)
index 0000000..db11154
--- /dev/null
@@ -0,0 +1,26 @@
+define [
+  'backbone',
+], (
+  Backbone,
+) ->
+
+  class AppRouter extends Backbone.Router
+
+    routes:
+      '': 'showCurrent'
+      'current': 'showCurrent'
+      'past': 'showPast'
+
+
+    initialize: (options) ->
+      @options = options
+
+
+    showCurrent: ->
+      @navigate 'current'
+      @options.app.state.set active: true
+
+
+    showPast: ->
+      @navigate 'past'
+      @options.app.state.set active: false
index 345c8a0728a8092d163e6200506a710177cb067d..237485c18e6bd8d13eea4e239634e862b05a6c97 100644 (file)
@@ -21,14 +21,14 @@ define [
 
 
     showPastReports: ->
-      @options.app.state.set active: false
+      @options.app.router.navigate 'past', trigger: true
 
 
     showCurrentActivity: ->
-      @options.app.state.set active: true
+      @options.app.router.navigate 'current', trigger: true
 
 
     serializeData: ->
       _.extend super,
         state: @options.app.state.toJSON()
-        total: if @collection.paging then @collection.paging.total else @collection.length
+        total: @collection.paging.total || 0
index 9215879a4f44f6e2820752c8a46bd90ee985409b..25b2680bf29d370569d3aefb64cd94c319063fe2 100644 (file)
@@ -17,3 +17,17 @@ define [
       @$el.addClass 'analysis-reports-report-working' if status is 'WORKING'
       @$el.addClass 'analysis-reports-report-done' if status is 'SUCCESS'
       @$el.addClass 'analysis-reports-report-failed' if status is 'FAIL'
+
+
+    serializeData: ->
+      duration = null
+      if @model.has('startedAt') && @model.has('finishedAt')
+        startedAtMoment = moment @model.get 'startedAt'
+        finishedAtMoment = moment @model.get 'finishedAt'
+        duration = finishedAtMoment.diff startedAtMoment
+        duration =
+          seconds: Math.floor (duration / 1000) % 60
+          minutes: Math.floor (duration / (1000 * 60)) % 60
+          hours: Math.floor (duration / (1000 * 60 * 60)) % 24
+      _.extend super,
+        duration: duration
diff --git a/server/sonar-web/src/main/coffee/analysis-reports/views/reports-empty-view.coffee b/server/sonar-web/src/main/coffee/analysis-reports/views/reports-empty-view.coffee
new file mode 100644 (file)
index 0000000..da789ce
--- /dev/null
@@ -0,0 +1,11 @@
+define [
+  'backbone.marionette'
+  'templates/analysis-reports'
+], (
+  Marionette
+  Templates
+) ->
+
+  class extends Marionette.ItemView
+    tagName: 'li'
+    template: Templates['analysis-reports-empty']
index 5da4e03a34ce48e3976c83a70c55dd6ae64854c9..adc409314369e15739ada9ddde16a978feddd89c 100644 (file)
@@ -1,16 +1,45 @@
 define [
   'backbone.marionette'
   'analysis-reports/views/report-view'
+  'analysis-reports/views/reports-empty-view'
 ], (
   Marionette
   ReportView
+  EmptyView
 ) ->
 
+  $ = jQuery
+
+
   class extends Marionette.CollectionView
     tagName: 'ol'
     className: 'navigator-results-list'
     itemView: ReportView
+    emptyView: EmptyView
 
 
     itemViewOptions: ->
       listView: @, app: @options.app
+
+
+    initialize: ->
+      @loadMoreThrottled = _.throttle @loadMore, 200
+
+
+    onClose: ->
+      @unbindScrollEvents()
+
+
+    bindScrollEvents: ->
+      $('.navigator-results').on 'scroll', (=> @loadMoreThrottled())
+
+
+    unbindScrollEvents: ->
+      $('.navigator-results').off 'scroll'
+
+
+    loadMore: ->
+      if $('.navigator-results').scrollTop() + $('.navigator-results').outerHeight() >= $('.navigator-results-list').outerHeight() - 40
+        @unbindScrollEvents()
+        @options.app.fetchNextPage().done =>
+          @bindScrollEvents() unless @collection.paging.maxResultsReached
diff --git a/server/sonar-web/src/main/hbs/analysis-reports/analysis-reports-empty.hbs b/server/sonar-web/src/main/hbs/analysis-reports/analysis-reports-empty.hbs
new file mode 100644 (file)
index 0000000..00cb7e8
--- /dev/null
@@ -0,0 +1 @@
+<li>No reports to show</li>
index 06e2dbf186233fd7211420ec781bbd46ff2673d8..9eec52a18e43901ef60eb430d9232ad61ec399ad 100644 (file)
@@ -1 +1,2 @@
 <h1 class="navigator-header-title">{{t 'analysis_reports.page'}}</h1>
+<div class="navigator-header-description">The server is in charge to process reports submitted by batch analyses. This page allows to monitor the queue of pending reports to process, and gives access to the history of past analyses.</div>
index c58a92151d2a2376d6d6dbf4237edcea655d4d38..fc2cf616177143fe7d0cea81fdf649d9cf5bf2d3 100644 (file)
@@ -4,23 +4,21 @@
     <a href="{{dashboardUrl projectKey}}">{{projectName}}</a>
   </span>
 
-  {{#if submittedAt}}
-    <span class="analysis-reports-timestamp line-small">
-      Submitted: {{dt submittedAt}}
-    </span>
-  {{/if}}
+  <span class="analysis-reports-timestamp line-small">
+    {{#if submittedAt}}Submitted: {{dt submittedAt}}<br>{{/if}}
+    {{#if startedAt}}Started: {{dt startedAt}}<br>{{/if}}
+    {{#if finishedAt}}Finished: {{dt finishedAt}}<br>{{/if}}
+  </span>
 
-  {{#if startedAt}}
+  {{#if duration}}
     <span class="analysis-reports-timestamp line-small">
-      Started: {{dt startedAt}}
+      Duration:
+      {{#gt duration.hours 0}}{{duration.hours}}h{{/gt}}
+      {{#gt duration.minutes 0}}{{duration.minutes}}m{{/gt}}
+      {{duration.seconds}}s
     </span>
   {{/if}}
 
-  {{#if finishedAt}}
-    <span class="analysis-reports-timestamp line-small">
-      Finished: {{dt finishedAt}}
-    </span>
-  {{/if}}
 </div>
 
 <div class="analysis-reports-report-id">{{id}} {{status}}</div>
index 1adb6a0ba1767aa516ba0bfa6e6f6c4fd274b71b..1613a496c5ecf65075a732beb9ccd39cb87b6223 100644 (file)
 .navigator-header-description {
   display: inline-block;
   vertical-align: middle;
+  max-width: 70%;
   margin-left: 16px;
   font-size: @smallFontSize;
   font-style: italic;