Commit 568854a9f50ac8798556196fe3c4411eda1d2338
Committed by
João M. M. da Silva
1 parent
e64fac10
Exists in
master
and in
29 other branches
[Mezuro] Started refactoring module result controller and view.
Showing
6 changed files
with
40 additions
and
33 deletions
Show diff stats
plugins/mezuro/controllers/profile/mezuro_plugin_module_controller.rb
@@ -3,10 +3,10 @@ class MezuroPluginModuleController < MezuroPluginProfileController | @@ -3,10 +3,10 @@ class MezuroPluginModuleController < MezuroPluginProfileController | ||
3 | append_view_path File.join(File.dirname(__FILE__) + '/../../views') | 3 | append_view_path File.join(File.dirname(__FILE__) + '/../../views') |
4 | 4 | ||
5 | def module_result | 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 | if project_content_has_errors? | 10 | if project_content_has_errors? |
11 | redirect_to_error_page(@content.errors[:base]) | 11 | redirect_to_error_page(@content.errors[:base]) |
12 | else | 12 | else |
@@ -15,9 +15,9 @@ class MezuroPluginModuleController < MezuroPluginProfileController | @@ -15,9 +15,9 @@ class MezuroPluginModuleController < MezuroPluginProfileController | ||
15 | end | 15 | end |
16 | 16 | ||
17 | def module_metrics_history | 17 | def module_metrics_history |
18 | - metric_name = params[:metric_name] | 18 | + module_result_id = params[:module_result_id] |
19 | @content = profile.articles.find(params[:id]) | 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 | if project_content_has_errors? | 21 | if project_content_has_errors? |
22 | redirect_to_error_page(@content.errors[:base]) | 22 | redirect_to_error_page(@content.errors[:base]) |
23 | else | 23 | else |
@@ -28,7 +28,7 @@ class MezuroPluginModuleController < MezuroPluginProfileController | @@ -28,7 +28,7 @@ class MezuroPluginModuleController < MezuroPluginProfileController | ||
28 | 28 | ||
29 | def module_grade_history | 29 | def module_grade_history |
30 | @content = profile.articles.find(params[:id]) | 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 | if project_content_has_errors? | 32 | if project_content_has_errors? |
33 | redirect_to_error_page(@content.errors[:base]) | 33 | redirect_to_error_page(@content.errors[:base]) |
34 | else | 34 | else |
@@ -42,16 +42,12 @@ class MezuroPluginModuleController < MezuroPluginProfileController | @@ -42,16 +42,12 @@ class MezuroPluginModuleController < MezuroPluginProfileController | ||
42 | private | 42 | private |
43 | 43 | ||
44 | def filtering_metric_history(metric_name, module_history) | 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 | end | 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 | end | 51 | end |
56 | end | 52 | end |
57 | 53 |
plugins/mezuro/lib/kalibro/metric_configuration_snapshot.rb
@@ -11,7 +11,11 @@ class Kalibro::MetricConfigurationSnapshot < Kalibro::Model | @@ -11,7 +11,11 @@ class Kalibro::MetricConfigurationSnapshot < Kalibro::Model | ||
11 | end | 11 | end |
12 | 12 | ||
13 | def range=(value) | 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 | end | 19 | end |
16 | 20 | ||
17 | end | 21 | end |
plugins/mezuro/lib/kalibro/metric_result.rb
@@ -10,6 +10,10 @@ class Kalibro::MetricResult < Kalibro::Model | @@ -10,6 +10,10 @@ class Kalibro::MetricResult < Kalibro::Model | ||
10 | @configuration = Kalibro::MetricConfigurationSnapshot.to_object value | 10 | @configuration = Kalibro::MetricConfigurationSnapshot.to_object value |
11 | end | 11 | end |
12 | 12 | ||
13 | + def metric_configuration_snapshot | ||
14 | + configuration | ||
15 | + end | ||
16 | + | ||
13 | def error=(value) | 17 | def error=(value) |
14 | @error = Kalibro::Throwable.to_object value | 18 | @error = Kalibro::Throwable.to_object value |
15 | end | 19 | end |
plugins/mezuro/lib/mezuro_plugin/helpers/content_viewer_helper.rb
@@ -45,8 +45,8 @@ class MezuroPlugin::Helpers::ContentViewerHelper | @@ -45,8 +45,8 @@ class MezuroPlugin::Helpers::ContentViewerHelper | ||
45 | selected_option.first | 45 | selected_option.first |
46 | end | 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 | end | 50 | end |
51 | 51 | ||
52 | def self.get_license_option(selected) | 52 | def self.get_license_option(selected) |
plugins/mezuro/public/javascripts/project_content.js
@@ -18,7 +18,7 @@ function display_metric_history() { | @@ -18,7 +18,7 @@ function display_metric_history() { | ||
18 | var metric_name = jQuery(this).attr('show-metric-history'); | 18 | var metric_name = jQuery(this).attr('show-metric-history'); |
19 | toggle_mezuro("." + metric_name); | 19 | toggle_mezuro("." + metric_name); |
20 | metricName = metric_name; | 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 | return false; | 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 | <hr/> | 4 | <hr/> |
4 | <div class="zoomable-image"> | 5 | <div class="zoomable-image"> |
@@ -12,26 +13,28 @@ | @@ -12,26 +13,28 @@ | ||
12 | </tr> | 13 | </tr> |
13 | </thead> | 14 | </thead> |
14 | <tbody> | 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 | <tr> | 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 | <td><%= MezuroPlugin::Helpers::ContentViewerHelper.format_grade(metric_result.value) %></td> | 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 | </span> | 28 | </span> |
26 | </td> | 29 | </td> |
27 | </tr> | 30 | </tr> |
28 | - <tr class="<%= MezuroPlugin::Helpers::ContentViewerHelper.format_name(metric_result) %>" style="display: none;"> | 31 | + <tr class="<%= formatted_name %>" style="display: none;"> |
29 | <td colspan="3"> | 32 | <td colspan="3"> |
30 | - <div id='historical-<%= MezuroPlugin::Helpers::ContentViewerHelper.format_name(metric_result) %>'> | 33 | + <div id='historical-<%= formatted_name %>'> |
31 | </div> | 34 | </div> |
32 | </td> | 35 | </td> |
33 | <td align="right"> | 36 | <td align="right"> |
34 | - <%= range.comments.nil? ? '' : range.comments %> | 37 | + <%= range_snapshot.comments.nil? ? '' : range_snapshot.comments %> |
35 | </td> | 38 | </td> |
36 | </tr> | 39 | </tr> |
37 | <% end %> | 40 | <% end %> |
@@ -43,7 +46,7 @@ | @@ -43,7 +46,7 @@ | ||
43 | <div id='historical-grade' style="display: none;"></div> | 46 | <div id='historical-grade' style="display: none;"></div> |
44 | </td> | 47 | </td> |
45 | <td align = "right"> | 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 | <strong> | 50 | <strong> |
48 | <%= _('Grade:') %> | 51 | <%= _('Grade:') %> |
49 | <%= "%.02f" % @module_result.grade %> | 52 | <%= "%.02f" % @module_result.grade %> |