diff options
author | Stas Vilchik <vilchiks@gmail.com> | 2014-06-20 16:30:51 +0600 |
---|---|---|
committer | Stas Vilchik <vilchiks@gmail.com> | 2014-06-20 16:31:01 +0600 |
commit | 2fc3bff79059a665e8da8f4df22b0660b2a58364 (patch) | |
tree | e776dda3729d4edece986afb4a0b243baa26812f | |
parent | 0f916e53e263389e554cfe049c1f5ec23eb12569 (diff) | |
download | sonarqube-2fc3bff79059a665e8da8f4df22b0660b2a58364.tar.gz sonarqube-2fc3bff79059a665e8da8f4df22b0660b2a58364.zip |
SONAR-5209 Permalink
7 files changed, 159 insertions, 3 deletions
diff --git a/sonar-server/Gruntfile.coffee b/sonar-server/Gruntfile.coffee index 637192424e1..6417a05a876 100644 --- a/sonar-server/Gruntfile.coffee +++ b/sonar-server/Gruntfile.coffee @@ -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 index 00000000000..eefb05a0836 --- /dev/null +++ b/sonar-server/src/main/coffee/component-viewer/app.coffee @@ -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() diff --git a/sonar-server/src/main/coffee/component-viewer/header.coffee b/sonar-server/src/main/coffee/component-viewer/header.coffee index 13c3a40488f..03a08c9954e 100644 --- a/sonar-server/src/main/coffee/component-viewer/header.coffee +++ b/sonar-server/src/main/coffee/component-viewer/header.coffee @@ -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 diff --git a/sonar-server/src/main/coffee/component-viewer/main.coffee b/sonar-server/src/main/coffee/component-viewer/main.coffee index 891acfbcf0f..71c5147bdf3 100644 --- a/sonar-server/src/main/coffee/component-viewer/main.coffee +++ b/sonar-server/src/main/coffee/component-viewer/main.coffee @@ -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) -> diff --git a/sonar-server/src/main/hbs/component-viewer/header.hbs b/sonar-server/src/main/hbs/component-viewer/header.hbs index 99a36d1fbdf..1bfdf8b57e5 100644 --- a/sonar-server/src/main/hbs/component-viewer/header.hbs +++ b/sonar-server/src/main/hbs/component-viewer/header.hbs @@ -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 index 00000000000..a43d77c5169 --- /dev/null +++ b/sonar-server/src/main/webapp/WEB-INF/app/controllers/component_viewer_controller.rb @@ -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 diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/component_viewer/index.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/component_viewer/index.html.erb index f5f2f0940a0..f6f0b264c07 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/views/component_viewer/index.html.erb +++ b/sonar-server/src/main/webapp/WEB-INF/app/views/component_viewer/index.html.erb @@ -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 |