This commit is contained in:
Nicolas Bally 2020-03-03 17:12:05 +01:00
parent 39feacb7dc
commit 1ec3b38ae4
26 changed files with 402 additions and 42 deletions

View File

@ -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])

View File

@ -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"

View File

@ -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

View File

@ -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

View File

@ -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},

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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}

View File

@ -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

View File

@ -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"

View File

@ -0,0 +1 @@
../p_customers/new.html.haml

View File

@ -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

View File

@ -0,0 +1 @@
../p_customers/new.html.haml

View File

@ -7,4 +7,34 @@
.qi_row
.qi_pannel.qi_plain.padding
=debug @file_tunel
%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}

View File

@ -1,10 +1,6 @@
.qi_header
%h1
Ventes
%span
=link_to "Clients", admin_p_customers_path
%span
Créer un nouveau client
= render 'form'

View File

@ -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

View File

@ -0,0 +1,7 @@
#odr_form
.form_pannel
%center
=debug @file_tunel_download

View File

@ -0,0 +1,8 @@
#odr_form
.form_pannel
%center
Merci pour ces informations, vous allez recevoir le lien vers votre fichier par mail.

View File

@ -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 !
<script type="text/javascript">
=raw "var clock_max = #{count};"
</script>
: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;
}
}

View File

View File

@ -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

View File

@ -0,0 +1,5 @@
class AddFileTunelToMailTypes < ActiveRecord::Migration[6.0]
def change
add_reference :mail_types, :file_tunel, foreign_key: true
end
end

View File

@ -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"