This commit is contained in:
Nicolas Bally 2020-03-03 18:19:59 +01:00
parent 1ec3b38ae4
commit 767bed7998
13 changed files with 162 additions and 34 deletions

View File

@ -2,3 +2,5 @@
@import "bootstrap";
@import "fontawesome/font-awesome";

View File

@ -42,4 +42,30 @@ class Public::FileTunelDownloadsController < ApplicationController
end
def download
@file_tunel_download = FileTunelDownload.where(:token => params[:id]).first
@file_tunel_send = @file_tunel_download.file_tunel_send
@data_to_send = File.open(@file_tunel_download.generate_pdf).read
params[:inline] = true
send_data @data_to_send, :filename =>"#{@file_tunel_download.token}.pdf" , :type => 'application/pdf',:disposition => (params[:inline] ? 'inline' : "attachment")
#render :inline => "y"
end
def fili
@file_tunel_download = FileTunelDownload.where(:token => params[:id]).first
@file_tunel_send = @file_tunel_download.file_tunel_send
@file_tunel = @file_tunel_send.file_tunel
end
end

View File

@ -7,6 +7,12 @@ class FileTunelDownload < ApplicationRecord
before_create { generate_token() }
include ActionView::Helpers::NumberHelper
include ActionView::Helpers::TranslationHelper
include ActionView::Helpers::UrlHelper
def generate_token()
begin
self[:token] = SecureRandom.urlsafe_base64
@ -22,8 +28,67 @@ class FileTunelDownload < ApplicationRecord
def send_mail_type(slug, element = nil)
if self.file_tunel_send and self.file_tunel_send.file_tunel and mail_type = self.file_tunel_send.file_tunel.mail_types.where(:slug => slug).first
mail_hist = MailHist.generate_mail(:fr, mail_type, self.file_tunel_send.email, {:arguments => {:nom => self.name, :civilite => self.civilite, :nom => self.name, :prenom => self.firstname, :lien => self.lien }, :element => self})
mail_hist = MailHist.generate_mail(:fr, mail_type, self.file_tunel_send.email, {:arguments => {:nom => self.name, :civilite => self.civilite, :nom => self.name, :prenom => self.firstname, :lien => self.lien }, :element => self, :file_tunel => self.file_tunel_send.file_tunel})
end
end
def generate_pdf
doc_number = self.token
@temp_file = "#{Rails.root}/pdf/price_documents/#{doc_number}_temp.pdf"
@final_file = "#{Rails.root}/pdf/price_documents/#{doc_number}_temp2.pdf"
@final_file2 = "#{Rails.root}/pdf/price_documents/#{doc_number}.pdf"
require 'posix/spawn'
#::POSIX::Spawn::Child.new 'pdftk', @temp_file, 'stamp', "#{Rails.root}/pdf_stamp/en-tete.pdf", 'output', @final_file
files = []
self.file_tunel_send.file_tunel.file_tunel_files.order("position ASC").each do |f|
files << f.file.path if f.file
end
puts requette = ['pdftk', files.join(" "), 'cat','output', @final_file].join(" ")
system requette
url = Rails.application.routes.url_helpers.fili_public_file_tunel_download_path(:id => self.token,:format => :html)
url = (Rails.env.development? ? "http://localhost:4000" : "https://offres.market-inn.fr").to_s+url
puts url
pdf = ("pdf")
node_file = @temp_file
system("node #{pdf}.js #{Shellwords.escape(url)} #{Shellwords.escape(@temp_file)}")
puts requette = ['pdftk', @final_file, 'stamp', @temp_file, 'output', @final_file2].join(" ")
system requette
return @final_file2
end
end

View File

@ -52,7 +52,7 @@ class FileTunelSend < ApplicationRecord
def send_mail_type(slug, element = nil)
if self.file_tunel and mail_type = self.file_tunel.mail_types.where(:slug => slug).first
mail_hist = MailHist.generate_mail(:fr, mail_type, self.email, {:arguments => {:email => self.email, :lien => self.lien }, :element => self})
mail_hist = MailHist.generate_mail(:fr, mail_type, self.email, {:arguments => {:email => self.email, :lien => self.lien }, :element => self, :file_tunel => self.file_tunel})
end
end

View File

@ -61,6 +61,8 @@ class MailHist < ApplicationRecord
@m_odr = options[:m_odr]
@m_odr_rep = options[:m_odr_rep]
@file_tunel = options[:file_tunel]
@arguments = @options[:arguments]
@ -88,9 +90,12 @@ class MailHist < ApplicationRecord
@from = @options[:from]
elsif @m_odr and @m_odr.email_from?
@from = @m_odr.email_from
elsif @file_tunel and @file_tunel.from_email?
@file_tunel = @file_tunel.from_email
end
@to_email = email
mail_history = MailHist.create(:lang_site => @lang_site, :to_email => @to_email, :from_email => @from, :element => options[:element], :subject => @subject, :body => @body, :m_odr => @m_odr, :m_odr_rep => @m_odr_rep, :mail_content => @mail_content, :mail_type => @mail_type)

View File

@ -2,6 +2,8 @@
.content
=f.inputs do
.qi_row
.qi_pannel.qi_plain.padding
= f.input :p_customer, :label => "Client :"
= f.input :name, :label => "Nom :"
@ -14,7 +16,7 @@
.qi_row
.qi_pannel.qi_plain.padding
Fichiers :
Fichiers à télécharger :
%hr
.file_tunel_files_form
@ -26,14 +28,14 @@
.qi_row
.qi_pannel.qi_plain.padding
Fichiers demandés :
Mails à contacter :
%hr
.file_tunel_sends_form
=f.semantic_fields_for :file_tunel_sends do |form|
=render :partial => "admin/file_tunel_sends/form", :locals => {:form => form}
%p= link_to_add_fields ic(:plus)+" Ajouter un fichier demandé", f, :file_tunel_sends
%p= link_to_add_fields ic(:plus)+" Ajouter un mail", f, :file_tunel_sends
.qi_row
.qi_pannel.qi_plain.padding

View File

@ -0,0 +1,19 @@
!!!
%html{:lang => "fr", :style => "background:transparent !important;" }
%head
%meta{ :"http-equiv" => "Content-Type", :content => "text/html; charset=utf-8" }
%body{:style => "background:transparent !important;"}
%div{:style => "font-size:3em;position:absolute;top:10cm;width:90%;left:5%;text-align:center;color:rgba(0,0,0,0.2);transform: rotate(-18deg);font-weight:bold; "}
-arguments = {:civilite => @file_tunel_download.civilite, :nom => @file_tunel_download.name, :prenom => @file_tunel_download.firstname}
-s = @file_tunel.fili_text
-arguments.each_pair do |key, value|
-s = s.gsub(/\[#{key.to_s}\]/, value.to_s)
=s.upcase

View File

@ -1,7 +1,14 @@
#odr_form
#odr_form{:style => "margin:50px auto;max-width:600px;"}
.form_pannel
%center
=debug @file_tunel_download
Votre fichier est prêt à être télécharger :
%br
%br
=link_to "Télécharger maintenant", download_public_file_tunel_download_path(:id => @file_tunel_download.token), :class => "btn btn-primary"
=debug fili_public_file_tunel_download_path(:id => @file_tunel_download.token)

View File

@ -1,7 +1,5 @@
#odr_form
#odr_form{:style => "margin:50px auto;max-width:600px;"}
.form_pannel
%center
Merci pour ces informations, vous allez recevoir le lien vers votre fichier par mail.

View File

@ -48,30 +48,26 @@
-if !@file_tunel_download
-@file_tunel_download = @file_tunel_send.file_tunel_downloads.build()
#odr_form
#odr_form{:style => "margin:50px auto;max-width:600px;"}
=semantic_form_for [:public, @file_tunel_download], html: { multipart: true } , :remote => false do |f|
=f.hidden_field :file_tunel_send_id
=hidden_field_tag :force, params[:force]
=#f.hidden_field :t
.form_pannel
%h3 Vous
%h3=@file_tunel_download.file_tunel_send.file_tunel.name
=simple_format @file_tunel_download.file_tunel_send.file_tunel.description
=f.inputs do
%table
%tr
%td{:style => "width:20%;padding-right:4px;"}
=f.input :civilite, :label => false, :placeholder => "Civilité", :as => :select, :collection => [[qit("don-particular-civilite-mme","Mme."), "Mme"], [qit("don-particular-civilite-m","M."), "M"]], :include_blank => true
%td{:style => "width:40%;padding-right:4px;"}
=f.input :name, :label => false, :placeholder => "Nom"
=f.input :civilite, :label => "Civilité", :as => :select, :collection => [[qit("don-particular-civilite-mme","Mme."), "Mme"], [qit("don-particular-civilite-m","M."), "M"]], :include_blank => true
%td{:style => "width:40%"}
=f.input :firstname, :label => false, :placeholder => "Prénom"
=f.input :name, :label => "Nom"
=f.input :firstname, :label => "Prénom"
%br
%center=f.submit "Envoyer", :class => "btn btn-primary btn-lg"
%center=f.submit "Recevoir mon lien de téléchargement", :class => "btn btn-primary"
%br
:scss

View File

@ -4,6 +4,8 @@ Rails.application.routes.draw do
resources :file_tunel_downloads do
member do
get :thank
get :download
get :fili
end
collection do

6
package-lock.json generated
View File

@ -131,9 +131,9 @@
}
},
"https-proxy-agent": {
"version": "2.2.2",
"resolved": "https://registry.npmjs.org/https-proxy-agent/-/https-proxy-agent-2.2.2.tgz",
"integrity": "sha512-c8Ndjc9Bkpfx/vCJueCPy0jlP4ccCCSNDp8xwCZzPjKJUm+B+u9WX2x98Qx4n1PiMNTWo3D7KK5ifNV/yJyRzg==",
"version": "2.2.4",
"resolved": "https://registry.npmjs.org/https-proxy-agent/-/https-proxy-agent-2.2.4.tgz",
"integrity": "sha512-OmvfoQ53WLjtA9HeYP9RNrWMJzzAz1JGaSFr1nijg0PVR1JaD/xbJq1mdEIIlxGpXp9eSe/O2LgU9DJmTPd0Eg==",
"requires": {
"agent-base": "^4.3.0",
"debug": "^3.1.0"

8
pdf.js
View File

@ -10,11 +10,17 @@ const createPdf = async() => {
//await page.setViewport({width: 794, height: 1122, deviceScaleFactor: 1});
await page.goto(process.argv[2], {timeout: 3000, waitUntil: 'networkidle2'});
await page.waitFor(250);
await page.emulateMedia('screen');
await page._emulationManager._client.send(
'Emulation.setDefaultBackgroundColorOverride',
{ color: { r: 0, g: 0, b: 0, a: 0 } }
);
await page.pdf({
path: process.argv[3],
format: 'A4',
margin: { top: "2cm", right: "1cm", bottom: "2cm", left: "1cm" },
printBackground: false
printBackground: true
});
} catch (err) {
console.log(err.message);