Need management from admin panel + customer mailing + admin mailing
This commit is contained in:
parent
a867e95951
commit
388d8d5cb6
4
Gemfile
4
Gemfile
@ -42,6 +42,7 @@ group :development, :test do
|
||||
gem 'web-console', '~> 2.0'
|
||||
|
||||
gem 'spring'
|
||||
|
||||
end
|
||||
|
||||
|
||||
@ -60,7 +61,6 @@ gem 'acts_as_commentable'
|
||||
|
||||
gem 'gravatar_image_tag'
|
||||
|
||||
|
||||
gem 'wicked_pdf'
|
||||
|
||||
gem 'wkhtmltopdf-binary'
|
||||
@ -68,3 +68,5 @@ gem 'wkhtmltopdf-binary'
|
||||
gem "geocoder"
|
||||
|
||||
gem "paranoia", "~> 2.0"
|
||||
|
||||
gem 'workflow', '~> 1.2.0'
|
||||
|
@ -215,6 +215,7 @@ GEM
|
||||
wicked_pdf (0.11.0)
|
||||
rails
|
||||
wkhtmltopdf-binary (0.9.9.3)
|
||||
workflow (1.2.0)
|
||||
|
||||
PLATFORMS
|
||||
ruby
|
||||
@ -251,6 +252,7 @@ DEPENDENCIES
|
||||
web-console (~> 2.0)
|
||||
wicked_pdf
|
||||
wkhtmltopdf-binary
|
||||
workflow (~> 1.2.0)
|
||||
|
||||
BUNDLED WITH
|
||||
1.10.6
|
||||
|
@ -42,6 +42,13 @@
|
||||
|
||||
}
|
||||
|
||||
.admin_table{
|
||||
td, th{
|
||||
|
||||
vertical-align:middle !important;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#admin_nav{
|
||||
border-radius:0px;
|
||||
|
@ -137,11 +137,11 @@ position:relative;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
.public-table{
|
||||
td, th{
|
||||
vertical-align:middle !important;
|
||||
}
|
||||
}
|
||||
|
||||
.bottom{
|
||||
background:#323232;
|
||||
@ -648,4 +648,3 @@ height: 100%;
|
||||
height:200px;
|
||||
|
||||
}
|
||||
|
||||
|
56
app/controllers/admin/needs_controller.rb
Normal file
56
app/controllers/admin/needs_controller.rb
Normal file
@ -0,0 +1,56 @@
|
||||
class Admin::NeedsController < ApplicationController
|
||||
layout "admin"
|
||||
|
||||
def index
|
||||
@needs_to_validate = Need.where(state: 'created').order(created_at: :desc)
|
||||
end
|
||||
|
||||
def edit
|
||||
@need = Need.find(params[:id])
|
||||
end
|
||||
|
||||
def update
|
||||
@need = Need.find(params[:id])
|
||||
if @need.update_attributes(need_params)
|
||||
flash[:notice] = "Besoin sauvegardé avec succès."
|
||||
redirect_to admin_needs_path
|
||||
else
|
||||
render :action => "edit"
|
||||
end
|
||||
end
|
||||
|
||||
def destroy
|
||||
@need = Need.find(params[:id])
|
||||
if(@need.destroy)
|
||||
flash[:notice] = "Besoin supprimé avec succès."
|
||||
end
|
||||
redirect_to admin_needs_path
|
||||
end
|
||||
|
||||
def validate
|
||||
@need = Need.find(params[:id])
|
||||
if @need.validate!
|
||||
flash[:notice] = "Besoin validé avec succès"
|
||||
CustomerMailer.validate_need(@need).deliver
|
||||
else
|
||||
flash[:error] = "L'état actuel de ce besoin ne permet sa validation"
|
||||
end
|
||||
redirect_to admin_needs_path
|
||||
end
|
||||
|
||||
def refuse
|
||||
@need = Need.find(params[:id])
|
||||
if @need.refuse!
|
||||
flash[:notice] = "Besoin refusé avec succès"
|
||||
CustomerMailer.refuse_need(@need).deliver
|
||||
else
|
||||
flash[:error] = "L'état actuel de ce besoin ne permet son refus"
|
||||
end
|
||||
redirect_to admin_needs_path
|
||||
end
|
||||
|
||||
def need_params
|
||||
params.require(:need).permit(:title, :description)
|
||||
end
|
||||
|
||||
end
|
@ -4,7 +4,6 @@ class ApplicationController < ActionController::Base
|
||||
protect_from_forgery with: :exception
|
||||
|
||||
|
||||
|
||||
def auth_customer
|
||||
|
||||
session[:devise_id] = params[:d] if params[:d]
|
||||
@ -72,4 +71,3 @@ class ApplicationController < ActionController::Base
|
||||
helper_method :current_admin, :current_customer
|
||||
|
||||
end
|
||||
|
||||
|
@ -5,7 +5,9 @@ class Public::MyAccountController < ApplicationController
|
||||
before_filter :auth_customer
|
||||
|
||||
def index
|
||||
@needs = Kaminari.paginate_array(current_customer.needs).page(params[:page]).per(2)
|
||||
@needs = Kaminari.paginate_array(current_customer.needs.order(created_at: :desc))
|
||||
.page(params[:page])
|
||||
.per(5)
|
||||
|
||||
end
|
||||
|
||||
|
@ -35,6 +35,12 @@ class Public::NeedsController < ApplicationController
|
||||
@need.author = current_customer
|
||||
if @need.save
|
||||
flash[:notice] = "Votre besoin à été créé avec succès."
|
||||
|
||||
# Find all admins with emails
|
||||
admins = Admin.where.not(email: nil)
|
||||
admins.each do |admin|
|
||||
AdminMailer.new_need(admin, @need).deliver
|
||||
end
|
||||
redirect_to public_my_account_path
|
||||
else
|
||||
render :action => "new"
|
||||
|
@ -1,6 +1,13 @@
|
||||
class AdminMailer < ActionMailer::Base
|
||||
class AdminMailer < ApplicationMailer
|
||||
layout "mail"
|
||||
|
||||
def password_reset(admin)
|
||||
@admin = admin
|
||||
mail :to => admin.email, :subject => "Reinitialisation du mot de passe.", :from => "info@nicolasbally.com"
|
||||
end
|
||||
|
||||
def new_need(admin, need)
|
||||
@need = need
|
||||
mail to: admin.email, subject: "Nouvelle proposition de besoin"
|
||||
end
|
||||
end
|
@ -1,4 +1,4 @@
|
||||
class ApplicationMailer < ActionMailer::Base
|
||||
default from: "from@example.com"
|
||||
default from: "\"Négos\" <contact@negos-pro.fr>"
|
||||
layout 'mailer'
|
||||
end
|
||||
|
@ -8,35 +8,44 @@ class CustomerMailer < ApplicationMailer
|
||||
def confirm(customer)
|
||||
@customer = customer
|
||||
|
||||
mail from: "contact@negos-pro.fr", to: customer.email, :subject => "Important : Activation de votre compte Négos"
|
||||
mail to: customer.email, :subject => "Important : Activation de votre compte Négos"
|
||||
end
|
||||
|
||||
def validate_account(customer)
|
||||
@customer = customer
|
||||
|
||||
mail from: "contact@negos-pro.fr", to: customer.email, :subject => "Important : Validation de votre compte Négos"
|
||||
mail to: customer.email, :subject => "Important : Validation de votre compte Négos"
|
||||
end
|
||||
|
||||
def confirm_ins(customer)
|
||||
@customer = customer
|
||||
|
||||
mail from: "contact@negos-pro.fr", to: customer.email, :subject => "Confirmation d’inscription"
|
||||
mail to: customer.email, :subject => "Confirmation d’inscription"
|
||||
end
|
||||
|
||||
def validate_ins(customer)
|
||||
@customer = customer
|
||||
|
||||
mail from: "contact@negos-pro.fr", to: customer.email, :subject => "Bienvenue chez NEGOS"
|
||||
mail to: customer.email, :subject => "Bienvenue chez NEGOS"
|
||||
end
|
||||
|
||||
def notify_ins(customer)
|
||||
@customer = customer
|
||||
|
||||
mail from: "contact@negos-pro.fr", to: "daniel@videlier.fr", bcc: "info@nicolasbally.com", :subject => "Nouveau compte client sur Negos"
|
||||
mail to: "daniel@videlier.fr", bcc: "info@nicolasbally.com", :subject => "Nouveau compte client sur Negos"
|
||||
end
|
||||
|
||||
def validate_need(need)
|
||||
@need = need
|
||||
@customer = need.author
|
||||
mail to: @customer.email, :subject => "Proposition de besoin validée"
|
||||
end
|
||||
|
||||
|
||||
def refuse_need(need)
|
||||
@need = need
|
||||
@customer = need.author
|
||||
mail to: @customer.email, :subject => "Proposition de besoin refusée"
|
||||
end
|
||||
|
||||
def new_user(customer)
|
||||
@customer = customer
|
||||
|
@ -1,15 +1,51 @@
|
||||
class Need < ActiveRecord::Base
|
||||
include Workflow
|
||||
|
||||
workflow_column :state
|
||||
max_paginates_per 10
|
||||
|
||||
|
||||
validates :title, :presence => true,
|
||||
:length => {:within => 4..128}
|
||||
|
||||
validates :description, :presence => true, length: {maximum: 65535}
|
||||
|
||||
belongs_to :author, class_name: 'Customer'
|
||||
|
||||
acts_as_paranoid
|
||||
|
||||
|
||||
validates :title, :presence => true, length: {within: 4..128}
|
||||
validates :description, presence: true, length: {maximum: 65535}
|
||||
belongs_to :author, class_name: 'Customer'
|
||||
|
||||
# Need's workflow lifecycle
|
||||
workflow do
|
||||
state :created do
|
||||
event :validate, :transitions_to => :verified
|
||||
event :refuse, :transitions_to => :refused
|
||||
end
|
||||
state :refused
|
||||
state :verified do
|
||||
event :negociate, :transitions_to => :negociating
|
||||
end
|
||||
state :negociating do
|
||||
event :accept, :transitions_to => :negociated
|
||||
event :reject, :transitions_to => :failed
|
||||
end
|
||||
state :negociated
|
||||
state :failed
|
||||
end
|
||||
|
||||
# Human state conversion
|
||||
def human_state
|
||||
case state
|
||||
when 'created'
|
||||
"En attente de validation"
|
||||
when 'verified'
|
||||
"Validé"
|
||||
when 'refused'
|
||||
"Refusé"
|
||||
when 'negociating'
|
||||
"En cours de negociation"
|
||||
when 'negociated'
|
||||
"Négociation effecutée"
|
||||
when 'failed'
|
||||
"Négociation échouée"
|
||||
else
|
||||
"Inconnu"
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
9
app/views/admin/needs/_form.html.haml
Normal file
9
app/views/admin/needs/_form.html.haml
Normal file
@ -0,0 +1,9 @@
|
||||
=semantic_form_for [:admin, @need] do |f|
|
||||
.content
|
||||
|
||||
|
||||
=f.inputs do
|
||||
=f.input :title, :label => "Titre : "
|
||||
=f.input :description, :label => "Description : ", :rows => 5, :input_html => {:style => "height:100px;"}
|
||||
|
||||
.actions= f.submit "Sauvegarder", :class => "btn btn-primary"
|
13
app/views/admin/needs/_need.html.haml
Normal file
13
app/views/admin/needs/_need.html.haml
Normal file
@ -0,0 +1,13 @@
|
||||
|
||||
%tr{:id => need.id}
|
||||
%td
|
||||
=need.title
|
||||
%td
|
||||
=link_to need.author.organisation, edit_admin_customer_path(need.author)
|
||||
%td
|
||||
Il y a #{time_ago_in_words( need.created_at)}
|
||||
%td.actions{:style => "width:150px;text-align:right"}
|
||||
= link_to i(:"trash-o"), [:admin, need], :data => {:confirm => 'Voulez-vous vraiment supprimer ce besoin ?'}, :method => :delete
|
||||
= link_to i(:pencil), edit_admin_need_path(need)
|
||||
= link_to i(:remove), refuse_admin_need_path(need), title: "Refuser", :data => {:confirm => 'Voulez-vous vraiment refuser ce besoin ?'}
|
||||
= link_to i(:check), validate_admin_need_path(need), title: "Valider", :data => {:confirm => 'Voulez-vous vraiment valider ce besoin ?'}
|
2
app/views/admin/needs/edit.html.haml
Normal file
2
app/views/admin/needs/edit.html.haml
Normal file
@ -0,0 +1,2 @@
|
||||
%h1 Modifier un besoin
|
||||
=render :partial => "form"
|
22
app/views/admin/needs/index.html.haml
Normal file
22
app/views/admin/needs/index.html.haml
Normal file
@ -0,0 +1,22 @@
|
||||
%h1 Gestion des besoins
|
||||
|
||||
-if @needs_to_validate.length > 0
|
||||
%h2 #{pluralize(@needs_to_validate.length, 'besoin')} à contrôler
|
||||
|
||||
|
||||
%table.table.admin_table.table-hover.table-striped
|
||||
%thead.rows_header
|
||||
|
||||
%tr
|
||||
%td
|
||||
Titre
|
||||
%td
|
||||
Émetteur
|
||||
%td
|
||||
Créé
|
||||
%td{:style => "width:100px"}
|
||||
|
||||
|
||||
%tbody.rows
|
||||
|
||||
=render @needs_to_validate
|
23
app/views/admin_mailer/new_need.html.haml
Normal file
23
app/views/admin_mailer/new_need.html.haml
Normal file
@ -0,0 +1,23 @@
|
||||
%p Bonjour,
|
||||
|
||||
%p
|
||||
Une proposition de besoin vient d'être ajoutée par le client
|
||||
%strong= @need.author.organisation.to_s
|
||||
|
||||
%p
|
||||
Vous pouvez vous rendre dans la rubrique
|
||||
=link_to "Gestion des besoins", admin_needs_path
|
||||
afin de valider ou refuser cette proposition.
|
||||
|
||||
%p
|
||||
Voici quelques informations sur le besoin
|
||||
|
||||
%p
|
||||
%strong Titre :
|
||||
%br
|
||||
=@need.title
|
||||
|
||||
%p
|
||||
%strong Description :
|
||||
%br
|
||||
=@need.description
|
5
app/views/customer_mailer/refuse_need.html.haml
Normal file
5
app/views/customer_mailer/refuse_need.html.haml
Normal file
@ -0,0 +1,5 @@
|
||||
%p Bonjour,
|
||||
|
||||
%p Nous avons le regret de vous annoncer que votre proposition de besoin "#{@need.title.to_s}" vient d'être refusée.
|
||||
|
||||
%p Celle-ci ne respectait pas la charte imposée par notre service.
|
7
app/views/customer_mailer/validate_need.html.haml
Normal file
7
app/views/customer_mailer/validate_need.html.haml
Normal file
@ -0,0 +1,7 @@
|
||||
%p Bonjour,
|
||||
|
||||
%p Nous avons le plaisir de vous annoncer que votre proposition de besoin "#{@need.title.to_s}" vient d'être validée.
|
||||
|
||||
%p Les autres utilisateurs vont dès à présent pouvoir montrer leurs intérêts pour ce nouveau besoin.
|
||||
|
||||
%p Merci !
|
@ -40,6 +40,12 @@
|
||||
|
||||
|
||||
%li= link_to "Comptes utilisateurs", admin_customers_path
|
||||
- unvalidated_need_count = Need.where(state: 'created').count
|
||||
-if unvalidated_need_count > 0
|
||||
%li= link_to content_tag(:span,unvalidated_need_count , class: 'badge') + " Gestion des besoins", admin_needs_path
|
||||
-else
|
||||
%li= link_to " Gestion des besoins", admin_needs_path
|
||||
|
||||
|
||||
|
||||
|
||||
@ -67,8 +73,3 @@
|
||||
|
||||
|
||||
#flashs= bootstrap_flash
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -48,13 +48,20 @@
|
||||
|
||||
.padding.center.white
|
||||
%h3
|
||||
Mes besoins
|
||||
Mes propositions de besoin
|
||||
%div.alert.alert-info
|
||||
%p
|
||||
Si vous avez un besoin qui ne fait pas encore parti de notre liste, vous pouvez vous-même le proposer à Négos.
|
||||
%br
|
||||
Votre proposition sera alors soumise à une courte validation par l'un de nos modérateurs.
|
||||
%br
|
||||
Vous serez informer par courriel dès l'acceptation de votre proposition.
|
||||
-if @needs.length > 0
|
||||
=render "public/needs/index", needs: @needs
|
||||
-else
|
||||
%p
|
||||
Vous n'avez pas encore créé de besoin
|
||||
=link_to "Déclarer un besoin", new_public_need_path, :class => "btn btn-primary"
|
||||
Vous n'avez pas encore proposer de besoin
|
||||
=link_to "Proposer un besoin", new_public_need_path, :class => "btn btn-primary"
|
||||
.padding.center.white
|
||||
%h3
|
||||
Ma liste de souhait
|
||||
|
@ -1,6 +1,5 @@
|
||||
%table.table.table-striped
|
||||
%table.table.public-table.table-striped
|
||||
%thead
|
||||
|
||||
%tr
|
||||
%th
|
||||
Titre du besoin
|
||||
@ -10,7 +9,6 @@
|
||||
Souhaité par
|
||||
%th{:style => "width:100px"}
|
||||
|
||||
|
||||
%tbody
|
||||
|
||||
=render @needs
|
||||
|
@ -1,10 +1,13 @@
|
||||
%tr{:id => need.id}
|
||||
-css_class = 'danger' if need.refused?
|
||||
|
||||
%tr{:id => need.id, class: css_class}
|
||||
%td
|
||||
=need.title
|
||||
%td
|
||||
|
||||
=need.human_state
|
||||
%td
|
||||
|
||||
%td.actions{:style => "width:150px;text-align:right"}
|
||||
= link_to i(:"trash-o btn btn-default"), [:public, need], :data => {:confirm => 'Voulez-vous vraiment supprimer ce besoin ?'}, method: :delete
|
||||
-if need.created? or need.refused?
|
||||
= link_to i(:"trash-o btn btn-default"), [:public, need], :data => {:confirm => 'Voulez-vous vraiment supprimer ce besoin ?'}, method: :delete
|
||||
= link_to i(:"pencil btn btn-primary"), edit_public_need_path(need)
|
||||
|
@ -39,8 +39,10 @@ Rails.application.configure do
|
||||
# Raises error for missing translations
|
||||
# config.action_view.raise_on_missing_translations = true
|
||||
|
||||
config.action_mailer.default_url_options = { :host => 'localhost:3000' }
|
||||
config.action_mailer.delivery_method = :file
|
||||
config.action_mailer.delivery_method = :smtp
|
||||
config.action_mailer.smtp_settings = { address: "localhost", port: 1025 }
|
||||
config.action_mailer.default_url_options = { host: 'rails-144740.nitrousapp.com', port: 3000}
|
||||
|
||||
|
||||
HOSTNAME="localhost:3000"
|
||||
end
|
||||
|
@ -235,12 +235,16 @@ Rails.application.routes.draw do
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
resources :needs do
|
||||
member do
|
||||
get :validate
|
||||
get :refuse
|
||||
end
|
||||
end
|
||||
resources :customers do
|
||||
member do
|
||||
get :validate
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
resources :categories do
|
||||
|
5
db/migrate/20151201090113_add_state_field_to_needs.rb
Normal file
5
db/migrate/20151201090113_add_state_field_to_needs.rb
Normal file
@ -0,0 +1,5 @@
|
||||
class AddStateFieldToNeeds < ActiveRecord::Migration
|
||||
def change
|
||||
add_column :needs, :state, :string
|
||||
end
|
||||
end
|
@ -11,7 +11,7 @@
|
||||
#
|
||||
# It's strongly recommended that you check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema.define(version: 20151130173626) do
|
||||
ActiveRecord::Schema.define(version: 20151201090113) do
|
||||
|
||||
create_table "admins", force: :cascade do |t|
|
||||
t.string "name", limit: 255
|
||||
@ -389,6 +389,7 @@ ActiveRecord::Schema.define(version: 20151130173626) do
|
||||
t.datetime "updated_at", null: false
|
||||
t.integer "author_id", limit: 4
|
||||
t.datetime "deleted_at"
|
||||
t.string "state", limit: 255
|
||||
end
|
||||
|
||||
add_index "needs", ["author_id"], name: "index_needs_on_author_id", using: :btree
|
||||
|
Loading…
x
Reference in New Issue
Block a user