This commit is contained in:
Marlburrow 2015-12-11 00:28:58 +01:00
commit 934cde8dad
23 changed files with 442 additions and 80 deletions

View File

@ -36,20 +36,31 @@
.customer_table{
td, th{
vertical-align:middle !important;
}
}
.admin_table{
.admin-table{
td, th{
vertical-align:middle !important;
}
}
}
.table tbody tr.success td {
background-color: #dff0d8 !important;
}
.table tbody tr.danger td {
background-color: #f2dede !important;
}
.table tbody tr.info td {
background-color: #d9edf7 !important;
}
.table tbody tr.warning td {
background-color: lightgoldenrodyellow !important;
}
#admin_nav{
border-radius:0px;
@ -709,7 +720,7 @@ margin-top:0;
.table-striped tr:nth-child(odd) td, .table-striped tr:nth-child(odd) th{
background:rgba(235,244,250,1) !important;
background:rgba(235,244,250,1) !important;
}

View File

@ -15,6 +15,38 @@
.info{
color:rgb(163, 159, 159);
}
.state{
position:absolute;
top:0px;
right:0px;
color:white;
padding:4px;
padding-left:8px;
padding-right:8px;
}
.state-success{
background-color:#5cb85c;
}
.state-danger{
background-color:#d9534f;
}
.state-info{
background-color:#428bca;
}
.state-warning{
background-color:#f0ad4e;
}
.offer{
display:block;
background: #eeeded;
padding:10px;
margin-bottom:5px;
.price{
font-size:25px;
font-weight:bold;
}
}
p.description{
margin-bottom:30px;
@ -23,7 +55,10 @@
.message-item{
background: #eeeded;
}
.content{
position:relative;
padding-bottom:50px;
}
.counters{
position:absolute;
left:0px;
@ -55,6 +90,29 @@
color:rgb(163, 159, 159);
}
.state{
position:absolute;
top:0px;
right:0px;
color:white;
padding:4px;
padding-left:8px;
padding-right:8px;
}
.state-success{
background-color:#5cb85c;
}
.state-danger{
background-color:#d9534f;
}
.state-info{
background-color:#428bca;
}
.state-warning{
background-color:#f0ad4e;
}
.counters{
position:absolute;
left:0px;
@ -85,7 +143,8 @@
}
margin-bottom:50px;
margin-bottom:30px;
h4{
margin-top:0px;
margin-bottom:0px;

View File

@ -55,8 +55,8 @@ class Admin::NeedsController < ApplicationController
"Les plus récents" => 'created-desc',
"Les plus populaires" => 'wishes-desc',
"Les plus commentés" => 'comments-desc',
"Alphabétique (de A à Z)" => 'alpha-asc',
"Alphabétique (de Z à A)" => 'alpha-desc'
"Titre (de A à Z)" => 'alpha-asc',
"Titre (de Z à A)" => 'alpha-desc'
}
end
@ -69,7 +69,7 @@ class Admin::NeedsController < ApplicationController
def create
@need = Need.new(need_params)
if @need.update_attributes(need_params)
if @need.save
flash[:notice] = "Besoin créé avec succès."
@need.validate!
redirect_to admin_needs_path
@ -144,12 +144,17 @@ class Admin::NeedsController < ApplicationController
def accept
@need = Need.find(params[:id])
if @need.reject!
flash[:notice] = "Le besoin est maintenant négocié"
if @need.offers.length < 1
flash[:error] = "Vous devez créer au moins une offre avant de passer ce besoin en négocié"
else
flash[:error] = "L'état actuel de ce besoin ne permet pas cette action"
if @need.accept!
flash[:notice] = "Le besoin est maintenant négocié"
else
flash[:error] = "L'état actuel de ce besoin ne permet pas cette action"
end
end
redirect_to new_admin_need_offer_path(@need)
redirect_to admin_needs_path
end
private

View File

@ -4,6 +4,55 @@ class Admin::OffersController < ApplicationController
def index
# filters default value
params[:o] ||= 'created-desc'
params[:r] ||= 10
if params[:need_id]
@need = Need.find(params[:need_id])
@offers = @need.offers
else
@offers = Offer.all
end
if(params[:q] and params[:q] != '')
@offers = @offers.joins(:need).where("needs.title like ? or offers.supplier like ?" ,"%#{params[:q]}%","%#{params[:q]}%")
end
case params[:o]
when 'created-asc'
@offers = @offers.order(created_at: :asc)
when 'created-desc'
@offers = @offers.order(created_at: :desc)
when 'alpha-asc'
@offers = @offers.order(supplier: :asc)
when 'alpha-desc'
@offers = @offers.order(supplier: :desc)
when 'price-asc'
@offers = @offers.order(price: :asc)
when 'price-desc'
@offers = @offers.order(price: :desc)
when 'need-alpha-asc'
@offers = @offers.joins(:need).order('needs.title asc')
when 'need-alpha-desc'
@offers = @offers.joins(:need).order('needs.title desc')
end
@orders = {
"Les plus récentes" => 'alpha-asc',
"Fournisseurs (de A à Z)" => 'alpha-asc',
"Fournisseurs (de Z à A)" => 'alpha-desc',
"Besoin (de A à Z)" => 'need-alpha-asc',
"Besoin (de Z à A)" => 'need-alpha-desc',
"Prix négociés croissants" => 'price-asc',
"Prix négociés décroissants" => 'price-desc'
}
@offers = @offers.page(params[:page]).per(params[:r])
end
def new
@ -12,19 +61,58 @@ class Admin::OffersController < ApplicationController
end
def create
@need = Need.find(params[:need_id])
@offer = Offer.new(offer_params)
if @offer.save
@need.offers << @offer
flash[:notice] = "Offre créée avec succès."
@offer.validate!
redirect_to admin_need_offers_path(@need)
else
render :action => "new"
end
end
def edit
@offer = Offer.find(params[:id])
if params[:need_id]
@need = Need.find(params[:need_id])
end
end
def update
@offer = Offer.find(params[:id])
if @offer.update_attributes(offer_params)
flash[:notice] = "Offre modifiée avec succès."
if params[:need_id]
@need = Need.find(params[:need_id])
redirect_to admin_need_offers_path(@need)
else
redirect_to admin_offers_path
end
else
render :action => "edit"
end
end
def destroy
@offer = Offer.find(params[:id])
if(@offer.destroy)
flash[:notice] = "Offre supprimée avec succès."
else
flash[:error] = "Impossible de supprimer cette offre"
end
if params[:need_id]
@need = Need.find(params[:need_id])
redirect_to admin_need_offers_path(@need)
else
redirect_to admin_offers_path
end
end
@ -32,8 +120,8 @@ class Admin::OffersController < ApplicationController
private
def order_params
params.require(:order).permit(:title, :description, :category_id, :author_id)
def offer_params
params.require(:offer).permit(:supplier, :price, :fee_percentage)
end
end

View File

@ -26,6 +26,10 @@ class Public::NeedsController < ApplicationController
@needs = @needs.where(category_id: ids)
end
if(params[:s] and params[:s] != '')
@needs = @needs.where(state: params[:s])
end
# Include order in the query
case params[:o]
when 'alpha-asc'
@ -100,7 +104,7 @@ class Public::NeedsController < ApplicationController
if @need.save
flash[:notice] = "Votre besoin à été créé avec succès."
redirect_to public_my_account_path
else
render :action => "new"

View File

@ -29,7 +29,7 @@ class Need < ActiveRecord::Base
has_many :wishes, dependent: :destroy
has_many :customers, -> { uniq }, through: :wishes
has_many :messages, dependent: :destroy
has_many :offers
has_many :offers, dependent: :destroy
belongs_to :category, class_name: "NeedCategory"
validates :title, :presence => true, length: {within: 4..128}
@ -106,13 +106,13 @@ class Need < ActiveRecord::Base
when 'created'
"En attente de validation"
when 'verified'
"Validé"
"En sondage"
when 'refused'
"Refusé"
when 'negociating'
"En négociation"
when 'negociated'
"Négociation effecutée"
"Négociation terminée"
when 'failed'
"Négociation échouée"
else

View File

@ -1,4 +1,16 @@
class Offer < ActiveRecord::Base
acts_as_paranoid
belongs_to :need
validates :supplier, :presence => true, length: {within: 1..128}
validates :price,
:presence => true,
numericality: {greater_than_or_equal_to: 0}
validates :fee_percentage,
:presence => true,
numericality: {:greater_than_or_equal_to => 0, :less_than_or_equal_to => 100}
end

View File

@ -1,7 +1,7 @@
-css_class = "warning" if need.negociating?
-css_class = "error" if need.failed?
-css_class = "danger" if need.failed?
-css_class = "success" if need.negociated?
%tr{:id => need.id}
%tr{:id => need.id, class: css_class}
%td
=link_to need.title, edit_admin_need_path(need)
%td
@ -19,8 +19,8 @@
&nbsp;&nbsp;
=link_to i(:"comment-o") + " " + need.messages.length.to_s, admin_need_messages_path(need)
%td{style: 'text-align:center' }
%td{class: css_class}
=link_to i(:"gift") + " " + need.offers.length.to_s, admin_need_offers_path(need)
%td
=need.human_state
%td.actions{:style => "width:150px;text-align:right"}
-if(need.verified?)

View File

@ -11,7 +11,7 @@
Si pour une raison ou pour une autre le besoin ne respecte pas la charte, cliquez sur le bouton <i class="fa fa-remove"></i>
%table.table.admin_table.table-hover.table-striped
%table.table.admin-table.table-hover.table-striped
%thead.rows_header
%tr
@ -31,6 +31,7 @@
=render collection: @needs_to_validate, partial: 'need_to_validate', as: :need
%br
%h2 Liste des besoins
<<<<<<< HEAD
-if @needs.length < 1
Aucun besoin
-else
@ -79,7 +80,6 @@
= link_to "Créer un besoin", new_admin_need_path, class:"btn btn-primary"
:javascript
$('#search_o').change(function(){$('#search_form').submit()})
$('#search_r').change(function(){$('#search_form').submit()})

View File

@ -0,0 +1,9 @@
=semantic_form_for [:admin, @need, @offer] do |f|
.content
=f.inputs do
=f.input :supplier, :label => "Nom du fournisseur : "
=f.input :price, :label => "Prix négocié : "
=f.input :fee_percentage, :label => "% de frais : "
.actions= f.submit "Sauvegarder", :class => "btn btn-primary"

View File

@ -0,0 +1,17 @@
%tr{:id => offer.id}
%td
= link_to offer.need.title, edit_admin_need_path(offer.need)
%td
=offer.supplier
%td
=number_to_currency(offer.price, locale: :fr)
%td
=number_to_percentage(offer.fee_percentage, significant: true )
%td.actions{:style => "width:150px;text-align:right"}
-if @need
= link_to i(:"trash"), [:admin,@need, offer], :data => {:confirm => 'Voulez-vous vraiment supprimer cette offre ?'}, :method => :delete
= link_to i(:pencil), edit_admin_need_offer_path(@need, offer)
-else
= link_to i(:"trash"), [:admin, offer], :data => {:confirm => 'Voulez-vous vraiment supprimer cette offre ?'}, :method => :delete
= link_to i(:pencil), edit_admin_offer_path(offer)

View File

@ -0,0 +1,4 @@
%h1
Modifier une offre
=render :partial => "form"

View File

@ -0,0 +1,68 @@
-if @need
%h1
Gestion des offres pour le besoin
%strong= @need.title
%p.alert.alert-info
Seul les offres concernant le besoin
%strong= @need.title
sont affichées sur cette page.
%br
Pour voir toutes les offres, aller dans l'onglet
%strong Gestion des offres
depuis la barre de navigation
-else
%h1
Gestion des offres
%p.alert.alert-info
Cette page affiche toutes les offres existantes.
%br
Pour créer une offre, il faut d'abord choisir un besoin. Pour cela, passer par l'onglet
%strong Gestion des besoins
puis cliquer sur le bouton
%strong= i(:gift)
en face du besoin de votre choix.
-if @offers.length < 1
Aucune offre actuellement
-else
.row
.col-md-2
= semantic_form_for :search, :html => {id: :search_form, :method => :get } do |f|
= f.inputs do
= f.inputs do
=f.input :q, :as => :search, label: "Recherche", input_html: {value: params[:q], :name => 'q' }, placeholder: "Besoin ou fournisseur"
.clear
= f.input :o, as: :order, selected: params[:o], input_html: {:name => 'o' }, label: "Ordre d'affichage", :include_blank => false , :as => :select, :collection => @orders
.clear
= f.input :r, as: :result, selected: params[:r], input_html: {:name => 'r' }, label: 'Résultats par page', :include_blank => false , :as => :select, :collection => [10,20,50,100]
.clear
.col-md-10
%table.table.admin-table.table-hover.table-striped
%thead.rows_header
%tr
%th
Besoin
%th
Fournisseur
%th
Prix négocié
%th
\% de frais
%th{:style => "width:100px"}
&nbsp;
%tbody.rows
=render @offers
.pagination.pull-right= paginate @offers
%br
%br
-if @need
=link_to "Ajouter une offre", new_admin_need_offer_path(@need),class:"btn btn-primary"
:javascript
$('#search_o').change(function(){$('#search_form').submit()})
$('#search_r').change(function(){$('#search_form').submit()})

View File

@ -0,0 +1,4 @@
%h1
Créer une offre pour le besoin
%strong= @need.title
=render :partial => "form"

View File

@ -47,6 +47,7 @@
%li= link_to " Gestion des besoins", admin_needs_path
%li= link_to " Gestion des catégories", admin_need_categories_path
%li= link_to " Gestion des offres", admin_offers_path

View File

@ -1,6 +1,6 @@
-css_class = 'warning' if need.created?
-css_class = 'danger' if need.refused?
-css_class = 'success' if need.verified?
-css_class = 'success' if need.verified? or need.negociated? or need.negociating? or need.failed?
-state = 'Validé' if need.verified? or need.negociated? or need.negociating? or need.failed?
-state = 'En attente de validation' if need.created?
-state = 'Refusée' if need.refused?

View File

@ -4,15 +4,36 @@
%h4
=link_to need.title.upcase, public_need_path(need)
-if need.author
%p.info=i(:"clock-o") + " Ajouté il y a #{time_ago_in_words(need.created_at)} par #{need.author.anonyme_nick}"
-else
%p.info=i(:"clock-o") + " Ajouté il y a #{time_ago_in_words(need.created_at)}"
-# -if need.author
-# %p.info=i(:"clock-o") + " Ajouté il y a #{time_ago_in_words(need.created_at)} par #{need.author.anonyme_nick}"
-# -else
-# %p.info=i(:"clock-o") + " Ajouté il y a #{time_ago_in_words(need.created_at)}"
-if need.category
.top-left-info
.top-left-info
-if need.category
=i(:"tag") + " " + need.category_path
-else
Non catégorisé
-if need.verified?
%span.state.state-info.pull-right
=need.human_state
-elsif need.negociating?
%span.state.state-warning.pull-right
=need.human_state
-elsif need.failed?
%span.state.state-danger.pull-right
=need.human_state
-elsif need.negociated?
%span.state.state-success.pull-right
-offers = need.offers.order(price: :asc)
-if offers.size > 1
Négocié à partir de
%strong="#{number_to_currency(offers.first.price, locale: :fr)}"
-elsif offers.size == 1
Négocié à
%strong="#{number_to_currency(offers.first.price, locale: :fr)}"
-else
Négocié
@ -24,9 +45,14 @@
.item=i(:"hand-paper-o") + " " + need.wishes.length.to_s
.item=i(:"comment-o") + " " + need.messages.length.to_s
-if(need.customers.include?(current_customer))
=link_to i(:"check") + " Intéressé", wish_public_need_path(need) , :class => "btn btn-success pull-right"
-else
=link_to i(:"hand-paper-o") + " Ça m'intéresse !", wish_public_need_path(need) , :class => "btn btn-primary pull-right"
.clear
-if(need.customers.include?(current_customer))
-if(need.verified? or need.negociating?)
=link_to i(:"check") + " Intéressé", wish_public_need_path(need) , class: "btn btn-success pull-right"
-elsif(need.negociated?)
=link_to "J'en profite!", public_need_path(need), class: "btn btn-success pull-right"
-else
=link_to i(:"hand-paper-o") + " Ça m'intéresse !", wish_public_need_path(need) , class: "btn btn-primary pull-right"
.clear

View File

@ -25,8 +25,11 @@
= f.inputs do
= f.input :c, as: :category, selected: params[:c], input_html: {:name => 'c' }, label: 'Filtrer par catégorie', :include_blank => "Toute catégorie" , :as => :select, :collection => @tree.map{|c| [(c.level > 0 ? ('&nbsp;&nbsp;&nbsp;' * (c.level - 1)) + "|- ": "").html_safe + c.name, c.id]}
.clear
= f.inputs do
= f.input :s, as: :state, selected: params[:s], input_html: {:name => 's' }, label: 'Filter par état', :include_blank => "Tous les états" , :as => :select, :collection => [["En sondage","verified"],["En négociation","negociating"],["Négocié","negociated"],["Négociation échouée","failed"]]
.clear
:javascript
$('#search_o').change(function(){$('#search_form').submit()})
$('#search_r').change(function(){$('#search_form').submit()})
$('#search_c').change(function(){$('#search_form').submit()})
$('#search_s').change(function(){$('#search_form').submit()})

View File

@ -1,43 +1,85 @@
.center.white
.show-need
%h1= @need.title.upcase
.center.white.show-need
.top-left-info
-if @need.verified?
%span.state.state-info.pull-right
=@need.human_state
-elsif @need.negociating?
%span.state.state-warning.pull-right
=@need.human_state
-elsif @need.failed?
%span.state.state-danger.pull-right
=@need.human_state
-elsif @need.negociated?
%span.state.state-success.pull-right
-offers = @need.offers.order(price: :asc)
-if offers.size > 1
Négocié à partir de
%strong="#{number_to_currency(offers.first.price, locale: :fr)}"
-elsif offers.size == 1
Négocié à
%strong="#{number_to_currency(offers.first.price, locale: :fr)}"
-else
Négocié
.content
%h1= @need.title.upcase
-if @need.author
%p.info=i(:"clock-o") + " Ajouté il y a #{time_ago_in_words(@need.created_at)} par #{@need.author.anonyme_nick}"
-else
%p.info=i(:"clock-o") + " Ajouté il y a #{time_ago_in_words(@need.created_at)}"
%p.info=i(:"tag") + " " + @need.category_path
%p.description= @need.description
.clear
.counters
-if(@need.wishes.length > 0)
.item=i(:"hand-paper-o") + " " + " #{pluralize(@need.wishes.length, 'Organisation')} #{"intéressé".pluralize(@need.wishes.length)} par ce besoin"
-if @need.author
%p.info
=i(:"clock-o") + " Proposé par "
%strong=@need.author.anonyme_nick
="il y a #{time_ago_in_words(@need.created_at)}"
-else
.item=i(:"hand-paper-o") + " Aucune organisation n'est intéressé par ce besoin"
%p.info=i(:"clock-o") + " Ajouté il y a #{time_ago_in_words(@need.created_at)}"
-if @need.category
%p.info=i(:"tag") + " " + @need.category_path
-else
%p.info=i(:"tag") + " Non catégorisé"
%p.description= @need.description
.clear
.counters
-if(@need.wishes.length > 0)
.item=i(:"hand-paper-o") + " " + " #{pluralize(@need.wishes.length, 'utilisateur')} #{"intéressé".pluralize(@need.wishes.length)} par ce besoin"
-else
.item=i(:"hand-paper-o") + " Aucun utilisateur n'est intéressé par ce besoin"
-if @need.verified? or @need.negociating?
-if(@need.customers.include?(current_customer))
=link_to i(:"check") + " Intéressé", wish_public_need_path(@need) , :class => "btn btn-square btn-lg btn-success pull-right"
-else
=link_to i(:"hand-paper-o") + " Ça m'intéresse !", wish_public_need_path(@need) , :class => "btn btn-square btn-lg btn-primary pull-right"
-elsif @need.negociated?
-if @need.offers.length > 0
%h2 Les offres négociées
-@need.offers.each do |offer|
.offer
.supplier
Négocié avec le fournisseur
%strong= offer.supplier
.price
=number_to_currency(offer.price, locale: :fr)
=link_to "Acheter", "", class: "btn btn-success pull-right"
-if(@need.customers.include?(current_customer))
=link_to i(:"check") + " Intéressé", wish_public_need_path(@need) , :class => "btn btn-square btn-lg btn-success pull-right"
-else
=link_to i(:"hand-paper-o") + " Ça m'intéresse !", wish_public_need_path(@need) , :class => "btn btn-square btn-lg btn-primary pull-right"
.clear
%hr
= semantic_form_for [:public, @need, @comment ], :html => {id: :message_form, :method => :post } do |f|
%h4 Poster un commentaire
= f.inputs do
= f.input :content, as: :text, label: false, rows: 5, :input_html => {:style => "height:100px;"}
%hr
= semantic_form_for [:public, @need, @comment ], :html => {id: :message_form, :method => :post } do |f|
%h4 Poster un commentaire
= f.inputs do
= f.input :content, as: :text, label: false, rows: 5, :input_html => {:style => "height:100px;"}
=f.submit "Envoyer", :class => "btn btn-square btn-primary pull-right"
.clear
=f.submit "Envoyer", :class => "btn btn-square btn-primary pull-right"
.clear
%h4= i(:"comment-o") + " #{pluralize(@need.messages.count, 'Commentaire')} pour ce besoin"
%h4= i(:"comment-o") + " #{pluralize(@need.messages.count, 'Commentaire')} pour ce besoin"
=render collection: @comments, partial: 'message'
=render collection: @comments, partial: 'message'
.pagination= paginate @comments
.pagination= paginate @comments

View File

@ -253,6 +253,7 @@ Rails.application.routes.draw do
get :reject
end
end
resources :offers
resources :customers do
member do

View File

@ -5,7 +5,7 @@ class CreateOffers < ActiveRecord::Migration
t.timestamps null: false
t.float :price
t.float :fee_percentage
t.references :needs, index: true
t.references :need, index: true
t.string :supplier
end
end

View File

@ -0,0 +1,6 @@
class AddDeletetedAtToOffers < ActiveRecord::Migration
def change
add_column :offers, :deleted_at, :datetime
add_index :offers, :deleted_at
end
end

View File

@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20151209125427) do
ActiveRecord::Schema.define(version: 20151210134428) do
create_table "admins", force: :cascade do |t|
t.string "name", limit: 255
@ -440,11 +440,13 @@ ActiveRecord::Schema.define(version: 20151209125427) do
t.datetime "updated_at", null: false
t.float "price", limit: 24
t.float "fee_percentage", limit: 24
t.integer "needs_id", limit: 4
t.integer "need_id", limit: 4
t.string "supplier", limit: 255
t.datetime "deleted_at"
end
add_index "offers", ["needs_id"], name: "index_offers_on_needs_id", using: :btree
add_index "offers", ["deleted_at"], name: "index_offers_on_deleted_at", using: :btree
add_index "offers", ["need_id"], name: "index_offers_on_need_id", using: :btree
create_table "pages", force: :cascade do |t|
t.text "title", limit: 65535