Welcome to mirror list, hosted at ThFree Co, Russian Federation.

taskable.rb « concerns « models « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 6e04578a7dfd2aa27db97d44526a4c2e3bb92b09 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
require 'task_list'

# 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
  # Called by `TaskList::Summary`
  def task_list_items
    return [] if description.blank?

    @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}")
    end
  end

  def tasks
    @tasks ||= TaskList.new(self)
  end

  # Return true if this object's description has any task list items.
  def tasks?
    tasks.summary.items?
  end

  # Return a string that describes the current state of this Taskable's task
  # list items, e.g. "20 tasks (12 done, 8 unfinished)"
  def task_status
    return '' if description.blank?

    sum = tasks.summary
    "#{sum.item_count} tasks (#{sum.complete_count} done, #{sum.incomplete_count} unfinished)"
  end
end