2015-04-29 17:47:55 -04:00
|
|
|
require 'task_list'
|
2015-06-10 01:38:45 -04:00
|
|
|
require 'task_list/filter'
|
2015-04-29 17:47:55 -04:00
|
|
|
|
2014-10-05 01:53:44 -04:00
|
|
|
# Contains functionality for objects that can have task lists in their
|
|
|
|
# descriptions. Task list items can be added with Markdown like "* [x] Fix
|
|
|
|
# bugs".
|
|
|
|
#
|
|
|
|
# Used by MergeRequest and Issue
|
|
|
|
module Taskable
|
2015-04-29 17:47:55 -04:00
|
|
|
# Called by `TaskList::Summary`
|
|
|
|
def task_list_items
|
|
|
|
return [] if description.blank?
|
2014-10-05 01:53:44 -04:00
|
|
|
|
2015-04-29 17:47:55 -04:00
|
|
|
@task_list_items ||= description.scan(TaskList::Filter::ItemPattern).collect do |item|
|
|
|
|
# ItemPattern strips out the hyphen, but Item requires it. Rabble rabble.
|
|
|
|
TaskList::Item.new("- #{item}")
|
2014-10-05 01:53:44 -04:00
|
|
|
end
|
2015-04-29 17:47:55 -04:00
|
|
|
end
|
2014-10-05 01:53:44 -04:00
|
|
|
|
2015-04-29 17:47:55 -04:00
|
|
|
def tasks
|
|
|
|
@tasks ||= TaskList.new(self)
|
2014-10-05 01:53:44 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
# Return true if this object's description has any task list items.
|
|
|
|
def tasks?
|
2015-04-29 17:47:55 -04:00
|
|
|
tasks.summary.items?
|
2014-10-05 01:53:44 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
# Return a string that describes the current state of this Taskable's task
|
2015-05-06 17:27:10 -04:00
|
|
|
# list items, e.g. "20 tasks (12 completed, 8 remaining)"
|
2014-10-05 01:53:44 -04:00
|
|
|
def task_status
|
2015-04-29 17:47:55 -04:00
|
|
|
return '' if description.blank?
|
2014-10-05 01:53:44 -04:00
|
|
|
|
2015-04-29 17:47:55 -04:00
|
|
|
sum = tasks.summary
|
2015-05-06 17:27:10 -04:00
|
|
|
"#{sum.item_count} tasks (#{sum.complete_count} completed, #{sum.incomplete_count} remaining)"
|
2014-10-05 01:53:44 -04:00
|
|
|
end
|
|
|
|
end
|