From 473eb6cc4e3abb900fd486ddf3b503635e1b9771 Mon Sep 17 00:00:00 2001 From: Guilherme Rojas V. de Lima Date: Tue, 5 Nov 2013 19:50:13 -0200 Subject: [PATCH] Created method to get a list of metric grades --- app/models/date_module_result.rb | 8 ++++++++ app/models/module_result.rb | 21 +++++++++++++++++++++ app/views/repositories/_metric_result.html.erb | 2 +- app/views/repositories/show.html.erb | 3 +-- 4 files changed, 31 insertions(+), 3 deletions(-) create mode 100644 app/models/date_module_result.rb diff --git a/app/models/date_module_result.rb b/app/models/date_module_result.rb new file mode 100644 index 0000000..77f8b46 --- /dev/null +++ b/app/models/date_module_result.rb @@ -0,0 +1,8 @@ +class DateModuleResult < KalibroEntities::Entities::DateModuleResult + include KalibroRecord + + def module_result + ModuleResult.new @module_result.to_hash + end + +end \ No newline at end of file diff --git a/app/models/module_result.rb b/app/models/module_result.rb index 6052df5..51fec94 100644 --- a/app/models/module_result.rb +++ b/app/models/module_result.rb @@ -4,4 +4,25 @@ class ModuleResult < KalibroEntities::Entities::ModuleResult def metric_results KalibroEntities::Entities::MetricResult.metric_results_of(@id) end + + def history_of() + KalibroEntities::Entities::ModuleResult.history_of(@id).map { |date_module_result| DateModuleResult.new date_module_result.to_hash } + end + + def history_of_grades_of(metric_name) + history_of_grades = Hash.new + + date_module_result_list = history_of(@id) + date_module_result_list.each do |date_module_result| + date_module_result.module_result.metric_results.each do |metric_result| + if metric_result.metric_configuration_snapshot.metric.name == metric_name then + metric_grade = metric_result.metric_configuration_snapshot.grade + break + end + end + history_of_grades[date_module_result.date] = metric_grade + end + history_of_grades + end + end \ No newline at end of file diff --git a/app/views/repositories/_metric_result.html.erb b/app/views/repositories/_metric_result.html.erb index 30f5755..cd8d25a 100644 --- a/app/views/repositories/_metric_result.html.erb +++ b/app/views/repositories/_metric_result.html.erb @@ -2,7 +2,7 @@ <% unless metric_configuration_snapshot.range_snapshot.nil? %> <% range_snapshot = find_range_snapshot(metric_result) %> - <%= metric_configuration_snapshot.metric.name %> + <%= link_to metric_configuration_snapshot.metric.name %> <%= format_grade(metric_result.value) %> <%= metric_configuration_snapshot.weight %> <%= range_snapshot.label %> diff --git a/app/views/repositories/show.html.erb b/app/views/repositories/show.html.erb index 96abe0d..d4ec76e 100644 --- a/app/views/repositories/show.html.erb +++ b/app/views/repositories/show.html.erb @@ -67,7 +67,6 @@ <% end %> -

Metric Results

@@ -80,7 +79,7 @@ - <%= render partial: 'metric_result', collection: @root_module_result.metric_results %> + <%= render partial: 'metric_result', collection: @root_module_result.metric_results, locals: {module_result: @root_module_result} %> -- libgit2 0.21.2