File: Task.rb

package info (click to toggle)
tj3 3.8.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 5,048 kB
  • sloc: ruby: 36,481; javascript: 1,113; sh: 19; makefile: 17
file content (115 lines) | stat: -rw-r--r-- 3,907 bytes parent folder | download | duplicates (4)
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
#!/usr/bin/env ruby -w
# encoding: UTF-8
#
# = Task.rb -- The TaskJuggler III Project Management Software
#
# Copyright (c) 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014
#               by Chris Schlaeger <cs@taskjuggler.org>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of version 2 of the GNU General Public License as
# published by the Free Software Foundation.
#

require 'taskjuggler/PropertyTreeNode'
require 'taskjuggler/TaskScenario'

class TaskJuggler

  class Task < PropertyTreeNode

    def initialize(project, id, name, parent)
      super(project.tasks, id, name, parent)
      project.addTask(self)

      @data = Array.new(@project.scenarioCount, nil)
      @project.scenarioCount.times do |i|
        TaskScenario.new(self, i, @scenarioAttributes[i])
      end
    end

    def readyForScheduling?(scenarioIdx)
      @data[scenarioIdx].readyForScheduling?
    end

    private

    # Create a blog-style list of all alert messages that match the Query.
    def journalText(query, longVersion, recursive)
      # The components of the message are either UTF-8 text or RichText. For
      # the RichText components, we use the originally provided markup since
      # we compose the result as RichText markup first.
      rText = ''
      if recursive
        list = @project['journal'].entriesByTaskR(self, query.start, query.end,
                                                  query.hideJournalEntry)
      else
        list = @project['journal'].entriesByTask(self, query.start, query.end,
                                                 query.hideJournalEntry)
      end
      list.setSorting([ [ :alert, -1 ], [ :date, -1 ], [ :seqno, 1 ] ])
      list.sort!
      list.each do |entry|
        tsRecord = entry.timeSheetRecord

        if entry.property.is_a?(Task)
          levelRecord = @project['alertLevels'][entry.alertLevel]
          if query.selfContained
            alertName = "<nowiki>[#{levelRecord.name}]</nowiki>"
          else
            alertName = "[[File:icons/flag-#{levelRecord.id}.png|" +
                        "alt=[#{levelRecord.name}]|text-bottom]]"
          end
          rText += "== #{alertName} <nowiki>#{entry.headline}</nowiki> ==\n" +
                   "''Reported on #{entry.date.to_s(query.timeFormat)}'' "
          if entry.author
            rText += "''by <nowiki>#{entry.author.name}</nowiki>''"
          end
          rText += "\n\n"
          unless entry.flags.empty?
            rText += "'''Flags:''' #{entry.flags.join(', ')}\n\n"
          end
          if tsRecord
            rText += "'''Work:''' #{tsRecord.actualWorkPercent.to_i}% "
            if tsRecord.remaining
              rText += "'''Remaining:''' #{tsRecord.actualRemaining}d "
            else
              rText += "'''End:''' " +
                       "#{tsRecord.actualEnd.to_s(query.timeFormat)} "
            end
            rText += "\n\n"
          end
        end
        unless entry.headline.empty?
          rText += "'''<nowiki>#{entry.headline}</nowiki>'''\n\n"
        end
        if entry.summary
          rText += entry.summary.richText.inputText + "\n\n"
        end
        if longVersion && entry.details
          rText += entry.details.richText.inputText + "\n\n"
        end
      end

      # Don't generate a RichText object for an empty String.
      return if rText.empty?

      # Now convert the RichText markup String into RichTextIntermediate
      # format.
      unless (rti = RichText.new(rText, RTFHandlers.create(@project)).
              generateIntermediateFormat)
        warning('task_journal_text', 'Syntax error in journal text')
        return nil
      end

      # No section numbers, please!
      rti.sectionNumbers = false
      # We use a special class to allow CSS formating.
      rti.cssClass = 'tj_journal'
      query.rti = rti
    end

  end

end