summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Rowden <hello@danrowden.com>2016-07-26 14:30:14 +0100
committerAlfredo Sumaran <alfredo@gitlab.com>2016-09-07 15:27:14 -0500
commit894bd04decf1a2e6a7ca7b1450db9ac7bddd4735 (patch)
treed4fb409bc83abcd48ee16e7ef52f333277afb149
parentdb116fa0811b41c220a2dd843426d81e40db42e7 (diff)
downloadgitlab-ce-894bd04decf1a2e6a7ca7b1450db9ac7bddd4735.tar.gz
Added a small helper to reduce logic in the view
-rw-r--r--app/helpers/milestones_helper.rb11
-rw-r--r--app/views/shared/_milestones_filter.html.haml6
2 files changed, 14 insertions, 3 deletions
diff --git a/app/helpers/milestones_helper.rb b/app/helpers/milestones_helper.rb
index 404a116d951..27f4354cf42 100644
--- a/app/helpers/milestones_helper.rb
+++ b/app/helpers/milestones_helper.rb
@@ -47,6 +47,17 @@ module MilestonesHelper
}
end
+ # Show 'active' class if provided GET param matches check
+ # `or_blank` allows the function to return 'active' when given an empty param
+ # Could be refactored to be simpler but that may make it harder to read
+ def milestone_class_for_state(param, check, match_blank_param=false)
+ if match_blank_param
+ 'active' if param.blank? || param == check
+ else
+ 'active' if param == check
+ end
+ end
+
def milestone_progress_bar(milestone)
options = {
class: 'progress-bar progress-bar-success',
diff --git a/app/views/shared/_milestones_filter.html.haml b/app/views/shared/_milestones_filter.html.haml
index 65cc2d6a401..73d288e2236 100644
--- a/app/views/shared/_milestones_filter.html.haml
+++ b/app/views/shared/_milestones_filter.html.haml
@@ -2,17 +2,17 @@
- counts = milestone_counts(@project.milestones)
%ul.nav-links
- %li{class: ("active" if params[:state].blank? || params[:state] == 'opened')}
+ %li{class: milestone_class_for_state(params[:state], 'opened', true)}
= link_to milestones_filter_path(state: 'opened') do
Open
- if @project
%span.badge #{counts[:opened]}
- %li{class: ("active" if params[:state] == 'closed')}
+ %li{class: milestone_class_for_state(params[:state], 'closed')}
= link_to milestones_filter_path(state: 'closed') do
Closed
- if @project
%span.badge #{counts[:closed]}
- %li{class: ("active" if params[:state] == 'all')}
+ %li{class: milestone_class_for_state(params[:state], 'all')}
= link_to milestones_filter_path(state: 'all') do
All
- if @project