Commit d9b5245f authored by James Lopez's avatar James Lopez

updated code based on feedback

parent e044bff7
......@@ -139,18 +139,20 @@ module IssuesHelper
end.to_h
end
def issues_weight_options(selected = nil)
options_for_select(issue_weights, selected || params[:weight])
end
def issues_weight_options(selected = nil, edit: false)
weights = edit ? edit_weights : issue_weights
def issues_weight_options_for_edit(selected = nil)
weights = [[Issue::WEIGHT_NONE, nil]] + issue_weights(Issue::WEIGHT_RANGE.to_a)
options_for_select(weights, selected || params[:weight])
end
def issue_weights(weight_array = Issue.weight_options)
weight_array.map {|op| [op] * 2}
weight_array.zip(weight_array)
end
def edit_weights
issue_weights([Issue::WEIGHT_NONE] + Issue::WEIGHT_RANGE.to_a)
end
# Required for Banzai::Filter::IssueReferenceFilter
module_function :url_for_issue
end
......@@ -26,7 +26,7 @@
- if controller.controller_name == 'issues'
.filter-item.inline.weight-filter
= select_tag('weight', issues_weight_options,
= select_tag('weight', issues_weight_options(edit: false),
class: 'select2 trigger-submit', include_blank: true,
data: {placeholder: 'Weight'})
......
......@@ -59,7 +59,7 @@
= f.label :label_ids, class: 'control-label' do
Weight
.col-sm-10
= f.select :weight, issues_weight_options_for_edit(issuable.weight), { include_blank: true },
= f.select :weight, issues_weight_options(issuable.weight, edit: true), { include_blank: true },
{ class: 'select2 js-select2', data: { placeholder: "Select weight" }}
.form-group
......
......@@ -115,7 +115,7 @@
- else
.light None
.selectbox
= f.select :weight, issues_weight_options_for_edit(issuable.weight), { include_blank: true },
= f.select :weight, issues_weight_options(issuable.weight, edit: true), { include_blank: true },
{ class: 'select2 js-select2', data: { placeholder: "Select weight" }}
= render "shared/issuable/participants", participants: issuable.participants(current_user)
......
......@@ -4,7 +4,7 @@ feature 'Issue filtering by Weight', feature: true do
include Select2Helper
let(:project) { create(:project, :public) }
let(:weight_num) {random_weight}
let(:weight_num) { random_weight }
before(:each) do
create(:issue, project: project, weight: nil)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment