]> source.dussan.org Git - sonarqube.git/blob
cb4b9b3f8a39f07782f82429b33b7691c9fb956b
[sonarqube.git] /
1 <%
2    technical_debt = measure('sqale_index')
3
4    root_characteristics = Internal.debt.rootCharacteristics().to_a
5
6    should_display_diff_measures = dashboard_configuration.selected_period? && technical_debt.variation(dashboard_configuration.period_index)!=nil
7    if technical_debt.nil? || root_characteristics.empty?
8 %>
9
10   <h3><%= message('widget.technical_debt_pyramid.name') -%></h3>
11   <span style="color: #777777; font-size: 93%; font-style:italic"><%= message('widget.technical_debt_pyramid.no_info_available') -%></span>
12
13 <%
14    else
15 %>
16   <style>
17     table.technicalDebtPyramid td {
18       padding: 4px 10px 4px 0;
19     }
20
21     table.technicalDebtPyramid td.label {
22       width: 1%;
23       white-space: nowrap;
24       text-align: left;
25       padding: 5px 10px 5px 0;
26     }
27
28     table.technicalDebtPyramid th.val {
29       width: 1%;
30       white-space: nowrap;
31       text-align: right;
32       padding: 0 0 0 10px;
33     }
34
35     table.technicalDebtPyramid td.val {
36       width: 1%;
37       white-space: nowrap;
38       text-align: right;
39       padding: 0 0 0 10px;
40     }
41
42     table.technicalDebtPyramid td.bar {
43       width: 97%;
44     }
45
46     table.technicalDebtPyramid .legendValue {
47       width: 10px;
48       height: 10px;
49       background-color: #92B7D3;
50       display: inline-block;
51       zoom: 1; /* IE hack to trigger hasLayout */
52       *display: inline; /* IE hack to achieve inline-block behavior */
53     }
54
55     table.technicalDebtPyramid .legendTotal {
56       width: 10px;
57       height: 10px;
58       background-color: #2A4269;
59       display: inline-block;
60       zoom: 1; /* IE hack to trigger hasLayout */
61       *display: inline; /* IE hack to achieve inline-block behavior */
62     }
63
64     table.technicalDebtPyramid td.bar>a>div>div {
65       float: right;
66     }
67   </style>
68
69   <table class="technicalDebtPyramid">
70     <thead>
71     <tr>
72       <th colspan="2"><h3><%= message('widget.technical_debt_pyramid.name') -%></h3></th>
73       <th class="val"><%= message('widget.technical_debt_pyramid.technical_debt') -%> <div class="legendValue"></div></th>
74       <th class="val"><%= message('widget.technical_debt_pyramid.total') -%> <div class="legendTotal"></div></th>
75     </tr>
76     </thead>
77     <tbody>
78     <%
79        measures_by_characteristic_id={}
80        ProjectMeasure.find(:all,
81                            :conditions => ['characteristic_id IN (?) AND snapshot_id=? AND metric_id=?',
82                                            root_characteristics.map{|c| c.id}, @snapshot.id, technical_debt.metric().id]).each do |measure|
83          measures_by_characteristic_id[measure.characteristic_id]=measure
84        end
85
86        total = technical_debt.value
87        cumulated=total
88
89        if should_display_diff_measures
90          diff_by_characteristic_id={}
91          total_diff = 0;
92          root_characteristics.each do |c|
93            measure = measures_by_characteristic_id[c.id]
94            if measure && measure.variation(dashboard_configuration.period_index)
95              diff_by_characteristic_id[c.id] = measure.variation(dashboard_configuration.period_index)
96              total_diff += measure.variation(dashboard_configuration.period_index)
97            end
98          end
99        end
100
101        root_characteristics.sort_by {|characteristic| characteristic.order}.each do |characteristic|
102          measure=measures_by_characteristic_id[characteristic.id]
103          value=(measure && measure.value ? measure.value : 0)
104          total_size=(total>0 ? (100*cumulated/total).to_i: 0)
105          value_size=(cumulated>0 ? (100*value/cumulated).to_i: 100)
106          drilldown_url = url_for_drilldown('sqale_index', :characteristic => characteristic.key)
107     %>
108       <tr>
109         <td class="label"><%= h(characteristic.name) -%></td>
110         <td class="bar">
111           <a href="<%= drilldown_url -%>">
112             <div style="width: <%=total_size-%>%; height: 17px; background-color: #2A4269;">
113               <div style="width: <%=value_size-%>%; height: 11px;background-color: #92B7D3;border-top:3px solid #2A4269"></div>
114             </div>
115           </a>
116         </td>
117         <td class="val value-debt-<%= h(characteristic.key) -%>">
118           <a href="<%= drilldown_url -%>" class="link-debt-<%= h(characteristic.key) -%>"><%= Internal.i18n.formatLongDuration(value.to_i, 'SHORT') -%></a>
119           <% if should_display_diff_measures %>
120             <% if diff_by_characteristic_id[characteristic.id] %>
121               <%= format_variation(measure) -%>
122             <% else %>
123               <span class="var"><b>(+0)</b></span>
124             <% end %>
125           <% end %>
126         </td>
127         <td class="val value-total-<%= h(characteristic.key) -%>">
128           <%= Internal.i18n.formatLongDuration(cumulated.to_i, 'SHORT') -%>
129           <%
130              if should_display_diff_measures
131                css_style = 'var'
132                css_style += 'b' if total_diff < 0
133                css_style += 'w' if total_diff > 0
134                diff_to_display = (total_diff < 0 ? '' : '+') + Internal.i18n.formatLongDuration(total_diff.to_i, 'SHORT')
135           %>
136             <span class="<%= css_style -%>"><b>(<%= diff_to_display -%>)</b></span>
137           <%
138              total_diff -= diff_by_characteristic_id[characteristic.id] if diff_by_characteristic_id[characteristic.id]
139              end
140           %>
141         </td>
142       </tr>
143     <%
144        cumulated-=value
145        end
146     %>
147     </tbody>
148   </table>
149
150 <% end %>