Skip to content

Commit

Permalink
Allow to set category for simulated estimation
Browse files Browse the repository at this point in the history
  • Loading branch information
sebaherrera07 committed Jan 11, 2024
1 parent 19ed237 commit 07fb47c
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 28 deletions.
20 changes: 14 additions & 6 deletions app/objects/estimation_category.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<td><%= estimation_item.label %></td>
<td><%= estimation_item.total_points %></td>
<td><%= estimation_item.avg_weekly_earned_value %></td>
<td><%= estimation_item.category.humanize %></td>
<td><%= EstimationCategory::CATEGORIES_TITLE[estimation_item.category] %></td>
<td><%= "#{estimation_item.remaining_earned_value.round}%" %></td>
<td><%= estimation_item.remaining_weeks %></td>
<td><%= estimation_item.estimated_finish_date.strftime("%a, %d %b %Y") %></td>
Expand Down
44 changes: 26 additions & 18 deletions app/views/shared/_create_estimation_button.html.erb
Original file line number Diff line number Diff line change
@@ -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] %>

<div class="row">
<% if category.blank? %>
<div class="col-lg-8">
<%= form.select :category, EstimationCategory.dropdown_options, { include_blank: false }, { class: "form-control" } %>
</div>
<% else %>
<%= form.hidden_field :category, value: category %>
<% end %>

<div class="col-lg-4">
<%= form.submit "Save", name: nil, class: "btn btn-primary btn-sm" %>
</div>
</div>
<% end %>
<% end %>
6 changes: 3 additions & 3 deletions app/views/shared/_epic_estimations_tables.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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),
Expand All @@ -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),
Expand Down

0 comments on commit 07fb47c

Please sign in to comment.