Commit 61a306aa authored by Mehmet Beydogan's avatar Mehmet Beydogan Committed by Robert Speicher

Fix functionality of due this week. Add due this month and overdue, remove due tomorrow to issues.

Fix typos on sorting dropdown related to due date
Remove constant array and add Structs on Issue to keep due date data to fill options
parent 83bda94f
...@@ -118,7 +118,19 @@ class IssuableFinder ...@@ -118,7 +118,19 @@ class IssuableFinder
end end
def filter_by_no_due_date? def filter_by_no_due_date?
due_date? && params[:due_date] == Issue::NO_DUE_DATE[1] due_date? && params[:due_date] == Issue::NoDueDate.name
end
def filter_by_overdue?
due_date? && params[:due_date] == Issue::OverDue.name
end
def filter_by_due_this_week?
due_date? && params[:due_date] == Issue::DueThisWeek.name
end
def filter_by_due_this_month?
due_date? && params[:due_date] == Issue::DueThisMonth.name
end end
def labels? def labels?
...@@ -295,11 +307,13 @@ class IssuableFinder ...@@ -295,11 +307,13 @@ class IssuableFinder
def by_due_date(items) def by_due_date(items)
if due_date? if due_date?
if filter_by_no_due_date? if filter_by_no_due_date?
items = items.no_due_date items = items.without_due_date
else elsif filter_by_overdue?
items = items.has_due_date items = items.overdue
# Must use issues prefix to avoid ambiguous match with Milestone#due_date elsif filter_by_due_this_week?
items = items.where("issues.due_date > ? AND issues.due_date <= ?", Date.today, params[:due_date]) items = items.due_between(Date.today.beginning_of_week, Date.today.end_of_week + 1.day)
elsif filter_by_due_this_month?
items = items.due_between(Date.today.beginning_of_month, Date.today.end_of_month + 1.day)
end end
end end
items items
......
...@@ -174,12 +174,14 @@ module IssuesHelper ...@@ -174,12 +174,14 @@ module IssuesHelper
def due_date_options def due_date_options
options = [ options = [
["Due to tomorrow", 1.day.from_now.to_date], Issue::AnyDueDate,
["Due in this week", 1.week.from_now.to_date] Issue::NoDueDate,
Issue::DueThisWeek,
Issue::DueThisMonth,
Issue::OverDue
] ]
options.unshift(Issue::ANY_DUE_DATE)
options.unshift(Issue::NO_DUE_DATE) options_from_collection_for_select(options, 'name', 'title', params[:due_date])
options_for_select(options, params[:due_date])
end end
......
...@@ -53,11 +53,11 @@ module SortingHelper ...@@ -53,11 +53,11 @@ module SortingHelper
end end
def sort_title_due_date_soon def sort_title_due_date_soon
'Due date soon' 'Due soon'
end end
def sort_title_due_date_later def sort_title_due_date_later
'Due date due later' 'Due later'
end end
def sort_title_name def sort_title_name
......
...@@ -39,8 +39,10 @@ module Issuable ...@@ -39,8 +39,10 @@ module Issuable
scope :order_milestone_due_asc, -> { joins(:milestone).reorder('milestones.due_date ASC, milestones.id ASC') } scope :order_milestone_due_asc, -> { joins(:milestone).reorder('milestones.due_date ASC, milestones.id ASC') }
scope :with_label, ->(title) { joins(:labels).where(labels: { title: title }) } scope :with_label, ->(title) { joins(:labels).where(labels: { title: title }) }
scope :without_label, -> { joins("LEFT OUTER JOIN label_links ON label_links.target_type = '#{name}' AND label_links.target_id = #{table_name}.id").where(label_links: { id: nil }) } scope :without_label, -> { joins("LEFT OUTER JOIN label_links ON label_links.target_type = '#{name}' AND label_links.target_id = #{table_name}.id").where(label_links: { id: nil }) }
scope :has_due_date, ->{ where("issues.due_date IS NOT NULL") } scope :without_due_date, ->{ where("issues.due_date IS NULL")}
scope :no_due_date, ->{ where("issues.due_date IS NULL")} scope :due_before, ->(date){ where("issues.due_date IS NOT NULL AND issues.due_date < ?", date)}
scope :due_between, ->(from_date, to_date){ where("issues.due_date >= ?", from_date).due_before(to_date) }
scope :overdue, ->{ where("issues.due_date < ?", Date.today)}
scope :join_project, -> { joins(:project) } scope :join_project, -> { joins(:project) }
scope :references_project, -> { references(:project) } scope :references_project, -> { references(:project) }
......
...@@ -18,8 +18,8 @@ module Sortable ...@@ -18,8 +18,8 @@ module Sortable
scope :order_updated_asc, -> { reorder(updated_at: :asc) } scope :order_updated_asc, -> { reorder(updated_at: :asc) }
scope :order_name_asc, -> { reorder(name: :asc) } scope :order_name_asc, -> { reorder(name: :asc) }
scope :order_name_desc, -> { reorder(name: :desc) } scope :order_name_desc, -> { reorder(name: :desc) }
scope :due_date_asc, -> { reorder("due_date IS NULL, due_date ASC") } scope :order_due_date_asc, -> { reorder("issues.due_date IS NULL, issues.due_date ASC") }
scope :due_date_desc, -> { reorder("due_date IS NULL, due_date DESC") } scope :order_due_date_desc, -> { reorder("issues.due_date IS NULL, issues.due_date DESC") }
end end
module ClassMethods module ClassMethods
...@@ -33,8 +33,8 @@ module Sortable ...@@ -33,8 +33,8 @@ module Sortable
when 'created_desc' then order_created_desc when 'created_desc' then order_created_desc
when 'id_desc' then order_id_desc when 'id_desc' then order_id_desc
when 'id_asc' then order_id_asc when 'id_asc' then order_id_asc
when 'due_date_asc' then due_date_asc when 'due_date_asc' then order_due_date_asc
when 'due_date_desc' then due_date_desc when 'due_date_desc' then order_due_date_desc
else else
all all
end end
......
...@@ -28,8 +28,12 @@ class Issue < ActiveRecord::Base ...@@ -28,8 +28,12 @@ class Issue < ActiveRecord::Base
include Sortable include Sortable
include Taskable include Taskable
NO_DUE_DATE = ['No Due Date', '0'] DueDateStruct = Struct.new(:title, :name)
ANY_DUE_DATE = ['Any Due Date', ''] NoDueDate = DueDateStruct.new('No Due Date', '0')
AnyDueDate = DueDateStruct.new('Any Due Date', '')
OverDue = DueDateStruct.new('Overdue', 'overdue')
DueThisWeek = DueDateStruct.new('Due This Week', 'week')
DueThisMonth = DueDateStruct.new('Due This Month', 'month')
ActsAsTaggableOn.strict_case_match = true ActsAsTaggableOn.strict_case_match = true
......
...@@ -21,9 +21,9 @@ ...@@ -21,9 +21,9 @@
= link_to page_filter_path(sort: sort_value_milestone_later) do = link_to page_filter_path(sort: sort_value_milestone_later) do
= sort_title_milestone_later = sort_title_milestone_later
= link_to page_filter_path(sort: sort_value_due_date_soon) do = link_to page_filter_path(sort: sort_value_due_date_soon) do
= sort_title_due_date_soon if controller_name == "issues" = sort_title_due_date_soon if @issues
= link_to page_filter_path(sort: sort_value_due_date_later) do = link_to page_filter_path(sort: sort_value_due_date_later) do
= sort_title_due_date_later if controller_name == "issues" = sort_title_due_date_later if @issues
= link_to page_filter_path(sort: sort_value_upvotes) do = link_to page_filter_path(sort: sort_value_upvotes) do
= sort_title_upvotes = sort_title_upvotes
= link_to page_filter_path(sort: sort_value_downvotes) do = link_to page_filter_path(sort: sort_value_downvotes) do
......
...@@ -24,7 +24,7 @@ ...@@ -24,7 +24,7 @@
.filter-item.inline.labels-filter .filter-item.inline.labels-filter
= render "shared/issuable/label_dropdown" = render "shared/issuable/label_dropdown"
- if controller.controller_name == 'issues' - if @issues
.filter-item.inline.due_date-filter .filter-item.inline.due_date-filter
= select_tag('due_date', due_date_options, = select_tag('due_date', due_date_options,
class: 'select2 trigger-submit', include_blank: true, class: 'select2 trigger-submit', include_blank: true,
......
...@@ -80,7 +80,6 @@ ...@@ -80,7 +80,6 @@
= icon('calendar') = icon('calendar')
%span %span
- if issuable.due_date - if issuable.due_date
= icon('calendar')
= issuable.due_date.to_s(:medium) = issuable.due_date.to_s(:medium)
- else - else
.light None .light None
......
...@@ -187,33 +187,49 @@ describe 'Issues', feature: true do ...@@ -187,33 +187,49 @@ describe 'Issues', feature: true do
end end
it 'filters by none' do it 'filters by none' do
visit namespace_project_issues_path(project.namespace, project, due_date: Issue::NO_DUE_DATE[1]) visit namespace_project_issues_path(project.namespace, project, due_date: Issue::NoDueDate.name)
expect(page).not_to have_content("foo") expect(page).not_to have_content("foo")
expect(page).not_to have_content("bar") expect(page).not_to have_content("bar")
expect(page).to have_content("baz") expect(page).to have_content("baz")
end end
it 'filters by any' do it 'filters by any' do
visit namespace_project_issues_path(project.namespace, project, due_date: Issue::ANY_DUE_DATE[1]) visit namespace_project_issues_path(project.namespace, project, due_date: Issue::AnyDueDate.name)
expect(page).to have_content("foo") expect(page).to have_content("foo")
expect(page).to have_content("bar") expect(page).to have_content("bar")
expect(page).to have_content("baz") expect(page).to have_content("baz")
end end
it 'filters by due to tomorrow' do it 'filters by due this week' do
visit namespace_project_issues_path(project.namespace, project, due_date: Date.tomorrow.to_s) foo.update(due_date: Date.today.beginning_of_week + 2.days)
bar.update(due_date: Date.today.end_of_week)
baz.update(due_date: Date.today - 8.days)
visit namespace_project_issues_path(project.namespace, project, due_date: Issue::DueThisWeek.name)
expect(page).to have_content("foo") expect(page).to have_content("foo")
expect(page).not_to have_content("bar") expect(page).to have_content("bar")
expect(page).not_to have_content("baz") expect(page).not_to have_content("baz")
end end
it 'filters by due in this week' do it 'filters by due this month' do
visit namespace_project_issues_path(project.namespace, project, due_date: 7.days.from_now.to_date.to_s) foo.update(due_date: Date.today.beginning_of_month + 2.days)
bar.update(due_date: Date.today.end_of_month)
baz.update(due_date: Date.today - 50.days)
visit namespace_project_issues_path(project.namespace, project, due_date: Issue::DueThisMonth.name)
expect(page).to have_content("foo") expect(page).to have_content("foo")
expect(page).to have_content("bar") expect(page).to have_content("bar")
expect(page).not_to have_content("baz") expect(page).not_to have_content("baz")
end end
it 'filters by overdue' do
foo.update(due_date: Date.today + 2.days)
bar.update(due_date: Date.today + 20.days)
baz.update(due_date: Date.yesterday)
visit namespace_project_issues_path(project.namespace, project, due_date: Issue::OverDue.name)
expect(page).not_to have_content("foo")
expect(page).not_to have_content("bar")
expect(page).to have_content("baz")
end
end end
describe 'sorting by milestone' do describe 'sorting by milestone' do
......
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