From 6fe10f5faa695006d27737e9ef6b7caea8255874 Mon Sep 17 00:00:00 2001 From: Nicolas VARROT Date: Tue, 18 Oct 2016 17:19:45 +0200 Subject: [PATCH] Ameliorations demandees par le client --- app/assets/stylesheets/public/need.scss | 2 +- app/controllers/admin/messages_controller.rb | 26 ++++++++++++++ .../public/customers_controller.rb | 21 ++++++----- .../public/my_account_controller.rb | 3 +- app/models/customer.rb | 6 ++++ app/models/message.rb | 1 + .../admin/accepted_offers/show.html.haml | 36 +++++++++++++------ app/views/admin/customers/_form.html.haml | 32 ++++++++--------- app/views/admin/messages/_message.html.haml | 9 ++++- app/views/admin/messages/index.html.haml | 11 ++++++ .../customer_post_comment.html.haml | 18 +++++++--- .../customer_mailer/need_commented.html.haml | 20 ++++++++--- .../public/documents/_document.html.haml | 33 +++++++++++------ app/views/public/my_account/_step2.html.haml | 24 +++++++------ app/views/public/needs/_message.html.haml | 10 +++++- app/views/public/needs/show.html.haml | 2 +- .../20161017150545_add_some_extra_fields.rb | 6 ++++ .../20161018122307_add_admin_to_message.rb | 5 +++ db/schema.rb | 7 +++- 19 files changed, 198 insertions(+), 74 deletions(-) mode change 100644 => 100755 app/views/admin_mailer/customer_post_comment.html.haml mode change 100644 => 100755 app/views/customer_mailer/need_commented.html.haml create mode 100755 db/migrate/20161017150545_add_some_extra_fields.rb create mode 100755 db/migrate/20161018122307_add_admin_to_message.rb diff --git a/app/assets/stylesheets/public/need.scss b/app/assets/stylesheets/public/need.scss index 18368ec..5b60941 100755 --- a/app/assets/stylesheets/public/need.scss +++ b/app/assets/stylesheets/public/need.scss @@ -78,7 +78,7 @@ .my-account-link{ display:inline-block; color:#3C763D; - font-size:10px; + font-size:15px; float:right; position:absolute; right:10px; diff --git a/app/controllers/admin/messages_controller.rb b/app/controllers/admin/messages_controller.rb index 83a249f..086c68f 100755 --- a/app/controllers/admin/messages_controller.rb +++ b/app/controllers/admin/messages_controller.rb @@ -9,6 +9,32 @@ class Admin::MessagesController < ApplicationController end + def create + @message = Message.new + @message.admin = current_admin + @message.content = params[:message][:content] + @need = Need.find(params[:need_id]) + @message.need = @need + if @message.save + admins = Admin.where.not(email: nil) + admins.each do |admin| + AdminMailer.customer_post_comment(admin, @need, @message).deliver + end + + @need.customers.each do |customer| + CustomerMailer.need_commented(customer, @need, @message).deliver + end + + flash[:notice] = "Commentaire envoyé" + + redirect_to action: 'index' + else + flash[:error] = "Impossible de créer ce commentaire" + + redirect_to action: 'index' + end + end + def destroy @message = Message.find(params['id']) if @message.destroy diff --git a/app/controllers/public/customers_controller.rb b/app/controllers/public/customers_controller.rb index a78c24f..180b7f6 100755 --- a/app/controllers/public/customers_controller.rb +++ b/app/controllers/public/customers_controller.rb @@ -63,6 +63,7 @@ class Public::CustomersController < ApplicationController @customer = Customer.new(params.require(:customer).permit!) if @customer.save + CustomerMailer.confirm(@customer).deliver CustomerMailer.notify_ins(@customer).deliver @@ -87,6 +88,7 @@ class Public::CustomersController < ApplicationController else + render :action => "new" end end @@ -108,6 +110,13 @@ class Public::CustomersController < ApplicationController def update @customer = Customer.find(params[:id]) + @accepted_offers = @customer.accepted_offers.order(created_at: :desc).page(params[:page_offers]).per(5) + @wishes = @customer.wishes.includes(:need).page(params[:page_wishes]).per(5) + + @needs = Kaminari.paginate_array(@customer.owned_needs.order(created_at: :desc)) + .page(params[:page_needs]) + .per(5) + if params[:order] @customer.force_address = true @@ -118,17 +127,13 @@ class Public::CustomersController < ApplicationController if @customer.update_attributes(params.require(:customer).permit!) - - redirect_to public_my_account_path + flash[:success] = "Vos informations ont bien été enregistrées" + redirect_to public_my_account_path else - if params[:customer][:step2] or params[:customer][:step3] + flash[:error] = "Certains champs sont invalides" + render :template => "public/my_account/edit_infos" - render :template => "public/my_account/index" - else - render :template => "public/my_account/edit_infos" - - end end end end diff --git a/app/controllers/public/my_account_controller.rb b/app/controllers/public/my_account_controller.rb index a4f63a5..21a358c 100755 --- a/app/controllers/public/my_account_controller.rb +++ b/app/controllers/public/my_account_controller.rb @@ -5,6 +5,7 @@ class Public::MyAccountController < ApplicationController before_filter :auth_customer def index + @accepted_offers = current_customer.accepted_offers.order(created_at: :desc).page(params[:page_offers]).per(5) @wishes = current_customer.wishes.includes(:need).page(params[:page_wishes]).per(5) @@ -13,8 +14,6 @@ class Public::MyAccountController < ApplicationController .page(params[:page_needs]) .per(5) - - end def edit_infos diff --git a/app/models/customer.rb b/app/models/customer.rb index 2becb08..87959f8 100755 --- a/app/models/customer.rb +++ b/app/models/customer.rb @@ -40,12 +40,18 @@ class Customer < ActiveRecord::Base validates_presence_of :name validates_presence_of :firstname + + + validates_presence_of :organisation validates_presence_of :phone #validates_presence_of :parent_code + validates :capital, :numericality => true, :presence => true, :if => :step2 + validates :role_signataire, :presence => true, :if => :step2 + validates_presence_of :password, :on => :create validates :email, :presence => true, :uniqueness => true, :format => /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\z/i diff --git a/app/models/message.rb b/app/models/message.rb index ea7f56d..c02d047 100755 --- a/app/models/message.rb +++ b/app/models/message.rb @@ -1,5 +1,6 @@ class Message < ActiveRecord::Base belongs_to :customer + belongs_to :admin belongs_to :need paginates_per 5 diff --git a/app/views/admin/accepted_offers/show.html.haml b/app/views/admin/accepted_offers/show.html.haml index 717b61a..9835d1a 100755 --- a/app/views/admin/accepted_offers/show.html.haml +++ b/app/views/admin/accepted_offers/show.html.haml @@ -40,29 +40,34 @@ %td{style:"text-align:center"} -if !document.document? = form_tag admin_offer_accepted_offer_document_upload_document_path(@offer, @accepted_offer, document), name: :document, method: :post, multipart: true do - %span.btn.btn-default.btn-file - ="Ouvrir (PDF)" + %span.btn.btn-xs.btn-default.btn-file + = ic(:'folder-open') = file_field_tag :document - = submit_tag("Charger" , class:"btn btn-primary") + %button.btn.btn-xs.upload-file{type: :submit, title: "Charger"} + = ic(:check) + + -else - =link_to i(:"download"),public_download_document_path(document.download_token, admin: true),title: "Télécharger le document" + =link_to ic(:"download"),public_download_document_path(document.download_token, admin: true),title: "Télécharger le document", class: "btn btn-primary btn-xs" -if !document.document_verified? - =link_to i(:"remove"), admin_offer_accepted_offer_document_delete_path(@offer, @accepted_offer, document), title: "Supprimer le fichier chargé", :data => {:confirm => 'Voulez-vous vraiment supprimer le fichier chargé ?'} + =link_to ic(:"remove"), admin_offer_accepted_offer_document_delete_path(@offer, @accepted_offer, document), title: "Supprimer le fichier chargé",class: "btn btn-danger btn-xs", :data => {:confirm => 'Voulez-vous vraiment supprimer le fichier chargé ?'} %td{style:"text-align:center"} -if !document.not_available? -if !document.returned_document? = form_tag admin_offer_accepted_offer_document_upload_returned_document_path(@offer, @accepted_offer, document), name: :returned_document, method: :post, multipart: true do - %span.btn.btn-default.btn-file - ="Ouvrir (PDF)" + %span.btn.btn-xs.btn-default.btn-file + = ic(:'folder-open') = file_field_tag :returned_document - = submit_tag("Charger manuellement" , class:"btn btn-primary") + %button.btn.btn-xs.upload-file{type: :submit, title: "Charger manuellement"} + = ic(:check) + -else - =link_to i(:"download"), admin_offer_accepted_offer_document_download_returned_path(@offer, @accepted_offer, document, :admin => true),title: "Télécharger le document" + =link_to ic(:"download"), admin_offer_accepted_offer_document_download_returned_path(@offer, @accepted_offer, document, :admin => true),class: "btn btn-primary btn-xs", title: "Télécharger le document" -if !document.document_verified? - =link_to i(:"remove"), admin_offer_accepted_offer_document_delete_returned_path(@offer, @accepted_offer, document), title: "Supprimer le fichier chargé", :data => {:confirm => 'Voulez-vous vraiment supprimer le fichier chargé ?'} + =link_to ic(:"remove"), admin_offer_accepted_offer_document_delete_returned_path(@offer, @accepted_offer, document),class: "btn btn-danger btn-xs", title: "Supprimer le fichier chargé", :data => {:confirm => 'Voulez-vous vraiment supprimer le fichier chargé ?'} -if document.document_returned? - =link_to i(:"check"), admin_offer_accepted_offer_document_verify_returned_path(@offer, @accepted_offer, document), :data => {:confirm => 'Voulez-vous vraiment marquer le document retourné par le client comme vérifié ?'}, title: "Marquer le document comme vérifié" + =link_to ic(:"check"), admin_offer_accepted_offer_document_verify_returned_path(@offer, @accepted_offer, document),class: "btn btn-success btn-xs", :data => {:confirm => 'Voulez-vous vraiment marquer le document retourné par le client comme vérifié ?'}, title: "Marquer le document comme vérifié" -else Charger un document d'abord @@ -80,3 +85,12 @@ =link_to ic(:check) + " Je confirme que tous les documents ont été retournés et vérifiés", validate_all_documents_admin_offer_accepted_offer_path(@offer, @accepted_offer), class:"btn btn-lg btn-success pull-right",:data => {:confirm => 'Voulez-vous vraiment confirmer que tous les documents ont été retournés et vérifiés ?'} =link_to ic(:"chevron-circle-left") + " Gestion des propositions par client pour le besoin #{@offer.need.title}", accepted_admin_offer_path(@offer), class: "btn btn-default" + + +:javascript + $(".upload-file").prop("disabled","disabled"); + $(".btn-file input").change(function(){ + + $(this).parent().next(".upload-file").prop("disabled",""); + $(this).parent().next(".upload-file").addClass("btn-success"); + }) diff --git a/app/views/admin/customers/_form.html.haml b/app/views/admin/customers/_form.html.haml index ee817d2..ff8b43f 100755 --- a/app/views/admin/customers/_form.html.haml +++ b/app/views/admin/customers/_form.html.haml @@ -1,45 +1,45 @@ -=semantic_form_for [:admin, @customer] do |f| +=semantic_form_for [:admin, @customer] do |f| .content =f.inputs do =f.input :domains, :label => "Domaine : ", :collection => Domain.all, :as => :check_boxes - + =f.input :organisation, :label => "Société : " - + =f.input :name, :label => "Nom : " =f.input :firstname, :label => "Prénom : " =f.input :email, :label => "Email : " =f.input :phone, :label => "Tél : " =f.input :password, :label => "Mot de passe : " - + =#f.hidden_field :step2 =f.input :tva_number, :label => "Numéro de TVA intra. :" =f.input :siret, :label => "Numéro de siret :" + =f.input :capital, :label => "Capital :" + =f.input :role_signataire, :label => "Fonction du signataire :" = f.input :address, :label => "Adresse" = f.input :address2, :label => "Adresse (suite)" = f.input :cp, :label => "Code postal" = f.input :city, :label => "Ville" - - + + =#f.hidden_field :step3 =f.input :need_1, :label => "1er besoin : ",:as => :select, :collection => [ "Materiel professionnel", "Matériel informatique", "Achat de véhicules", "Energie"] =f.input :need_2, :label => "2ième besoin : ",:as => :select, :collection => [ "Materiel professionnel", "Matériel informatique", "Achat de véhicules", "Energie"] =f.input :need_3, :label => "3ième besoin : ", :placeholder => "Autre, précisez ",:rows => 5, :input_html => {:style => "height:100px;"} - + =f.input :particulars_text, :label => "En-tête contrats : ",:rows => 5, :input_html => {:style => "height:100px;"} - - - - + + + + =f.input :newsgroups, :label => "Newsletters :", :collection => Newsgroup.all, :as => :check_boxes - - - + + + .actions= f.submit "Sauvegarder", :class => "btn btn-primary" - - diff --git a/app/views/admin/messages/_message.html.haml b/app/views/admin/messages/_message.html.haml index 2917573..890351f 100755 --- a/app/views/admin/messages/_message.html.haml +++ b/app/views/admin/messages/_message.html.haml @@ -1,6 +1,13 @@ .white.padding.message-item - %h4=message.customer.anonyme_nick + -if message.customer + %h4 + =message.customer.anonyme_nick + ="(#{message.customer.fullname} de #{message.customer.organisation})" + + -elsif message.admin + %h4="#{message.admin.fullname} (ADMINISTRATEUR)" + %p.info="Posté le #{message.created_at.strftime('%d/%m/%Y à %H:%M')}, il y a #{time_ago_in_words(message.created_at)}" diff --git a/app/views/admin/messages/index.html.haml b/app/views/admin/messages/index.html.haml index e98cf3f..cc85607 100755 --- a/app/views/admin/messages/index.html.haml +++ b/app/views/admin/messages/index.html.haml @@ -1,5 +1,16 @@ %h1= "Commentaires du besoin #{@need.title}" += semantic_form_for [:admin, @need, Message.new], :html => {id: :message_form, :method => :post } do |f| + + + + %h4 Écrire un nouveau message + = 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" + + %h4= " #{pluralize(@need.messages.count, 'Commentaire')} pour ce besoin" =render collection: @comments, partial: 'message' diff --git a/app/views/admin_mailer/customer_post_comment.html.haml b/app/views/admin_mailer/customer_post_comment.html.haml old mode 100644 new mode 100755 index 35a1d3c..cfe4ede --- a/app/views/admin_mailer/customer_post_comment.html.haml +++ b/app/views/admin_mailer/customer_post_comment.html.haml @@ -1,10 +1,18 @@ %p Bonjour, -%p - Un client a laissé un commentaire sur le besoin - %strong= @need.title +-if @comment.customer + %p + Un utilisateur a laissé un commentaire sur le besoin + %strong= @need.title -%p - %strong= @comment.customer.fullname + %p + %strong= @comment.customer.fullname +-elsif @comment.admin + %p + Un administrateur a laissé un commentaire sur le besoin + %strong= @need.title + + %p + %strong= @comment.admin.fullname %p= @comment.content diff --git a/app/views/customer_mailer/need_commented.html.haml b/app/views/customer_mailer/need_commented.html.haml old mode 100644 new mode 100755 index 6d703b2..84cc7b4 --- a/app/views/customer_mailer/need_commented.html.haml +++ b/app/views/customer_mailer/need_commented.html.haml @@ -1,10 +1,20 @@ %p Bonjour, -%p - Un autre utilisateur a laissé un commentaire sur le besoin - %strong= @need.title -%p - %strong= @comment.customer.fullname +-if @comment.customer + %p + Un autre utilisateur a laissé un commentaire sur le besoin + %strong= @need.title + + %p + %strong= @comment.customer.anonyme_nick +-elsif @comment.admin + %p + Un administrateur a laissé un commentaire sur le besoin + %strong= @need.title + + %p + %strong= @comment.admin.fullname + %p= @comment.content diff --git a/app/views/public/documents/_document.html.haml b/app/views/public/documents/_document.html.haml index c02d057..b6d38d0 100755 --- a/app/views/public/documents/_document.html.haml +++ b/app/views/public/documents/_document.html.haml @@ -1,23 +1,34 @@ %tr{class: document.document_verified? ? "success" : ""} %td = i(:file) + " " + document.title - %td{style:"text-align:center"} + %td{style:"text-align:center;vertical-align:middle"} -if document.document? - =link_to ic(:download), public_download_document_path(document.download_token),class: "btn btn-primary btn-sm",title: "Télécharger le document" + =link_to ic(:download), public_download_document_path(document.download_token),class: "btn btn-primary btn-xs",title: "Télécharger le document" -else Pas encore disponible - %td{style:"text-align:center"} + %td{style:"text-align:center;vertical-align:middle"} -if !document.not_available? -if !document.returned_document? = form_tag upload_returned_public_accepted_offer_document_path(@accepted_offer, document), name: :returned_document, method: :post, multipart: true do - %span.btn.btn-default.btn-file - ="Ouvrir (PDF)" + %span.btn.btn-xs.btn-default.btn-file + = ic(:'folder-open') = file_field_tag :returned_document - = submit_tag("Charger" , class:"btn btn-primary") - -else - =link_to i(:"download"),download_returned_public_accepted_offer_document_path(@accepted_offer, document), class:"btn btn-sm btn-primary",title: "Télécharger le document" - -if !document.document_verified? - =link_to i(:"remove"),destroy_returned_public_accepted_offer_document_path(@accepted_offer, document), class:"btn btn-sm btn-danger", title: "Supprimer le fichier chargé", :data => {:confirm => 'Voulez-vous vraiment supprimer le fichier chargé ?'} + %button.btn.btn-xs.upload-file{type: :submit, title: "Valider le document"} + = ic(:check) - %td{style:"text-align:right"} + -else + =link_to i(:"download"),download_returned_public_accepted_offer_document_path(@accepted_offer, document), class:"btn btn-xs btn-primary",title: "Télécharger le document" + -if !document.document_verified? + =link_to i(:"remove"),destroy_returned_public_accepted_offer_document_path(@accepted_offer, document), class:"btn btn-xs btn-danger", title: "Supprimer le fichier chargé", :data => {:confirm => 'Voulez-vous vraiment supprimer le fichier chargé ?'} + -else + = "Pas encore disponible" + %td{style:"text-align:right;vertical-align:middle"} =document.human_state + +:javascript + $(".upload-file").prop("disabled","disabled"); + $(".btn-file input").change(function(){ + + $(this).parent().next(".upload-file").prop("disabled",""); + $(this).parent().next(".upload-file").addClass("btn-success"); + }) diff --git a/app/views/public/my_account/_step2.html.haml b/app/views/public/my_account/_step2.html.haml index 0122177..d3b5114 100755 --- a/app/views/public/my_account/_step2.html.haml +++ b/app/views/public/my_account/_step2.html.haml @@ -2,25 +2,27 @@ -@customer = @customer || current_customer -@customer.step2 = true -= semantic_form_for [:public, @customer] do |f| - - - += semantic_form_for [:public, @customer] do |f| + + + %h2 Informations détaillées - =f.inputs do + =f.inputs do =f.hidden_field :step2 =f.input :tva_number, :label => "Numéro de TVA intra. :" =f.input :siret, :label => "Numéro de siret :" - + =f.input :capital, :label => "Capital :" + =f.input :role_signataire, :label => "Fonction du signataire :" + =render :partial => "public/my_account/address", :locals => {:f => f} =#%h2 Préférences concernant les envois de mail - - + + =#f.inputs do =#f.input :newsgroups, :label => "Les types d'informations qui m'intéressent :", :collection => Newsgroup.all, :as => :check_boxes - - - + + + =f.submit "Sauvegarder", :class => "btn btn-primary" %br diff --git a/app/views/public/needs/_message.html.haml b/app/views/public/needs/_message.html.haml index 1611e71..05a3172 100755 --- a/app/views/public/needs/_message.html.haml +++ b/app/views/public/needs/_message.html.haml @@ -1,6 +1,14 @@ .white.padding.message-item - %h4= i(:"user") + " " + message.customer.anonyme_nick + -if message.customer + %h4 + =message.customer.anonyme_nick + -elsif message.admin + %h4 + ="#{message.admin.fullname}" + %span{style:"color:red"} + ="ADMINISTRATEUR" + %p.info=i(:"clock-o") + " Posté le #{message.created_at.strftime('%d/%m/%Y à %H:%M')}, il y a #{time_ago_in_words(message.created_at)}" %p= message.content diff --git a/app/views/public/needs/show.html.haml b/app/views/public/needs/show.html.haml index 40bddd7..2dfc65a 100755 --- a/app/views/public/needs/show.html.haml +++ b/app/views/public/needs/show.html.haml @@ -114,7 +114,7 @@ -if offer.need.customers.include?(current_customer) -if !offer.customers.include?(current_customer) .accept-offer - =link_to i(:"check") + " Accepter l'offre", accept_public_need_offer_path(@need, offer), data: {confirm: "Voulez-vous vraiment accepter cette offre ? Attention, cette action vous engage à payer la somme proposée."}, class: "btn btn-lg btn-success " + =link_to i(:"check") + " J'accepte l'offre et je retourne le mandat signé", accept_public_need_offer_path(@need, offer), data: {confirm: "Pour que l’offre soit validée veuillez retourné le mandat signé que vous allez recevoir"}, class: "btn btn-lg btn-success " -else .offer-accepted =i(:"check") + " Offre Acceptée" diff --git a/db/migrate/20161017150545_add_some_extra_fields.rb b/db/migrate/20161017150545_add_some_extra_fields.rb new file mode 100755 index 0000000..833672f --- /dev/null +++ b/db/migrate/20161017150545_add_some_extra_fields.rb @@ -0,0 +1,6 @@ +class AddSomeExtraFields < ActiveRecord::Migration + def change + add_column :customers, :capital,:float + add_column :customers, :role_signataire,:string + end +end diff --git a/db/migrate/20161018122307_add_admin_to_message.rb b/db/migrate/20161018122307_add_admin_to_message.rb new file mode 100755 index 0000000..49400fc --- /dev/null +++ b/db/migrate/20161018122307_add_admin_to_message.rb @@ -0,0 +1,5 @@ +class AddAdminToMessage < ActiveRecord::Migration + def change + add_reference :messages, :admin, index: true + end +end diff --git a/db/schema.rb b/db/schema.rb index 0eb9936..2910c70 100755 --- 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: 20160926090902) do +ActiveRecord::Schema.define(version: 20161018122307) do create_table "accepted_offers", force: :cascade do |t| t.datetime "created_at", null: false @@ -225,6 +225,8 @@ ActiveRecord::Schema.define(version: 20160926090902) do t.float "longitude", limit: 24 t.datetime "last_activity" t.text "particulars_text", limit: 65535 + t.float "capital", limit: 24 + t.string "role_signataire", limit: 255 end create_table "data_files", force: :cascade do |t| @@ -468,8 +470,11 @@ ActiveRecord::Schema.define(version: 20160926090902) do t.integer "customer_id", limit: 4 t.integer "need_id", limit: 4 t.text "content", limit: 65535 + t.integer "admin_id", limit: 4 end + add_index "messages", ["admin_id"], name: "index_messages_on_admin_id", using: :btree + create_table "need_categories", force: :cascade do |t| t.datetime "created_at", null: false t.datetime "updated_at", null: false