summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStefan Wintermeyer <stefan.wintermeyer@amooma.de>2013-02-13 15:29:43 +0100
committerStefan Wintermeyer <stefan.wintermeyer@amooma.de>2013-02-13 15:29:43 +0100
commit3db09ff394b92b5d168c32c355d4529fd3861d36 (patch)
tree970071fcd4fe108de60461e5b70223d1e54fecef
parent24e085ddcc30b8d6acec7dde8b165e105da5f004 (diff)
Improvements in the fax_document model and in FaxDocument#show.
-rw-r--r--app/models/fax_document.rb24
-rw-r--r--app/uploaders/thumbnail_uploader.rb18
-rw-r--r--app/views/fax_documents/show.html.haml97
3 files changed, 75 insertions, 64 deletions
diff --git a/app/models/fax_document.rb b/app/models/fax_document.rb
index 16fdc70..4db4980 100644
--- a/app/models/fax_document.rb
+++ b/app/models/fax_document.rb
@@ -47,19 +47,21 @@ class FaxDocument < ActiveRecord::Base
transition [:new] => :inbound
end
end
+
+ def to_s
+ "#{self.remote_station_id}-#{self.created_at}-#{self.id}".gsub(/[^a-zA-Z0-9]/,'')
+ end
def render_thumbnails
- directory = "/tmp/GS-#{GsParameter.get('GEMEINSCHAFT_VERSION')}/fax_thumbnails/#{self.id}"
- system('mkdir -p ' + directory)
- system("cd #{directory} && convert #{Rails.root.to_s}/public#{self.document.to_s}[0-100] -colorspace Gray PNG:'fax_page.png'")
- number_of_thumbnails = Dir["#{directory}/fax_page-*.png"].count
- (0..(number_of_thumbnails-1)).each do |i|
+ tmp_dir = "/tmp/fax_convertions/#{self.id}"
+ FileUtils.mkdir_p tmp_dir
+ system("cd #{tmp_dir} && convert #{self.document.path} -colorspace Gray PNG:'fax_page.png'")
+ Dir.glob("#{tmp_dir}/fax_page*.png").each do |thumbnail|
fax_thumbnail = self.fax_thumbnails.build
- fax_thumbnail.thumbnail = File.open("#{directory}/fax_page-#{i}.png")
- fax_thumbnail.save!
+ fax_thumbnail.thumbnail = File.open(thumbnail)
+ fax_thumbnail.save
end
- system("rm -rf #{directory}")
- self.update_attributes(:document_total_pages => number_of_thumbnails) if self.document_total_pages.nil?
+ FileUtils.rm_rf tmp_dir
end
private
@@ -67,12 +69,12 @@ class FaxDocument < ActiveRecord::Base
page_size_a4 = '595 842'
page_size_command = "<< /Policies << /PageSize 3 >> /InputAttributes currentpagedevice /InputAttributes get dup { pop 1 index exch undef } forall dup 0 << /PageSize [ #{page_size_a4} ] >> put >> setpagedevice"
directory = "/tmp/GS-#{GsParameter.get('GEMEINSCHAFT_VERSION')}/faxes/#{self.id}"
- system('mkdir -p ' + directory)
+ FileUtils.mkdir_p directory
tiff_file_name = File.basename(self.document.to_s.downcase, ".pdf") + '.tiff'
system "cd #{directory} && gs -q -r#{self.fax_resolution.resolution_value} -dNOPAUSE -dBATCH -dSAFER -sDEVICE=tiffg3 -sOutputFile=\"#{tiff_file_name}\" -c \"#{page_size_command}\" -- \"#{Rails.root.to_s}/public#{self.document.to_s}\""
self.tiff = File.open("#{directory}/#{tiff_file_name}")
self.save
- system("rm -rf #{directory}")
+ FileUtils.rm_rf directory
end
end
diff --git a/app/uploaders/thumbnail_uploader.rb b/app/uploaders/thumbnail_uploader.rb
index a401a91..4b4cc09 100644
--- a/app/uploaders/thumbnail_uploader.rb
+++ b/app/uploaders/thumbnail_uploader.rb
@@ -34,17 +34,17 @@ class ThumbnailUploader < CarrierWave::Uploader::Base
process :resize_to_limit => [75, 75]
end
- version :thumb do
- process :resize_to_limit => [150, 150]
- end
+ # version :thumb do
+ # process :resize_to_limit => [150, 150]
+ # end
- version :medium do
- process :resize_to_limit => [400, 400]
- end
+ # version :medium do
+ # process :resize_to_limit => [400, 400]
+ # end
- version :big do
- process :resize_to_limit => [800, 800]
- end
+ # version :big do
+ # process :resize_to_limit => [800, 800]
+ # end
# Add a white list of extensions which are allowed to be uploaded.
diff --git a/app/views/fax_documents/show.html.haml b/app/views/fax_documents/show.html.haml
index de8c1cc..3419d5c 100644
--- a/app/views/fax_documents/show.html.haml
+++ b/app/views/fax_documents/show.html.haml
@@ -2,49 +2,58 @@
- child = @fax_document
- parent = @fax_document.fax_account
-%table.table.table-striped
- %tr
- %td
- %strong= t('fax_documents.index.state') + ":"
- %td
- = t("fax_documents.states.#{@fax_document.state}")
- %tr
- %td
- %strong= t('fax_documents.index.result_code') + ":"
- %td
- = @fax_document.result_code
- %tr
- %td
- %strong= t('fax_documents.index.result_text') + ":"
- %td
- = t("fax_documents.result_codes.code_#{@fax_document.result_code}")
- %tr
- %td
- %strong= t('fax_documents.show.document_transferred_pages') + ":"
- %td
- = @fax_document.document_transferred_pages
- %tr
- %td
- %strong= t('fax_documents.show.remote_station_id') + ":"
- %td
- = @fax_document.remote_station_id
- %tr
- %td
- %strong= t('fax_documents.show.fax_resolution') + ":"
- %td
- = @fax_document.fax_resolution
+.row
+ .span12
+ %table.table.table-striped
+ %tr
+ %td
+ %strong= t('fax_documents.index.state') + ":"
+ %td
+ = t("fax_documents.states.#{@fax_document.state}")
+ %tr
+ %td
+ %strong= t('fax_documents.index.result_code') + ":"
+ %td
+ = @fax_document.result_code
+ %tr
+ %td
+ %strong= t('fax_documents.index.result_text') + ":"
+ %td
+ = t("fax_documents.result_codes.code_#{@fax_document.result_code}")
+ %tr
+ %td
+ %strong= t('fax_documents.show.document_transferred_pages') + ":"
+ %td
+ = @fax_document.document_transferred_pages
+ %tr
+ %td
+ %strong= t('fax_documents.show.remote_station_id') + ":"
+ %td
+ = @fax_document.remote_station_id
+ %tr
+ %td
+ %strong= t('fax_documents.show.fax_resolution') + ":"
+ %td
+ = @fax_document.fax_resolution
-- if @fax_document.fax_thumbnails.count > 0
- - i = @fax_document.fax_thumbnails.count
- - i = 10 if i > 10
- %p
- - @fax_document.fax_thumbnails.limit(i).each do |fax_thumbnail|
- =image_tag fax_thumbnail.thumbnail_url(:medium), :class => 'FaxThumbnail', :alt => "Thumbnail of page \##{fax_thumbnail.position}"
+ - if @fax_document.document?
+ %p
+ %a{:href => @fax_document.document.url}
+ %i{:class => 'icon-download'}
+ = t("fax_documents.index.actions.download_pdf") + " (#{number_to_human_size(@fax_document.document.size, :precision => 2)})"
-- if @fax_document.document.path
- %p
- %a{:href => "#{request.protocol}#{request.host_with_port}#{request.fullpath.split("?")[0]}.pdf"}
- %i{:class => 'icon-download'}
- = t("fax_documents.index.actions.download_pdf")
-
-= render :partial => 'shared/show_edit_destroy_part', :locals => { :parent => @fax_document.fax_account, :child => @fax_document }
+.row
+ .span12
+ - if @fax_document.fax_thumbnails.any?
+ %ul.thumbnails
+ - @fax_document.fax_thumbnails.each do |fax_thumbnail|
+ %li.span4
+ %div.thumbnail
+ %a.thumbnail{:href => fax_thumbnail.thumbnail.url}
+ =image_tag(fax_thumbnail.thumbnail.url, :alt => "Page #{fax_thumbnail.position}")
+ %p
+ = "#{fax_thumbnail.position}/#{@fax_document.fax_thumbnails.count}"
+
+.row
+ .span12
+ = render :partial => 'shared/show_edit_destroy_part', :locals => { :parent => @fax_document.fax_account, :child => @fax_document }