]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-5209 Permalink
authorStas Vilchik <vilchiks@gmail.com>
Fri, 20 Jun 2014 10:30:51 +0000 (16:30 +0600)
committerStas Vilchik <vilchiks@gmail.com>
Fri, 20 Jun 2014 10:31:01 +0000 (16:31 +0600)
sonar-server/Gruntfile.coffee
sonar-server/src/main/coffee/component-viewer/app.coffee [new file with mode: 0644]
sonar-server/src/main/coffee/component-viewer/header.coffee
sonar-server/src/main/coffee/component-viewer/main.coffee
sonar-server/src/main/hbs/component-viewer/header.hbs
sonar-server/src/main/webapp/WEB-INF/app/controllers/component_viewer_controller.rb [new file with mode: 0644]
sonar-server/src/main/webapp/WEB-INF/app/views/component_viewer/index.html.erb

index 637192424e14bfde8bb0c7f824ae44fdcc02be82..6417a05a8760c8bcbb4711a9f3b4c60cbd30f56f 100644 (file)
@@ -187,6 +187,10 @@ module.exports = (grunt) ->
         name: 'dashboard/file-app'
         out: '<%= pkg.assets %>build/js/dashboard/file-app.js'
 
+      componentViewer: options:
+        name: 'component-viewer/app'
+        out: '<%= pkg.assets %>build/js/component-viewer/app.js'
+
 
     handlebars:
       options:
diff --git a/sonar-server/src/main/coffee/component-viewer/app.coffee b/sonar-server/src/main/coffee/component-viewer/app.coffee
new file mode 100644 (file)
index 0000000..eefb05a
--- /dev/null
@@ -0,0 +1,93 @@
+requirejs.config
+  baseUrl: "#{baseUrl}/js"
+
+  paths:
+    'backbone': 'third-party/backbone'
+    'backbone.marionette': 'third-party/backbone.marionette'
+    'handlebars': 'third-party/handlebars'
+    'jquery.mockjax': 'third-party/jquery.mockjax'
+
+  shim:
+    'backbone.marionette':
+      deps: ['backbone']
+      exports: 'Marionette'
+    'backbone':
+      exports: 'Backbone'
+    'handlebars':
+      exports: 'Handlebars'
+
+
+requirejs [
+  'backbone.marionette'
+  'component-viewer/main'
+], (
+  Marionette
+  ComponentViewer
+) ->
+
+  $ = jQuery
+  API_ISSUE = "#{baseUrl}/api/issues/show"
+  App = new Marionette.Application()
+
+
+  App.addRegions
+    viewerRegion: '#component-viewer'
+
+
+  App.requestComponentViewer = (s) ->
+    if s?
+      settings = issues: false, coverage: false, duplications: false, scm: false, workspace: false
+      s.split(',').forEach (d) -> settings[d] = true
+    else settings = null
+    unless App.componentViewer?
+      App.componentViewer = new ComponentViewer settings: settings
+      App.viewerRegion.show App.componentViewer
+    App.componentViewer
+
+
+  App.addInitializer ->
+    # Define parameters
+    paramsHash = location.hash.substr(1)
+    params = {}
+    paramsHash.split('&').forEach (d) ->
+      t = d.split '='
+      params[t[0]] = decodeURIComponent t[1]
+
+    viewer = App.requestComponentViewer params.settings
+    if params.component?
+      loadIssue = (key) ->
+        $.get API_ISSUE, key: key, (r) =>
+          viewer.showIssues false, r.issue
+
+      if params.line?
+        viewer.sourceView.highlightedLine = params.line
+      viewer.open params.component
+      viewer.on 'loaded', ->
+        if params.tab? && params.item? && params.period?
+          viewer.headerView.enableBar(params.tab).done ->
+            viewer.enablePeriod +params.period, params.item
+        else if params.tab? && params.item?
+          viewer.state.set activeHeaderTab: params.tab, activeHeaderItem: params.item
+          viewer.headerView.render()
+        else if params.tab? && params.period?
+          viewer.headerView.enableBar(params.tab).done ->
+            viewer.enablePeriod params.period
+        else if params.tab? && params.currentIssue?
+          loadIssue(params.currentIssue).done ->
+            viewer.state.set activeHeaderTab: params.tab
+            viewer.headerView.render()
+        else if params.tab?
+          viewer.state.set activeHeaderTab: params.tab
+          viewer.headerView.render()
+        else if params.currentIssue?
+          loadIssue params.currentIssue
+        else viewer.showAllLines()
+
+
+  # Message bundles
+  l10nXHR = window.requestMessages()
+
+
+  $.when(l10nXHR).done ->
+    # Start the application
+    App.start()
index 13c3a40488fb41e1ae69f9e7b0e70f795905fd96..03a08c9954e4e7d4d2ba389a4b76d775e3b84abb 100644 (file)
@@ -57,6 +57,7 @@ define [
       'click .js-favorite': 'toggleFavorite'
       'click .js-extensions': 'showExtensionsPopup'
       'click .js-extension-close': 'closeExtension'
+      'click .js-permalink': 'getPermalink'
       'click @ui.expandLinks': 'showExpandedBar'
       'click .js-toggle-issues': 'toggleIssues'
       'click .js-toggle-coverage': 'toggleCoverage'
@@ -208,6 +209,31 @@ define [
       method.call @options.main, extra
 
 
+    getPermalink: ->
+      params = []
+      params.push key: 'component', value: @options.main.component.get 'key'
+      settings = []
+      _.map @options.main.settings.toJSON(), (v, k) -> settings.push k if v
+      params.push key: 'settings', value: settings.join ','
+      activeHeaderTab = @state.get 'activeHeaderTab'
+      if activeHeaderTab
+        params.push key: 'tab', value: activeHeaderTab
+      activeHeaderItem = @state.get 'activeHeaderItem'
+      if activeHeaderItem
+        params.push key: 'item', value: activeHeaderItem
+      highlightedLine = @options.main.sourceView.highlightedLine
+      period = @state.get 'period'
+      if period?
+        params.push key: 'period', value: period.get 'key'
+      if @options.main.currentIssue
+        params.push key: 'currentIssue', value: @options.main.currentIssue
+      if highlightedLine
+        params.push key: 'line', value: highlightedLine
+      hash = params.map((d) -> "#{d.key}=#{encodeURIComponent(d.value)}" ).join '&'
+      window.open "#{baseUrl}/component_viewer/index##{hash}"
+
+
+
     serializeData: ->
       component = @component.toJSON()
       if component.measures
index 891acfbcf0f0b52366b42fe3384339a003fab7c2..71c5147bdf3c0b87e47dab331ac48b9616a1f887 100644 (file)
@@ -77,7 +77,8 @@ define [
 
     initialize: (options) ->
       @settings = new Backbone.Model @getDefaultSettings()
-      @settings.set options.settings
+      if options.settings?
+        @settings.set options.settings
 
       @state = new State()
 
@@ -230,10 +231,12 @@ define [
           if @settings.get('coverage') then @showCoverage() else @hideCoverage()
           if @settings.get('duplications') then @showDuplications() else @hideDuplications()
           if @settings.get('scm') then @showSCM() else @hideSCM()
+          @trigger 'loaded'
       .fail =>
         @state.set 'removed', true
         @state.set 'hasSource', false
         @render()
+        @trigger 'loaded'
 
 
     toggleWorkspace: (store = false) ->
index 99a36d1fbdfe59f99b917fec00eb2997be64edb7..1bfdf8b57e5a93fb9e2ecd3d5d134d2d02ec218e 100644 (file)
@@ -28,7 +28,7 @@
 
   {{#unless state.removed}}
     <div class="component-viewer-header-links">
-      <a><i class="icon-link"></i></a>
+      <a class="js-permalink"><i class="icon-link"></i></a>
       {{#ifNotEmpty state.extensions}}
         <a class="js-extensions">
           <i class="icon-extension"></i>
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/controllers/component_viewer_controller.rb b/sonar-server/src/main/webapp/WEB-INF/app/controllers/component_viewer_controller.rb
new file mode 100644 (file)
index 0000000..a43d77c
--- /dev/null
@@ -0,0 +1,28 @@
+#
+# SonarQube, open source software quality management tool.
+# Copyright (C) 2008-2014 SonarSource
+# mailto:contact AT sonarsource DOT com
+#
+# SonarQube is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 3 of the License, or (at your option) any later version.
+#
+# SonarQube is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public License
+# along with this program; if not, write to the Free Software Foundation,
+# Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+#
+
+class ComponentViewerController < ApplicationController
+
+  # GET /component_viewer/index
+  def index
+
+  end
+
+end
index f5f2f0940a03500a6ab6f43f258998a633d96552..f6f0b264c072b68ae857ae67a5949afc60101c40 100644 (file)
@@ -1,3 +1,5 @@
 <% content_for :script do %>
   <script data-main="<%= ApplicationController.root_context -%>/js/component-viewer/app" src="<%= ApplicationController.root_context -%>/js/require.js"></script>
-<% end %>
\ No newline at end of file
+<% end %>
+
+<div id="component-viewer"></div>
\ No newline at end of file