diff --git a/app/assets/stylesheets/public.scss b/app/assets/stylesheets/public.scss
index 23e3515..d8939d0 100644
--- a/app/assets/stylesheets/public.scss
+++ b/app/assets/stylesheets/public.scss
@@ -11,9 +11,7 @@
@import "public/binary";
@import "public/account";
@import "public/affiliation";
-
-
-
+@import "public/need";
diff --git a/app/assets/stylesheets/public/need.scss b/app/assets/stylesheets/public/need.scss
new file mode 100644
index 0000000..7589c9c
--- /dev/null
+++ b/app/assets/stylesheets/public/need.scss
@@ -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;
+ }
+
+}
diff --git a/app/controllers/admin/needs_controller.rb b/app/controllers/admin/needs_controller.rb
index b1f55e2..7463e69 100644
--- a/app/controllers/admin/needs_controller.rb
+++ b/app/controllers/admin/needs_controller.rb
@@ -2,7 +2,14 @@ class Admin::NeedsController < ApplicationController
layout "admin"
def index
+
+ # Get all needs to validate
@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
def edit
diff --git a/app/controllers/public/my_account_controller.rb b/app/controllers/public/my_account_controller.rb
index 0ab1ace..81bc954 100644
--- a/app/controllers/public/my_account_controller.rb
+++ b/app/controllers/public/my_account_controller.rb
@@ -5,10 +5,11 @@ class Public::MyAccountController < ApplicationController
before_filter :auth_customer
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])
.per(5)
+
end
def edit_infos
diff --git a/app/controllers/public/needs_controller.rb b/app/controllers/public/needs_controller.rb
index 8c65aa3..1841270 100644
--- a/app/controllers/public/needs_controller.rb
+++ b/app/controllers/public/needs_controller.rb
@@ -4,6 +4,10 @@ class Public::NeedsController < ApplicationController
before_filter :auth_customer
+ def index
+ @needs = Need.shared
+ end
+
def new
@need = Need.new()
end
@@ -51,4 +55,19 @@ class Public::NeedsController < ApplicationController
params.require(:need).permit(:title, :description)
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
diff --git a/app/models/customer.rb b/app/models/customer.rb
index 45cf9d8..ab3437c 100644
--- a/app/models/customer.rb
+++ b/app/models/customer.rb
@@ -2,7 +2,9 @@ class Customer < ActiveRecord::Base
# 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 :annonce_favs, :through => :customer_favs, :class_name => "Annonce", :source => :annonce
diff --git a/app/models/need.rb b/app/models/need.rb
index 5f88e86..6476944 100644
--- a/app/models/need.rb
+++ b/app/models/need.rb
@@ -1,15 +1,27 @@
class Need < ActiveRecord::Base
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
max_paginates_per 10
acts_as_paranoid
+ has_many :wishes
+ has_many :customers, -> { uniq }, through: :wishes
validates :title, :presence => true, length: {within: 4..128}
validates :description, presence: true, length: {maximum: 65535}
belongs_to :author, class_name: 'Customer'
+
# Need's workflow lifecycle
workflow do
state :created do
diff --git a/app/models/wish.rb b/app/models/wish.rb
new file mode 100644
index 0000000..4939408
--- /dev/null
+++ b/app/models/wish.rb
@@ -0,0 +1,6 @@
+class Wish < ActiveRecord::Base
+ belongs_to :customer
+ belongs_to :need
+
+
+end
diff --git a/app/views/admin/needs/_need.html.haml b/app/views/admin/needs/_need.html.haml
index 50def80..24b4824 100644
--- a/app/views/admin/needs/_need.html.haml
+++ b/app/views/admin/needs/_need.html.haml
@@ -9,5 +9,6 @@
%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(: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 ?'}
- = link_to i(:check), validate_admin_need_path(need), title: "Valider", :data => {:confirm => 'Voulez-vous vraiment valider ce besoin ?'}
+ -if(need.created?)
+ = 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 ?'}
diff --git a/app/views/admin/needs/index.html.haml b/app/views/admin/needs/index.html.haml
index 46a45ee..0a3745f 100644
--- a/app/views/admin/needs/index.html.haml
+++ b/app/views/admin/needs/index.html.haml
@@ -1,7 +1,12 @@
%h1 Gestion des besoins
+
-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
+ %br
+ Si pour une raison ou pour une autre le besoin ne respecte pas la charte, cliquez sur le bouton
%table.table.admin_table.table-hover.table-striped
@@ -20,3 +25,27 @@
%tbody.rows
=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"}
+
+
+ %tbody.rows
+
+ =render @needs
+
+
+.pagination.pull-right= paginate @needs
diff --git a/app/views/public/needs/_index.html.haml b/app/views/public/needs/_index.html.haml
index 125ca23..b431c1e 100644
--- a/app/views/public/needs/_index.html.haml
+++ b/app/views/public/needs/_index.html.haml
@@ -5,8 +5,6 @@
Titre du besoin
%th
État
- %th
- Souhaité par
%th{:style => "width:100px"}
%tbody
diff --git a/app/views/public/needs/_need.html.haml b/app/views/public/needs/_need.html.haml
index db58a91..eb127a4 100644
--- a/app/views/public/needs/_need.html.haml
+++ b/app/views/public/needs/_need.html.haml
@@ -5,8 +5,6 @@
=need.title
%td
=need.human_state
- %td
-
%td.actions{:style => "width:150px;text-align:right"}
-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
diff --git a/app/views/public/needs/_need_item.html.haml b/app/views/public/needs/_need_item.html.haml
new file mode 100644
index 0000000..3bb43ed
--- /dev/null
+++ b/app/views/public/needs/_need_item.html.haml
@@ -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
diff --git a/app/views/public/needs/index.html.haml b/app/views/public/needs/index.html.haml
new file mode 100644
index 0000000..930f39a
--- /dev/null
+++ b/app/views/public/needs/index.html.haml
@@ -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
diff --git a/app/views/public/shared/_menu.html.haml b/app/views/public/shared/_menu.html.haml
index 84488a8..3dc4dac 100644
--- a/app/views/public/shared/_menu.html.haml
+++ b/app/views/public/shared/_menu.html.haml
@@ -4,12 +4,12 @@
-if current_customer
%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 "Se déconnecter", logout_public_customers_auths_path, :class => "btn"
-
-
+
+
-else
%ul
%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"
-
\ No newline at end of file
diff --git a/config/database.yml b/config/database.yml
index 240f2d9..c26b1ba 100644
--- a/config/database.yml
+++ b/config/database.yml
@@ -14,7 +14,9 @@ default: &default
development:
<<: *default
username: root
- socket: /tmp/mysql.sock
+ password: mysqlpassword
+ socket: /var/run/mysqld/mysqld.sock
+
# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
diff --git a/config/routes.rb b/config/routes.rb
index ac8b33d..3b1f099 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -88,7 +88,11 @@ Rails.application.routes.draw do
get 'my_account/my_annonces', :as => "my_annonces"
get 'my_account/reconfirm', :as => "reconfirm_email"
- resources :needs
+ resources :needs do
+ member do
+ get 'wish', as: 'wish'
+ end
+ end
end
@@ -307,14 +311,8 @@ Rails.application.routes.draw do
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"
diff --git a/db/migrate/20151202165807_create_wishes.rb b/db/migrate/20151202165807_create_wishes.rb
new file mode 100644
index 0000000..9168022
--- /dev/null
+++ b/db/migrate/20151202165807_create_wishes.rb
@@ -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
diff --git a/db/schema.rb b/db/schema.rb
index 505978e..e7bc365 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: 20151201090113) do
+ActiveRecord::Schema.define(version: 20151202165807) do
create_table "admins", force: :cascade do |t|
t.string "name", limit: 255
@@ -489,6 +489,13 @@ ActiveRecord::Schema.define(version: 20151201090113) do
t.datetime "updated_at"
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", "newsgroups"
end
diff --git a/test/fixtures/wishes.yml b/test/fixtures/wishes.yml
new file mode 100644
index 0000000..937a0c0
--- /dev/null
+++ b/test/fixtures/wishes.yml
@@ -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
diff --git a/test/models/wish_test.rb b/test/models/wish_test.rb
new file mode 100644
index 0000000..a1f098a
--- /dev/null
+++ b/test/models/wish_test.rb
@@ -0,0 +1,7 @@
+require 'test_helper'
+
+class WishTest < ActiveSupport::TestCase
+ # test "the truth" do
+ # assert true
+ # end
+end