diff --git a/app/controllers/admin/file_tunel_sends_controller.rb b/app/controllers/admin/file_tunel_sends_controller.rb index fcd26fc..08a85a9 100644 --- a/app/controllers/admin/file_tunel_sends_controller.rb +++ b/app/controllers/admin/file_tunel_sends_controller.rb @@ -24,6 +24,12 @@ class Admin::FileTunelSendsController < ApplicationController end + def send_mail + @file_tunel_send = FileTunelSend.find(params[:id]) + @file_tunel_send.send_mail_type("envoi_lien") + redirect_to [:admin,@file_tunel_send.file_tunel ] + end + def show @file_tunel_send = FileTunelSend.find(params[:id]) diff --git a/app/controllers/admin/file_tunels_controller.rb b/app/controllers/admin/file_tunels_controller.rb index a50e810..4870a2e 100644 --- a/app/controllers/admin/file_tunels_controller.rb +++ b/app/controllers/admin/file_tunels_controller.rb @@ -43,7 +43,7 @@ class Admin::FileTunelsController < ApplicationController @file_tunel = FileTunel.new(params.require(:file_tunel).permit!) if @file_tunel.save - + redirect_to [:admin, @file_tunel] else render action: "new" @@ -57,7 +57,7 @@ class Admin::FileTunelsController < ApplicationController if @file_tunel.update_attributes(params.require(:file_tunel).permit!) - + redirect_to [:admin, @file_tunel] else render action: "edit" diff --git a/app/controllers/public/file_tunel_downloads_controller.rb b/app/controllers/public/file_tunel_downloads_controller.rb new file mode 100644 index 0000000..5c65cc5 --- /dev/null +++ b/app/controllers/public/file_tunel_downloads_controller.rb @@ -0,0 +1,45 @@ +# -*- encoding : utf-8 -*- + +class Public::FileTunelDownloadsController < ApplicationController + layout "public" + + + + def create + @file_tunel_download = FileTunelDownload.new(params.require(:file_tunel_download).permit!) + @file_tunel_send = @file_tunel_download.file_tunel_send + + + + if @file_tunel_download.save + @file_tunel_download.send_mail_type("envoi_fichier") + + + redirect_to thank_public_file_tunel_download_path(@file_tunel_download.token) + + + + else + render :template => "public/file_tunel_sends/show" + + end + + end + + + def thank + @file_tunel_download = FileTunelDownload.where(:token => params[:id]).first + @file_tunel_send = @file_tunel_download.file_tunel_send + + + end + + def show + @file_tunel_download = FileTunelDownload.where(:token => params[:id]).first + @file_tunel_send = @file_tunel_download.file_tunel_send + + + end + + +end diff --git a/app/controllers/public/file_tunel_sends_controller.rb b/app/controllers/public/file_tunel_sends_controller.rb new file mode 100644 index 0000000..65b4194 --- /dev/null +++ b/app/controllers/public/file_tunel_sends_controller.rb @@ -0,0 +1,16 @@ +# -*- encoding : utf-8 -*- +class Public::FileTunelSendsController < ApplicationController + + layout "public" + + + def show + @file_tunel_send = FileTunelSend.where(:token => params[:id]).first + + @file_tunel = @file_tunel_send.file_tunel + + + + end + +end diff --git a/app/models/file_tunel.rb b/app/models/file_tunel.rb index e957d65..80bba7e 100644 --- a/app/models/file_tunel.rb +++ b/app/models/file_tunel.rb @@ -10,12 +10,17 @@ class FileTunel < ApplicationRecord accepts_nested_attributes_for :file_tunel_files, :allow_destroy => true + + has_many :mail_types, :dependent => :destroy + accepts_nested_attributes_for :mail_types, :allow_destroy => true + + + + QI_DYNAMICS = %w() eval(QI_DYNAMICS_CORE) - has_many :m_odr_virements, :dependent => :nullify - def self.qi_table_order { :created_at => {:name => "Date", :reorder => true}, diff --git a/app/models/file_tunel_download.rb b/app/models/file_tunel_download.rb index 998bdae..e7d2c11 100644 --- a/app/models/file_tunel_download.rb +++ b/app/models/file_tunel_download.rb @@ -1,7 +1,9 @@ class FileTunelDownload < ApplicationRecord belongs_to :file_tunel - belongs_to :file_tunel_send_id + belongs_to :file_tunel_send + validates :name, :presence => true + validates :firstname, :presence => true before_create { generate_token() } @@ -11,4 +13,17 @@ class FileTunelDownload < ApplicationRecord end while FileTunelDownload.exists?(:token => self[:token]) end + def lien + Rails.application.routes.url_helpers.public_file_tunel_download_url(:id => self.token, :slug => self.file_tunel_send.file_tunel .slug, :format => :html) + + end + + + 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}) + end + end + end diff --git a/app/models/file_tunel_file.rb b/app/models/file_tunel_file.rb index a6bb97a..f420dde 100644 --- a/app/models/file_tunel_file.rb +++ b/app/models/file_tunel_file.rb @@ -12,4 +12,39 @@ class FileTunelFile < ApplicationRecord mount_uploader :file, OdrUploader validates :file, :presence => true + + + + QI_DYNAMICS = %w() + + eval(QI_DYNAMICS_CORE) + + def self.qi_table_order + { + :created_at => {:name => "Date", :reorder => true}, + :name => {:name => "Nom", :reorder => true}, + + :file => {:name => "Fichier", :reorder => true}, + + :actions => "Actions", + + } + + end + + def self.valid_sort + r = [] + self.qi_table_order.each do |key, value| + if value.instance_of? Hash + if value[:reorder] and value[:reorder] == true + r << key.to_s if value[:reorder] + end + end + end + return r + + + end + + end diff --git a/app/models/file_tunel_send.rb b/app/models/file_tunel_send.rb index 16820ac..63dcfb0 100644 --- a/app/models/file_tunel_send.rb +++ b/app/models/file_tunel_send.rb @@ -1,4 +1,11 @@ class FileTunelSend < ApplicationRecord + + include ActionView::Helpers::NumberHelper + include ActionView::Helpers::TranslationHelper + include ActionView::Helpers::UrlHelper + + has_many :file_tunel_downloads + belongs_to :file_tunel before_create { generate_token() } @@ -8,4 +15,51 @@ class FileTunelSend < ApplicationRecord self[:token] = SecureRandom.urlsafe_base64 end while FileTunelSend.exists?(:token => self[:token]) end + + + + + QI_DYNAMICS = %w() + + eval(QI_DYNAMICS_CORE) + + def self.qi_table_order + { + :created_at => {:name => "Date", :reorder => true}, + :email => {:name => "Nom", :reorder => true}, + + :lien => {:name => "Lien", :reorder => true}, + + :actions => "Actions", + + } + + end + + def self.valid_sort + r = [] + self.qi_table_order.each do |key, value| + if value.instance_of? Hash + if value[:reorder] and value[:reorder] == true + r << key.to_s if value[:reorder] + end + end + end + return r + + + end + 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}) + end + end + + def lien + Rails.application.routes.url_helpers.public_file_tunel_send_url(:id => self.token, :slug => self.file_tunel.slug, :format => :html) + + end + + end diff --git a/app/models/mail_type.rb b/app/models/mail_type.rb index e65e801..e9a2c9c 100644 --- a/app/models/mail_type.rb +++ b/app/models/mail_type.rb @@ -2,6 +2,6 @@ class MailType < ApplicationRecord has_many :mail_contents belongs_to :mail_type_reference, :class_name => "MailType" - + accepts_nested_attributes_for :mail_contents end diff --git a/app/views/admin/file_tunel_files/_file_tunel_file.html.haml b/app/views/admin/file_tunel_files/_file_tunel_file.html.haml index 52743aa..b223eeb 100644 --- a/app/views/admin/file_tunel_files/_file_tunel_file.html.haml +++ b/app/views/admin/file_tunel_files/_file_tunel_file.html.haml @@ -1,6 +1,11 @@ %tr#file_tunel_file_row{:id => file_tunel_file.id} -tr = {} - + -tr[:file] = capture do + %td + -if file_tunel_file.file + =File.basename file_tunel_file.file.path + =link_to "Télécharger", download_admin_m_odr_file_path(file_tunel_file.file, :disposition => "attachment") + -tr[:actions] = capture do %td.actions = link_to i(:"trash-o"), [:admin, file_tunel_file], method: :delete, data: { confirm: 'Voulez-vous vraiment supprimer cet enregistrement ? ' } , :remote => true diff --git a/app/views/admin/file_tunel_sends/_file_tunel_send.html.haml b/app/views/admin/file_tunel_sends/_file_tunel_send.html.haml index 10d18a4..e890f77 100644 --- a/app/views/admin/file_tunel_sends/_file_tunel_send.html.haml +++ b/app/views/admin/file_tunel_sends/_file_tunel_send.html.haml @@ -4,10 +4,11 @@ -tr[:actions] = capture do %td.actions = link_to i(:"trash-o"), [:admin, file_tunel_send], method: :delete, data: { confirm: 'Voulez-vous vraiment supprimer cet enregistrement ? ' } , :remote => true - = link_to i(:pencil), edit_admin_file_tunel_send_path(file_tunel_send), :remote => true - = link_to i(:eye), admin_file_tunel_send_path(file_tunel_send), :remote => true + + + = link_to i(:envelope), send_mail_admin_file_tunel_send_path(file_tunel_send), :remote => false - - + -tr[:lien] = capture do + %td= link_to public_file_tunel_send_url(:id => file_tunel_send.token, :slug => file_tunel_send.file_tunel.slug, :format => :html), public_file_tunel_send_url(:id => file_tunel_send.token, :slug => file_tunel_send.file_tunel.slug, :format => :html) =render :partial => "qi/qi_ordered_table_object", :locals => {:tr => tr, :object => file_tunel_send} \ No newline at end of file diff --git a/app/views/admin/file_tunels/_file_tunel.html.haml b/app/views/admin/file_tunels/_file_tunel.html.haml index 55edcaa..fd782c8 100644 --- a/app/views/admin/file_tunels/_file_tunel.html.haml +++ b/app/views/admin/file_tunels/_file_tunel.html.haml @@ -4,8 +4,8 @@ -tr[:actions] = capture do %td.actions = link_to i(:"trash-o"), [:admin, file_tunel], method: :delete, data: { confirm: 'Voulez-vous vraiment supprimer cet enregistrement ? ' } , :remote => true - = link_to i(:pencil), edit_admin_file_tunel_path(file_tunel), :remote => true - = link_to i(:eye), admin_file_tunel_path(file_tunel), :remote => true + = link_to i(:pencil), edit_admin_file_tunel_path(file_tunel), :remote => false + = link_to i(:eye), admin_file_tunel_path(file_tunel), :remote => false diff --git a/app/views/admin/file_tunels/_form.html.haml b/app/views/admin/file_tunels/_form.html.haml index 368715b..b0b3f25 100644 --- a/app/views/admin/file_tunels/_form.html.haml +++ b/app/views/admin/file_tunels/_form.html.haml @@ -1,4 +1,4 @@ -=semantic_form_for [:admin, @file_tunel], html: { multipart: true }, :remote => true do |f| +=semantic_form_for [:admin, @file_tunel], html: { multipart: true }, :remote => false do |f| .content =f.inputs do @@ -35,6 +35,19 @@ %p= link_to_add_fields ic(:plus)+" Ajouter un fichier demandé", f, :file_tunel_sends + .qi_row + .qi_pannel.qi_plain.padding + + = f.input :from_email, :label => "Email d'envoi :" + + Mails types : + %hr + + .mail_types_form + =f.semantic_fields_for :mail_types do |form| + =render :partial => "admin/mail_types/form", :locals => {:form => form} + + %p= link_to_add_fields ic(:plus)+" Ajouter un mail type", f, :mail_types .actions=f.submit "sauvegarder", :class => "btn btn-primary" diff --git a/app/views/admin/file_tunels/edit.html.haml b/app/views/admin/file_tunels/edit.html.haml new file mode 120000 index 0000000..331ebdc --- /dev/null +++ b/app/views/admin/file_tunels/edit.html.haml @@ -0,0 +1 @@ +../p_customers/new.html.haml \ No newline at end of file diff --git a/app/views/admin/file_tunels/index.html.haml b/app/views/admin/file_tunels/index.html.haml index 8328b71..d2c87d9 100644 --- a/app/views/admin/file_tunels/index.html.haml +++ b/app/views/admin/file_tunels/index.html.haml @@ -1,5 +1,5 @@ .qi_header - .right= link_to 'Ajouter ', new_admin_file_tunel_path(), :class => "btn btn-primary", :remote => true + .right= link_to 'Ajouter ', new_admin_file_tunel_path(), :class => "btn btn-primary", :remote => false %h1 %span diff --git a/app/views/admin/file_tunels/new.html.haml b/app/views/admin/file_tunels/new.html.haml new file mode 120000 index 0000000..331ebdc --- /dev/null +++ b/app/views/admin/file_tunels/new.html.haml @@ -0,0 +1 @@ +../p_customers/new.html.haml \ No newline at end of file diff --git a/app/views/admin/file_tunels/show.html.haml b/app/views/admin/file_tunels/show.html.haml index d00f18a..6a708ee 100644 --- a/app/views/admin/file_tunels/show.html.haml +++ b/app/views/admin/file_tunels/show.html.haml @@ -7,4 +7,34 @@ .qi_row .qi_pannel.qi_plain.padding - =debug @file_tunel \ No newline at end of file + %table.table.table-striped.table-hover.table-bordered + %tr + %td{:style => "width:200px;"} Nom + %td + =@file_tunel.name + + + + %hr + Fichiers + + -params[:search][:per_page] = params[:search][:per_page] || 50 + -per_page = params[:search][:per_page] + -page = (params[:page] and params[:page] != "") ? params[:page] : 1 + -@file_tunel_files = @file_tunel.file_tunel_files + -@file_tunel_files = sort_by_sorting(@file_tunel_files, "position ASC") + -@file_tunel_files = @file_tunel_files.page(page).per(per_page) + + =render :partial => "qi/qi_ordered_table", :locals => {:qi_ordered_table_collection => @file_tunel_files} + + %hr + Liste + + -params[:search][:per_page] = params[:search][:per_page] || 50 + -per_page = params[:search][:per_page] + -page = (params[:page] and params[:page] != "") ? params[:page] : 1 + -@file_tunel_sends = @file_tunel.file_tunel_sends + -@file_tunel_sends = sort_by_sorting(@file_tunel_sends, "created_at DESC") + -@file_tunel_sends = @file_tunel_sends.page(page).per(per_page) + + =render :partial => "qi/qi_ordered_table", :locals => {:qi_ordered_table_collection => @file_tunel_sends} \ No newline at end of file diff --git a/app/views/admin/p_customers/new.html.haml b/app/views/admin/p_customers/new.html.haml index a3ca07d..67d7e34 100644 --- a/app/views/admin/p_customers/new.html.haml +++ b/app/views/admin/p_customers/new.html.haml @@ -1,10 +1,6 @@ .qi_header %h1 - Ventes - %span - =link_to "Clients", admin_p_customers_path - %span - Créer un nouveau client + = render 'form' diff --git a/app/views/layouts/mail.html.haml b/app/views/layouts/mail.html.haml index a15d8af..f16015c 100755 --- a/app/views/layouts/mail.html.haml +++ b/app/views/layouts/mail.html.haml @@ -8,29 +8,30 @@ %meta{ :"http-equiv" => "Content-Type", :content => "text/html; charset=utf-8" } %body - %br - %br + -if @m_odr + %br + %br - -if @m_odr.logo_image_file - =image_tag "https://"+HOSTNAME+@m_odr.logo_image_file.file.url, :class => "odr_logo", :style => (@m_odr.logo_image_file_width? ? "max-width:#{@m_odr.logo_image_file_width}px;margin:auto;": "") + -if @m_odr.logo_image_file + =image_tag "https://"+HOSTNAME+@m_odr.logo_image_file.file.url, :class => "odr_logo", :style => (@m_odr.logo_image_file_width? ? "max-width:#{@m_odr.logo_image_file_width}px;margin:auto;": "") - -if @m_odr.logo_image_file - =image_tag "https://"+HOSTNAME+@m_odr.banner_image_file.file.url, :class => "odr_banner", :style => (@m_odr.banner_image_file_width? ? "max-width:#{@m_odr.banner_image_file_width}px;margin:auto;margin-bottom:40px;": "") + -if @m_odr.logo_image_file + =image_tag "https://"+HOSTNAME+@m_odr.banner_image_file.file.url, :class => "odr_banner", :style => (@m_odr.banner_image_file_width? ? "max-width:#{@m_odr.banner_image_file_width}px;margin:auto;margin-bottom:40px;": "") - -background = (@m_odr.background_image_file ? "https://"+HOSTNAME+@m_odr.background_image_file.file.url : "") - :scss - body{ - background:url('#{background}') fixed; - background-size:100%; - background-size: cover; - font-family:arial, sans-serif; - } - .odr_logo,.odr_banner{ - width:90%; - display:block; - margin:auto; - } + -background = (@m_odr.background_image_file ? "https://"+HOSTNAME+@m_odr.background_image_file.file.url : "") + :scss + body{ + background:url('#{background}') fixed; + background-size:100%; + background-size: cover; + font-family:arial, sans-serif; + } + .odr_logo,.odr_banner{ + width:90%; + display:block; + margin:auto; + } #odr_form diff --git a/app/views/public/file_tunel_downloads/show.html.haml b/app/views/public/file_tunel_downloads/show.html.haml new file mode 100644 index 0000000..d546aec --- /dev/null +++ b/app/views/public/file_tunel_downloads/show.html.haml @@ -0,0 +1,7 @@ + + + +#odr_form + .form_pannel + %center + =debug @file_tunel_download \ 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 new file mode 100644 index 0000000..6480a14 --- /dev/null +++ b/app/views/public/file_tunel_downloads/thank.html.haml @@ -0,0 +1,8 @@ + + + +#odr_form + .form_pannel + %center + Merci pour ces informations, vous allez recevoir le lien vers votre fichier par mail. + \ No newline at end of file diff --git a/app/views/public/file_tunel_sends/show.html.haml b/app/views/public/file_tunel_sends/show.html.haml new file mode 100644 index 0000000..0e48eaf --- /dev/null +++ b/app/views/public/file_tunel_sends/show.html.haml @@ -0,0 +1,88 @@ + + + +-if false + %div{:style => "margin-top:30px;font-weight:bold;font-weight:800;font-size:2em;text-transform:uppercase;font-family: 'Open Sans','Helvetica Neue', Helvetica, sans-serif;text-align:center;"} + -count = ((@m_odr.start_at) - (Date.today)) + + -if @m_odr.landing_text? + =@m_odr.landing_text + -else + Démarrage + %div{:style => "font-weight:bold;font-weight:800;text-transform:uppercase;font-family: 'Open Sans','Helvetica Neue', Helvetica, sans-serif;text-align:center;line-height:200px;position:relative;top:-40px"} + dans + .clock{:style => "margin:2em;display:inline-block;width:auto;margin:0 auto;position:relative;top:35px"} + -if count > 1 + jours ! + -else + jour ! + + :javascript + var countup; + + var clock = $('.clock').FlipClock(0, { + clockFace: 'Counter', + minimumDigits: 1, + callbacks:{ + init:function (){ + + } + } + }); + if(clock_max > 0){ + countup = setInterval(function() { + clock.increment(); + if(clock.getTime().time >= clock_max) { + clock.stop(); + clearInterval(countup); + } + }, 0);} + + -if false + %p{:style => "font-weight:bold;font-size:2em;text-transform:uppercase;font-family:'Helvetica Neue', Helvetica, sans-serif;"} + jours avant l'ouverture + +-else + -if !@file_tunel_download + -@file_tunel_download = @file_tunel_send.file_tunel_downloads.build() + + #odr_form + =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 + + =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" + + %br + %center=f.submit "Envoyer", :class => "btn btn-primary btn-lg" + %br + + :scss + abbr[title="required"] { + //display: none; + text-decoration:none; + border:0; + } + form{ + td{ + vertical-align:top; + } + + } \ No newline at end of file diff --git a/app/views/public/untitled.txt b/app/views/public/untitled.txt new file mode 100644 index 0000000..e69de29 diff --git a/config/routes.rb b/config/routes.rb index 4162976..450b459 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,5 +1,30 @@ Rails.application.routes.draw do + namespace :public do + resources :file_tunel_downloads do + member do + get :thank + end + collection do + + end + end + end + + namespace :public do + resources :file_tunel_sends do + member do + + end + collection do + + end + end + end + + + + namespace :admin do resources :file_tunel_files do member do @@ -25,7 +50,7 @@ Rails.application.routes.draw do namespace :admin do resources :file_tunel_sends do member do - + get :send_mail end collection do diff --git a/db/migrate/20200303153308_add_file_tunel_to_mail_types.rb b/db/migrate/20200303153308_add_file_tunel_to_mail_types.rb new file mode 100644 index 0000000..22bee03 --- /dev/null +++ b/db/migrate/20200303153308_add_file_tunel_to_mail_types.rb @@ -0,0 +1,5 @@ +class AddFileTunelToMailTypes < ActiveRecord::Migration[6.0] + def change + add_reference :mail_types, :file_tunel, foreign_key: true + end +end diff --git a/db/schema.rb b/db/schema.rb index 3772355..1d67887 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 2020_03_03_104720) do +ActiveRecord::Schema.define(version: 2020_03_03_153308) do create_table "accounting_zones", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4", force: :cascade do |t| t.string "name" @@ -926,6 +926,8 @@ ActiveRecord::Schema.define(version: 2020_03_03_104720) do t.datetime "updated_at", precision: 6, null: false t.bigint "m_odr_id" t.text "tags" + t.bigint "file_tunel_id" + t.index ["file_tunel_id"], name: "index_mail_types_on_file_tunel_id" t.index ["m_odr_id"], name: "index_mail_types_on_m_odr_id" t.index ["mail_type_reference_id"], name: "index_mail_types_on_mail_type_reference_id" end @@ -2552,6 +2554,7 @@ ActiveRecord::Schema.define(version: 2020_03_03_104720) do add_foreign_key "mail_hists", "m_odrs" add_foreign_key "mail_hists", "mail_contents" add_foreign_key "mail_hists", "mail_types" + add_foreign_key "mail_types", "file_tunels" add_foreign_key "mail_types", "m_odrs" add_foreign_key "p_contact_contact_types", "p_contact_types" add_foreign_key "p_contact_contact_types", "p_contacts"