diff --git a/app/assets/stylesheets/admin.css.scss b/app/assets/stylesheets/admin.css.scss index 5438d6f..416dc66 100644 --- a/app/assets/stylesheets/admin.css.scss +++ b/app/assets/stylesheets/admin.css.scss @@ -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; } diff --git a/app/assets/stylesheets/public/need.scss b/app/assets/stylesheets/public/need.scss index 43fa7aa..7a2f0af 100644 --- a/app/assets/stylesheets/public/need.scss +++ b/app/assets/stylesheets/public/need.scss @@ -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; diff --git a/app/controllers/admin/needs_controller.rb b/app/controllers/admin/needs_controller.rb index 47d71d3..bc23bc6 100644 --- a/app/controllers/admin/needs_controller.rb +++ b/app/controllers/admin/needs_controller.rb @@ -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 diff --git a/app/controllers/admin/offers_controller.rb b/app/controllers/admin/offers_controller.rb index ac63498..03c9fb7 100644 --- a/app/controllers/admin/offers_controller.rb +++ b/app/controllers/admin/offers_controller.rb @@ -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 diff --git a/app/controllers/public/needs_controller.rb b/app/controllers/public/needs_controller.rb index d066dbd..a5e65ed 100644 --- a/app/controllers/public/needs_controller.rb +++ b/app/controllers/public/needs_controller.rb @@ -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" diff --git a/app/models/need.rb b/app/models/need.rb index 705c65a..f22d5a7 100644 --- a/app/models/need.rb +++ b/app/models/need.rb @@ -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 diff --git a/app/models/offer.rb b/app/models/offer.rb index a676208..d18f882 100644 --- a/app/models/offer.rb +++ b/app/models/offer.rb @@ -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 diff --git a/app/views/admin/needs/_need.html.haml b/app/views/admin/needs/_need.html.haml index d9f1cdf..3674eb5 100644 --- a/app/views/admin/needs/_need.html.haml +++ b/app/views/admin/needs/_need.html.haml @@ -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 @@    =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?) diff --git a/app/views/admin/needs/index.html.haml b/app/views/admin/needs/index.html.haml index 23d276f..01f11af 100755 --- a/app/views/admin/needs/index.html.haml +++ b/app/views/admin/needs/index.html.haml @@ -11,7 +11,7 @@ Si pour une raison ou pour une autre le besoin ne respecte pas la charte, cliquez sur le bouton - %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()}) diff --git a/app/views/admin/offers/_form.html.haml b/app/views/admin/offers/_form.html.haml new file mode 100644 index 0000000..41def45 --- /dev/null +++ b/app/views/admin/offers/_form.html.haml @@ -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" diff --git a/app/views/admin/offers/_offer.html.haml b/app/views/admin/offers/_offer.html.haml new file mode 100644 index 0000000..e136294 --- /dev/null +++ b/app/views/admin/offers/_offer.html.haml @@ -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) diff --git a/app/views/admin/offers/edit.html.haml b/app/views/admin/offers/edit.html.haml new file mode 100644 index 0000000..812d77d --- /dev/null +++ b/app/views/admin/offers/edit.html.haml @@ -0,0 +1,4 @@ +%h1 + Modifier une offre + +=render :partial => "form" diff --git a/app/views/admin/offers/index.html.haml b/app/views/admin/offers/index.html.haml index e69de29..723a7ef 100644 --- a/app/views/admin/offers/index.html.haml +++ b/app/views/admin/offers/index.html.haml @@ -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"} +   + + %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()}) diff --git a/app/views/admin/offers/new.html.haml b/app/views/admin/offers/new.html.haml index e69de29..d22684c 100644 --- a/app/views/admin/offers/new.html.haml +++ b/app/views/admin/offers/new.html.haml @@ -0,0 +1,4 @@ +%h1 + Créer une offre pour le besoin + %strong= @need.title +=render :partial => "form" diff --git a/app/views/layouts/admin.html.haml b/app/views/layouts/admin.html.haml index f1fe23d..e63d98c 100644 --- a/app/views/layouts/admin.html.haml +++ b/app/views/layouts/admin.html.haml @@ -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 diff --git a/app/views/public/needs/_need.html.haml b/app/views/public/needs/_need.html.haml index dab5a8a..5505de0 100644 --- a/app/views/public/needs/_need.html.haml +++ b/app/views/public/needs/_need.html.haml @@ -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? diff --git a/app/views/public/needs/_need_item.html.haml b/app/views/public/needs/_need_item.html.haml index dbbe475..c339c95 100644 --- a/app/views/public/needs/_need_item.html.haml +++ b/app/views/public/needs/_need_item.html.haml @@ -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 diff --git a/app/views/public/needs/index.html.haml b/app/views/public/needs/index.html.haml index 95dc1a9..f890bbe 100644 --- a/app/views/public/needs/index.html.haml +++ b/app/views/public/needs/index.html.haml @@ -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 ? ('   ' * (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()}) diff --git a/app/views/public/needs/show.html.haml b/app/views/public/needs/show.html.haml index b8082c6..df865de 100644 --- a/app/views/public/needs/show.html.haml +++ b/app/views/public/needs/show.html.haml @@ -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 diff --git a/config/routes.rb b/config/routes.rb index 08c05b9..7974439 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -253,6 +253,7 @@ Rails.application.routes.draw do get :reject end end + resources :offers resources :customers do member do diff --git a/db/migrate/20151209125427_create_offers.rb b/db/migrate/20151209125427_create_offers.rb index 0b8223a..47c5fc6 100644 --- a/db/migrate/20151209125427_create_offers.rb +++ b/db/migrate/20151209125427_create_offers.rb @@ -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 diff --git a/db/migrate/20151210134428_add_deleteted_at_to_offers.rb b/db/migrate/20151210134428_add_deleteted_at_to_offers.rb new file mode 100644 index 0000000..2bf9eca --- /dev/null +++ b/db/migrate/20151210134428_add_deleteted_at_to_offers.rb @@ -0,0 +1,6 @@ +class AddDeletetedAtToOffers < ActiveRecord::Migration + def change + add_column :offers, :deleted_at, :datetime + add_index :offers, :deleted_at + end +end diff --git a/db/schema.rb b/db/schema.rb index 8084b77..119cf00 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -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