summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTiago Botelho <tiagonbotelho@hotmail.com>2017-04-19 15:10:28 +0100
committerTiago Botelho <tiagonbotelho@hotmail.com>2017-04-20 14:22:01 +0100
commit9d43ff2f8995604803569db7d442390c502477d3 (patch)
tree762e50e11574dde2ced870f6975b1b559583a2c7
parent554d29749326bdf9bc9ec7723311195dd1a42e9b (diff)
downloadgitlab-ce-30326-add-upcoming-and-started-milestone-filters-to-issuables.tar.gz
add upcoming and started milestone filters to issuable30326-add-upcoming-and-started-milestone-filters-to-issuables
-rw-r--r--app/models/milestone.rb8
-rw-r--r--app/services/issuable_base_service.rb27
-rw-r--r--app/views/shared/issuable/_sidebar.html.haml2
-rw-r--r--app/views/shared/issuable/form/_metadata.html.haml2
4 files changed, 32 insertions, 7 deletions
diff --git a/app/models/milestone.rb b/app/models/milestone.rb
index 652b1551928..1b30f7a5538 100644
--- a/app/models/milestone.rb
+++ b/app/models/milestone.rb
@@ -64,6 +64,14 @@ class Milestone < ActiveRecord::Base
where(t[:title].matches(pattern).or(t[:description].matches(pattern)))
end
+
+ def upcoming
+ where('due_date > ?', Time.now).order(due_date: :asc).first
+ end
+
+ def started
+ where('start_date <= ?', Time.now).order(start_date: :asc).first
+ end
end
def self.reference_prefix
diff --git a/app/services/issuable_base_service.rb b/app/services/issuable_base_service.rb
index b071a398481..a6541740fcb 100644
--- a/app/services/issuable_base_service.rb
+++ b/app/services/issuable_base_service.rb
@@ -87,12 +87,29 @@ class IssuableBaseService < BaseService
def filter_milestone
milestone_id = params[:milestone_id]
- return unless milestone_id
- if milestone_id == IssuableFinder::NONE ||
- project.milestones.find_by(id: milestone_id).nil?
- params[:milestone_id] = ''
- end
+ return unless milestone_id || project.milestones.find_by(id: milestone_id).nil?
+
+ params[:milestone_id] =
+ if filter_by_upcoming_milestone?
+ project.milestones.upcoming&.id
+ elsif filter_by_started_milestone?
+ project.milestones.started&.id
+ elsif filter_by_no_milestone?
+ ''
+ end
+ end
+
+ def filter_by_upcoming_milestone?
+ params[:milestone_id] == Milestone::Upcoming.id.to_s
+ end
+
+ def filter_by_started_milestone?
+ params[:milestone_id] == Milestone::Started.id.to_s
+ end
+
+ def filter_by_no_milestone?
+ params[:milestone_id] == Milestone::None.id.to_s
end
def filter_labels
diff --git a/app/views/shared/issuable/_sidebar.html.haml b/app/views/shared/issuable/_sidebar.html.haml
index 2e0d6a129fb..ef89dc7dcff 100644
--- a/app/views/shared/issuable/_sidebar.html.haml
+++ b/app/views/shared/issuable/_sidebar.html.haml
@@ -72,7 +72,7 @@
.selectbox.hide-collapsed
= f.hidden_field 'milestone_id', value: issuable.milestone_id, id: nil
- = dropdown_tag('Milestone', options: { title: 'Assign milestone', toggle_class: 'js-milestone-select js-extra-options', filter: true, dropdown_class: 'dropdown-menu-selectable', placeholder: 'Search milestones', data: { show_no: true, field_name: "#{issuable.to_ability_name}[milestone_id]", project_id: @project.id, issuable_id: issuable.id, milestones: namespace_project_milestones_path(@project.namespace, @project, :json), ability_name: issuable.to_ability_name, issue_update: issuable_json_path(issuable), use_id: true }})
+ = dropdown_tag('Milestone', options: { title: 'Assign milestone', toggle_class: 'js-milestone-select js-extra-options', filter: true, dropdown_class: 'dropdown-menu-selectable', placeholder: 'Search milestones', data: { show_no: true, show_upcoming: true, show_started: true, field_name: "#{issuable.to_ability_name}[milestone_id]", project_id: @project.id, issuable_id: issuable.id, milestones: namespace_project_milestones_path(@project.namespace, @project, :json), ability_name: issuable.to_ability_name, issue_update: issuable_json_path(issuable), use_id: true }})
- if issuable.has_attribute?(:time_estimate)
#issuable-time-tracker.block
%issuable-time-tracker{ ':time_estimate' => 'issuable.time_estimate', ':time_spent' => 'issuable.total_time_spent', ':human_time_estimate' => 'issuable.human_time_estimate', ':human_time_spent' => 'issuable.human_total_time_spent', 'docs-url' => help_page_path('workflow/time_tracking.md') }
diff --git a/app/views/shared/issuable/form/_metadata.html.haml b/app/views/shared/issuable/form/_metadata.html.haml
index 9dbfedb84f1..fb26d58727d 100644
--- a/app/views/shared/issuable/form/_metadata.html.haml
+++ b/app/views/shared/issuable/form/_metadata.html.haml
@@ -21,7 +21,7 @@
= form.label :milestone_id, "Milestone", class: "control-label #{"col-lg-4" if has_due_date}"
.col-sm-10{ class: ("col-lg-8" if has_due_date) }
.issuable-form-select-holder
- = render "shared/issuable/milestone_dropdown", selected: issuable.milestone, name: "#{issuable.class.model_name.param_key}[milestone_id]", show_any: false, show_upcoming: false, show_started: false, extra_class: "js-issuable-form-dropdown js-dropdown-keep-input", dropdown_title: "Select milestone"
+ = render "shared/issuable/milestone_dropdown", selected: issuable.milestone, name: "#{issuable.class.model_name.param_key}[milestone_id]", show_any: false, show_upcoming: true, show_started: true, extra_class: "js-issuable-form-dropdown js-dropdown-keep-input", dropdown_title: "Select milestone"
.form-group
- has_labels = @labels && @labels.any?
= form.label :label_ids, "Labels", class: "control-label #{"col-lg-4" if has_due_date}"