Public need page added (can be wish or on unwish)

This commit is contained in:
Nicolas VARROT 2015-12-02 23:14:09 +01:00
parent 388d8d5cb6
commit 22b86c191f
21 changed files with 190 additions and 24 deletions

View File

@ -11,9 +11,7 @@
@import "public/binary"; @import "public/binary";
@import "public/account"; @import "public/account";
@import "public/affiliation"; @import "public/affiliation";
@import "public/need";

View File

@ -0,0 +1,36 @@
.need-item{
height: 150px;
background-color:#fff;
padding-top:30px;
p{
font-size:12px;
color:rgb(163, 159, 159);
}
span{
background-color: #ede8e8;
position:absolute;
padding:5px;
top:0px;
right:15px;
.time{
color:rgb(121, 120, 120);
text-align:right;
font-size:10px;
}
}
margin-bottom:30px;
h3{
margin-top:0px;
}
.btn{
border-radius: 0px;
position:absolute;
right:15px;
bottom:30px;
}
}

View File

@ -2,7 +2,14 @@ class Admin::NeedsController < ApplicationController
layout "admin" layout "admin"
def index def index
# Get all needs to validate
@needs_to_validate = Need.where(state: 'created').order(created_at: :desc) @needs_to_validate = Need.where(state: 'created').order(created_at: :desc)
# Get all controlled needs
@needs = Kaminari.paginate_array(Need.shared.order(created_at: :desc))
.page(params[:page])
.per(10)
end end
def edit def edit

View File

@ -5,10 +5,11 @@ class Public::MyAccountController < ApplicationController
before_filter :auth_customer before_filter :auth_customer
def index def index
@needs = Kaminari.paginate_array(current_customer.needs.order(created_at: :desc)) @needs = Kaminari.paginate_array(current_customer.owned_needs.order(created_at: :desc))
.page(params[:page]) .page(params[:page])
.per(5) .per(5)
end end
def edit_infos def edit_infos

View File

@ -4,6 +4,10 @@ class Public::NeedsController < ApplicationController
before_filter :auth_customer before_filter :auth_customer
def index
@needs = Need.shared
end
def new def new
@need = Need.new() @need = Need.new()
end end
@ -51,4 +55,19 @@ class Public::NeedsController < ApplicationController
params.require(:need).permit(:title, :description) params.require(:need).permit(:title, :description)
end end
def wish
@need = Need.find(params[:id])
if (!@need.customers.include?(current_customer))
@need.customers << current_customer
flash[:notice] = "Vous avez signalé votre intérêt pour ce besoin"
else
@need.customers.delete(current_customer)
flash[:error] = "Vous n'être plus marqué comme intéressé par ce besoin"
end
redirect_to :back
end
end end

View File

@ -2,7 +2,9 @@ class Customer < ActiveRecord::Base
# Relationships # Relationships
has_many :needs, foreign_key: 'author_id' has_many :owned_needs, foreign_key: 'author_id', class_name: 'Need'
has_many :wishes
has_many :needs, -> { uniq }, through: :wishes
has_many :customer_favs has_many :customer_favs
has_many :annonce_favs, :through => :customer_favs, :class_name => "Annonce", :source => :annonce has_many :annonce_favs, :through => :customer_favs, :class_name => "Annonce", :source => :annonce

View File

@ -1,15 +1,27 @@
class Need < ActiveRecord::Base class Need < ActiveRecord::Base
include Workflow include Workflow
scope :shared, -> {
where(state: ["verified", "negociating", "negociated", "failed"])
}
scope :top, -> { joins('left join wishes on wishes.need_id = needs.id')
.select('needs.*, count(wishes.id) as wishes_count')
.group("needs.id")
.order("wishes_count DESC") }
workflow_column :state workflow_column :state
max_paginates_per 10 max_paginates_per 10
acts_as_paranoid acts_as_paranoid
has_many :wishes
has_many :customers, -> { uniq }, through: :wishes
validates :title, :presence => true, length: {within: 4..128} validates :title, :presence => true, length: {within: 4..128}
validates :description, presence: true, length: {maximum: 65535} validates :description, presence: true, length: {maximum: 65535}
belongs_to :author, class_name: 'Customer' belongs_to :author, class_name: 'Customer'
# Need's workflow lifecycle # Need's workflow lifecycle
workflow do workflow do
state :created do state :created do

6
app/models/wish.rb Normal file
View File

@ -0,0 +1,6 @@
class Wish < ActiveRecord::Base
belongs_to :customer
belongs_to :need
end

View File

@ -9,5 +9,6 @@
%td.actions{:style => "width:150px;text-align:right"} %td.actions{:style => "width:150px;text-align:right"}
= link_to i(:"trash-o"), [:admin, need], :data => {:confirm => 'Voulez-vous vraiment supprimer ce besoin ?'}, :method => :delete = link_to i(:"trash-o"), [:admin, need], :data => {:confirm => 'Voulez-vous vraiment supprimer ce besoin ?'}, :method => :delete
= link_to i(:pencil), edit_admin_need_path(need) = link_to i(:pencil), edit_admin_need_path(need)
= link_to i(:remove), refuse_admin_need_path(need), title: "Refuser", :data => {:confirm => 'Voulez-vous vraiment refuser ce besoin ?'} -if(need.created?)
= link_to i(:check), validate_admin_need_path(need), title: "Valider", :data => {:confirm => 'Voulez-vous vraiment valider ce besoin ?'} = link_to i(:remove), refuse_admin_need_path(need), title: "Refuser", :data => {:confirm => 'Voulez-vous vraiment refuser ce besoin ?'}
= link_to i(:check), validate_admin_need_path(need), title: "Valider", :data => {:confirm => 'Voulez-vous vraiment valider ce besoin ?'}

View File

@ -1,7 +1,12 @@
%h1 Gestion des besoins %h1 Gestion des besoins
-if @needs_to_validate.length > 0 -if @needs_to_validate.length > 0
%h2 #{pluralize(@needs_to_validate.length, 'besoin')} à contrôler %h2 Modération des besoins
%div.alert.alert-info
Avant qu'un besoin soit visible par l'ensemble des clients, vous devez le valider en cliquant sur le bouton <i class="fa fa-check"></i>
%br
Si pour une raison ou pour une autre le besoin ne respecte pas la charte, cliquez sur le bouton <i class="fa fa-remove"></i>
%table.table.admin_table.table-hover.table-striped %table.table.admin_table.table-hover.table-striped
@ -20,3 +25,27 @@
%tbody.rows %tbody.rows
=render @needs_to_validate =render @needs_to_validate
%h2 Liste des besoins
%table.table.admin_table.table-hover.table-striped
%thead.rows_header
%tr
%td
Titre
%td
Émetteur
%td
Créé
%td{:style => "width:100px"}
&nbsp;
%tbody.rows
=render @needs
.pagination.pull-right= paginate @needs

View File

@ -5,8 +5,6 @@
Titre du besoin Titre du besoin
%th %th
État État
%th
Souhaité par
%th{:style => "width:100px"} %th{:style => "width:100px"}
&nbsp; &nbsp;
%tbody %tbody

View File

@ -5,8 +5,6 @@
=need.title =need.title
%td %td
=need.human_state =need.human_state
%td
%td.actions{:style => "width:150px;text-align:right"} %td.actions{:style => "width:150px;text-align:right"}
-if need.created? or need.refused? -if need.created? or need.refused?
= link_to i(:"trash-o btn btn-default"), [:public, need], :data => {:confirm => 'Voulez-vous vraiment supprimer ce besoin ?'}, method: :delete = link_to i(:"trash-o btn btn-default"), [:public, need], :data => {:confirm => 'Voulez-vous vraiment supprimer ce besoin ?'}, method: :delete

View File

@ -0,0 +1,16 @@
.col-md-6
.padding.need-item
%h3=need.title.upcase
%span
.time= i(:"clock-o") + " Ajouté il y a #{time_ago_in_words(need.created_at)}"
%p=truncate(need.description, length: 100)
-if(need.customers.include?(current_customer))
=link_to i(:"hand-grab-o") + " Ça ne m'intéresse plus", wish_public_need_path(need) , :class => "btn btn-danger pull-right"
-else
=link_to i(:"hand-paper-o") + " Ça m'intéresse", wish_public_need_path(need) , :class => "btn btn-success pull-right"
.clear

View File

@ -0,0 +1,9 @@
.center.row
.row.col-md-9.gutter
=render collection: @needs, partial: 'need_item', as: :need
.row.col-md-3
.white
%h3 Sidebar

View File

@ -4,6 +4,7 @@
-if current_customer -if current_customer
%ul %ul
%li=link_to ic(:star)+" Besoins", public_needs_path, :class => "btn"
%li=link_to ic(:user)+" Mon compte", public_my_account_path, :class => "btn" %li=link_to ic(:user)+" Mon compte", public_my_account_path, :class => "btn"
%li=link_to "Se déconnecter", logout_public_customers_auths_path, :class => "btn" %li=link_to "Se déconnecter", logout_public_customers_auths_path, :class => "btn"
@ -12,4 +13,3 @@
%ul %ul
%li=link_to "S'inscrire", new_public_customer_path(:p => params[:p]), :class => "btn" %li=link_to "S'inscrire", new_public_customer_path(:p => params[:p]), :class => "btn"
%li=link_to "Se connecter", new_public_customers_auth_path(:p => params[:p]), :class => "btn" %li=link_to "Se connecter", new_public_customers_auth_path(:p => params[:p]), :class => "btn"

View File

@ -14,7 +14,9 @@ default: &default
development: development:
<<: *default <<: *default
username: root username: root
socket: /tmp/mysql.sock password: mysqlpassword
socket: /var/run/mysqld/mysqld.sock
# Warning: The database defined as "test" will be erased and # Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake". # re-generated from your development database when you run "rake".

View File

@ -88,7 +88,11 @@ Rails.application.routes.draw do
get 'my_account/my_annonces', :as => "my_annonces" get 'my_account/my_annonces', :as => "my_annonces"
get 'my_account/reconfirm', :as => "reconfirm_email" get 'my_account/reconfirm', :as => "reconfirm_email"
resources :needs resources :needs do
member do
get 'wish', as: 'wish'
end
end
end end
@ -307,14 +311,8 @@ Rails.application.routes.draw do
resources :download_data_files resources :download_data_files
get 'admin' => "admin/admin_auths#index" get 'admin' => "admin/admin_auths#index"
get '*url.html' => 'public/menu_items#show', :as => :menu_item, :f => "html" get '*url.html' => 'public/menu_items#show', :as => :menu_item, :f => "html"
get '*url.:f' => 'public/menu_items#redirect', :f => "html" get '*url.:f' => 'public/menu_items#redirect', :f => "html"

View File

@ -0,0 +1,9 @@
class CreateWishes < ActiveRecord::Migration
def change
create_table :wishes do |t|
t.references :customer
t.references :need
t.timestamps null: false
end
end
end

View File

@ -11,7 +11,7 @@
# #
# It's strongly recommended that you check this file into your version control system. # It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20151201090113) do ActiveRecord::Schema.define(version: 20151202165807) do
create_table "admins", force: :cascade do |t| create_table "admins", force: :cascade do |t|
t.string "name", limit: 255 t.string "name", limit: 255
@ -489,6 +489,13 @@ ActiveRecord::Schema.define(version: 20151201090113) do
t.datetime "updated_at" t.datetime "updated_at"
end end
create_table "wishes", force: :cascade do |t|
t.integer "customer_id", limit: 4
t.integer "need_id", limit: 4
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
add_foreign_key "customer_newsgroups", "customers" add_foreign_key "customer_newsgroups", "customers"
add_foreign_key "customer_newsgroups", "newsgroups" add_foreign_key "customer_newsgroups", "newsgroups"
end end

11
test/fixtures/wishes.yml vendored Normal file
View File

@ -0,0 +1,11 @@
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
# This model initially had no columns defined. If you add columns to the
# model remove the '{}' from the fixture names and add the columns immediately
# below each fixture, per the syntax in the comments below
#
one: {}
# column: value
#
two: {}
# column: value

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

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