admin can upload a logo for his procedure

This commit is contained in:
Xavier J 2015-12-10 17:13:39 +01:00
parent 8755ce2ab1
commit d49e9fe75a
13 changed files with 119 additions and 26 deletions

View file

@ -19,7 +19,7 @@ h5 span {
img { img {
max-width: 150px; max-width: 150px;
max-height: 70px; max-height: 60px;
} }
} }

View file

@ -47,6 +47,7 @@ class Admin::ProceduresController < AdminController
flash.now.alert = @procedure.errors.full_messages.join('<br />').html_safe flash.now.alert = @procedure.errors.full_messages.join('<br />').html_safe
return render 'edit' return render 'edit'
end end
flash.notice = 'Préocédure modifiée' flash.notice = 'Préocédure modifiée'
redirect_to admin_procedures_path redirect_to admin_procedures_path
end end
@ -66,7 +67,7 @@ class Admin::ProceduresController < AdminController
private private
def create_procedure_params def create_procedure_params
params.require(:procedure).permit(:libelle, :description, :organisation, :direction, :lien_demarche, :euro_flag, module_api_carto_attributes: [:id, :use_api_carto, :quartiers_prioritaires, :cadastre]).merge(administrateur_id: current_administrateur.id) params.require(:procedure).permit(:libelle, :description, :organisation, :direction, :lien_demarche, :euro_flag, :logo, module_api_carto_attributes: [:id, :use_api_carto, :quartiers_prioritaires, :cadastre]).merge(administrateur_id: current_administrateur.id)
end end
def create_module_api_carto_params def create_module_api_carto_params

View file

@ -4,4 +4,9 @@ class ProcedureDecorator < Draper::Decorator
def lien def lien
h.new_users_dossiers_url(procedure_id: id) h.new_users_dossiers_url(procedure_id: id)
end end
def logo_img
return 'logo-tps.png' if logo.blank?
logo
end
end end

View file

@ -8,6 +8,8 @@ class Procedure < ActiveRecord::Base
accepts_nested_attributes_for :module_api_carto accepts_nested_attributes_for :module_api_carto
belongs_to :administrateur belongs_to :administrateur
mount_uploader :logo, ProcedureLogoUploader
validates :libelle, presence: true, allow_blank: false, allow_nil: false validates :libelle, presence: true, allow_blank: false, allow_nil: false
validates :description, presence: true, allow_blank: false, allow_nil: false validates :description, presence: true, allow_blank: false, allow_nil: false

View file

@ -0,0 +1,51 @@
# encoding: utf-8
class ProcedureLogoUploader < CarrierWave::Uploader::Base
# Include RMagick or MiniMagick support:
# include CarrierWave::RMagick
# include CarrierWave::MiniMagick
# Choose what kind of storage to use for this uploader:
storage :file
# storage :fog
# Override the directory where uploaded files will be stored.
# This is a sensible default for uploaders that are meant to be mounted:
def store_dir
"uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
end
# Provide a default URL as a default if there hasn't been a file uploaded:
# def default_url
# # For Rails 3.1+ asset pipeline compatibility:
# # ActionController::Base.helpers.asset_path("fallback/" + [version_name, "default.png"].compact.join('_'))
#
# "/images/fallback/" + [version_name, "default.png"].compact.join('_')
# end
# Process files as they are uploaded:
# process :scale => [200, 300]
#
# def scale(width, height)
# # do something
# end
# Create different versions of your uploaded files:
# version :thumb do
# process :resize_to_fit => [50, 50]
# end
# Add a white list of extensions which are allowed to be uploaded.
# For images you might use something like this:
def extension_white_list
%w(jpg jpeg png)
end
# Override the filename of the uploaded files:
# Avoid using model.id or version_name here, see uploader/store.rb for details.
# def filename
# "something.jpg" if original_filename
# end
end

View file

@ -7,12 +7,21 @@
=value =value
=f.text_field key, class: 'form-control', placeholder: value =f.text_field key, class: 'form-control', placeholder: value
%h4 Drapeau européen .row
%label .col-md-6.col-lg-6
=f.check_box :euro_flag %h4 Logo de la procédure
Afficher le drapeau européen = f.file_field(:logo, accept: 'image/png, image/jpg,image/jpeg')
%div{style:'margin-top:5px'}
%i
Fichier accepté : JPG / JPEG / PNG
.col-md-6.col-lg-6
%h4 Drapeau européen
%label
=f.check_box :euro_flag
Afficher le drapeau européen
%br
%br %br
%h4 Cartographie %h4 Cartographie

View file

@ -13,7 +13,7 @@
= link_to('Pièces justificatives', admin_procedure_pieces_justificatives_path(@procedure)) = link_to('Pièces justificatives', admin_procedure_pieces_justificatives_path(@procedure))
#procedure_new.section.section-label #procedure_new.section.section-label
= form_for @procedure, url: url_for({controller: 'admin/procedures', action: :update, id: @procedure.id}) do |f| = form_for @procedure, url: url_for({controller: 'admin/procedures', action: :update, id: @procedure.id}), multipart: true do |f|
= render partial: 'informations', locals: {f: f} = render partial: 'informations', locals: {f: f}
= f.submit 'Editer', class: 'btn btn-success', style: 'float:right' = f.submit 'Editer', class: 'btn btn-success', style: 'float:right'
%br %br

View file

@ -1,6 +1,6 @@
%h2 Nouvelle procédure %h2 Nouvelle procédure
#procedure_new.section.section-label #procedure_new.section.section-label
= form_for @procedure, url: {controller: 'admin/procedures', action: :create} do |f| = form_for @procedure, url: {controller: 'admin/procedures', action: :create}, multipart: true do |f|
=render partial: 'informations', locals: {f: f} =render partial: 'informations', locals: {f: f}
=f.submit 'Valider', class: 'btn btn-info', style: 'float:right' =f.submit 'Valider', class: 'btn btn-info', style: 'float:right'

View file

@ -9,8 +9,7 @@
=image_tag('drapeau_europe.png') =image_tag('drapeau_europe.png')
#logo_procedure.flag #logo_procedure.flag
=image_tag('logo-tps.png') =image_tag( @dossier.procedure.decorate.logo_img )
%h2#titre_procedure.text-info %h2#titre_procedure.text-info
= @dossier.procedure.libelle = @dossier.procedure.libelle

View file

@ -0,0 +1,5 @@
class AddLogoToProcedure < ActiveRecord::Migration
def change
add_column :procedures, :logo, :string
end
end

View file

@ -11,7 +11,7 @@
# #
# It's strongly recommended that you check this file into your version control system. # It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20151210134135) do ActiveRecord::Schema.define(version: 20151210150958) do
# These are extensions that must be enabled in order to support this database # These are extensions that must be enabled in order to support this database
enable_extension "plpgsql" enable_extension "plpgsql"
@ -161,6 +161,7 @@ ActiveRecord::Schema.define(version: 20151210134135) do
t.integer "administrateur_id" t.integer "administrateur_id"
t.boolean "archived", default: false t.boolean "archived", default: false
t.boolean "euro_flag", default: false t.boolean "euro_flag", default: false
t.string "logo"
end end
create_table "quartier_prioritaires", force: :cascade do |t| create_table "quartier_prioritaires", force: :cascade do |t|

View file

@ -15,6 +15,8 @@ describe Procedure do
it { is_expected.to have_db_column(:organisation) } it { is_expected.to have_db_column(:organisation) }
it { is_expected.to have_db_column(:direction) } it { is_expected.to have_db_column(:direction) }
it { is_expected.to have_db_column(:test) } it { is_expected.to have_db_column(:test) }
it { is_expected.to have_db_column(:euro_flag) }
it { is_expected.to have_db_column(:logo) }
end end
describe 'validation' do describe 'validation' do

View file

@ -3,29 +3,47 @@ require 'spec_helper'
describe 'users/dossiers/new.html.haml', type: :view do describe 'users/dossiers/new.html.haml', type: :view do
let(:user) { create(:user) } let(:user) { create(:user) }
let(:euro_flag) { false } let(:euro_flag) { false }
let(:procedure) { create(:procedure, euro_flag: euro_flag) } let(:logo) { '' }
let!(:dossier) { create(:dossier, procedure: procedure, user: user,).decorate } let(:procedure) { create(:procedure, euro_flag: euro_flag, logo: logo) }
let!(:dossier) { create(:dossier, procedure: procedure, user: user).decorate }
before do
sign_in user
assign(:dossier, dossier.decorate)
render
end
subject { rendered }
it { is_expected.to have_css('#users_siret_index') }
describe 'euro flag' do describe 'euro flag' do
before do
sign_in user
assign(:dossier, dossier.decorate)
render
end
subject { rendered }
it { is_expected.to have_css('#users_siret_index') }
context 'euro flag is not present' do context 'euro flag is not present' do
it { is_expected.not_to have_css('#euro_flag.flag') } it { is_expected.not_to have_css('#euro_flag.flag') }
end end
context 'euro flag is present' do context 'euro flag is present' do
let(:euro_flag) { true } let(:euro_flag) { true }
it { is_expected.to have_css('#euro_flag.flag') } it { is_expected.to have_css('#euro_flag.flag') }
end end
end end
describe 'logo procedure' do
context 'procedure have no logo' do
it 'MPS logo is present' do
is_expected.to have_css("img[src='/assets#{asset_path('logo-tps.png')}']")
end
end
context 'procedure have logo' do
let(:logo) { fixture_file_upload('app/assets/images/logo_FC_02.png', 'image/png') }
it 'Procedure logo is present' do
p subject
is_expected.to have_css("img[src='#{procedure.logo}']")
end
end
end
end end