Commit e86864395b0f47ac34b4926d2d3c46d95bae75e1

Authored by João M. M. da Silva + Caio Salgado + Alessandro Palmeira
Committed by Paulo Meireles
1 parent 077b3df7

[Mezuro] added history to grade value

plugins/mezuro/controllers/mezuro_plugin_profile_controller.rb
@@ -43,8 +43,16 @@ class MezuroPluginProfileController < ProfileController @@ -43,8 +43,16 @@ class MezuroPluginProfileController < ProfileController
43 metric_name = params[:metric_name] 43 metric_name = params[:metric_name]
44 content = profile.articles.find(params[:id]) 44 content = profile.articles.find(params[:id])
45 module_history = content.result_history(params[:module_name]) 45 module_history = content.result_history(params[:module_name])
46 - date_history = module_history.collect { |x| x.date }  
47 - metric_history = module_history.collect { |x| (x.metric_results.select { |y| y.metric.name.delete("() ") == metric_name })[0] }  
48 - render :partial => 'content_viewer/metric_history', :locals => {:metric_history => metric_history, :date_history => date_history } 46 + date_history = module_history.collect { |module_result| module_result.date }
  47 + score_history = (module_history.collect { |module_result| (module_result.metric_results.select { |metric_result| metric_result.metric.name.delete("() ") == metric_name })[0] }).collect { |metric_result| metric_result.value }
  48 + render :partial => 'content_viewer/score_history', :locals => {:score_history => score_history, :date_history => date_history }
  49 + end
  50 +
  51 + def module_grade_history
  52 + content = profile.articles.find(params[:id])
  53 + modules_results = content.result_history(params[:module_name])
  54 + date_history = modules_results.collect { |module_result| module_result.date }
  55 + score_history = modules_results.collect { |module_result| module_result.grade }
  56 + render :partial => 'content_viewer/score_history', :locals => {:date_history => date_history, :score_history => score_history }
49 end 57 end
50 end 58 end
plugins/mezuro/public/javascripts/project_content.js
@@ -22,7 +22,8 @@ function display_metric_history() { @@ -22,7 +22,8 @@ function display_metric_history() {
22 } 22 }
23 23
24 function display_grade_history() { 24 function display_grade_history() {
25 - alert(jQuery(this).attr('show-grade-history')); 25 + var module_name = jQuery(this).attr('show-grade-history');
  26 + callAction('module_grade_history', {module_name: module_name}, show_grades);
26 return false; 27 return false;
27 } 28 }
28 29
@@ -30,6 +31,10 @@ function show_metrics(content) { @@ -30,6 +31,10 @@ function show_metrics(content) {
30 jQuery('#historical-' + metricName).html(content); 31 jQuery('#historical-' + metricName).html(content);
31 } 32 }
32 33
  34 +function show_grades(content) {
  35 + jQuery('#historical-grade').html(content);
  36 +}
  37 +
33 function toggle_mezuro(){ 38 function toggle_mezuro(){
34 var element = jQuery(this).attr('data-show'); 39 var element = jQuery(this).attr('data-show');
35 jQuery(element).toggle(); 40 jQuery(element).toggle();
plugins/mezuro/test/functional/mezuro_plugin_profile_controller_test.rb
@@ -20,7 +20,7 @@ class MezuroPluginProfileControllerTest < ActionController::TestCase @@ -20,7 +20,7 @@ class MezuroPluginProfileControllerTest < ActionController::TestCase
20 @project = @project_result.project 20 @project = @project_result.project
21 @name = @project.name 21 @name = @project.name
22 22
23 - @date = "2012-04-13T20:39:41+04:00" 23 + @date = "2012-04-13T20:39:41+04:00"
24 end 24 end
25 25
26 should 'not find module result for inexistent project content' do 26 should 'not find module result for inexistent project content' do
@@ -92,7 +92,7 @@ class MezuroPluginProfileControllerTest < ActionController::TestCase @@ -92,7 +92,7 @@ class MezuroPluginProfileControllerTest < ActionController::TestCase
92 end 92 end
93 93
94 should 'get project tree without date' do 94 should 'get project tree without date' do
95 - create_project_content 95 + create_project_content
96 Kalibro::Client::ProjectResultClient.expects(:last_result).with(@name).returns(@project_result) 96 Kalibro::Client::ProjectResultClient.expects(:last_result).with(@name).returns(@project_result)
97 Kalibro::Client::ProjectClient.expects(:project).with(@name).returns(@project) 97 Kalibro::Client::ProjectClient.expects(:project).with(@name).returns(@project)
98 get :project_tree, :profile => @profile.identifier, :id => @content.id, :module_name => @name 98 get :project_tree, :profile => @profile.identifier, :id => @content.id, :module_name => @name
@@ -101,13 +101,23 @@ class MezuroPluginProfileControllerTest < ActionController::TestCase @@ -101,13 +101,23 @@ class MezuroPluginProfileControllerTest < ActionController::TestCase
101 end 101 end
102 102
103 should 'get project tree from a specific date' do 103 should 'get project tree from a specific date' do
104 - create_project_content 104 + create_project_content
105 mock_project_result 105 mock_project_result
106 Kalibro::Client::ProjectClient.expects(:project).with(@name).returns(@project) 106 Kalibro::Client::ProjectClient.expects(:project).with(@name).returns(@project)
107 get :project_tree, :profile => @profile.identifier, :id => @content.id, :module_name => @name, :date => "2012-04-13T20:39:41+04:00" 107 get :project_tree, :profile => @profile.identifier, :id => @content.id, :module_name => @name, :date => "2012-04-13T20:39:41+04:00"
108 assert_response 200 108 assert_response 200
109 end 109 end
110 110
  111 + should 'get grade history' do
  112 + create_project_content
  113 + client = mock
  114 + Kalibro::Client::ModuleResultClient.expects(:new).returns(client)
  115 + client.expects(:result_history).returns([@module_result])
  116 + get :module_grade_history, :profile => @profile.identifier, :id => @content.id, :module_name => @name
  117 + assert_equal assings(:modules_results)[0].grade, 10.0
  118 + assert_response 200
  119 + end
  120 +
111 private 121 private
112 122
113 def create_project_content 123 def create_project_content
plugins/mezuro/views/content_viewer/_metric_history.rhtml
@@ -1,10 +0,0 @@ @@ -1,10 +0,0 @@
1 -<table width="100%">  
2 - <% cont = 0 %>  
3 - <% date_history.each do |date| %>  
4 - <tr>  
5 - <td width="70%"> <b> <%= date %> </b> </td>  
6 - <td width="30%"> <%= MezuroPlugin::Helpers::ContentViewerHelper.format_grade(metric_history[cont].value) %> </td>  
7 - </tr>  
8 - <% cont = cont + 1 %>  
9 - <% end %>  
10 - </table>  
plugins/mezuro/views/content_viewer/_module_result.rhtml
@@ -26,25 +26,29 @@ @@ -26,25 +26,29 @@
26 </tr> 26 </tr>
27 <tr class="<%= metric_result.metric.name.delete("() ")%>" style="display: none;"> 27 <tr class="<%= metric_result.metric.name.delete("() ")%>" style="display: none;">
28 <td colspan="4"> 28 <td colspan="4">
29 - <div id='historical-<%= metric_result.metric.name.delete("() ") %>'>  
30 - <a href="#" show-metric-history="<%= metric_result.metric.name.delete("() ") %>" data-module-name="<%= the_module.name %>" data-metric-name="<%= metric_result.metric.name.delete("() ") %>"> <p style="text-indent: 3em;"> Get Historical Values </p> </a>  
31 - </div> 29 + <div id='historical-<%= metric_result.metric.name.delete("() ") %>'>
  30 + <a href="#" show-metric-history="<%= metric_result.metric.name.delete("() ") %>" data-module-name="<%= the_module.name %>" data-metric-name="<%= metric_result.metric.name.delete("() ") %>"> <p style="text-indent: 3em;"> Get Historical Values </p> </a>
  31 + </div>
32 </td> 32 </td>
33 <td colspan="3" align="right"> 33 <td colspan="3" align="right">
34 <%= range.comments.nil? ? '' : range.comments %> 34 <%= range.comments.nil? ? '' : range.comments %>
35 </td> 35 </td>
36 </tr> 36 </tr>
37 - <% end %> 37 + <% end %>
38 <% end %> 38 <% end %>
39 </tbody> 39 </tbody>
40 <tfoot> 40 <tfoot>
41 <tr> 41 <tr>
42 - <td colspan = "4" align = "right"> <a href="#" show-grade-history="<%= module_result.grade %>" >  
43 - <strong>  
44 - <%= _('Grade:') %>  
45 - <%= "%.02f" % module_result.grade %>  
46 - </strong>  
47 - </a> 42 + <td colspan = "1">
  43 + <div id='historical-grade'>
  44 + </td>
  45 + <td colspan = "4" align = "right">
  46 + <a href="#" show-grade-history="<%= module_result.module.name %>" >
  47 + <strong>
  48 + <%= _('Grade:') %>
  49 + <%= "%.02f" % module_result.grade %>
  50 + </strong>
  51 + </a>
48 </td> 52 </td>
49 </tr> 53 </tr>
50 </tfoot> 54 </tfoot>
plugins/mezuro/views/content_viewer/_score_history.rhtml 0 → 100644
@@ -0,0 +1,10 @@ @@ -0,0 +1,10 @@
  1 +<table width="100%">
  2 + <% cont = 0 %>
  3 + <% date_history.each do |date| %>
  4 + <tr>
  5 + <td width="70%"> <b> <%= date %> </b> </td>
  6 + <td width="30%"> <%= MezuroPlugin::Helpers::ContentViewerHelper.format_grade(score_history[cont]) %> </td>
  7 + </tr>
  8 + <% cont = cont + 1 %>
  9 + <% end %>
  10 + </table>