From a867e95951a96adbb63eab2662d045bc1e21d0dc Mon Sep 17 00:00:00 2001 From: Nicolas VARROT Date: Mon, 30 Nov 2015 19:13:50 +0100 Subject: [PATCH] Need added (migrations+model+controller+templates+soft-deleting) --- Gemfile | 10 +- Gemfile.lock | 3 + .../public/my_account_controller.rb | 50 +++--- app/controllers/public/needs_controller.rb | 48 +++++ app/models/customer.rb | 7 + app/models/need.rb | 15 ++ app/views/public/customers/index.haml | 2 +- app/views/public/my_account/index.html.haml | 50 ++++-- app/views/public/needs/_form.html.haml | 6 + app/views/public/needs/_index.html.haml | 18 ++ app/views/public/needs/_need.html.haml | 10 ++ app/views/public/needs/edit.html.haml | 4 + app/views/public/needs/new.html.haml | 4 + config/routes.rb | 170 +++++++++--------- db/migrate/20151130121325_create_needs.rb | 10 ++ ...1130124831_add_author_reference_to_need.rb | 5 + .../20151130173626_add_delete_at_to_needs.rb | 6 + db/schema.rb | 14 +- test/fixtures/needs.yml | 9 + test/models/need_test.rb | 7 + 20 files changed, 320 insertions(+), 128 deletions(-) create mode 100644 app/controllers/public/needs_controller.rb create mode 100644 app/models/need.rb create mode 100644 app/views/public/needs/_form.html.haml create mode 100644 app/views/public/needs/_index.html.haml create mode 100644 app/views/public/needs/_need.html.haml create mode 100644 app/views/public/needs/edit.html.haml create mode 100644 app/views/public/needs/new.html.haml create mode 100644 db/migrate/20151130121325_create_needs.rb create mode 100644 db/migrate/20151130124831_add_author_reference_to_need.rb create mode 100644 db/migrate/20151130173626_add_delete_at_to_needs.rb create mode 100644 test/fixtures/needs.yml create mode 100644 test/models/need_test.rb diff --git a/Gemfile b/Gemfile index dacc622..d648c9b 100644 --- a/Gemfile +++ b/Gemfile @@ -33,12 +33,12 @@ group :development, :test do gem 'byebug' #gem 'capistrano-rails' #gem "rvm-capistrano" - + gem "capistrano", '2.15.5', group: :development gem "rvm-capistrano",'1.4.1', group: :development, require: false gem 'net-ssh', '~>2.7.0' - - + + gem 'web-console', '~> 2.0' gem 'spring' @@ -65,4 +65,6 @@ gem 'wicked_pdf' gem 'wkhtmltopdf-binary' -gem "geocoder" \ No newline at end of file +gem "geocoder" + +gem "paranoia", "~> 2.0" diff --git a/Gemfile.lock b/Gemfile.lock index 2329602..fe838bb 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -128,6 +128,8 @@ GEM net-ssh (>= 2.6.5) nokogiri (1.6.6.2) mini_portile (~> 0.6.0) + paranoia (2.1.4) + activerecord (~> 4.0) rack (1.6.0) rack-test (0.6.3) rack (>= 1.0) @@ -235,6 +237,7 @@ DEPENDENCIES kaminari-bootstrap mysql2 net-ssh (~> 2.7.0) + paranoia (~> 2.0) rails (= 4.2.0) rmagick rvm-capistrano (= 1.4.1) diff --git a/app/controllers/public/my_account_controller.rb b/app/controllers/public/my_account_controller.rb index 3c3e98d..4913d96 100644 --- a/app/controllers/public/my_account_controller.rb +++ b/app/controllers/public/my_account_controller.rb @@ -1,12 +1,12 @@ class Public::MyAccountController < ApplicationController - - layout "public" - - before_filter :auth_customer - - def index - + layout "public" + + before_filter :auth_customer + + def index + @needs = Kaminari.paginate_array(current_customer.needs).page(params[:page]).per(2) + end def edit_infos @@ -16,44 +16,44 @@ class Public::MyAccountController < ApplicationController def my_annonces @no_search = true end - + def binary @no_search = true if params[:parrain_id] and current_customer.binary_child_ids.include?(params[:parrain_id].to_i) @parrain = Customer.find(params[:parrain_id]) - - - + + + else - @parrain = current_customer + @parrain = current_customer end end - + def filleuls @no_search = true @filleuls = current_customer.children - + session[:mail_prev] = public_filleuls_path - + end - + def reconfirm @no_search = true CustomerMailer.confirm(current_customer).deliver - + redirect_to public_my_account_path, :notice => "Le mail vous a été renvoyé" end - - + + def favoris - + per_page = (params[:per_page] and params[:per_page] != "") ? params[:per_page] : 10 - - page = (params[:page] and params[:page] != "") ? params[:page] : 1 - + + page = (params[:page] and params[:page] != "") ? params[:page] : 1 + @annonces = current_customer.annonce_favs.valid_to_show @annonces = @annonces.page(page).per(per_page).all end - - + + end diff --git a/app/controllers/public/needs_controller.rb b/app/controllers/public/needs_controller.rb new file mode 100644 index 0000000..640735a --- /dev/null +++ b/app/controllers/public/needs_controller.rb @@ -0,0 +1,48 @@ +class Public::NeedsController < ApplicationController + + layout "public" + + before_filter :auth_customer + + def new + @need = Need.new() + end + + def destroy + @need = Need.find(params[:id]) + if(@need.destroy) + flash[:notice] = "Besoin supprimé avec succès." + end + redirect_to public_my_account_path + 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 public_my_account_path + else + render :action => "edit" + end + end + + def create + @need = Need.new(need_params) + @need.author = current_customer + if @need.save + flash[:notice] = "Votre besoin à été créé avec succès." + redirect_to public_my_account_path + else + render :action => "new" + end + end + + def need_params + params.require(:need).permit(:title, :description) + end + +end diff --git a/app/models/customer.rb b/app/models/customer.rb index fb03a0c..45cf9d8 100644 --- a/app/models/customer.rb +++ b/app/models/customer.rb @@ -2,6 +2,8 @@ class Customer < ActiveRecord::Base # Relationships + has_many :needs, foreign_key: 'author_id' + has_many :customer_favs has_many :annonce_favs, :through => :customer_favs, :class_name => "Annonce", :source => :annonce @@ -44,6 +46,7 @@ class Customer < ActiveRecord::Base validates :need_1 , :presence => true, :if => :step3 + # Geocoder reverse_geocoded_by :latitude, :longitude @@ -213,6 +216,10 @@ class Customer < ActiveRecord::Base "#{address} #{address2} #{cp} #{city}" end + def fullname + "#{firstname.capitalize} #{name.upcase}" + end + def pseudo if self.pro self.organisation diff --git a/app/models/need.rb b/app/models/need.rb new file mode 100644 index 0000000..4a80dd9 --- /dev/null +++ b/app/models/need.rb @@ -0,0 +1,15 @@ +class Need < ActiveRecord::Base + + 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 + +end diff --git a/app/views/public/customers/index.haml b/app/views/public/customers/index.haml index 7b49cfe..c0065d0 100644 --- a/app/views/public/customers/index.haml +++ b/app/views/public/customers/index.haml @@ -10,4 +10,4 @@ %th Messages -if moderator? %th Actions - =render @users \ No newline at end of file + =render @users diff --git a/app/views/public/my_account/index.html.haml b/app/views/public/my_account/index.html.haml index 1ee02e1..0327c01 100644 --- a/app/views/public/my_account/index.html.haml +++ b/app/views/public/my_account/index.html.haml @@ -9,30 +9,52 @@ %p Le mail a été envoyé à l'adresse : %strong= current_customer.email - =link_to "renvoyer le mail de confirmation", public_reconfirm_email_path, :class => "btn btn-primary" + =link_to "renvoyer le mail de confirmation", public_reconfirm_email_path, :class => "btn btn-primary" -.padding.center.white - %h2 - =current_customer.organisation - -if !current_customer.address or current_customer.need_1 == nil - - +-if !current_customer.address or current_customer.need_1 == nil or !current_customer.account_validated + + .padding.center.white + %h2 + =current_customer.organisation + -if !current_customer.address %p Merci pour votre inscription, dernière étape et votre profil sera complet. =render :partial => "public/my_account/step2" -elsif !current_customer.need_1 %center - =render :partial => "public/my_account/step3" - -else + -elsif !current_customer.account_validated + %p + Merci ! Votre profil est complet, nous vous contacterons prochainement. + %p + =link_to "Modifier mes infos", public_edit_infos_path, :class => "btn btn-primary" + + + +-if current_customer.account_validated + .padding.center.white + %h2 + =current_customer.organisation %p - Merci ! Votre profil est complet, nous vous contacterons prochainement. + %i.fa.fa-user + #{current_customer.fullname} + %p + %i.fa.fa-map-marker + #{ current_customer.full_address} %p =link_to "Modifier mes infos", public_edit_infos_path, :class => "btn btn-primary" - - - - + .padding.center.white + %h3 + Mes besoins + -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" + .padding.center.white + %h3 + Ma liste de souhait diff --git a/app/views/public/needs/_form.html.haml b/app/views/public/needs/_form.html.haml new file mode 100644 index 0000000..a64d7a2 --- /dev/null +++ b/app/views/public/needs/_form.html.haml @@ -0,0 +1,6 @@ += semantic_form_for [:public, @need] do |f| + =f.inputs do + = f.input :title, :label => "Titre de votre besoin" + = f.input :description, :label => "Description", :rows => 5, :input_html => {:style => "height:100px;"} + %br + =f.submit "Sauvegarder", :class => "btn btn-primary" diff --git a/app/views/public/needs/_index.html.haml b/app/views/public/needs/_index.html.haml new file mode 100644 index 0000000..76dcbbf --- /dev/null +++ b/app/views/public/needs/_index.html.haml @@ -0,0 +1,18 @@ +%table.table.table-striped + %thead + + %tr + %th + Titre du besoin + %th + État + %th + Souhaité par + %th{:style => "width:100px"} +   + + %tbody + + =render @needs + +.pagination= paginate @needs diff --git a/app/views/public/needs/_need.html.haml b/app/views/public/needs/_need.html.haml new file mode 100644 index 0000000..2160d8f --- /dev/null +++ b/app/views/public/needs/_need.html.haml @@ -0,0 +1,10 @@ +%tr{:id => need.id} + %td + =need.title + %td + + %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 + = link_to i(:"pencil btn btn-primary"), edit_public_need_path(need) diff --git a/app/views/public/needs/edit.html.haml b/app/views/public/needs/edit.html.haml new file mode 100644 index 0000000..6fa3992 --- /dev/null +++ b/app/views/public/needs/edit.html.haml @@ -0,0 +1,4 @@ +.center.padding.white + %h2 + Modification d'un besoin existant + =render :partial => "public/needs/form" diff --git a/app/views/public/needs/new.html.haml b/app/views/public/needs/new.html.haml new file mode 100644 index 0000000..fa37da7 --- /dev/null +++ b/app/views/public/needs/new.html.haml @@ -0,0 +1,4 @@ +.center.padding.white + %h2 + Déclaration d'un nouveau besoin + =render :partial => "public/needs/form" diff --git a/config/routes.rb b/config/routes.rb index d558d19..b667f05 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,28 +1,29 @@ Rails.application.routes.draw do get 'mail_assets/:token.png' => "admin/mail_trackings#update", :as => :image_tracking - - + + constraints subdomain: 'affiliation' do get "/:mlm_token" => "public/home#affiliation" get "/" => "public/home#affiliation" end - + get "affiliation/:mlm_token" => "public/home#affiliation" get "affiliation" => "public/home#affiliation" - - + + constraints domain: ['sideplace-affiliation.dev', 'affiliation-sideplace.com'] do get "/:mlm_token" => "public/home#redirect_affiliation" get "/" => "public/home#redirect_affiliation" - + end get 'p/:mlm_token' => "public/customers#parrainage", :as => :mlm_token namespace :public do + resources :customer_favs resources :customer_ribs do - + end resources :annonce_cats do collection do @@ -36,16 +37,16 @@ Rails.application.routes.draw do get :e_trans_ipn get :e_trans_refuse get :e_trans_effectue - + get :billing get :bills end - + member do get :bill_print get :paid get :paid_force - + end end resources :credit_products @@ -56,17 +57,17 @@ Rails.application.routes.draw do end resources :credits resources :mlm_points - + resources :annonce_photos do member do - get :rotate + get :rotate end end resources :annonces do collection do - - + + get :geocode end member do @@ -78,7 +79,7 @@ Rails.application.routes.draw do get :buy_option end end - + get 'my_account/favoris', :as => "favs" get 'my_account/filleuls', :as => "filleuls" get 'my_account/binary', :as => "binary" @@ -86,76 +87,79 @@ Rails.application.routes.draw do get 'my_account/edit_infos', :as => "edit_infos" get 'my_account/my_annonces', :as => "my_annonces" get 'my_account/reconfirm', :as => "reconfirm_email" + + resources :needs + end get "evenements/:id.html" => "public/events#show", :as => "public_event" get "evenements.html" => "public/events#index", :as => "public_events" - - + + post "search.:f" => "public/annonces#search", :as => :search_public_annonces, :f => "html" get "search.:f" => "public/annonces#search", :f => "html" - - + + constraints subdomain: 'blog' do - get "blog/archives/:year/:month.html"=> "public/articles#archives", :as => :archive_public_article - get "blog/tags/:id.html"=> "public/articles#tags", :as => :public_tag + get "blog/archives/:year/:month.html"=> "public/articles#archives", :as => :archive_public_article + get "blog/tags/:id.html"=> "public/articles#tags", :as => :public_tag get "blog/categorie/:slug.:f"=> "public/articles#category", :as => :category_public_article, :f => "html" get 'blog/:id.html' => "public/articles#show", :as => "public_article" get 'blog/:slug.:f' => 'public/articles#show', :as => :article, :f => "html" get 'blog.:f' => 'public/articles#index', :as => :articles, :f => "html" get '/' => 'public/articles#index' - + end - - - - - - get "/" => "public/ebooks#show",:id => "arreter-de-fumer" ,:constraints => {:domain => ["arreter-de-fumer-avec-eft.dev", "bally.me", "arreter-de-fumer-avec-eft.com"]} - - - - + + + + + + get "/" => "public/ebooks#show",:id => "arreter-de-fumer" ,:constraints => {:domain => ["arreter-de-fumer-avec-eft.dev", "bally.me", "arreter-de-fumer-avec-eft.com"]} + + + + get "categorie/:id.:f" => "public/annonces#search", :as => :public_annonce_category, :f => "html" post "categorie/:id.:f" => "public/annonces#search", :as => :post_public_annonce_category, :f => "html" - - - - + + + + get "sitemap.:f" => "public/sitemap#sitemap" namespace :public do resources :virements resources :comments resources :annonce_messages - resources :customers do + resources :customers do member do get :confirm get :mail get :mail_confirm get :show_details end - + collection do get :find_parrain end - + end - + resources :customers_auths do - + collection do - + get :logout - + end end - + resources :password_resets - + end - + namespace :portlet do resources :event_contents resources :break_contents @@ -184,13 +188,13 @@ Rails.application.routes.draw do end end end - + namespace :admin do - + resources :annonces do - + end - + resources :orders do member do get :cancel @@ -198,24 +202,24 @@ Rails.application.routes.draw do post :force end end - + resources :virements do - member do - + member do + get :valid end end resources :virement_remises do - member do - + member do + get :sended end end resources :annonces resources :annonce_photos resources :customer_ribs do - member do - + member do + get :valid end end @@ -223,22 +227,22 @@ Rails.application.routes.draw do member do get :history get :history_detail - + get "select_recipients" put "select_recipients" post "send_test" post "send_newsletter" end end - - + + resources :customers do member do get :validate end - + end - + resources :categories do collection do post :reorder @@ -248,27 +252,27 @@ Rails.application.routes.draw do resources :comments resources :articles resources :events - + resources :tags resources :password_resets - + resources :admin_auths do - collection do + collection do get :logout end end - + resources :admins - - - + + + resources :external_links do collection do get :cible end end - - + + resources :menus resources :menu_items do collection do @@ -293,25 +297,25 @@ Rails.application.routes.draw do resources :blocks resources :albums resources :cibles - + end - + resources :download_data_files - + get 'admin' => "admin/admin_auths#index" - - - - - + + + + + get '*url.html' => 'public/menu_items#show', :as => :menu_item, :f => "html" get '*url.:f' => 'public/menu_items#redirect', :f => "html" - + root 'public/customers#new' - - - + + + end diff --git a/db/migrate/20151130121325_create_needs.rb b/db/migrate/20151130121325_create_needs.rb new file mode 100644 index 0000000..cf0affe --- /dev/null +++ b/db/migrate/20151130121325_create_needs.rb @@ -0,0 +1,10 @@ +class CreateNeeds < ActiveRecord::Migration + def change + create_table :needs do |t| + t.string :title + t.text :description + + t.timestamps null: false + end + end +end diff --git a/db/migrate/20151130124831_add_author_reference_to_need.rb b/db/migrate/20151130124831_add_author_reference_to_need.rb new file mode 100644 index 0000000..3ddf450 --- /dev/null +++ b/db/migrate/20151130124831_add_author_reference_to_need.rb @@ -0,0 +1,5 @@ +class AddAuthorReferenceToNeed < ActiveRecord::Migration + def change + add_reference :needs, :author, index: true + end +end diff --git a/db/migrate/20151130173626_add_delete_at_to_needs.rb b/db/migrate/20151130173626_add_delete_at_to_needs.rb new file mode 100644 index 0000000..3ce4fdf --- /dev/null +++ b/db/migrate/20151130173626_add_delete_at_to_needs.rb @@ -0,0 +1,6 @@ +class AddDeleteAtToNeeds < ActiveRecord::Migration + def change + add_column :needs, :deleted_at, :datetime + add_index :needs, :deleted_at + end +end diff --git a/db/schema.rb b/db/schema.rb index 7f8ae58..2c992c5 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: 20151130111157) do +ActiveRecord::Schema.define(version: 20151130173626) do create_table "admins", force: :cascade do |t| t.string "name", limit: 255 @@ -382,6 +382,18 @@ ActiveRecord::Schema.define(version: 20151130111157) do t.datetime "updated_at" end + create_table "needs", force: :cascade do |t| + t.string "title", limit: 255 + t.text "description", limit: 65535 + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.integer "author_id", limit: 4 + t.datetime "deleted_at" + end + + add_index "needs", ["author_id"], name: "index_needs_on_author_id", using: :btree + add_index "needs", ["deleted_at"], name: "index_needs_on_deleted_at", using: :btree + create_table "newsgroups", force: :cascade do |t| t.string "name", limit: 255 t.string "slug", limit: 255 diff --git a/test/fixtures/needs.yml b/test/fixtures/needs.yml new file mode 100644 index 0000000..97fbfc4 --- /dev/null +++ b/test/fixtures/needs.yml @@ -0,0 +1,9 @@ +# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html + +one: + title: MyString + description: MyText + +two: + title: MyString + description: MyText diff --git a/test/models/need_test.rb b/test/models/need_test.rb new file mode 100644 index 0000000..b38c1f3 --- /dev/null +++ b/test/models/need_test.rb @@ -0,0 +1,7 @@ +require 'test_helper' + +class NeedTest < ActiveSupport::TestCase + # test "the truth" do + # assert true + # end +end