Commit 568854a9f50ac8798556196fe3c4411eda1d2338

Authored by Diego Camarinha
Committed by João M. M. da Silva
1 parent e64fac10

[Mezuro] Started refactoring module result controller and view.

plugins/mezuro/controllers/profile/mezuro_plugin_module_controller.rb
... ... @@ -3,10 +3,10 @@ class MezuroPluginModuleController < MezuroPluginProfileController
3 3 append_view_path File.join(File.dirname(__FILE__) + '/../../views')
4 4  
5 5 def module_result
6   - @content = profile.articles.find(params[:id])
7   - @module_result = @content.module_result(params)
8   - @module = @module_result.module
9   - @module_label = "#{@module.name} (#{@module.granularity})"
  6 + project_content = profile.articles.find(params[:id])
  7 + repositories = project_content.repositories
  8 + @module_result = project_content.module_result(repositories.first.id)
  9 + @metric_results = Kalibro::MetricResult.metric_results_of(@module_result.id)
10 10 if project_content_has_errors?
11 11 redirect_to_error_page(@content.errors[:base])
12 12 else
... ... @@ -15,9 +15,9 @@ class MezuroPluginModuleController < MezuroPluginProfileController
15 15 end
16 16  
17 17 def module_metrics_history
18   - metric_name = params[:metric_name]
  18 + module_result_id = params[:module_result_id]
19 19 @content = profile.articles.find(params[:id])
20   - module_history = @content.result_history(params[:module_name])
  20 + module_history = @content.result_history(params[:module_result_id])
21 21 if project_content_has_errors?
22 22 redirect_to_error_page(@content.errors[:base])
23 23 else
... ... @@ -28,7 +28,7 @@ class MezuroPluginModuleController < MezuroPluginProfileController
28 28  
29 29 def module_grade_history
30 30 @content = profile.articles.find(params[:id])
31   - modules_results = @content.result_history(params[:module_name])
  31 + modules_results = @content.result_history(params[:module_result_id])
32 32 if project_content_has_errors?
33 33 redirect_to_error_page(@content.errors[:base])
34 34 else
... ... @@ -42,16 +42,12 @@ class MezuroPluginModuleController < MezuroPluginProfileController
42 42 private
43 43  
44 44 def filtering_metric_history(metric_name, module_history)
45   - metrics_history = module_history.map do |module_result|
46   - [module_result.metric_results, format_date_to_simple_form(module_result.date)]
47   - end
48   - metric_history = metrics_history.map do |metric_results_with_date|
49   - [(metric_results_with_date.first.select do |metric_result|
50   - metric_result.metric.name.delete("() ") == metric_name
51   - end).first, metric_results_with_date.last]
  45 + metrics_history = module_history.select do |m|
  46 + m.metric_result.configuration.metric.name.delete("() ") == metric_name
52 47 end
53   - metric_history.map do |metric_result_with_date|
54   - [metric_result_with_date.first.value, metric_result_with_date.last]
  48 +
  49 + metric_history = metrics_history.map do |m|
  50 + [m.metric_result.value, format_date_to_simple_form(m.date)]
55 51 end
56 52 end
57 53  
... ...
plugins/mezuro/lib/kalibro/metric_configuration_snapshot.rb
... ... @@ -11,7 +11,11 @@ class Kalibro::MetricConfigurationSnapshot < Kalibro::Model
11 11 end
12 12  
13 13 def range=(value)
14   - @range = Kalibro::Range.to_object value
  14 + @range = Kalibro::RangeSnapshot.to_object value
  15 + end
  16 +
  17 + def range_snapshot
  18 + range
15 19 end
16 20  
17 21 end
... ...
plugins/mezuro/lib/kalibro/metric_result.rb
... ... @@ -10,6 +10,10 @@ class Kalibro::MetricResult < Kalibro::Model
10 10 @configuration = Kalibro::MetricConfigurationSnapshot.to_object value
11 11 end
12 12  
  13 + def metric_configuration_snapshot
  14 + configuration
  15 + end
  16 +
13 17 def error=(value)
14 18 @error = Kalibro::Throwable.to_object value
15 19 end
... ...
plugins/mezuro/lib/mezuro_plugin/helpers/content_viewer_helper.rb
... ... @@ -45,8 +45,8 @@ class MezuroPlugin::Helpers::ContentViewerHelper
45 45 selected_option.first
46 46 end
47 47  
48   - def self.format_name(metric_result)
49   - metric_result.configuration.metric.name.delete("() ")
  48 + def self.format_name(metric_configuration_snapshot)
  49 + metric_configuration_snapshot.metric.name.delete("() ")
50 50 end
51 51  
52 52 def self.get_license_option(selected)
... ...
plugins/mezuro/public/javascripts/project_content.js
... ... @@ -18,7 +18,7 @@ function display_metric_history() {
18 18 var metric_name = jQuery(this).attr('show-metric-history');
19 19 toggle_mezuro("." + metric_name);
20 20 metricName = metric_name;
21   - callAction('module', 'module_metrics_history', {module_name: module_name, metric_name: metric_name}, show_metrics);
  21 + callAction('module', 'module_metrics_history', {module_id: module_id, module_result_id: module_result_id}, show_metrics);
22 22 return false;
23 23 }
24 24  
... ...
plugins/mezuro/views/mezuro_plugin_module/_module_result.rhtml
1   -<h5><%= _('Metric results for: ') + @module_label %> </h5>
  1 +<% module_name = @module_result.module.name
  2 +<h5><%= _('Metric results for: #{module_name} (#{@module_result.module.granularity}) ') %> </h5>
2 3  
3 4 <hr/>
4 5 <div class="zoomable-image">
... ... @@ -12,26 +13,28 @@
12 13 </tr>
13 14 </thead>
14 15 <tbody>
15   - <% @module_result.metric_results.each do |metric_result| %>
16   - <% range = metric_result.range %>
17   - <% if !range.nil? %>
  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? %>
18 21 <tr>
19   - <td style="width: 74%"><a href="#" show-metric-history="<%= MezuroPlugin::Helpers::ContentViewerHelper.format_name(metric_result) %>" data-module-name="<%= @module.name %>"><%= metric_result.metric.name %></a></td>
  22 + <td style="width: 74%"><a href="#" show-metric-history="<%= formatted_name %>" data-module-name="<%= module_name %>"><%= metric_configuration_snapshot.metric.name %></a></td>
20 23 <td><%= MezuroPlugin::Helpers::ContentViewerHelper.format_grade(metric_result.value) %></td>
21   - <td><%= metric_result.weight %></td>
22   - <td style="background-color: #<%= range.color[2..-1] %>">
23   - <span title="<%= range.comments %>" >
24   - <%= range.label %>
  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 %>
25 28 </span>
26 29 </td>
27 30 </tr>
28   - <tr class="<%= MezuroPlugin::Helpers::ContentViewerHelper.format_name(metric_result) %>" style="display: none;">
  31 + <tr class="<%= formatted_name %>" style="display: none;">
29 32 <td colspan="3">
30   - <div id='historical-<%= MezuroPlugin::Helpers::ContentViewerHelper.format_name(metric_result) %>'>
  33 + <div id='historical-<%= formatted_name %>'>
31 34 </div>
32 35 </td>
33 36 <td align="right">
34   - <%= range.comments.nil? ? '' : range.comments %>
  37 + <%= range_snapshot.comments.nil? ? '' : range_snapshot.comments %>
35 38 </td>
36 39 </tr>
37 40 <% end %>
... ... @@ -43,7 +46,7 @@
43 46 <div id='historical-grade' style="display: none;"></div>
44 47 </td>
45 48 <td align = "right">
46   - <a href="#" show-grade-history="<%= @module_result.module.name %>" data-module-name="<%= @module.name%>" >
  49 + <a href="#" show-grade-history="<%= module_name %>" data-module-name="<%= module_name%>" >
47 50 <strong>
48 51 <%= _('Grade:') %>
49 52 <%= "%.02f" % @module_result.grade %>
... ...