aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-server/src/main/webapp/WEB-INF/app/controllers/treemap_controller.rb
blob: 9288782b57b6c35fe53d35e738c14f4e46f6245a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#
# Sonar, entreprise quality control tool.
# Copyright (C) 2008-2012 SonarSource
# mailto:contact AT sonarsource DOT com
#
# Sonar 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.
#
# Sonar 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 Sonar; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02
#
class TreemapController < ApplicationController
  helper :metrics

  SECTION=Navigation::SECTION_HOME

  def index
    html_id = params[:id]
    bad_request('Missing required property: id') if html_id.blank?

    width = params[:width]
    bad_request('Missing required property: width') if width.blank?
    bad_request('Bad width') if width.to_i<=0

    height = params[:height]
    bad_request('Missing required property: height') if height.blank?
    bad_request('Bad height') if height.to_i<=0

    size_metric=Metric.by_key(params[:size_metric]||'lines')
    bad_request('Unknown metric: ' + params[:size_metric]) unless size_metric

    color_metric=(params[:color_metric].present? ? Metric.by_key(params[:color_metric]) : nil)

    resource = nil
    if params[:resource]
      resource = Project.by_key(params[:resource])
      bad_request('Unknown resource: ' + params[:resource]) unless resource
      access_denied unless has_role?(:user, resource)
    end

    treemap = Sonar::Treemap.new(html_id, size_metric, width.to_i, height.to_i, {
      :color_metric => color_metric,
      :root_snapshot => (resource ? resource.last_snapshot : nil),
      :period_index => params[:period_index].to_i,
      :browsable => true
    })

    render :update do |page|
      page.replace_html  "tm-#{html_id}", :partial => 'treemap', :object => treemap
      page.replace_html  "tm-gradient-#{html_id}", :partial => 'gradient', :locals => {:metric => color_metric}
      page.hide "tm-loading-#{html_id}"
    end
  end

end