File: Resource.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 (103 lines) | stat: -rw-r--r-- 3,356 bytes parent folder | download | duplicates (2)
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
#!/usr/bin/env ruby -w
# encoding: UTF-8
#
# = Resource.rb -- The TaskJuggler III Project Management Software
#
# Copyright (c) 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2019
#               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/ResourceScenario'

class TaskJuggler

  class Resource < PropertyTreeNode

    def initialize(project, id, name, parent)
      super(project.resources, id, name, parent)
      project.addResource(self)

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

    # Just a shortcut to avoid the slower calls via method_missing.
    def book(scenarioIdx, sbIdx, task)
      @data[scenarioIdx].book(sbIdx, task)
    end

    # Many Resource functions are scenario specific. These functions are
    # provided by the class ResourceScenario. In case we can't find a
    # function called for the Resource class we try to find it in
    # ResourceScenario.
    def method_missing(func, scenarioIdx = 0, *args, &block)
      @data[scenarioIdx].method(func).call(*args, &block)
    end

    def query_dashboard(query)
      dashboard(query)
    end

    private

    # Create a dashboard-like list of all task that have a current alert
    # status.
    def dashboard(query)
      scenarioIdx = @project['trackingScenarioIdx']
      taskList = []
      unless scenarioIdx
        rText = "No 'trackingscenario' defined."
      else
        @project.tasks.each do |task|
          if task['responsible', scenarioIdx].include?(self) &&
            !@project['journal'].currentEntries(query.end, task,
                                                0, query.start,
                                                query.hideJournalEntry).empty?
            taskList << task
          end
        end
      end

      if taskList.empty?
        rText = "We have no current status for any task that #{name} " +
                "is responsible for."
      else
        # 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 = ''

        taskList.each do |task|
          rText += "=== <nowiki>[</nowiki>" +
                   "#{task.query_alert(query).richText.inputText}" +
                   "<nowiki>] Task: #{task.name}</nowiki> " +
                   "(#{task.fullId}) ===\n\n"
          rText += task.query_journalmessages(query).richText.inputText + "\n\n"
        end
      end

      # Now convert the RichText markup String into RichTextIntermediate
      # format.
      unless (rti = RichText.new(rText, RTFHandlers.create(@project)).
              generateIntermediateFormat)
        warning('res_dashboard', 'Syntax error in dashboard 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