diff --git a/app/assets/stylesheets/public.scss b/app/assets/stylesheets/public.scss index 5491bc2..9768138 100644 --- a/app/assets/stylesheets/public.scss +++ b/app/assets/stylesheets/public.scss @@ -1,4 +1,6 @@ @import "vendor/flipclock"; @import "bootstrap"; -@import "fontawesome/font-awesome"; \ No newline at end of file +@import "fontawesome/font-awesome"; + + diff --git a/app/controllers/public/file_tunel_downloads_controller.rb b/app/controllers/public/file_tunel_downloads_controller.rb index 5c65cc5..e123af7 100644 --- a/app/controllers/public/file_tunel_downloads_controller.rb +++ b/app/controllers/public/file_tunel_downloads_controller.rb @@ -40,6 +40,32 @@ 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 diff --git a/app/models/file_tunel_download.rb b/app/models/file_tunel_download.rb index e7d2c11..913c29d 100644 --- a/app/models/file_tunel_download.rb +++ b/app/models/file_tunel_download.rb @@ -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 diff --git a/app/models/file_tunel_send.rb b/app/models/file_tunel_send.rb index 63dcfb0..1b965cb 100644 --- a/app/models/file_tunel_send.rb +++ b/app/models/file_tunel_send.rb @@ -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 diff --git a/app/models/mail_hist.rb b/app/models/mail_hist.rb index dd91db0..3999792 100644 --- a/app/models/mail_hist.rb +++ b/app/models/mail_hist.rb @@ -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) diff --git a/app/views/admin/file_tunels/_form.html.haml b/app/views/admin/file_tunels/_form.html.haml index b0b3f25..7424906 100644 --- a/app/views/admin/file_tunels/_form.html.haml +++ b/app/views/admin/file_tunels/_form.html.haml @@ -2,19 +2,21 @@ .content =f.inputs do - = f.input :p_customer, :label => "Client :" + .qi_row + .qi_pannel.qi_plain.padding + = f.input :p_customer, :label => "Client :" - = f.input :name, :label => "Nom :" - = f.input :description, :label => "Description :" - = f.input :slug, :label => "Permalien :" - = f.input :start_at, :label => "Date de début :", :as => :date - = f.input :end_at, :label => "Date de fin :" , :as => :date - = f.input :fili_text, :label => "Texte filigrame :" + = f.input :name, :label => "Nom :" + = f.input :description, :label => "Description :" + = f.input :slug, :label => "Permalien :" + = f.input :start_at, :label => "Date de début :", :as => :date + = f.input :end_at, :label => "Date de fin :" , :as => :date + = f.input :fili_text, :label => "Texte filigrame :" .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 diff --git a/app/views/public/file_tunel_downloads/fili.html.haml b/app/views/public/file_tunel_downloads/fili.html.haml new file mode 100644 index 0000000..436b6b6 --- /dev/null +++ b/app/views/public/file_tunel_downloads/fili.html.haml @@ -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 + \ No newline at end of file diff --git a/app/views/public/file_tunel_downloads/show.html.haml b/app/views/public/file_tunel_downloads/show.html.haml index d546aec..d913847 100644 --- a/app/views/public/file_tunel_downloads/show.html.haml +++ b/app/views/public/file_tunel_downloads/show.html.haml @@ -1,7 +1,14 @@ -#odr_form +#odr_form{:style => "margin:50px auto;max-width:600px;"} .form_pannel %center - =debug @file_tunel_download \ No newline at end of file + 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) \ No newline at end of file diff --git a/app/views/public/file_tunel_downloads/thank.html.haml b/app/views/public/file_tunel_downloads/thank.html.haml index 6480a14..4080ec6 100644 --- a/app/views/public/file_tunel_downloads/thank.html.haml +++ b/app/views/public/file_tunel_downloads/thank.html.haml @@ -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. diff --git a/app/views/public/file_tunel_sends/show.html.haml b/app/views/public/file_tunel_sends/show.html.haml index 0e48eaf..b477d71 100644 --- a/app/views/public/file_tunel_sends/show.html.haml +++ b/app/views/public/file_tunel_sends/show.html.haml @@ -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" - - %td{:style => "width:40%"} - =f.input :firstname, :label => false, :placeholder => "Pré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 + + =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 diff --git a/config/routes.rb b/config/routes.rb index 450b459..b0654ca 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -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 diff --git a/package-lock.json b/package-lock.json index 0c9c44e..b446a36 100644 --- a/package-lock.json +++ b/package-lock.json @@ -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" diff --git a/pdf.js b/pdf.js index de101ac..ee15af6 100644 --- a/pdf.js +++ b/pdf.js @@ -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);