Commit d9b5245f authored by James Lopez's avatar James Lopez

updated code based on feedback

parent e044bff7
...@@ -139,18 +139,20 @@ module IssuesHelper ...@@ -139,18 +139,20 @@ module IssuesHelper
end.to_h end.to_h
end end
def issues_weight_options(selected = nil) def issues_weight_options(selected = nil, edit: false)
options_for_select(issue_weights, selected || params[:weight]) weights = edit ? edit_weights : issue_weights
end
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]) options_for_select(weights, selected || params[:weight])
end end
def issue_weights(weight_array = Issue.weight_options) 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 end
# Required for Banzai::Filter::IssueReferenceFilter # Required for Banzai::Filter::IssueReferenceFilter
module_function :url_for_issue module_function :url_for_issue
end end
...@@ -26,7 +26,7 @@ ...@@ -26,7 +26,7 @@
- if controller.controller_name == 'issues' - if controller.controller_name == 'issues'
.filter-item.inline.weight-filter .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, class: 'select2 trigger-submit', include_blank: true,
data: {placeholder: 'Weight'}) data: {placeholder: 'Weight'})
......
...@@ -59,7 +59,7 @@ ...@@ -59,7 +59,7 @@
= f.label :label_ids, class: 'control-label' do = f.label :label_ids, class: 'control-label' do
Weight Weight
.col-sm-10 .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" }} { class: 'select2 js-select2', data: { placeholder: "Select weight" }}
.form-group .form-group
......
...@@ -115,7 +115,7 @@ ...@@ -115,7 +115,7 @@
- else - else
.light None .light None
.selectbox .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" }} { class: 'select2 js-select2', data: { placeholder: "Select weight" }}
= render "shared/issuable/participants", participants: issuable.participants(current_user) = render "shared/issuable/participants", participants: issuable.participants(current_user)
......
...@@ -3,8 +3,8 @@ require 'rails_helper' ...@@ -3,8 +3,8 @@ require 'rails_helper'
feature 'Issue filtering by Weight', feature: true do feature 'Issue filtering by Weight', feature: true do
include Select2Helper include Select2Helper
let(:project) { create(:project, :public) } let(:project) { create(:project, :public) }
let(:weight_num) {random_weight} let(:weight_num) { random_weight }
before(:each) do before(:each) do
create(:issue, project: project, weight: nil) 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