aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-server/src/main/webapp/WEB-INF/app/helpers/measures_helper.rb
blob: 7d27e92ed4f770dc5b921c87dcc0b9178fe0dfe6 (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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#
# 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
#
module MeasuresHelper

  def list_column_html(filter, column)

    if column.sort?
      html = link_to_function(h(column.name), "reloadParameters({asc:'#{(!filter.sort_asc?).to_s}', sort:'#{column.key}'})")
    else
      html=h(column.name)
    end
    if filter.sort_key==column.key
      html << (filter.sort_asc? ? image_tag("asc12.png") : image_tag("desc12.png"))
    end
    "<th class='#{column.align}'>#{html}</th>"
  end

  def list_cell_html(column, result)
    if column.metric
      format_measure(result.measure(column.metric))
    elsif column.key=='name'
      "#{qualifier_icon(result.snapshot)} #{link_to(result.snapshot.resource.name(true), {:controller => 'dashboard', :id => result.snapshot.resource_id}, :title => result.snapshot.resource.key)}"
    elsif column.key=='short_name'
      "#{qualifier_icon(result.snapshot)} #{link_to(result.snapshot.resource.name(false), {:controller => 'dashboard', :id => result.snapshot.resource_id}, :title => result.snapshot.resource.key)}"
    elsif column.key=='date'
      human_short_date(result.snapshot.created_at)
    elsif column.key=='key'
      "<span class='small'>#{result.snapshot.resource.kee}</span>"
    elsif column.key=='description'
      h result.snapshot.resource.description
    elsif column.key=='version'
      h result.snapshot.version
    elsif column.key=='language'
      h result.snapshot.resource.language
    elsif column.key=='links' && result.links
      html = ''
      result.links.select { |link| link.href.start_with?('http') }.each do |link|
        html += link_to(image_tag(link.icon, :alt => link.name), link.href, :class => 'nolink', :popup => true) unless link.custom?
      end
      html
    end
  end

  def measure_filter_star(filter, is_favourite)
    if is_favourite
      style='fav'
      title=message('click_to_remove_from_favourites')
    else
      style='notfav'
      title=message('click_to_add_to_favourites')
    end

    "<a href='#' class='measure-filter-star #{style}' filter-id='#{filter.id}' title='#{title}'></a>"
  end

  CLOUD_MIN_SIZE_PERCENT=60.0
  CLOUD_MAX_SIZE_PERCENT=240.0

  def cloud_font_size(value, min_size_value, max_size_value)
    divisor=max_size_value - min_size_value
    size=CLOUD_MIN_SIZE_PERCENT
    if divisor!=0.0
      multiplier=(CLOUD_MAX_SIZE_PERCENT - CLOUD_MIN_SIZE_PERCENT)/divisor
      size=CLOUD_MIN_SIZE_PERCENT + ((max_size_value - (max_size_value-(value - min_size_value)))*multiplier)
    end
    size.to_i
  end
end