Commit 04b93769 authored by Alexandre Friquet's avatar Alexandre Friquet
Browse files

Replaces tabs with spaces.

parent 2171bd0d
......@@ -21,42 +21,42 @@
# along with OLIGAA. If not, see <http://www.gnu.org/licenses/>.
#
class NewslettersController < ApplicationController
before_action :authorize, except: [:index, :show]
before_action :authorize, except: [:index, :show]
def index
@newsletters = admin? ? Newsletter.ordered : Newsletter.ordered.published
@for_nav = Newsletter.for_nav
@newsletters = admin? ? Newsletter.ordered : Newsletter.ordered.published
@for_nav = Newsletter.for_nav
end
def new
@newsletter = Newsletter.new({partner_ids: settings.partners.map(&:id)})
@newsletter = Newsletter.new({partner_ids: settings.partners.map(&:id)})
prepare_partners
end
def create
@newsletter = Newsletter.new(newsletter_params)
if @newsletter.save
schedule_pdf
redirect_to @newsletter
else
render :new
end
@newsletter = Newsletter.new(newsletter_params)
if @newsletter.save
schedule_pdf
redirect_to @newsletter
else
render :new
end
end
def show
@newsletter = Newsletter.find(params[:id])
@newsletter = Newsletter.find(params[:id])
@partners = @newsletter.partners
if admin? || @newsletter.published?
if admin? || @newsletter.published?
respond_to do |format|
format.html
format.pdf do
if @newsletter.has_pdf?
send_file @newsletter.pdf_path, type: 'application/pdf'
expires_now
else
flash[:alert] = "Le PDF n'a pas encore été généré. Merci de revenir plus tard."
redirect_to @newsletter
end
if @newsletter.has_pdf?
send_file @newsletter.pdf_path, type: 'application/pdf'
expires_now
else
flash[:alert] = "Le PDF n'a pas encore été généré. Merci de revenir plus tard."
redirect_to @newsletter
end
end
end
else
......@@ -65,23 +65,23 @@ class NewslettersController < ApplicationController
end
def edit
@newsletter = Newsletter.find(params[:id])
@newsletter = Newsletter.find(params[:id])
prepare_partners
end
def update
@newsletter = Newsletter.find(params[:id])
if @newsletter.update_attributes(newsletter_params)
schedule_pdf
redirect_to @newsletter
else
render :edit
end
@newsletter = Newsletter.find(params[:id])
if @newsletter.update_attributes(newsletter_params)
schedule_pdf
redirect_to @newsletter
else
render :edit
end
end
def destroy
Newsletter.find(params[:id]).destroy
redirect_to newsletters_path
Newsletter.find(params[:id]).destroy
redirect_to newsletters_path
end
private
......@@ -90,20 +90,20 @@ class NewslettersController < ApplicationController
@partners = Partner.by_name
end
def schedule_pdf
if @newsletter.published?
File.delete(@newsletter.pdf_path) if @newsletter.has_pdf?
Delayed::Job.enqueue(PdfJob.new(newsletter_url(@newsletter), @newsletter.pdf_filename))
flash[:notice] = "La génération du PDF a été planifiée."
end
end
def schedule_pdf
if @newsletter.published?
File.delete(@newsletter.pdf_path) if @newsletter.has_pdf?
Delayed::Job.enqueue(PdfJob.new(newsletter_url(@newsletter), @newsletter.pdf_filename))
flash[:notice] = "La génération du PDF a été planifiée."
end
end
def newsletter_params
params.require(:newsletter).permit(:title, :published, partner_ids: [],
items_attributes: [
:id, :content, :newsletter_id, :title, :photo, :delete_photo, :_destroy, activity_ids: [],
images_attributes: image_permitted_attributes,
attached_files_attributes: attached_file_permitted_attributes
])
end
def newsletter_params
params.require(:newsletter).permit(:title, :published, partner_ids: [],
items_attributes: [
:id, :content, :newsletter_id, :title, :photo, :delete_photo, :_destroy, activity_ids: [],
images_attributes: image_permitted_attributes,
attached_files_attributes: attached_file_permitted_attributes
])
end
end
......@@ -55,7 +55,7 @@ class SettingsController < ApplicationController
def settings_params
params.require(:settings).permit(:contact_email, :gcal_pass, :gcal_user, :home_message, :motto, :title,
:site_logo, :motto_logo, :newsletters_title, :contact_message,
:main_color, :secondary_color, :h1_color, :h2_color,
:main_color, :secondary_color, :h1_color, :h2_color,
map_member_group_ids: [], partner_ids: [], platform_collaborating_club_ids: [])
end
end
......@@ -21,10 +21,10 @@
# along with OLIGAA. If not, see <http://www.gnu.org/licenses/>.
#
module MembersHelper
def localized_status
class_name = @member.geocoded? ? "notice_message" : "error_message"
content_tag :span, class: class_name do
@member.localized_status
end
end
def localized_status
class_name = @member.geocoded? ? "notice_message" : "error_message"
content_tag :span, class: class_name do
@member.localized_status
end
end
end
......@@ -21,23 +21,23 @@
# along with OLIGAA. If not, see <http://www.gnu.org/licenses/>.
#
module NewslettersHelper
def partner_link(partner, size = :standard, with_title = true)
data = ""
if partner.url.present? && partner.logo?
# image cliquable + nom normal
data << "<span>#{partner.name}</span>" if with_title
data << link_to(image_tag(partner.logo.url(size), alt: partner.name), partner.url, class: "externe")
elsif partner.url.present? && !partner.logo?
# nom cliquable
data << link_to(partner.name, partner.url, class: "externe")
elsif !partner.url.present? && partner.logo?
# image normale + nom normal
data << "<span>#{partner.name}</span>"
data << image_tag(partner.logo.url(size), alt: partner.name)
else
# nom normal
data << "<span>#{partner.name}</span>"
end
data.html_safe
end
def partner_link(partner, size = :standard, with_title = true)
data = ""
if partner.url.present? && partner.logo?
# image cliquable + nom normal
data << "<span>#{partner.name}</span>" if with_title
data << link_to(image_tag(partner.logo.url(size), alt: partner.name), partner.url, class: "externe")
elsif partner.url.present? && !partner.logo?
# nom cliquable
data << link_to(partner.name, partner.url, class: "externe")
elsif !partner.url.present? && partner.logo?
# image normale + nom normal
data << "<span>#{partner.name}</span>"
data << image_tag(partner.logo.url(size), alt: partner.name)
else
# nom normal
data << "<span>#{partner.name}</span>"
end
data.html_safe
end
end
\ No newline at end of file
......@@ -22,16 +22,16 @@
#
module SettingsHelper
def gcal_service_status
begin
return content_tag :span, class: %w(notice_message rounded_box) do
"Status OK"
end if GoogleAgenda::Service.instance.api_client
rescue Exception => ex
return content_tag :span, class: %w(error_message rounded_box) do
"Status #{ex.message}"
end
end
end
def gcal_service_status
begin
return content_tag :span, class: %w(notice_message rounded_box) do
"Status OK"
end if GoogleAgenda::Service.instance.api_client
rescue Exception => ex
return content_tag :span, class: %w(error_message rounded_box) do
"Status #{ex.message}"
end
end
end
end
\ No newline at end of file
......@@ -21,11 +21,11 @@
# along with OLIGAA. If not, see <http://www.gnu.org/licenses/>.
#
class Newsletter < ApplicationRecord
include URLEncoding
include URLEncoding
has_many :items, class_name: "NewsletterItem", :dependent => :destroy
accepts_nested_attributes_for :items, :allow_destroy => true
has_and_belongs_to_many :partners
has_many :items, class_name: "NewsletterItem", :dependent => :destroy
accepts_nested_attributes_for :items, :allow_destroy => true
has_and_belongs_to_many :partners
validates :title, presence: true
validates_associated :items
......@@ -34,15 +34,15 @@ class Newsletter < ApplicationRecord
scope :ordered, -> { order("created_at DESC") }
scope :for_nav, -> { published.ordered.limit(3) }
def pdf_filename
"#{ENV['APP_NAME']} - #{my_url_encode(title.chomp)}.pdf"
end
def pdf_filename
"#{ENV['APP_NAME']} - #{my_url_encode(title.chomp)}.pdf"
end
def has_pdf?
File.exists?(pdf_path)
end
def has_pdf?
File.exists?(pdf_path)
end
def pdf_path
Rails.root + "public/system/pdfs/newsletters/" + pdf_filename
end
def pdf_path
Rails.root + "public/system/pdfs/newsletters/" + pdf_filename
end
end
......@@ -21,22 +21,22 @@
# along with OLIGAA. If not, see <http://www.gnu.org/licenses/>.
#
class NewsletterItem < ApplicationRecord
belongs_to :newsletter
has_and_belongs_to_many :activities
belongs_to :newsletter
has_and_belongs_to_many :activities
acts_as_list scope: :newsletter
has_many :attached_files, :as => :attachable, :dependent => :destroy
accepts_nested_attributes_for :attached_files, :allow_destroy => true
has_many :images, :as => :imageable, :dependent => :destroy
accepts_nested_attributes_for :images, :allow_destroy => true
has_many :images, :as => :imageable, :dependent => :destroy
accepts_nested_attributes_for :images, :allow_destroy => true
attr_accessor :delete_photo
validates :title, :content, presence: true
before_validation do
photo.clear if delete_photo == '1'
photo.clear if delete_photo == '1'
end
scope :ordered, -> { order("position ASC") }
......
......@@ -21,35 +21,35 @@
# along with OLIGAA. If not, see <http://www.gnu.org/licenses/>.
#
class Partner < ApplicationRecord
belongs_to :website, optional: true
belongs_to :group, class_name: "PartnersGroup", optional: true
has_attached_file :logo, :styles => { :thumb => "100x86", :standard => "160x120" }, :convert_options => { :all => '-strip -colorspace RGB'}
do_not_validate_attachment_file_type :logo
validates_attachment_size :logo, :less_than => 1.megabyte, :message => "doit faire moins de 1 Mo"
has_and_belongs_to_many :newsletters
belongs_to :website, optional: true
belongs_to :group, class_name: "PartnersGroup", optional: true
has_attached_file :logo, :styles => { :thumb => "100x86", :standard => "160x120" }, :convert_options => { :all => '-strip -colorspace RGB'}
do_not_validate_attachment_file_type :logo
validates_attachment_size :logo, :less_than => 1.megabyte, :message => "doit faire moins de 1 Mo"
has_and_belongs_to_many :newsletters
acts_as_list scope: :group
acts_as_list scope: :group
validates :name, presence: true
validates :url, url_format: true, allow_blank: true
validates :name, presence: true
validates :url, url_format: true, allow_blank: true
default_scope { order("position ASC") }
scope :ungrouped, -> { where(group_id: nil) }
default_scope { order("position ASC") }
scope :ungrouped, -> { where(group_id: nil) }
def self.by_name
unscoped.order("name ASC")
end
def self.by_name
unscoped.order("name ASC")
end
def check_scope
scope_name = "group_id"
if changes.include?(scope_name)
old_scope_id = changes[scope_name].first
new_scope_id = changes[scope_name].last
self[scope_name] = old_scope_id
send("decrement_positions_on_lower_items")
self.position = nil
self[scope_name] = new_scope_id
send("add_to_list_bottom")
end
end
def check_scope
scope_name = "group_id"
if changes.include?(scope_name)
old_scope_id = changes[scope_name].first
new_scope_id = changes[scope_name].last
self[scope_name] = old_scope_id
send("decrement_positions_on_lower_items")
self.position = nil
self[scope_name] = new_scope_id
send("add_to_list_bottom")
end
end
end
......@@ -21,9 +21,9 @@
# along with OLIGAA. If not, see <http://www.gnu.org/licenses/>.
#
class PartnersGroup < ApplicationRecord
has_many :partners, foreign_key: "group_id"
has_many :partners, foreign_key: "group_id"
acts_as_list
acts_as_list
validates :title, presence: true
......
......@@ -21,19 +21,19 @@
# along with OLIGAA. If not, see <http://www.gnu.org/licenses/>.
#
class Website < ApplicationRecord
has_many :map_member_group_settings, class_name: 'MemberGroupSetting::Map'
has_many :map_member_groups, through: :map_member_group_settings, source: :member_group
has_many :platform_collaborating_club_settings, class_name: 'MemberGroupSetting::PlatformCollaboratingClub'
has_many :platform_collaborating_clubs, through: :platform_collaborating_club_settings, source: :member_group
has_many :map_member_group_settings, class_name: 'MemberGroupSetting::Map'
has_many :map_member_groups, through: :map_member_group_settings, source: :member_group
has_many :platform_collaborating_club_settings, class_name: 'MemberGroupSetting::PlatformCollaboratingClub'
has_many :platform_collaborating_clubs, through: :platform_collaborating_club_settings, source: :member_group
has_many :partners
has_attached_file :site_logo, :styles => { :standard => "300x110" }, :convert_options => { :all => '-strip -colorspace RGB'}
has_attached_file :motto_logo, :styles => { :standard => "300x110" }, :convert_options => { :all => '-strip -colorspace RGB'}
has_attached_file :site_logo, :styles => { :standard => "300x110" }, :convert_options => { :all => '-strip -colorspace RGB'}
has_attached_file :motto_logo, :styles => { :standard => "300x110" }, :convert_options => { :all => '-strip -colorspace RGB'}
attr_accessor :_destroy_site_logo, :_destroy_motto_logo
attr_accessor :_destroy_site_logo, :_destroy_motto_logo
validates :contact_email, email_format: true, allow_blank: true
validates_attachment_size :site_logo, :less_than => 1.megabyte, :message => "doit faire moins de 1 Mo", :if => Proc.new { |file| !file.site_logo_file_name.blank? }
do_not_validate_attachment_file_type :site_logo
validates_attachment_size :motto_logo, :less_than => 1.megabyte, :message => "doit faire moins de 1 Mo", :if => Proc.new { |file| !file.site_logo_file_name.blank? }
do_not_validate_attachment_file_type :motto_logo
validates_attachment_size :site_logo, :less_than => 1.megabyte, :message => "doit faire moins de 1 Mo", :if => Proc.new { |file| !file.site_logo_file_name.blank? }
do_not_validate_attachment_file_type :site_logo
validates_attachment_size :motto_logo, :less_than => 1.megabyte, :message => "doit faire moins de 1 Mo", :if => Proc.new { |file| !file.site_logo_file_name.blank? }
do_not_validate_attachment_file_type :motto_logo
end
......@@ -21,7 +21,7 @@
# along with OLIGAA. If not, see <http://www.gnu.org/licenses/>.
#
module URLEncoding
private
private
def my_url_encode(string)
string.gsub(/[éèê]/,'e').gsub(/à/,'a').gsub(/[ïî]/,'i').gsub(/[ùû]/,'u').gsub(/[ôö]/,'o').gsub(/[^\sa-zA-Z0-9\+]/, '').gsub(/\s/, '_')
......
......@@ -21,13 +21,13 @@
# along with OLIGAA. If not, see <http://www.gnu.org/licenses/>.
#
FactoryGirl.define do
factory :activity do
title {"Activité #{Faker::Lorem.unique.word}"}
presentation { |a| "Présentation de #{a.title}"}
description { |a| "Description de #{a.title}"}
factory :activity do
title {"Activité #{Faker::Lorem.unique.word}"}
presentation { |a| "Présentation de #{a.title}"}
description { |a| "Description de #{a.title}"}
factory :activity_with_poster do
poster { fixture_file_upload(sample_image_path, 'image/png') }
end
end
factory :activity_with_poster do
poster { fixture_file_upload(sample_image_path, 'image/png') }
end
end
end
......@@ -21,8 +21,8 @@
# along with OLIGAA. If not, see <http://www.gnu.org/licenses/>.
#
FactoryGirl.define do
factory :activity_category do
title {"Catégorie d activité #{Faker::Lorem.unique.word}"}
description { |cat| "Description de #{cat.title}" }
end
factory :activity_category do
title {"Catégorie d activité #{Faker::Lorem.unique.word}"}
description { |cat| "Description de #{cat.title}" }
end
end
......@@ -23,9 +23,9 @@
include ActionDispatch::TestProcess
FactoryGirl.define do
factory :attached_file do
name {"Pièce jointe #{Faker::Lorem.unique.word}"}
description { |a| "Description de #{a.name}" }
file { fixture_file_upload(sample_text_path, 'text/plain') }
end
factory :attached_file do
name {"Pièce jointe #{Faker::Lorem.unique.word}"}
description { |a| "Description de #{a.name}" }
file { fixture_file_upload(sample_text_path, 'text/plain') }
end
end
......@@ -21,7 +21,7 @@
# along with OLIGAA. If not, see <http://www.gnu.org/licenses/>.
#
FactoryGirl.define do
factory :contact_type do
title {"Type de contact #{Faker::Lorem.unique.word}"}
end
factory :contact_type do
title {"Type de contact #{Faker::Lorem.unique.word}"}
end
end
......@@ -21,11 +21,11 @@
# along with OLIGAA. If not, see <http://www.gnu.org/licenses/>.
#
FactoryGirl.define do
factory :email do
sender "sender@example.com"
recipients "recipient1@example.com, recipient2@example.com"
other_recipients "others@example.com"
member
novel
end
factory :email do
sender "sender@example.com"
recipients "recipient1@example.com, recipient2@example.com"
other_recipients "others@example.com"
member
novel
end
end
......@@ -21,10 +21,10 @@
# along with OLIGAA. If not, see <http://www.gnu.org/licenses/>.
#
FactoryGirl.define do
factory :event_type do
title {"Type événement #{Faker::Lorem.unique.word}"}
description { |et| "Description de #{et.title}" }
color "#aabbcc"
should_have_gcal false
end
factory :event_type do
title {"Type événement #{Faker::Lorem.unique.word}"}
description { |et| "Description de #{et.title}" }
color "#aabbcc"
should_have_gcal false
end
end
......@@ -21,10 +21,10 @@
# along with OLIGAA. If not, see <http://www.gnu.org/licenses/>.
#
FactoryGirl.define do
factory :event do
title {"Evénément #{Faker::Lorem.unique.word}"}
description { |e| "Description de #{e.title}" }
location { |e| "Lieu de #{e.title}"}
price "Gratuit"
end
factory :event do
title {"Evénément #{Faker::Lorem.unique.word}"}
description { |e| "Description de #{e.title}" }
location { |e| "Lieu de #{e.title}"}
price "Gratuit"
end
end
......@@ -23,9 +23,9 @@
include ActionDispatch::TestProcess
FactoryGirl.define do
factory :image do
title {"Image #{Faker::Lorem.unique.word}"}
description { |i| "Description de #{i.title}" }
img_file { fixture_file_upload(sample_image_path, 'image/png') }
end
factory :image do
title {"Image #{Faker::Lorem.unique.word}"}
description { |i| "Description de #{i.title}" }
img_file { fixture_file_upload(sample_image_path, 'image/png') }
end
end
......@@ -23,8 +23,8 @@
include ActionDispatch::TestProcess
FactoryGirl.define do
factory :logo do
img { fixture_file_upload(sample_image_path, 'image/png') }
displayed false
end
factory :logo do
img { fixture_file_upload(sample_image_path, 'image/png') }
displayed false
end
end
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment