Class: TaskJuggler::StatusSheetSender

Inherits:
SheetSender show all
Defined in:
lib/taskjuggler/StatusSheetSender.rb

Overview

The StatusSheetSender class generates status sheet templates for the current week and sends them out to the managers. For this to work, the resources must provide the ‘Email’ custom attribute with their email address. The actual project data is accessed via tj3client on a tj3 server process.

Instance Attribute Summary collapse

Attributes inherited from SheetSender

#force, #intervalDuration

Attributes inherited from SheetHandlerBase

#dryRun, #workingDir

Instance Method Summary collapse

Methods inherited from SheetSender

#sendTemplates

Methods included from StdIoWrapper

#stdIoWrapper

Methods inherited from SheetHandlerBase

#addToScm, #cutOut, #error, #htmlMailBody, #info, #log, #sendEmail, #sendRichTextEmail, #setWorkingDir, #warning

Constructor Details

#initialize(appName) ⇒ StatusSheetSender

Returns a new instance of StatusSheetSender.



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
# File 'lib/taskjuggler/StatusSheetSender.rb', line 26

def initialize(appName)
  super(appName, 'status')

  # This is a LogicalExpression string that controls what resources should
  # not be getting a status sheet.
  @hideResource = '0'
  # The base directory of the status sheet templates.
  @templateDir = 'StatusSheetTemplates'
  # The base directory of the received time sheets.
  @timeSheetDir = 'TimeSheets'
  # This file contains the time intervals that the StatusSheetReceiver will
  # accept as a valid interval.
  @signatureFile = "#{@templateDir}/acceptable_intervals"
  # The log file
  @logFile = 'statussheets.log'

  @signatureFilter = /^[ ]*statussheet\s[a-z][a-z0-9_]*\s([0-9:\-+]*\s-\s[0-9:\-+]*)/
  @introText = <<'EOT'
Please find enclosed your weekly status report template. Please fill out the
form and send it back to the sender of this email. You can either use the
attached file or the body of the email. In case you send it in the body of the
email, make sure it only contains the 'statussheet' syntax. It must be plain
text, UTF-8 encoded and the status sheet header from 'statussheet' to the period
end date must be in a single line that starts at the beginning of the line.

EOT
  # tj3ts_summary generates a list of resources that have not submitted
  # their reports yet. If you want to generate the warning below, make
  # sure you run tj3ts_summary immediately before you sent the status sheet
  # templates.
  defaulters = defaulterList
  unless defaulters.empty?
    @introText += <<"EOT"
=============================== W A R N I N G ==============================

The following people have not submitted their report yet. The status reports
for the work they have done is not included in this template! You can either
manually add their status to the tasks or asked them to send their time sheet
immediately and re-request this template.

#{defaulters.join}

EOT
  end

  @mailSubject = "Your weekly status report template for %s"
end

Instance Attribute Details

#dateObject

Returns the value of attribute date.



24
25
26
# File 'lib/taskjuggler/StatusSheetSender.rb', line 24

def date
  @date
end

#hideResourceObject

Returns the value of attribute hideResource.



24
25
26
# File 'lib/taskjuggler/StatusSheetSender.rb', line 24

def hideResource
  @hideResource
end

Instance Method Details

#defaulterListObject



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
# File 'lib/taskjuggler/StatusSheetSender.rb', line 74

def defaulterList
  dirs = Dir.glob("#{@timeSheetDir}/????-??-??").sort
  tsDir = nil
  # The status sheet intervals and the time sheet intervals are not
  # identical. The status sheet interval can be smaller and is somewhat
  # later. But it always includes the end date of the corresponding time
  # sheet period. To get the file with the IDs of the resources that have
  # not submitted their report, we need to find the time sheet directory
  # that is within the status sheet period.
  repDate = Time.local(*@date.split('-'))
  dirs.each do |dir|
    dirDate = Time.local(*dir[-10..-1].split('-'))
    if dirDate < repDate
      tsDir = dir
    else
      break
    end
  end
  # Check if there is a time sheet directory.
  return [] unless tsDir

  missingFile = "#{tsDir}/missing-reports"
  # Check if it's got a missing-reports file.
  return [] if !File.exist?(missingFile)

  # The sheet could have been submitted after tj3ts_summary was run. We
  # ignore the entry if a time sheet file now exists. There is a race
  # condition here. The file may exist, but it may not yet be loaded for
  # the current project that is used to generate the status report. There
  # is a race condition here. The file may exist, but it may not yet be
  # loaded for the current project that is used to generate the status
  # report.
  list = File.readlines(missingFile)
  list.delete_if do |resource|
    tsDate = tsDir[-10..-1]
    File.exist?("#{tsDir}/#{resource.chomp}_#{tsDate}.tji")
  end

  # Return the content of the file.
  list
end