Skip to content

Instantly share code, notes, and snippets.

@ebisawa
Created September 28, 2010 05:27
Show Gist options
  • Save ebisawa/600455 to your computer and use it in GitHub Desktop.
Save ebisawa/600455 to your computer and use it in GitHub Desktop.
customized gantt_start_compare for Redmine
def gantt_start_compare(x, y)
def cmp(a, b)
if a != nil && b != nil
a <=> b
else
0
end
end
def effective_date(x)
if (x.class == Version)
return x.effective_date
else
return x.fixed_version.effective_date if x.fixed_version != nil
end
nil
end
def fixed_version(x)
if (x.class == Version)
return x.id
else
return x.fixed_version.id if x.fixed_version != nil
end
nil
end
def due_date(x)
if x.due_date != nil
return x.due_date
else
return x.fixed_version.effective_date if x.fixed_version != nil
end
nil
end
if x.start_date.nil?
-1
elsif y.start_date.nil?
1
else
# sort by project
r = cmp(x.project_id, y.project_id)
return r if r != 0
# sort by version
r = cmp(effective_date(x), effective_date(y))
return r if r != 0
r = cmp(fixed_version(x), fixed_version(y))
return r if r != 0
# sort by start date
r = x.start_date <=> y.start_date
return r if r != 0
# sort by end date
r = cmp(due_date(x), due_date(y))
return r if r != 0
x.id <=> y.id
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment