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:
--- /dev/null
+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()
'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'
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
initialize: (options) ->
@settings = new Backbone.Model @getDefaultSettings()
- @settings.set options.settings
+ if options.settings?
+ @settings.set options.settings
@state = new State()
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) ->
{{#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>
--- /dev/null
+#
+# 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
<% 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