From 07fb47c6e95412a96bf45e288cdf3b9f115b58aa Mon Sep 17 00:00:00 2001 From: Sebastian Herrera Date: Thu, 11 Jan 2024 17:59:25 -0300 Subject: [PATCH] Allow to set category for simulated estimation --- app/objects/estimation_category.rb | 20 ++++++--- .../_epic_estimations_history_table.html.erb | 2 +- .../shared/_create_estimation_button.html.erb | 44 +++++++++++-------- .../shared/_epic_estimations_tables.html.erb | 6 +-- 4 files changed, 44 insertions(+), 28 deletions(-) diff --git a/app/objects/estimation_category.rb b/app/objects/estimation_category.rb index d3f0d6e..3ce82a8 100644 --- a/app/objects/estimation_category.rb +++ b/app/objects/estimation_category.rb @@ -4,20 +4,28 @@ class EstimationCategory PESSIMISTIC = :pessimistic NEUTRAL = :neutral OPTIMISTIC = :optimistic - ACTUAL_SINCE_BEGINNING = :actual_since_beginning - ACTUAL_SINCE_LAST_3_WEEKS = :actual_since_last_3_weeks + AVERAGE_SINCE_BEGINNING = :avg_since_beginning + AVERAGE_LAST_3_WEEKS = :avg_last_3_weeks CATEGORIES = { PESSIMISTIC => 0, NEUTRAL => 1, OPTIMISTIC => 2, - ACTUAL_SINCE_BEGINNING => 3, - ACTUAL_SINCE_LAST_3_WEEKS => 4 + AVERAGE_SINCE_BEGINNING => 3, + AVERAGE_LAST_3_WEEKS => 4 + }.with_indifferent_access.freeze + + CATEGORIES_TITLE = { + PESSIMISTIC => PESSIMISTIC.to_s.humanize, + NEUTRAL => NEUTRAL.to_s.humanize, + OPTIMISTIC => OPTIMISTIC.to_s.humanize, + AVERAGE_SINCE_BEGINNING => 'Avg. since beginning', + AVERAGE_LAST_3_WEEKS => 'Avg. last 3 weeks' }.with_indifferent_access.freeze def self.dropdown_options - CATEGORIES.except(ACTUAL_SINCE_BEGINNING, ACTUAL_SINCE_LAST_3_WEEKS).keys.map do |category| - [category.humanize, category] + [NEUTRAL, PESSIMISTIC, OPTIMISTIC].map do |category| + [CATEGORIES_TITLE[category], category.to_s] end end end diff --git a/app/views/estimations/_epic_estimations_history_table.html.erb b/app/views/estimations/_epic_estimations_history_table.html.erb index 4ae8592..2903522 100644 --- a/app/views/estimations/_epic_estimations_history_table.html.erb +++ b/app/views/estimations/_epic_estimations_history_table.html.erb @@ -19,7 +19,7 @@ <%= estimation_item.label %> <%= estimation_item.total_points %> <%= estimation_item.avg_weekly_earned_value %> - <%= estimation_item.category.humanize %> + <%= EstimationCategory::CATEGORIES_TITLE[estimation_item.category] %> <%= "#{estimation_item.remaining_earned_value.round}%" %> <%= estimation_item.remaining_weeks %> <%= estimation_item.estimated_finish_date.strftime("%a, %d %b %Y") %> diff --git a/app/views/shared/_create_estimation_button.html.erb b/app/views/shared/_create_estimation_button.html.erb index 8e354cd..c428345 100644 --- a/app/views/shared/_create_estimation_button.html.erb +++ b/app/views/shared/_create_estimation_button.html.erb @@ -1,20 +1,28 @@ <% if avg_weekly_earned_value.positive? %> - <%= - button_to "Save", - project_epic_create_estimation_path(project_id: project_id, epic_id: epic_id), - params: { - avg_weekly_earned_value: avg_weekly_earned_value, - category: category, - expected_average: params[:expected_average], - implementation_start_date: implementation_start_date, - labels: params[:labels], - last_completed_week_number: last_completed_week_number, - remaining_earned_value: remaining_earned_value, - remaining_weeks: remaining_weeks, - remaining_weeks_with_uncertainty: remaining_weeks_with_uncertainty, - total_points: total_points, - uncertainty_level: params[:uncertainty_level] - }, - class: "btn btn-primary btn-sm" - %> + <%= form_with url: project_epic_create_estimation_path(project_id: project_id, epic_id: epic_id), method: :post do |form| %> + <%= form.hidden_field :avg_weekly_earned_value, value: avg_weekly_earned_value %> + <%= form.hidden_field :expected_average, value: params[:expected_average] %> + <%= form.hidden_field :implementation_start_date, value: implementation_start_date %> + <%= form.hidden_field :labels, value: params[:labels] %> + <%= form.hidden_field :last_completed_week_number, value: last_completed_week_number %> + <%= form.hidden_field :remaining_earned_value, value: remaining_earned_value %> + <%= form.hidden_field :remaining_weeks, value: remaining_weeks %> + <%= form.hidden_field :remaining_weeks_with_uncertainty, value: remaining_weeks_with_uncertainty %> + <%= form.hidden_field :total_points, value: total_points %> + <%= form.hidden_field :uncertainty_level, value: params[:uncertainty_level] %> + +
+ <% if category.blank? %> +
+ <%= form.select :category, EstimationCategory.dropdown_options, { include_blank: false }, { class: "form-control" } %> +
+ <% else %> + <%= form.hidden_field :category, value: category %> + <% end %> + +
+ <%= form.submit "Save", name: nil, class: "btn btn-primary btn-sm" %> +
+
+ <% end %> <% end %> diff --git a/app/views/shared/_epic_estimations_tables.html.erb b/app/views/shared/_epic_estimations_tables.html.erb index 659dce4..0c34b79 100644 --- a/app/views/shared/_epic_estimations_tables.html.erb +++ b/app/views/shared/_epic_estimations_tables.html.erb @@ -4,7 +4,7 @@ render 'shared/epic_estimations_table', period: 'Since Beginning', avg_points: epic_estimation_presenter.avg_points_per_week, - category: EstimationCategory::ACTUAL_SINCE_BEGINNING, + category: EstimationCategory::AVERAGE_SINCE_BEGINNING, epic_id: epic_id, estimated_weeks_to_complete_without_uncertainty: epic_estimation_presenter.estimated_weeks_to_complete_without_uncertainty, estimated_weeks_to_complete_with_uncertainty: epic_estimation_presenter.estimated_weeks_to_complete_with_uncertainty, @@ -21,7 +21,7 @@ render 'shared/epic_estimations_table', period: 'Since Last 3 Weeks', avg_points: epic_estimation_presenter.avg_points_per_week(weeks_ago_since: 3), - category: EstimationCategory::ACTUAL_SINCE_LAST_3_WEEKS, + category: EstimationCategory::AVERAGE_LAST_3_WEEKS, epic_id: epic_id, estimated_weeks_to_complete_without_uncertainty: epic_estimation_presenter.estimated_weeks_to_complete_without_uncertainty(weeks_ago_since: 3), estimated_weeks_to_complete_with_uncertainty: epic_estimation_presenter.estimated_weeks_to_complete_with_uncertainty(weeks_ago_since: 3), @@ -39,7 +39,7 @@ render 'shared/epic_estimations_table', period: 'Expected', avg_points: epic_estimation_presenter.avg_points_per_week_expected, - category: EstimationCategory::NEUTRAL, # TODO: change this to allow selecting the category + category: nil, epic_id: epic_id, estimated_weeks_to_complete_without_uncertainty: epic_estimation_presenter.estimated_weeks_to_complete_without_uncertainty(use_expected: true), estimated_weeks_to_complete_with_uncertainty: epic_estimation_presenter.estimated_weeks_to_complete_with_uncertainty(use_expected: true),