Need added (migrations+model+controller+templates+soft-deleting)

This commit is contained in:
Nicolas VARROT 2015-11-30 19:13:50 +01:00
parent 11d419aba1
commit a867e95951
20 changed files with 320 additions and 128 deletions

10
Gemfile
View File

@ -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"
gem "geocoder"
gem "paranoia", "~> 2.0"

View File

@ -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)

View File

@ -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

View File

@ -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

View File

@ -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

15
app/models/need.rb Normal file
View File

@ -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

View File

@ -10,4 +10,4 @@
%th Messages
-if moderator?
%th Actions
=render @users
=render @users

View File

@ -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

View File

@ -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"

View File

@ -0,0 +1,18 @@
%table.table.table-striped
%thead
%tr
%th
Titre du besoin
%th
État
%th
Souhaité par
%th{:style => "width:100px"}
&nbsp;
%tbody
=render @needs
.pagination= paginate @needs

View File

@ -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)

View File

@ -0,0 +1,4 @@
.center.padding.white
%h2
Modification d'un besoin existant
=render :partial => "public/needs/form"

View File

@ -0,0 +1,4 @@
.center.padding.white
%h2
Déclaration d'un nouveau besoin
=render :partial => "public/needs/form"

View File

@ -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

View File

@ -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

View File

@ -0,0 +1,5 @@
class AddAuthorReferenceToNeed < ActiveRecord::Migration
def change
add_reference :needs, :author, index: true
end
end

View File

@ -0,0 +1,6 @@
class AddDeleteAtToNeeds < ActiveRecord::Migration
def change
add_column :needs, :deleted_at, :datetime
add_index :needs, :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: 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

9
test/fixtures/needs.yml vendored Normal file
View File

@ -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

7
test/models/need_test.rb Normal file
View File

@ -0,0 +1,7 @@
require 'test_helper'
class NeedTest < ActiveSupport::TestCase
# test "the truth" do
# assert true
# end
end