messagerie privée

This commit is contained in:
Nicolas Bally 2017-06-06 16:15:40 +02:00
parent 0f03e81385
commit e9d2c53e22
44 changed files with 505 additions and 20 deletions

View File

@ -236,6 +236,9 @@ $("document").ready ->
offset= 0
resize = ->
$(".customer_message_list .height_frame").css
"height" : $(".customer_message_show").height()+"px"
min_height = 0
min_height = $(window).height() - $(".top").height() - $(".top_home").height() - $(".bottom").height() - 30

View File

@ -932,3 +932,37 @@ height: 100%;
}
}
.things, .pseudo{
.customer, .reseaux{
display:inline-block;
margin-left:3px;
margin-right:3px;
padding:2px 8px ;
border-radius:15px;
border:1px solid #d9e0e6;
background:#d0e6fb;
font-weight:normal;
color:#20242d;
}
.reseaux{
background:#cdd89f;
}
}
.sub_commission{
font-weight:normal;
font-size:92%;
}

View File

@ -3,11 +3,11 @@ class Admin::ReseauxesController < ApplicationController
def index
@reseauxes = Reseaux.order(:name)
@reseauxes = Reseaux.where(:parent_id => nil).order(:name)
end
def new
@reseaux = Reseaux.new()
@reseaux = Reseaux.new(:parent_id => params[:parent_id])
end
@ -16,7 +16,13 @@ class Admin::ReseauxesController < ApplicationController
if @reseaux.save
flash[:notice] = "Catégorie créée avec succès."
if @reseaux.parent
redirect_to admin_reseaux_path(@reseaux.parent_id)
else
redirect_to admin_reseauxes_path
end
else
render "new"
@ -37,7 +43,12 @@ class Admin::ReseauxesController < ApplicationController
@reseaux = Reseaux.find(params[:id])
if @reseaux.update_attributes(reseaux_params)
flash[:notice] = "Catégorie modifiée avec succès."
if @reseaux.parent
redirect_to admin_reseaux_path(@reseaux.parent_id)
else
redirect_to admin_reseauxes_path
end
else
render :action => "edit"
@ -49,7 +60,8 @@ class Admin::ReseauxesController < ApplicationController
if @reseaux.destroy
flash[:notice] = "Reseaux supprimée avec succès."
else
flash[:error] = "Impossible de supprimer ce reseaux."
flash[:error] = "Impossible de supprimer ce reseaux
."
end
redirect_to :action => :index

View File

@ -0,0 +1,18 @@
class Public::ConversationsController < ApplicationController
layout "public"
before_filter :auth_customer
def index
end
def show
@conversation = Conversation.find(params[:id])
end
end

View File

@ -14,6 +14,12 @@ class Public::CustomerMessagesController < ApplicationController
@customer_messages = @customer_messages.order("last_message_at DESC, created_at DESC").all
reseaux_ids= current_customer.reseauxes.pluck(:id)
#current_customer.reseauxes.each do |r|
# reseaux_ids += r.children.pluck(:id)
#end
@conversations = Conversation.joins(:thing_conversations).where("(thing_conversations.thing_type = ? and thing_conversations.thing_id = ?) or (thing_conversations.thing_type = ? and thing_conversations.thing_id IN (?))", "Customer", current_customer.id, "Reseaux", reseaux_ids ).uniq
end
@ -57,6 +63,9 @@ class Public::CustomerMessagesController < ApplicationController
def new
@customer_message = CustomerMessage.new(:conversation_id => params[:conversation_id], :thing_type => params[:thing_type], :thing_id => params[:thing_id])
end
@ -68,12 +77,23 @@ class Public::CustomerMessagesController < ApplicationController
def create
@customer_message = CustomerMessage.new(params.require(:customer_message).permit!)
@customer_message.expediteur = current_customer if current_customer
@customer_message.remote_ip = request.remote_ip
@customer_message.last_message_at = Time.now
@customer_message.expediteur = current_customer
if @customer_message.save
if !@customer_message.conversation
@conversation = Conversation.create()
@conversation.thing_conversations << ThingConversation.create(:thing_type => @customer_message.thing_type, :thing_id => @customer_message.thing_id)
@conversation.thing_conversations << ThingConversation.create(:thing_type => "Customer", :thing_id => current_customer.id)
@conversation.customer_messages << @customer_message
else
end
redirect_to public_customer_messages_path
else
render :action => :new
end
end

View File

@ -0,0 +1,13 @@
class Conversation < ActiveRecord::Base
has_many :thing_conversations
#has_many :things, :through => :thing_conversations
has_many :customer_messages
#accepts_nested_attributes_for :customer_messages
end

View File

@ -1,5 +1,14 @@
class Customer < ActiveRecord::Base
has_many :thing_conversations, :as => :thing
has_many :conversations, :through => :thing_conversations
has_many :domains, :through => :domain_customers
has_many :domain_customers, :dependent => :destroy

View File

@ -6,6 +6,9 @@ class CustomerMessage < ActiveRecord::Base
validates :message, :presence => true
acts_as_tree
belongs_to :conversation
attr_accessor :thing_type, :thing_id
def not_blocked
true

View File

@ -9,6 +9,14 @@ class Reseaux < ActiveRecord::Base
has_many :offer_reseauxes
has_many :offers, :through => :offer_reseauxes
has_many :thing_conversations, :as => :thing
has_many :conversations, :through => :thing_conversations
acts_as_tree
before_create do
self.generate_token
end

View File

@ -0,0 +1,5 @@
class ThingConversation < ActiveRecord::Base
belongs_to :conversation
belongs_to :thing, :polymorphic => true
end

View File

@ -11,7 +11,13 @@
.col-sm-6
=f.input :domains, :label => "Domaine : ", :collection => Domain.all, :as => :check_boxes
.col-sm-6
=f.input :reseauxes, :label => "Réseaux : ", :collection => Reseaux.all, :as => :check_boxes
<input type="hidden" name="image_file[reseaux_ids][]" id="image_file_tags_none" value="">
%ul#reseaux_ids_form=render :partial => "admin/reseauxes/reseaux_form", :collection => Reseaux.where(:parent_id => nil).order(:name), :locals => {:form => f}
=f.input :organisation, :label => "Société : "

View File

@ -1,9 +1,16 @@
=semantic_form_for [:admin, @reseaux] do |f|
.content
=f.hidden_field :parent_id
-if @reseaux.parent
%p
Sous réseau de
%strong
=@reseaux.parent.name
=f.inputs do
=f.input :name, :label => "Nom du réseau : "
-if !@reseaux.parent
=f.input :chef_reseau, :label => "Chef réseau : ", :collection => Customer.where(:chef_reseau => true).pluck(Arel.sql("CONCAT(`firstname`, ' ', `name`)"), :id)
.actions= f.submit "Sauvegarder", :class => "btn btn-primary"

View File

@ -0,0 +1,16 @@
-reseaux = reseaux_form
%li
=check_box_tag "customer[reseaux_ids][]", reseaux.id, (true if form.object.reseaux_ids.include?(reseaux.id))
%label
=reseaux.name
-if reseaux.children.count > 0
%ul
=render :partial => "admin/reseauxes/reseaux_form", :collection => reseaux.children, :locals => {:form => form}

View File

@ -3,6 +3,27 @@
%h1 Détail d'un réseau
%h2=@reseaux.name
.right
= link_to "Ajouter un reseaux", new_admin_reseaux_path(:parent_id => @reseaux.id), class:"btn btn-primary"
%h2 Sous réseaux
%table.table.admin_table.table-hover.table-striped
%thead.rows_header
%tr
%th
Nom
%th
Chef réseau
%th
Code
%th Utilisateurs
%th{:style => "width:100px"}
&nbsp;
%tbody.rows
=render @reseaux.children
%h2 Membres du réseau

View File

@ -0,0 +1,8 @@
=link_to [:public, conversation], :class => "customer_message_li", :id => "customer_message_#{conversation.id}", :remote => true do
.time
=l conversation.created_at, :format => "%d/%m/%y"
.pseudo
= render conversation.thing_conversations
.clear

View File

@ -0,0 +1,45 @@
-if customer_message.destinataire == current_customer
-customer_message.readed = true
-customer_message.save
.customer_message_container{:class => ("me" if customer_message.expediteur and customer_message.expediteur == current_customer).to_s }
.side
.square
.pseudo
-if customer_message.expediteur and customer_message.expediteur == current_customer
moi
-else
-if current_customer.own_customers.include?(customer_message.expediteur)
=link_to customer_message.expediteur.anonyme_nick, [:public, customer_message.expediteur]
-else
=customer_message.expediteur.anonyme_nick
.sub_commission
-customer_message.expediteur.reseauxes.where("parent_id is not null").each do |reseaux|
%span=reseaux.name
.time
=l customer_message.created_at, :format => "%d/%m/%y"
.content
-if customer_message.title
%p
=customer_message.title
%hr
=simple_format customer_message.message

View File

@ -0,0 +1,10 @@
.things= render @conversation.thing_conversations
.answer_link
%p{:style => "margin:40px;"}
%center=link_to "Répondre", new_public_customer_message_path(:conversation_id => @conversation.id), :remote => true, :class => "btn btn-primary"
#message_form
#message_answers
=render :partial => "customer_message_show", :collection => @conversation.customer_messages.order("created_at DESC"), :as => :customer_message

View File

@ -0,0 +1 @@
=render :partial => "show"

View File

@ -0,0 +1,4 @@
$(".customer_message_show").html("<%= escape_javascript(render(:partial => "show")) %>");
$(".customer_message_li").removeClass("active");
$("#customer_message_<%= @conversation.id %>").addClass("active");
$("#customer_message_<%= @conversation.id %> .new").hide();

View File

@ -13,6 +13,9 @@
moi
-else
= customer_message.expediteur.anonyme_nick
DF
-customer_message.expediteur.reseauxes.where("parent_id is not null").each do |reseaux|
.sub_reseaux=reseaux.name

View File

@ -20,7 +20,10 @@
=link_to customer_message.expediteur.anonyme_nick, [:public, customer_message.expediteur]
.sub_reseaux
A
-customer_message.expediteur.reseauxes.where("parent_id is not null").each do |reseaux|
=reseaux.name

View File

@ -1,11 +1,19 @@
=semantic_form_for [:public, @customer_message], :url => answer_save_public_customer_message_path(@parent_customer_message), :remote => true do |f|
=semantic_form_for [:public, @customer_message], :remote => (true if @customer_message.id ) do |f|
=#f.input :tel, :label => qit("votre-numero-de-telephone-label","Votre numéro de téléphone :")
=#f.input :expediteur_mail, :label => qit("your-mail-label","Votre mail :")
=f.hidden_field :conversation_id
=f.hidden_field :thing_type
=f.hidden_field :thing_id
=f.input :message, :label => "Message"
=f.hidden_field :destinataire_id
=f.submit "Envoyer mon message", :class => "btn btn-primary"

View File

@ -1,13 +1,15 @@
.center.padding
%h1 Boite de réception
%h1 Conversations
.col-md-3.customer_message_list
.inner.height_frame{:style => "overflow:auto;height:300px;"}
=render @customer_messages
=render @conversations
.col-md-9.customer_message_show_container
.customer_message_show.inner.height_frame{:style => "overflow:auto;height:300px;"}

View File

@ -0,0 +1,8 @@
.center.padding
.things
Message à
-if @customer_message.thing_type == "Reseaux"
.reseaux=Reseaux.find(@customer_message.thing_id).name
-elsif @customer_message.thing_type == "Customer"
.customer=Customer.find(@customer_message.thing_id).anonyme_nick
=render :partial => "form"

View File

@ -0,0 +1,3 @@
$("#message_form").html("<%= escape_javascript(render(:partial => "form")) %>");
$(".answer_link").hide();

View File

@ -27,5 +27,5 @@
%td.actions{:style => "width:150px;text-align:right;"}
=link_to i(:eye), public_customer_path(customer)
=link_to i(:envelope), mail_public_customer_path(customer)
=link_to i(:envelope), new_public_customer_message_path(:thing_type => "Customer", :thing_id => customer.id)

View File

@ -45,6 +45,51 @@
#{ current_customer.full_address}
%p
=link_to "Modifier mes infos", public_edit_infos_path, :class => "btn btn-primary"
.padding.center.white
%h3 Mes réseaux
%table.table.admin_table.table-hover.table-striped
%thead.rows_header
%tr
%th
Nom
%th
%tbody.rows
-current_customer.reseauxes.where(:parent_id => nil).each do |reseaux|
%tr
%td
=reseaux.name
=link_to i(:envelope), new_public_customer_message_path(:thing_type => "Reseaux", :thing_id => reseaux.id)
%td
-if reseaux.chef_reseau
Chef réseaux :
=reseaux.chef_reseau.anonyme_nick
=link_to i(:envelope), new_public_customer_message_path(:thing_type => "Customer", :thing_id => reseaux.chef_reseau.id)
-current_customer.reseauxes.where(:parent_id => reseaux.id).each do |reseaux|
%tr
%td
&nbsp;
&nbsp;
&nbsp;
=reseaux.name
=link_to i(:envelope), new_public_customer_message_path(:thing_type => "Reseaux", :thing_id => reseaux.id)
%td
-if reseaux.chef_reseau
Chef réseaux :
=reseaux.chef_reseau.anonyme_nick
=link_to i(:envelope), new_public_customer_message_path(:thing_type => "Customer", :thing_id => reseaux.chef_reseau.id)
.padding.center.white
%h3
Mes offres acceptées

View File

@ -8,3 +8,4 @@
%td.actions{:style => "width:150px;text-align:right"}
= link_to i(:eye), public_reseaux_path(reseaux)
=link_to i(:envelope), new_public_customer_message_path(:thing_type => "Reseaux", :thing_id => reseaux.id)

View File

@ -1,11 +1,34 @@
-@read_only = true
.center.row
.right
=link_to i(:envelope)+" Ecrire à tout mon réseau", new_public_customer_message_path(:thing_type => "Reseaux", :thing_id => @reseaux.id), :class => "btn btn-primary"
%h1
Mon réseau :
=@reseaux.name
%h3 Sous réseaux
%table.table.admin_table.table-hover.table-striped
%thead.rows_header
%tr
%th
Nom
%th Utilisateurs
%th{:style => "width:100px"}
&nbsp;
%tbody.rows
=render @reseaux.children
%h3 Membres du réseau
%div{:style => "position:relative"}
%table.table.table-hover.table-striped.customer_table
@ -74,7 +97,7 @@
%td.actions{:style => "width:150px;text-align:right;"}
=link_to i(:eye), public_customer_path(customer)
=link_to i(:envelope), mail_public_customer_path(customer)
=link_to i(:envelope), new_public_customer_message_path(:thing_type => "Customer", :thing_id => customer.id)
%div{:style => "position:absolute;top:-30px;right:10px;"}

View File

@ -0,0 +1,20 @@
-if thing_conversation.thing_type == "Customer"
.customer
-if thing_conversation.thing == current_customer
moi
-else
=#link_to thing_conversation.thing.anonyme_nick, [:public, thing_conversation.thing]
=thing_conversation.thing.anonyme_nick
-chef = false
- current_customer.reseauxes.each do |reseaux|
-if thing_conversation.thing == reseaux.chef_reseau
-chef = true
-if chef
(chef réseau)
-if thing_conversation.thing_type == "Reseaux"
.reseaux
=thing_conversation.thing.name

View File

@ -20,7 +20,7 @@ Rails.application.routes.draw do
get 'p/:mlm_token' => "public/customers#parrainage", :as => :mlm_token
namespace :public do
resources :conversations
get 'documents/:download_token', to: 'documents#download', as: :download_document

View File

@ -0,0 +1,5 @@
class AddParentIdToReseauxes < ActiveRecord::Migration
def change
add_column :reseauxes, :parent_id, :integer
end
end

View File

@ -0,0 +1,11 @@
class CreateConversations < ActiveRecord::Migration
def change
create_table :conversations do |t|
t.boolean :oneone
t.integer :first_customer_id
t.string :second_customer_id
t.timestamps null: false
end
end
end

View File

@ -0,0 +1,12 @@
class CreateThingConversations < ActiveRecord::Migration
def change
create_table :thing_conversations do |t|
t.integer :thing_id
t.string :thing_type
t.references :conversation, index: true
t.timestamps null: false
end
add_foreign_key :thing_conversations, :conversations
end
end

View File

@ -0,0 +1,6 @@
class AddConversationToCustomerMessages < ActiveRecord::Migration
def change
add_reference :customer_messages, :conversation, index: true
add_foreign_key :customer_messages, :conversations
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: 20170523073951) do
ActiveRecord::Schema.define(version: 20170605134146) do
create_table "accepted_offers", force: :cascade do |t|
t.datetime "created_at", null: false
@ -158,6 +158,14 @@ ActiveRecord::Schema.define(version: 20170523073951) do
t.datetime "updated_at", null: false
end
create_table "conversations", force: :cascade do |t|
t.boolean "oneone", limit: 1
t.integer "first_customer_id", limit: 4
t.string "second_customer_id", limit: 255
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
create_table "customer_messages", force: :cascade do |t|
t.string "title", limit: 255
t.text "message", limit: 65535
@ -173,8 +181,11 @@ ActiveRecord::Schema.define(version: 20170523073951) do
t.boolean "readed", limit: 1
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.integer "conversation_id", limit: 4
end
add_index "customer_messages", ["conversation_id"], name: "index_customer_messages_on_conversation_id", using: :btree
create_table "customer_newsgroups", force: :cascade do |t|
t.integer "customer_id", limit: 4
t.integer "newsgroup_id", limit: 4
@ -606,6 +617,7 @@ ActiveRecord::Schema.define(version: 20170523073951) do
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.string "token", limit: 255
t.integer "parent_id", limit: 4
end
create_table "sessions", force: :cascade do |t|
@ -659,6 +671,16 @@ ActiveRecord::Schema.define(version: 20170523073951) do
t.datetime "updated_at"
end
create_table "thing_conversations", force: :cascade do |t|
t.integer "thing_id", limit: 4
t.string "thing_type", limit: 255
t.integer "conversation_id", limit: 4
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
add_index "thing_conversations", ["conversation_id"], name: "index_thing_conversations_on_conversation_id", using: :btree
create_table "title_contents", force: :cascade do |t|
t.text "content", limit: 65535
t.integer "level", limit: 4
@ -677,6 +699,7 @@ ActiveRecord::Schema.define(version: 20170523073951) do
t.decimal "qte", precision: 10, scale: 2, default: 1.0
end
add_foreign_key "customer_messages", "conversations"
add_foreign_key "customer_newsgroups", "customers"
add_foreign_key "customer_newsgroups", "newsgroups"
add_foreign_key "domain_customers", "customers"
@ -689,4 +712,5 @@ ActiveRecord::Schema.define(version: 20170523073951) do
add_foreign_key "offer_reseauxes", "reseauxes"
add_foreign_key "reseaux_customers", "customers"
add_foreign_key "reseaux_customers", "reseauxes"
add_foreign_key "thing_conversations", "conversations"
end

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

@ -0,0 +1,11 @@
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
one:
oneone: false
first_customer_id: 1
second_customer_id: MyString
two:
oneone: false
first_customer_id: 1
second_customer_id: MyString

View File

@ -0,0 +1,9 @@
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
one:
customer_id:
conversation_id:
two:
customer_id:
conversation_id:

View File

@ -0,0 +1,9 @@
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
one:
reseaux_id:
conversation_id:
two:
reseaux_id:
conversation_id:

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

@ -0,0 +1,11 @@
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
one:
thing_id: 1
thing_type: MyString
conversation_id:
two:
thing_id: 1
thing_type: MyString
conversation_id:

View File

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

View File

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

View File

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

View File

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