From 426591453bc92e473edebc100cd9f2e645d1df7c Mon Sep 17 00:00:00 2001 From: Nicolas VARROT Date: Wed, 9 Mar 2016 17:50:08 +0100 Subject: [PATCH] Document manager finished --- app/assets/stylesheets/public.scss | 21 ++++++ .../admin/accepted_offers_controller.rb | 51 +++---------- app/controllers/admin/documents_controller.rb | 32 ++++++++- .../public/documents_controller.rb | 72 +++++++++++++++++++ app/uploaders/document_uploader.rb | 2 +- .../accepted_offers/_documents.html.haml | 1 + .../admin/accepted_offers/index.html.haml | 1 - .../admin/accepted_offers/show.html.haml | 10 ++- app/views/admin/offers/accepted.html.haml | 2 + .../public/documents/_document.html.haml | 23 ++++++ app/views/public/documents/index.html.haml | 26 +++++++ .../public/needs/_accepted_offer.html.haml | 2 +- config/database.yml | 1 + config/routes.rb | 21 ++++-- 14 files changed, 210 insertions(+), 55 deletions(-) create mode 100644 app/controllers/public/documents_controller.rb create mode 100644 app/views/public/documents/_document.html.haml create mode 100644 app/views/public/documents/index.html.haml diff --git a/app/assets/stylesheets/public.scss b/app/assets/stylesheets/public.scss index d8939d0..b3df104 100755 --- a/app/assets/stylesheets/public.scss +++ b/app/assets/stylesheets/public.scss @@ -646,3 +646,24 @@ height: 100%; height:200px; } + +.btn-file { + position: relative; + overflow: hidden; +} +.btn-file input[type=file] { + + position: absolute; + top: 0; + right: 0; + min-width: 100%; + min-height: 100%; + font-size: 100px; + text-align: right; + filter: alpha(opacity=0); + opacity: 0; + outline: none; + background: white; + cursor: inherit; + display: block; +} diff --git a/app/controllers/admin/accepted_offers_controller.rb b/app/controllers/admin/accepted_offers_controller.rb index 9fe706c..b552725 100755 --- a/app/controllers/admin/accepted_offers_controller.rb +++ b/app/controllers/admin/accepted_offers_controller.rb @@ -8,57 +8,24 @@ class Admin::AcceptedOffersController < ApplicationController @documents = @accepted_offer.documents end - def upload_devis - @accepted_offer = AcceptedOffer.find(params[:id]) - if !params[:devis] - flash[:error] = "Vous devez sélectionner un fichier" + def validate_all_documents + @offer = Offer.find(params[:offer_id]) + @accepted_offer = @offer.accepted_offers.find(params[:id]) + @accepted_offer.state = :documents_completed + + if @accepted_offer.save + flash[:success] = "Confirmation OK" else - - @accepted_offer.devis = params[:devis] - - - - if @accepted_offer.save - - @accepted_offer.state = :devis_available - @accepted_offer.save - - - else - flash[:error] = "Impossible de charger le devis" - end + flash[:error] = "Impossible de confirmer" end - redirect_back_or_default :root - - + redirect_to :back end - def download - @accepted_offer = AcceptedOffer.find(params[:id]) - send_file @accepted_offer.devis.file.path - end - def delete - @accepted_offer = AcceptedOffer.find(params[:id]) - @accepted_offer.remove_devis! - @accepted_offer.state = :waiting_devis - @accepted_offer.save - flash[:notice] = "Devis supprimé" - redirect_back_or_default :root - end - def received - @accepted_offer = AcceptedOffer.find(params[:id]) - - @accepted_offer.state = :devis_received - @accepted_offer.save - - flash[:notice] = "Devis marqué comme reçu et signé" - redirect_back_or_default :root - end end diff --git a/app/controllers/admin/documents_controller.rb b/app/controllers/admin/documents_controller.rb index 7895118..388085d 100755 --- a/app/controllers/admin/documents_controller.rb +++ b/app/controllers/admin/documents_controller.rb @@ -24,7 +24,10 @@ class Admin::DocumentsController < ApplicationController @document = @accepted_offer.documents.find(params[:document_id]) @document.document = params[:document] if @document.save - @document.upload_document! if @document.not_available? + @document.state = :document_available + if @document.returned_document? + @document.remove_returned_document! + end @document.save flash[:success] = "Document chargé" else @@ -70,7 +73,13 @@ class Admin::DocumentsController < ApplicationController def delete @document = @accepted_offer.documents.find(params[:document_id]) - if @document.remove_document! + if @document.document? && @document.state != :document_verified + @document.remove_document! + if @document.returned_document? + @document.remove_returned_document! + end + @document.state = :not_available + @document.save flash[:success] = "Fichier supprimé" else flash[:error] = "Impossible de supprimer le fichier" @@ -81,6 +90,7 @@ class Admin::DocumentsController < ApplicationController def destroy @document = @accepted_offer.documents.find(params[:document_id]) if @document.destroy + flash[:success] = "Document Supprimé" else flash[:error] = "Impossible de supprimer le document" @@ -90,7 +100,10 @@ class Admin::DocumentsController < ApplicationController def delete_returned @document = @accepted_offer.documents.find(params[:document_id]) - if @document.remove_returned_document! + if @document.returned_document? && @document.state != :document_verified + @document.remove_returned_document! + @document.state = :document_available + @document.save flash[:success] = "Fichier supprimé" else flash[:error] = "Impossible de supprimer le fichier" @@ -98,6 +111,19 @@ class Admin::DocumentsController < ApplicationController redirect_to :back end + def force_verified + @document = @accepted_offer.documents.find(params[:document_id]) + @document.state = :document_verified + + + if @document.save + flash[:success] = "Document vérifié" + else + flash[:error] = "Impossible vérifier le document" + end + redirect_to :back + end + def verify_returned @document = @accepted_offer.documents.find(params[:document_id]) @document.state = :document_verified diff --git a/app/controllers/public/documents_controller.rb b/app/controllers/public/documents_controller.rb new file mode 100644 index 0000000..5b1fadb --- /dev/null +++ b/app/controllers/public/documents_controller.rb @@ -0,0 +1,72 @@ +class Public::DocumentsController < ApplicationController + + layout "public" + + before_filter :auth_customer + before_filter :check_owner + + def index + + @documents = @accepted_offer.documents + + end + + def download + @document = @accepted_offer.documents.find(params[:id]) + if @document.state == :document_available + @document.state = :document_downloaded + @document.save + end + send_file @document.document.file.path + + end + + def download_returned + @document = @accepted_offer.documents.find(params[:id]) + send_file @document.returned_document.file.path + + end + + def destroy_returned + @document = @accepted_offer.documents.find(params[:id]) + if @document.returned_document? + @document.remove_returned_document! + end + @document.state = :document_downloaded + if @document.save + flash[:success] = "Document chargé" + else + flash[:success] = "Impossible de supprimer le document" + end + redirect_to :back + + end + + + def upload_returned + if !params[:returned_document] + flash[:error] = "Vous devez sélectionner un fichier" + else + + @document = @accepted_offer.documents.find(params[:id]) + @document.returned_document = params[:returned_document] + if @document.save + @document.return_document! + flash[:success] = "Document chargé" + else + flash[:error] = "Impossible de charger le document" + end + end + redirect_to :back + + end + + def check_owner + @accepted_offer = AcceptedOffer.find(params[:accepted_offer_id]) + + if @accepted_offer.customer.id != current_customer.id + flash[:error] = "Vous n'avez pas la permission d'accéder à cette page" + redirect_back_or_default :root + end + end +end diff --git a/app/uploaders/document_uploader.rb b/app/uploaders/document_uploader.rb index 6421947..7e55829 100755 --- a/app/uploaders/document_uploader.rb +++ b/app/uploaders/document_uploader.rb @@ -6,7 +6,7 @@ class DocumentUploader < CarrierWave::Uploader::Base def filename - "#{mounted_as}-#{friendly_filename(model.title)}.#{file.extension}" if original_filename.present? + "#{friendly_filename(model.title)}_#{friendly_filename(model.accepted_offer.customer.organisation)}_besoin#{model.accepted_offer.offer.need.id}_offre#{model.accepted_offer.offer.id}_#{mounted_as}.#{file.extension}" if original_filename.present? end def store_dir diff --git a/app/views/admin/accepted_offers/_documents.html.haml b/app/views/admin/accepted_offers/_documents.html.haml index ef97ef6..a1f1c69 100755 --- a/app/views/admin/accepted_offers/_documents.html.haml +++ b/app/views/admin/accepted_offers/_documents.html.haml @@ -1,3 +1,4 @@ +.padding.white.gutter %tr %td Titre du document diff --git a/app/views/admin/accepted_offers/index.html.haml b/app/views/admin/accepted_offers/index.html.haml index f71d6f2..e69de29 100755 --- a/app/views/admin/accepted_offers/index.html.haml +++ b/app/views/admin/accepted_offers/index.html.haml @@ -1 +0,0 @@ -ezrf diff --git a/app/views/admin/accepted_offers/show.html.haml b/app/views/admin/accepted_offers/show.html.haml index f291a68..9c64d20 100755 --- a/app/views/admin/accepted_offers/show.html.haml +++ b/app/views/admin/accepted_offers/show.html.haml @@ -62,11 +62,19 @@ -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é ?'} -if document.document_returned? - =link_to ic(:"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é et signé ?'}, title: "Marquer le document comme vérifié et signé" + =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é" -else Charger un document d'abord %td{style:"text-align:left"} =document.human_admin_state %td{style:"text-align:right"} + -if !document.document_verified? + =link_to i(:"check"), admin_offer_accepted_offer_document_force_verified_path(@offer, @accepted_offer, document), title: "Marquer ce document comme vérifié", :data => {:confirm => 'Voulez-vous vraiment marquer ce document comme vérifié ?'} + =link_to i(:"trash"), admin_offer_accepted_offer_document_destroy_path(@offer, @accepted_offer, document), title: "Supprimer le document", :data => {:confirm => 'Voulez-vous vraiment supprimer ce document ?'} + +-if @accepted_offer.waiting_documents? && @accepted_offer.documents.where(state: :document_verified).count == @accepted_offer.documents.count + =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" diff --git a/app/views/admin/offers/accepted.html.haml b/app/views/admin/offers/accepted.html.haml index 1df31b3..71cfb28 100755 --- a/app/views/admin/offers/accepted.html.haml +++ b/app/views/admin/offers/accepted.html.haml @@ -78,4 +78,6 @@ -else Pas encore acceptée +=link_to ic(:"chevron-circle-left") + " Gestion des offres", admin_offers_path, class: "btn btn-default" + :javascript diff --git a/app/views/public/documents/_document.html.haml b/app/views/public/documents/_document.html.haml new file mode 100644 index 0000000..3fc743d --- /dev/null +++ b/app/views/public/documents/_document.html.haml @@ -0,0 +1,23 @@ +%tr{class: document.document_verified? ? "success" : ""} + %td + = i(:file) + " " + document.title + %td{style:"text-align:center"} + -if document.document? + =link_to ic(:download), download_public_accepted_offer_document_path(@accepted_offer, document),class: "btn btn-primary btn-sm",title: "Télécharger le document" + -else + Pas encore disponible + %td{style:"text-align:center"} + -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)" + = 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é ?'} + + %td{style:"text-align:right"} + =document.human_state diff --git a/app/views/public/documents/index.html.haml b/app/views/public/documents/index.html.haml new file mode 100644 index 0000000..eb57aee --- /dev/null +++ b/app/views/public/documents/index.html.haml @@ -0,0 +1,26 @@ + +.center.white.row + .row.gutter + %h1 + Documents à retourner + =" (#{@accepted_offer.documents.where(state: :document_verified).count} / #{@accepted_offer.documents.count})" + %table.table.admin-table.table-hover.table-striped + %thead.rows_header + %tr + %th + Titre du document + %th{style:"text-align:center"} + Fichier à télécharger + %th{style:"text-align:center"} + Fichier à retourner + %th{style:"text-align:right"} + État du document + + + + + %tbody.rows + + =render @documents + + =link_to i(:"chevron-circle-left") + " Mon Compte", public_my_account_path, class:" btn btn-default" diff --git a/app/views/public/needs/_accepted_offer.html.haml b/app/views/public/needs/_accepted_offer.html.haml index f7ad432..b66f1c6 100755 --- a/app/views/public/needs/_accepted_offer.html.haml +++ b/app/views/public/needs/_accepted_offer.html.haml @@ -13,4 +13,4 @@ %td{style: 'text-align:center'} =accepted_offer.human_state %td{style: 'text-align:right'} - =link_to i(:"file") + " #{accepted_offer.documents.where(state: :document_verified).count} / #{accepted_offer.documents.count}", public_documents_path(accepted_offer), class: "btn btn-sm btn-primary" + =link_to i(:"file") + " #{accepted_offer.documents.where(state: :document_verified).count} / #{accepted_offer.documents.count}", public_accepted_offer_documents_path(accepted_offer), class: "btn btn-sm btn-primary" diff --git a/config/database.yml b/config/database.yml index c26b1ba..5476b46 100755 --- a/config/database.yml +++ b/config/database.yml @@ -15,6 +15,7 @@ development: <<: *default username: root password: mysqlpassword + host: "127.0.0.1" socket: /var/run/mysqld/mysqld.sock diff --git a/config/routes.rb b/config/routes.rb index 9f2b9bb..90fafb6 100755 --- a/config/routes.rb +++ b/config/routes.rb @@ -89,10 +89,18 @@ Rails.application.routes.draw do get 'my_account/reconfirm', :as => "reconfirm_email" resources :accepted_offers do - member do - resources :documents + resources :documents do + member do + get :download + get :download_returned + post :upload_returned + get :destroy_returned + + end end + + end resources :needs do resources :messages @@ -289,12 +297,13 @@ Rails.application.routes.draw do get :delete_returned get :verify_returned get :destroy + get :force_verified end member do - post :upload_devis - get :download - get :delete - get :received + + + get :validate_all_documents + end end