Commit 782f5a15849257865cdd1f03cab44160aacbd8ab

Authored by João M. M. da Silva + Alessandro Palmeira
Committed by João M. M. da Silva
1 parent b18ed7d2

[Mezuro] fixed history view, finished module_result view and metric_results view

plugins/mezuro/controllers/profile/mezuro_plugin_module_result_controller.rb
@@ -4,15 +4,10 @@ class MezuroPluginModuleResultController < MezuroPluginProfileController @@ -4,15 +4,10 @@ class MezuroPluginModuleResultController < MezuroPluginProfileController
4 4
5 def module_result 5 def module_result
6 @module_result = Kalibro::ModuleResult.find(params[:module_result_id].to_i) 6 @module_result = Kalibro::ModuleResult.find(params[:module_result_id].to_i)
  7 + @metric_results = Kalibro::MetricResult.metric_results_of(@module_result.id)
7 render :partial => 'module_result' 8 render :partial => 'module_result'
8 end 9 end
9 10
10 - def metric_results  
11 - @module_result_id = params[:module_result_id].to_i  
12 - @metric_results = Kalibro::MetricResult.metric_results_of(@module_result_id)  
13 - render :partial => 'metric_results'  
14 - end  
15 -  
16 def metric_result_history 11 def metric_result_history
17 @history = Kalibro::MetricResult.history_of(params[:metric_name], params[:module_result_id].to_i) 12 @history = Kalibro::MetricResult.history_of(params[:metric_name], params[:module_result_id].to_i)
18 render :partial => 'score_history' 13 render :partial => 'score_history'
plugins/mezuro/lib/kalibro/date_metric_result.rb
@@ -9,5 +9,8 @@ class Kalibro::DateMetricResult < Kalibro::Model @@ -9,5 +9,8 @@ class Kalibro::DateMetricResult < Kalibro::Model
9 def metric_result=(value) 9 def metric_result=(value)
10 @metric_result = Kalibro::MetricResult.to_object value 10 @metric_result = Kalibro::MetricResult.to_object value
11 end 11 end
12 - 12 +
  13 + def result
  14 + @metric_result.value
  15 + end
13 end 16 end
plugins/mezuro/lib/kalibro/date_module_result.rb
@@ -10,4 +10,8 @@ class Kalibro::DateModuleResult < Kalibro::Model @@ -10,4 +10,8 @@ class Kalibro::DateModuleResult < Kalibro::Model
10 @module_result = Kalibro::ModuleResult.to_object value 10 @module_result = Kalibro::ModuleResult.to_object value
11 end 11 end
12 12
  13 + def result
  14 + @module_result.grade
  15 + end
  16 +
13 end 17 end
plugins/mezuro/lib/mezuro_plugin/helpers/content_viewer_helper.rb
@@ -26,8 +26,8 @@ class MezuroPlugin::Helpers::ContentViewerHelper @@ -26,8 +26,8 @@ class MezuroPlugin::Helpers::ContentViewerHelper
26 values = [] 26 values = []
27 labels = [] 27 labels = []
28 score_history.each do |score_data| 28 score_history.each do |score_data|
29 - values << score_data.first  
30 - labels << score_data.last 29 + values << score_data.result
  30 + labels << score_data.date
31 end 31 end
32 labels = discretize_array labels 32 labels = discretize_array labels
33 Gchart.line( 33 Gchart.line(
plugins/mezuro/test/fixtures/metric_configuration_snapshot_fixtures.rb
@@ -14,7 +14,7 @@ class MetricConfigurationSnapshotFixtures @@ -14,7 +14,7 @@ class MetricConfigurationSnapshotFixtures
14 :aggregation_form => 'AVERAGE', 14 :aggregation_form => 'AVERAGE',
15 :metric => MetricFixtures.amloc_hash, 15 :metric => MetricFixtures.amloc_hash,
16 :base_tool_name => "Analizo", 16 :base_tool_name => "Analizo",
17 - :range => [RangeSnapshotFixtures.range_snapshot_hash], 17 + :range => RangeSnapshotFixtures.range_snapshot_hash,
18 :attributes! => { 18 :attributes! => {
19 :metric => { 19 :metric => {
20 'xmlns:xsi'=> 'http://www.w3.org/2001/XMLSchema-instance', 20 'xmlns:xsi'=> 'http://www.w3.org/2001/XMLSchema-instance',
@@ -34,7 +34,7 @@ class MetricConfigurationSnapshotFixtures @@ -34,7 +34,7 @@ class MetricConfigurationSnapshotFixtures
34 :aggregation_form => 'AVERAGE', 34 :aggregation_form => 'AVERAGE',
35 :metric => MetricFixtures.compound_metric, 35 :metric => MetricFixtures.compound_metric,
36 :base_tool_name => "Analizo", 36 :base_tool_name => "Analizo",
37 - :range => [RangeSnapshotFixtures.range_snapshot_hash], 37 + :range => RangeSnapshotFixtures.range_snapshot_hash,
38 :attributes! => { 38 :attributes! => {
39 :metric => { 39 :metric => {
40 'xmlns:xsi'=> 'http://www.w3.org/2001/XMLSchema-instance', 40 'xmlns:xsi'=> 'http://www.w3.org/2001/XMLSchema-instance',
plugins/mezuro/test/functional/profile/mezuro_plugin_module_result_controller_test.rb
@@ -22,18 +22,11 @@ class MezuroPluginModuleResultControllerTest &lt; ActionController::TestCase @@ -22,18 +22,11 @@ class MezuroPluginModuleResultControllerTest &lt; ActionController::TestCase
22 should 'find module result on kalibro' do 22 should 'find module result on kalibro' do
23 Kalibro::ModuleResult.expects(:request).with(:get_module_result, { :module_result_id => @module_result_hash[:id] }). 23 Kalibro::ModuleResult.expects(:request).with(:get_module_result, { :module_result_id => @module_result_hash[:id] }).
24 returns({:module_result => @module_result_hash}) 24 returns({:module_result => @module_result_hash})
25 - get :module_result, :profile => @profile.identifier, :module_result_id => @module_result_hash[:id]  
26 - assert_equal @module_result_hash[:grade], assigns(:module_result).grade  
27 - assert_response 200  
28 - #TODO assert_select('h5', 'Metric results for: Qt-Calculator (APPLICATION)')  
29 - end  
30 -  
31 - should 'get metric_results' do  
32 Kalibro::MetricResult.expects(:request).with(:metric_results_of, { :module_result_id => @module_result_hash[:id] }). 25 Kalibro::MetricResult.expects(:request).with(:metric_results_of, { :module_result_id => @module_result_hash[:id] }).
33 returns({:metric_result => @metric_result_hash}) 26 returns({:metric_result => @metric_result_hash})
34 - get :metric_results, :profile => @profile.identifier, :module_result_id => @module_result_hash[:id] 27 + get :module_result, :profile => @profile.identifier, :module_result_id => @module_result_hash[:id]
  28 + assert_equal @module_result_hash[:grade], assigns(:module_result).grade
35 assert_equal @metric_result_hash[:value], assigns(:metric_results).first.value 29 assert_equal @metric_result_hash[:value], assigns(:metric_results).first.value
36 - assert_equal @module_result_hash[:id], assigns(:module_result_id)  
37 assert_response 200 30 assert_response 200
38 #TODO assert_select('h5', 'Metric results for: Qt-Calculator (APPLICATION)') 31 #TODO assert_select('h5', 'Metric results for: Qt-Calculator (APPLICATION)')
39 end 32 end
@@ -43,7 +36,7 @@ class MezuroPluginModuleResultControllerTest &lt; ActionController::TestCase @@ -43,7 +36,7 @@ class MezuroPluginModuleResultControllerTest &lt; ActionController::TestCase
43 Kalibro::MetricResult.expects(:request).with(:history_of, { :metric_name => metric_name, :module_result_id => @module_result_hash[:id] }). 36 Kalibro::MetricResult.expects(:request).with(:history_of, { :metric_name => metric_name, :module_result_id => @module_result_hash[:id] }).
44 returns({:date_metric_result => @date_metric_result_hash}) 37 returns({:date_metric_result => @date_metric_result_hash})
45 get :metric_result_history, :profile => @profile.identifier, :module_result_id => @module_result_hash[:id], :metric_name => metric_name 38 get :metric_result_history, :profile => @profile.identifier, :module_result_id => @module_result_hash[:id], :metric_name => metric_name
46 - assert_equal @date_metric_result_hash[:date], assigns(:date_metric_results).first.date 39 + assert_equal DateTime.parse(@date_metric_result_hash[:date]), assigns(:history).first.date
47 assert_response 200 40 assert_response 200
48 #TODO assert_select 41 #TODO assert_select
49 end 42 end
@@ -52,7 +45,7 @@ class MezuroPluginModuleResultControllerTest &lt; ActionController::TestCase @@ -52,7 +45,7 @@ class MezuroPluginModuleResultControllerTest &lt; ActionController::TestCase
52 Kalibro::ModuleResult.expects(:request).with(:history_of_module, { :module_result_id => @module_result_hash[:id] }). 45 Kalibro::ModuleResult.expects(:request).with(:history_of_module, { :module_result_id => @module_result_hash[:id] }).
53 returns({:date_module_result => @date_module_result_hash}) 46 returns({:date_module_result => @date_module_result_hash})
54 get :module_result_history, :profile => @profile.identifier, :module_result_id => @module_result_hash[:id] 47 get :module_result_history, :profile => @profile.identifier, :module_result_id => @module_result_hash[:id]
55 - assert_equal @date_module_result_hash[:date], assigns(:date_module_results).first.date 48 + assert_equal DateTime.parse(@date_module_result_hash[:date]), assigns(:history).first.date
56 assert_response 200 49 assert_response 200
57 #TODO assert_select 50 #TODO assert_select
58 end 51 end
plugins/mezuro/views/mezuro_plugin_module_result/_metric_results.rhtml 0 → 100644
@@ -0,0 +1,36 @@ @@ -0,0 +1,36 @@
  1 +<thead>
  2 + <tr>
  3 + <th style="width: 74%">Metric</th>
  4 + <th>Value</th>
  5 + <th>Weight</th>
  6 + <th>Threshold</th>
  7 + </tr>
  8 +</thead>
  9 +<tbody>
  10 + <% @metric_results.each do |metric_result| %>
  11 + <% metric_configuration_snapshot = metric_result.metric_configuration_snapshot%>
  12 + <% range_snapshot = metric_configuration_snapshot.range_snapshot %>
  13 + <% formatted_name = MezuroPlugin::Helpers::ContentViewerHelper.format_name(metric_configuration_snapshot) %>
  14 + <% if !range_snapshot.nil? %>
  15 + <tr>
  16 + <td style="width: 74%"><a href="#" show-metric-history="<%= formatted_name %>" data-module-id="<%= @module_result_id %>"><%= metric_configuration_snapshot.metric.name %></a></td>
  17 + <td><%= MezuroPlugin::Helpers::ContentViewerHelper.format_grade(metric_result.value) %></td>
  18 + <td><%= metric_configuration_snapshot.weight %></td>
  19 + <td style="background-color: #<%= range_snapshot.color %>">
  20 + <span title="<%= range_snapshot.comments %>" >
  21 + <%= range_snapshot.label %>
  22 + </span>
  23 + </td>
  24 + </tr>
  25 + <tr class="<%= formatted_name %>" style="display: none;">
  26 + <td colspan="3">
  27 + <div id='historical-<%= formatted_name %>'>
  28 + </div>
  29 + </td>
  30 + <td align="right">
  31 + <%= range_snapshot.comments.nil? ? '' : range_snapshot.comments %>
  32 + </td>
  33 + </tr>
  34 + <% end %>
  35 + <% end %>
  36 +</tbody>
plugins/mezuro/views/mezuro_plugin_module_result/_module_result.rhtml
1 -<% module_name = @module_result.module.name  
2 -<h5><%= _('Metric results for: #{module_name} (#{@module_result.module.granularity}) ') %> </h5> 1 +<% TODO source tree %>
  2 +<h5><%= _('Metric results for: #{@module_result.module.name} (#{@module_result.module.granularity}) ') %> </h5>
3 3
4 <hr/> 4 <hr/>
5 <div class="zoomable-image"> 5 <div class="zoomable-image">
6 <table style="width: 100%"> 6 <table style="width: 100%">
7 - <thead>  
8 - <tr>  
9 - <th style="width: 74%">Metric</th>  
10 - <th>Value</th>  
11 - <th>Weight</th>  
12 - <th>Threshold</th>  
13 - </tr>  
14 - </thead>  
15 - <tbody>  
16 - <% @metric_results.each do |metric_result| %>  
17 - <% metric_configuration_snapshot = metric_result.metric_configuration_snapshot%>  
18 - <% range_snapshot = metric_configuration_snapshot.range_snapshot %>  
19 - <% formatted_name = MezuroPlugin::Helpers::ContentViewerHelper.format_name(metric_configuration_snapshot) %>  
20 - <% if !range_snapshot.nil? %>  
21 - <tr>  
22 - <td style="width: 74%"><a href="#" show-metric-history="<%= formatted_name %>" data-module-name="<%= module_name %>"><%= metric_configuration_snapshot.metric.name %></a></td>  
23 - <td><%= MezuroPlugin::Helpers::ContentViewerHelper.format_grade(metric_result.value) %></td>  
24 - <td><%= metric_configuration_snapshot.weight %></td>  
25 - <td style="background-color: #<%= range_snapshot.color %>">  
26 - <span title="<%= range_snapshot.comments %>" >  
27 - <%= range_snapshot.label %>  
28 - </span>  
29 - </td>  
30 - </tr>  
31 - <tr class="<%= formatted_name %>" style="display: none;">  
32 - <td colspan="3">  
33 - <div id='historical-<%= formatted_name %>'>  
34 - </div>  
35 - </td>  
36 - <td align="right">  
37 - <%= range_snapshot.comments.nil? ? '' : range_snapshot.comments %>  
38 - </td>  
39 - </tr>  
40 - <% end %>  
41 - <% end %>  
42 - </tbody> 7 + <%= render :partial => "metric_results", :locals => {:metric_results => @metric_results, :module_result_id => @module_result.id} %>
43 <tfoot> 8 <tfoot>
44 <tr> 9 <tr>
45 <td colspan = "3"> 10 <td colspan = "3">
46 <div id='historical-grade' style="display: none;"></div> 11 <div id='historical-grade' style="display: none;"></div>
47 </td> 12 </td>
48 <td align = "right"> 13 <td align = "right">
49 - <a href="#" show-grade-history="<%= module_name %>" data-module-name="<%= module_name%>" > 14 + <a href="#" show-grade-history="<%= @module_result.id %>" data-module-id="<%= module_result.id %>" >
50 <strong> 15 <strong>
51 <%= _('Grade:') %> 16 <%= _('Grade:') %>
52 <%= "%.02f" % @module_result.grade %> 17 <%= "%.02f" % @module_result.grade %>
plugins/mezuro/views/mezuro_plugin_module_result/_score_history.rhtml
1 -<%= image_tag(MezuroPlugin::Helpers::ContentViewerHelper.generate_chart(@score_history)) %> 1 +<%= image_tag(MezuroPlugin::Helpers::ContentViewerHelper.generate_chart(@history)) %>
plugins/mezuro/views/mezuro_plugin_module_result/_source_tree.rhtml
1 -<% unless @content.errors[:base].nil? %>  
2 - <%= @content.errors[:base] %>  
3 -<% else %>  
4 - <h4><%= _('Source tree') %></h4>  
5 - <% module_name = @source_tree.module.name %>  
6 - <% module_label = "#{module_name} (#{@source_tree.module.granularity})" %> 1 +<h4><%= _('Source tree') %></h4>
  2 +<% module_name = @source_tree.module.name %>
  3 +<% module_label = "#{module_name} (#{@source_tree.module.granularity})" %>
7 4
8 - <p><h2 class="path">  
9 - <% if module_name != @project_name %>  
10 - <a href="#" class="source-tree-link" data-module-name="<%= @project_name %>">  
11 - <%= @project_name %>  
12 - </a>  
13 - <% end %> 5 +<p><h2 class="path">
  6 + <% if module_name != @project_name %>
  7 + <a href="#" class="source-tree-link" data-module-name="<%= @project_name %>">
  8 + <%= @project_name %>
  9 + </a>
  10 + <% end %>
14 11
15 12
16 - <% split_link = @source_tree.module.ancestor_names %>  
17 - <% split_link.each do |link| %>  
18 - /<a href="#" class="source-tree-link" data-module-name="<%= link %>">  
19 - <%= link.split(".").last %>  
20 - </a>  
21 - <% end %>  
22 - </h2></p>  
23 -  
24 - <% if @source_tree.children %>  
25 - <table border="0" class="source-tree">  
26 - <% @source_tree.children.each do |child| %>  
27 - <% if child.module.granularity=='PACKAGE' %>  
28 - <tr>  
29 - <td class="icon"><%= image_tag('/plugins/mezuro/images/folder.png')%></td>  
30 - <td class="source-tree-text"><a href='#' class="source-tree-link" data-module-name="<%= child.module.name %>"><%= child.module.name %></a></td>  
31 - </tr>  
32 - <% else %>  
33 - <tr>  
34 - <td class="icon"><%= image_tag('/plugins/mezuro/images/file.png') %></td>  
35 - <td class="source-tree-text">  
36 - <a href='#' class="source-tree-link" data-module-name="<%= child.module.name %>">  
37 - <%= child.module.name %>  
38 - </a>  
39 - </td>  
40 - </tr>  
41 - <% end %>  
42 - <% end %>  
43 - </table> 13 + <% split_link = @source_tree.module.ancestor_names %>
  14 + <% split_link.each do |link| %>
  15 + /<a href="#" class="source-tree-link" data-module-name="<%= link %>">
  16 + <%= link.split(".").last %>
  17 + </a>
44 <% end %> 18 <% end %>
  19 +</h2></p>
  20 +
  21 +<% if @source_tree.children %>
  22 + <table border="0" class="source-tree">
  23 + <% @source_tree.children.each do |child| %>
  24 + <% if child.module.granularity=='PACKAGE' %>
  25 + <tr>
  26 + <td class="icon"><%= image_tag('/plugins/mezuro/images/folder.png')%></td>
  27 + <td class="source-tree-text"><a href='#' class="source-tree-link" data-module-name="<%= child.module.name %>"><%= child.module.name %></a></td>
  28 + </tr>
  29 + <% else %>
  30 + <tr>
  31 + <td class="icon"><%= image_tag('/plugins/mezuro/images/file.png') %></td>
  32 + <td class="source-tree-text">
  33 + <a href='#' class="source-tree-link" data-module-name="<%= child.module.name %>">
  34 + <%= child.module.name %>
  35 + </a>
  36 + </td>
  37 + </tr>
  38 + <% end %>
  39 + <% end %>
  40 + </table>
45 <% end %> 41 <% end %>