aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--app/controllers/request_controller.rb6
-rw-r--r--app/models/incoming_message.rb14
-rw-r--r--config/packages1
-rw-r--r--public/stylesheets/main.css31
4 files changed, 45 insertions, 7 deletions
diff --git a/app/controllers/request_controller.rb b/app/controllers/request_controller.rb
index 5a03f0317..d2500dc21 100644
--- a/app/controllers/request_controller.rb
+++ b/app/controllers/request_controller.rb
@@ -578,12 +578,12 @@ class RequestController < ApplicationController
# the same cache code in cache_attachments above will display them.
image_dir = File.dirname(ActionController::Base.cache_store.cache_path + "/views" + url_for(params.merge(:only_path => true)))
FileUtils.mkdir_p(image_dir)
- html = @attachment.body_as_html(image_dir)
+ html, wrapper_class = @attachment.body_as_html(image_dir)
view_html_stylesheet = render_to_string :partial => "request/view_html_stylesheet"
html.sub!(/<head>/i, "<head>" + view_html_stylesheet)
- html.sub!(/<body[^>]*>/i, '<body><prefix-here><div id="wrapper"><div id="view_html_content">' + view_html_stylesheet)
- html.sub!(/<\/body[^>]*>/i, '</div></div></body>' + view_html_stylesheet)
+ html.sub!(/<body[^>]*>/i, '<body><prefix-here><div id="wrapper" class="' + wrapper_class + '"><div id="view_html_content">')
+ html.sub!(/<\/body[^>]*>/i, '</div></div></body>')
view_html_prefix = render_to_string :partial => "request/view_html_prefix"
html.sub!("<prefix-here>", view_html_prefix)
diff --git a/app/models/incoming_message.rb b/app/models/incoming_message.rb
index 81cbffe06..242fc3ebf 100644
--- a/app/models/incoming_message.rb
+++ b/app/models/incoming_message.rb
@@ -313,6 +313,8 @@ class FOIAttachment
return true
elsif self.content_type == 'application/vnd.ms-word'
return true
+ elsif self.content_type == 'application/vnd.ms-excel'
+ return true
elsif self.content_type == 'application/pdf'
return true
elsif self.content_type == 'application/rtf'
@@ -327,6 +329,8 @@ class FOIAttachment
return "Text file"
elsif self.content_type == 'application/vnd.ms-word'
return "Word document"
+ elsif self.content_type == 'application/vnd.ms-excel'
+ return "Excel spreadsheet"
elsif self.content_type == 'application/pdf'
return "PDF file"
elsif self.content_type == 'application/rtf'
@@ -337,6 +341,7 @@ class FOIAttachment
# For "View as HTML" of attachment
def body_as_html(dir)
html = nil
+ wrapper_class = "default_output"
# simple cases, can never fail
if self.content_type == 'text/plain'
@@ -344,7 +349,7 @@ class FOIAttachment
text = CGI.escapeHTML(text)
text = MySociety::Format.make_clickable(text)
html = text.gsub(/\n/, '<br>')
- return "<html><head></head><body>" + html + "</body></html>"
+ return "<html><head></head><body>" + html + "</body></html>", wrapper_class
end
# the extractions will also produce image files, which go in the
@@ -360,6 +365,11 @@ class FOIAttachment
system("/usr/bin/wvHtml --charset=UTF-8 " + tempfile.path + " " + tempfile.path + ".html")
html = File.read(tempfile.path + ".html")
File.unlink(tempfile.path + ".html")
+ elsif self.content_type == 'application/vnd.ms-excel'
+ IO.popen("/usr/bin/xlhtml -a " + tempfile.path + "", "r") do |child|
+ html = child.read()
+ wrapper_class = "xhtml_output"
+ end
elsif self.content_type == 'application/pdf'
IO.popen("/usr/bin/pdftohtml -nodrm -zoom 1.0 -stdout -enc UTF-8 -noframes " + tempfile.path + "", "r") do |child|
html = child.read()
@@ -391,7 +401,7 @@ class FOIAttachment
return "<html><head></head><body><p>Sorry, the conversion to HTML failed. Please use the download link at the top right.</p></body></html>"
end
- return html
+ return html, wrapper_class
end
end
diff --git a/config/packages b/config/packages
index b3ed12bfb..03ef1e2d7 100644
--- a/config/packages
+++ b/config/packages
@@ -12,6 +12,7 @@ catdoc
links
elinks
unrtf
+xlhtml
libxapian-ruby1.8
gnuplot-nox
ttf-bitstream-vera
diff --git a/public/stylesheets/main.css b/public/stylesheets/main.css
index df363c973..71f9fa81d 100644
--- a/public/stylesheets/main.css
+++ b/public/stylesheets/main.css
@@ -215,7 +215,7 @@ body
}
-/*------------------------------------------------ wrapper*/
+/*------------------------------------------------ wrapper round view HTML version of attachments */
#wrapper
{
@@ -224,11 +224,38 @@ body
top: 0px;
padding-top: 100px;
margin: 0px auto 1.2em auto;
- width: 53em;
/* = 800px at default size? so 1em = 16px*/
text-align: left;
overflow: visible;
}
+.default_output {
+ width: 53em;
+}
+.xhtml_output {
+ width: 90%;
+}
+#wrapper table {
+ border-collapse: collapse;
+ margin-bottom: 1em;
+}
+#wrapper td, th {
+ border: solid 1px #000000;
+}
+#wrapper td {
+ vertical-align: top
+}
+#wrapper td {
+ max-width: 30em;
+ overflow: auto;
+}
+#wrapper tr:nth-child(odd) {
+ background-color: #bbbbbb;
+}
+#wrapper tr:nth-child(even) {
+ background-color: #dddddd;
+}
+
+
/*------------------------------------------------ content */