lib/reports/Report.rb in taskjuggler-0.0.4 vs lib/reports/Report.rb in taskjuggler-0.0.5

- old
+ new

@@ -14,11 +14,13 @@ require 'PropertyTreeNode' require 'reports/TextReport' require 'reports/TaskListRE' require 'reports/ResourceListRE' require 'reports/TjpExportRE' +require 'reports/StatusSheetReport' require 'reports/TimeSheetReport' +require 'reports/NikuReport' require 'reports/CSVFile' require 'reports/Navigator' require 'reports/ReportContext' require 'HTMLDocument' @@ -46,18 +48,22 @@ # generated according the the requested output format(s). def generate begin @content = nil case @typeSpec + when :export + @content = TjpExportRE.new(self) + when :niku + @content = NikuReport.new(self) when :resourcereport @content = ResourceListRE.new(self) when :textreport @content = TextReport.new(self) when :taskreport @content = TaskListRE.new(self) - when :export - @content = TjpExportRE.new(self) + when :statusSheet + @content = StatusSheetReport.new(self) when :timeSheet @content = TimeSheetReport.new(self) else raise "Unknown report type" end @@ -72,14 +78,16 @@ when :html generateHTML copyAuxiliaryFiles when :csv generateCSV + when :niku + generateNiku when :tjp generateTJP else - raise 'Unknown report output format.' + raise 'Unknown report output format #{format}.' end end rescue TjException error('reporting_failed', $!.message) end @@ -98,22 +106,23 @@ get(attribute) end # Generate an HTML version of the report. def generateHTML - html = HTMLDocument.new(:transitional) - html << (head = XMLElement.new('head')) - head << XMLNamedText.new("TaskJuggler Report - #{@name}", 'title') + html = HTMLDocument.new(:strict) + head = html.generateHead("TaskJuggler Report - #{@name}", + 'description' => 'TaskJuggler Report', + 'keywords' => 'taskjuggler, project, management') if a('selfcontained') auxSrcDir = AppConfig.dataDirs('data/css')[0] cssFileName = auxSrcDir + '/tjreport.css' if auxSrcDir.nil? || !File.exists?(cssFileName) raise TjException.new, <<"EOT" Cannot find '#{cssFileName}'. This is usually the result of an improper TaskJuggler installation. If you know where to find the data directory, you can use the TASKJUGGLER_DATA_PATH environment variable to specify the -location. +location. The variable should be set to the path without the /data at the end. EOT end cssFile = IO.read(cssFileName) if cssFile.empty? raise TjException.new, <<"EOT" @@ -131,13 +140,12 @@ 'href' => 'css/tjreport.css') end html << (body = XMLElement.new('body')) unless a('selfcontained') - body << (script = XMLElement.new('script', 'type' => 'text/javascript', - 'src' => 'scripts/wz_tooltip.js')) - script.mayNotBeEmpty = true + body << XMLElement.new('script', 'type' => 'text/javascript', + 'src' => 'scripts/wz_tooltip.js') body << (noscript = XMLElement.new('noscript')) noscript << (nsdiv = XMLElement.new('div', 'style' => 'text-align:center; ' + 'color:#FF0000')) nsdiv << XMLText.new(<<'EOT' @@ -147,12 +155,11 @@ ) end # Make sure we have some margins around the report. - body << (frame = XMLElement.new('div', - 'style' => 'margin: 35px 5% 25px 5%; ')) + body << (frame = XMLElement.new('div', 'class' => 'tj_page')) frame << @content.to_html if @content # The footer with some administrative information. frame << (div = XMLElement.new('div', 'class' => 'copyright')) @@ -163,12 +170,12 @@ "with ") div << XMLNamedText.new("#{AppConfig.softwareName}", 'a', 'href' => "#{AppConfig.contact}") div << XMLText.new(" v#{AppConfig.version}") - html.write((@name[0] == '/' ? '' : @project.outputDir) + - @name + (@name == '.' ? '' : '.html')) + html.write(((@name[0] == '/' ? '' : @project.outputDir) + + @name + (@name == '.' ? '' : '.html')).untaint) end # Generate a CSV version of the report. def generateCSV return nil unless @content @@ -204,19 +211,46 @@ end end # Use the CSVFile class to write the Array of Arrays to a colon # separated file. Write to $stdout if the filename was set to '.'. - CSVFile.new(csv, ';').write((@name[0] == '/' ? '' : @project.outputDir) + - @name + (@name == '.' ? '' : '.csv')) + begin + fileName = (@name == '.' ? @name : + (@name[0] == '/' ? '' : @project.outputDir) + + @name + '.csv').untaint + CSVFile.new(csv, ';').write(fileName) + rescue IOError + error('write_csv', "Cannot write to file #{fileName}.\n#{$!}") + end end # Generate time sheet drafts. def generateTJP - f = @name == '.' ? $stdout : - File.new((@name[0] == '/' ? '' : @project.outputDir) + - @name, 'w') - f.puts "#{@content.to_tjp}" + begin + fileName = '.' + if @name == '.' + $stdout.write(@content.to_tjp) + else + fileName = (@name[0] == '/' ? '' : @project.outputDir) + @name + fileName += a('definitions').include?('project') ? '.tjp' : '.tji' + fileName.untaint + File.open(fileName, 'w') { |f| f.write(@content.to_tjp) } + end + rescue IOError + error('write_tjp', "Cannot write to file #{fileName}.\n#{$!}") + end + end + + # Generate Niku report + def generateNiku + begin + f = @name == '.' ? $stdout : + File.new(((@name[0] == '/' ? '' : @project.outputDir) + + @name + '.xml').untaint, 'w') + f.puts "#{@content.to_niku}" + rescue IOError + error('write_niku', "Cannot write to file #{@name}.\n#{$!}") + end end def copyAuxiliaryFiles return if @name == '.' # Don't copy files if output is stdout.