sonar_widget_block.rb
1.71 KB
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
class SerproIntegrationPlugin::SonarWidgetBlock < Block
#FIXME make this test
AVAILABLE_WIDGETS = {
'project_motion_chart' => 'Project Motion Chart',
'timeline' => 'Timeline',
'complexity' => 'Complexity'
}
#FIXME make this test. Make test for default widget
settings_items :widget, :type => String, :default => 'timeline'
def self.description
_('Sonar Widgets')
end
def help
_('This block adds sonar widgets on profile.')
end
#FIXME make this test
def sonar_host
self.owner.serpro_integration_plugin['host']
end
#FIXME make this test
def sonar_project
self.owner.serpro_integration_plugin['project']
end
#FIXME make this test
def widget_url
self.sonar_host + 'widget?id=' + self.widget + '&resource=' + self.sonar_project + '&metric1=complexity&metric2=ncloc'
end
#FIXME make this test
def is_widget_well_formed_url?
!self.widget_url.match(/http[s]?:\/\/[\w|.|\/]+\/widget\?id=[\w]+&resource=[\w|\W]+/).nil?
end
#FIXME make this test
def widget_width
case widget
when 'project_motion_chart'
'360px'
when 'timeline'
'100%'
when 'complexity'
'100%'
else
'300px'
end
end
#FIXME make this test
def widget_height
case widget
when 'project_motion_chart'
'450px'
when 'timeline'
'205px'
when 'complexity'
'170px'
else
'300px'
end
end
def content(args={})
# render this url
#http://sonar.serpro/widget?id=timeline&resource=br.gov.fazenda.coaf.siscoaf:siscoaf-parent&metric1=complexity&metric2=ncloc
block = self
proc do
render :file => 'sonar_widget_block', :locals => { :block => block }
end
end
end