Commit 5666ddf2289c3d6a1529d3ce661514d7e82c6324

Authored by Caio
Committed by Paulo Meireles
2 parents 1e80f8b2 32b790e7

[Mezuro] Merge branch 'metric_history' of gitorious.org:+mezuro/noosfero/mezuro into metric_history

Conflicts:
	plugins/mezuro/public/javascripts/project_content.js
plugins/mezuro/controllers/mezuro_plugin_profile_controller.rb
... ... @@ -136,6 +136,14 @@ class MezuroPluginProfileController < ProfileController
136 136 redirect_to "/#{profile.identifier}/#{configuration_name.downcase.gsub(/\s/, '-')}"
137 137 end
138 138  
  139 + def module_metrics_history
  140 + metric_name = params[:metric_name]
  141 + content = profile.articles.find(params[:id])
  142 + module_history = content.result_history(params[:module_name])
  143 + date_history = module_history.collect { |x| x.date }
  144 + metric_history = module_history.collect { |x| (x.metric_results.select { |y| y.metric.name.delete("() ") == metric_name })[0] }
  145 + render :partial => 'content_viewer/metric_history', :locals => {:metric_history => metric_history, :date_history => date_history }
  146 + end
139 147 private
140 148  
141 149 def new_metric_configuration_instance
... ... @@ -166,5 +174,5 @@ class MezuroPluginProfileController < ProfileController
166 174 range.comments = params[:range][:comments]
167 175 range
168 176 end
169   -end
170 177  
  178 +end
... ...
plugins/mezuro/lib/kalibro/client/module_result_client.rb
1 1 class Kalibro::Client::ModuleResultClient
2 2  
3   - # TODO test this
4   - def self.module_result(project_content, module_name)
5   - project_result = project_content.project_result
6   - new.module_result(project_result.project.name, module_name, project_result.date)
7   - end
8   -
9 3 def initialize
10 4 @port = Kalibro::Client::Port.new('ModuleResult')
11 5 end
... ... @@ -23,4 +17,11 @@ class Kalibro::Client::ModuleResultClient
23 17 Kalibro::Entities::Entity.new.to_entity_array(value, Kalibro::Entities::ModuleResult)
24 18 end
25 19  
26   -end
27 20 \ No newline at end of file
  21 + private
  22 +
  23 + def date_with_milliseconds(date)
  24 + milliseconds = "." + (date.sec_fraction * 60 * 60 * 24 * 1000).to_s
  25 + date.to_s[0..18] + milliseconds + date.to_s[19..-1]
  26 + end
  27 +
  28 +end
... ...
plugins/mezuro/lib/mezuro_plugin/project_content.rb
... ... @@ -35,7 +35,16 @@ class MezuroPlugin::ProjectContent < Article
35 35 end
36 36  
37 37 def module_result(module_name)
38   - @module_client ||= Kalibro::Client::ModuleResultClient.module_result(self, module_name)
  38 + module_name = project.name if module_name.nil?
  39 + @module_client ||= module_result_client.module_result(project.name, module_name, project_result.date)
  40 + end
  41 +
  42 + def result_history(module_name)
  43 + @result_history ||= module_result_client.result_history(project.name, module_name)
  44 + end
  45 +
  46 + def module_result_client
  47 + @module_result_client ||= Kalibro::Client::ModuleResultClient.new
39 48 end
40 49  
41 50 after_save :send_project_to_service
... ...
plugins/mezuro/public/javascripts/project_content.js
1 1 var processingTree = false;
  2 +var metricName;
2 3 jQuery(function (){
3 4 jQuery('.source-tree-link').live("click", reloadModule);
4 5 jQuery('[data-show]').live("click", toggle_mezuro);
5   - jQuery('#project_history_date').live("submit", reloadProjectWithDate);
  6 + jQuery('[show-metric-history]').live("click", display_metric_history);
6 7 showLoadingProcess(true);
7 8 showProjectContent();
8 9 });
... ... @@ -11,6 +12,18 @@ function showProjectContent() {
11 12 callAction('project_state', {}, showProjectContentFor);
12 13 }
13 14  
  15 +function display_metric_history() {
  16 + var module_name = jQuery(this).attr('data-module-name');
  17 + var metric_name = jQuery(this).attr('data-metric-name');
  18 + metricName = metric_name;
  19 + callAction('module_metrics_history', {module_name: module_name, metric_name: metric_name}, show_metrics);
  20 + return false;
  21 +}
  22 +
  23 +function show_metrics(content) {
  24 + jQuery('#historical-' + metricName).html(content);
  25 +}
  26 +
14 27 function toggle_mezuro(){
15 28 var element = jQuery(this).attr('data-show');
16 29 jQuery(element).toggle();
... ...
plugins/mezuro/test/functional/mezuro_plugin_profile_controller_test.rb
... ... @@ -68,7 +68,10 @@ class MezuroPluginProfileControllerTest < ActionController::TestCase
68 68  
69 69 should 'get module result' do
70 70 create_project_content
71   - Kalibro::Client::ModuleResultClient.expects(:module_result).with(@content, @name).returns(@module_result)
  71 + module_result_client = mock
  72 + Kalibro::Client::ProjectResultClient.expects(:last_result).with(@name).returns(@project_result)
  73 + Kalibro::Client::ModuleResultClient.expects(:new).returns(module_result_client)
  74 + module_result_client.expects(:module_result).with(@name, @name, @project_result.date).returns(@module_result)
72 75 get :module_result, :profile => @profile.identifier, :id => @content.id, :module_name => @name
73 76 assert_response 200
74 77 assert_select('h5', 'Metric results for: Qt-Calculator (APPLICATION)')
... ...
plugins/mezuro/test/unit/kalibro/client/module_result_client_test.rb
... ... @@ -26,5 +26,4 @@ class ModuleResultClientTest < ActiveSupport::TestCase
26 26 @port.expects(:request).with(:get_result_history, request_body).returns(response)
27 27 assert_equal [@result], @client.result_history('Qt-Calculator', 'main')
28 28 end
29   -
30   -end
31 29 \ No newline at end of file
  30 +end
... ...
plugins/mezuro/test/unit/mezuro_plugin/project_content_test.rb
... ... @@ -46,17 +46,35 @@ class ProjectContentTest < ActiveSupport::TestCase
46 46 should 'get module result from service' do
47 47 module_name = 'My module name'
48 48 module_result = mock
49   - Kalibro::Client::ModuleResultClient.expects(:module_result).with(@content, module_name).
  49 + module_result_client = mock
  50 + project_result = mock
  51 + @content.expects(:project_result).returns(project_result)
  52 + project_result.expects(:date).returns('12/04/2012')
  53 + @content.expects(:module_result_client).returns(module_result_client)
  54 + module_result_client.expects(:module_result).with(@project.name, module_name, '12/04/2012').
50 55 returns(module_result)
51 56 assert_equal module_result, @content.module_result(module_name)
52 57 end
53 58  
54   - should 'get module result root when project name is give' do
  59 + should 'get module result root when nil is given' do
55 60 module_result = mock
56   - Kalibro::Client::ModuleResultClient.expects(:module_result).with(@content, @project.name).
  61 + module_result_client = mock
  62 + project_result = mock
  63 + @content.expects(:project_result).returns(project_result)
  64 + project_result.expects(:date).returns('12/04/2012')
  65 + @content.expects(:module_result_client).returns(module_result_client)
  66 + module_result_client.expects(:module_result).with(@project.name, @project.name, '12/04/2012').
57 67 returns(module_result)
58   - assert_equal module_result, @content.module_result(@project.name)
59   - end
  68 + assert_equal module_result, @content.module_result(nil)
  69 + end
  70 +
  71 + should 'get result history' do
  72 + module_name = 'Qt-Calculator'
  73 + module_result_client = mock
  74 + @content.expects(:module_result_client).returns(module_result_client)
  75 + module_result_client.expects(:result_history).with(@project.name, module_name)
  76 + @content.result_history(module_name)
  77 + end
60 78  
61 79 should 'send project to service after saving' do
62 80 @content.expects :send_project_to_service
... ...
plugins/mezuro/views/content_viewer/_metric_history.rhtml 0 → 100644
... ... @@ -0,0 +1,14 @@
  1 +<table width="100%">
  2 + <tr>
  3 + <% date_history.each do |date| %>
  4 + <td> <b> <%= date %> </b> </td>
  5 + <% end %>
  6 + </tr>
  7 + <tr>
  8 + <% metric_history.each do |metric_result| %>
  9 + <td>
  10 + <%= MezuroPlugin::Helpers::ContentViewerHelper.format_grade(metric_result.value) %>
  11 + </td>
  12 + <% end %>
  13 + </tr>
  14 + </table>
... ...
plugins/mezuro/views/content_viewer/_module_result.rhtml
... ... @@ -17,21 +17,24 @@
17 17 <tbody>
18 18 <% module_result.metric_results.each do |metric_result| %>
19 19 <% range = metric_result.range %>
20   - <tr>
21   - <td><a href="#" data-show=".<%= metric_result.metric.name.delete("() ")%>"><%= metric_result.metric.name %></a></td>
22   - <td><%= "%.02f" % metric_result.value %></td>
23   - <td><%= metric_result.weight %></td>
24   - <% if range.nil? %>
25   - <td></td>
26   - <% else %>
  20 + <% if !range.nil? %>
  21 + <tr>
  22 + <td><a href="#" data-show=".<%= metric_result.metric.name.delete("() ")%>"><%= metric_result.metric.name %></a></td>
  23 + <td><%= MezuroPlugin::Helpers::ContentViewerHelper.format_grade(metric_result.value) %></td>
  24 + <td><%= metric_result.weight %></td>
27 25 <td style="background-color: #<%= range.color[2..-1] %>"><%= range.label %></td>
28   - <% end %>
29   - </tr>
30   - <tr class="<%= metric_result.metric.name.delete("() ")%>" style="display: none;">
31   - <td colspan="4" align="right">
32   - <%= range.nil? or range.comments.nil? ? 'comment empty' : range.comments %>
33   - </td>
34   - </tr>
  26 + </tr>
  27 + <tr class="<%= metric_result.metric.name.delete("() ")%>" style="display: none;">
  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;"> Draw Historical Graphic </p> </a>
  31 + </div>
  32 + </td>
  33 + <td colspan="3" align="right">
  34 + <%= range.comments.nil? ? '' : range.comments %>
  35 + </td>
  36 + </tr>
  37 + <% end %>
35 38 <% end %>
36 39 </tbody>
37 40 <tfoot>
... ...