This commit is contained in:
Nicolas Bally 2016-10-07 13:51:18 +02:00
parent 7935d77684
commit 1b86493950
29 changed files with 369 additions and 15 deletions

View File

@ -11,6 +11,7 @@
@import "vendor/select2";
@import "admin/topics";
@import "admin/contacts";
#admin_navbar{
border-radius:0px;

View File

@ -0,0 +1,15 @@
#contact_actions{
margin-top:50px;
.contact_action{
margin-bottom:50px;
padding:20px;
border:2px solid black;
.name{
float:right;
}
}
}

View File

@ -0,0 +1,71 @@
class Admin::ContactActionsController < ApplicationController
layout "admin"
before_filter :auth_admin
def index
@contact_actions = ContactAction.order("created_at DESC").all
end
def show
@contact_action = ContactAction.find(params[:id])
@contact_action_actions = @contact_action.contact_action_actions
end
def new
@contact_action = ContactAction.new(:contact_id => params[:contact_id],:admin_id => current_admin.id, :action_at => Time.now)
end
def edit
@contact_action = ContactAction.find(params[:id])
@contact_action.action_at = @contact_action.action_at.in_time_zone("Paris")
end
def create
@contact_action = ContactAction.new(contact_action_params)
@contact = @contact_action.contact
if @contact_action.save
@contact_actions = @contact.contact_actions.order("action_at DESC").all
else
render :action => "new"
end
end
def update
@contact_action = ContactAction.find(params[:id])
@contact = @contact_action.contact
if @contact_action.update_attributes(contact_action_params)
@contact_actions = @contact.contact_actions.order("action_at DESC").all
else
render :action => "edit"
end
end
def destroy
@contact_action = ContactAction.find(params[:id])
@contact_action.destroy
@contact = @contact_action.contact
@contact_actions = @contact.contact_actions.order("action_at DESC").all
end
private
def contact_action_params
params.require(:contact_action).permit!
end
end

View File

@ -5,7 +5,14 @@ class Admin::ContactsController < ApplicationController
def index
@contacts = Contact.order("created_at DESC").all
@contacts = Contact.order("created_at DESC")
if params[:archived]
@contacts = @contacts.where(:archived => true)
else
@contacts = @contacts.where("archived IS NULL or archived = 0")
end
end
@ -16,6 +23,8 @@ class Admin::ContactsController < ApplicationController
@contact.readed = true
@contact.save
end
@contact_actions = @contact.contact_actions
end

View File

@ -1,5 +1,7 @@
class Contact < ActiveRecord::Base
belongs_to :admin
has_many :contact_actions
validates :name, :presence => true
validates :email, :presence => true, :format => /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\Z/i
validates :message, :presence => true

View File

@ -0,0 +1,5 @@
class ContactAction < ActiveRecord::Base
belongs_to :contact
belongs_to :admin
belongs_to :contact_action_pattern
end

View File

@ -0,0 +1,2 @@
class ContactActionPattern < ActiveRecord::Base
end

View File

@ -0,0 +1,27 @@
.contact_action#contact_action{:id => contact_action.id, :style => "border-color:#{contact_action.admin.color};"}
%p.name
-if contact_action.contact.admin
%span{:style => "background:#{contact_action.admin.color};padding:5px 10px;color:white"}
=contact_action.admin.username
%p
=l contact_action.action_at
%p
%strong
-if contact_action.contact_action_pattern
=contact_action.contact_action_pattern.title
%p
= contact_action.action_message
.actions
= link_to i(:"trash-o"), [:admin, contact_action], :confirm => 'Voulez-vous vraiment supprimer cette action ?', :method => :delete, :remote => true
= link_to i(:pencil), edit_admin_contact_action_path(contact_action), :remote => true

View File

@ -0,0 +1,15 @@
= semantic_form_for [:admin, @contact_action], :remote => true do |f|
.content
=f.hidden_field :contact_id
=f.inputs do
= f.input :contact_action_pattern_id, :label => "Action", :collection => (ContactActionPattern.all.map{|u|[ u.title, u.id]}), :as => :select, :include_blank => false
= f.input :action_at, :label => "Date", :as =>:qi_datetime_picker
= f.input :admin_id, :label => "Par ?", :collection => (Admin.where(:contact_role => true).all.map{|u|[ u.username, u.id]}), :as => :select
= f.input :action_message, :label => "Message"
.actions
=f.submit "Sauvegarder", :class => "btn btn-primary"

View File

@ -0,0 +1,63 @@
%table.table
%tr
%td
Date
%td
=l @contact.created_at
%tr
%td
Nom
%td
=@contact.name
%tr
%td
Email
%td
=@contact.email
%tr
%td
Téléphone
%td
=@contact.tel
%tr
%td
Lieu
%td
=@contact.place
%hr
=simple_format @contact.message
%hr
%table.table
%tr
%td
Adresse
%td
=@contact.address
%tr
%td
Adresse suite
%td
=@contact.address2
%tr
%td
Ville
%td
=@contact.cp
=@contact.city
%tr
%td
Pays
%td
=@contact.country
%hr
=simple_format @contact.notes
%hr

View File

@ -0,0 +1,2 @@
$('#contact_actions').html("<%= escape_javascript(render(@contact_actions))%>");
close_pane_hover();

View File

@ -0,0 +1 @@
$('#contact_action_<%= @contact_action.id %>').remove();

View File

@ -0,0 +1,4 @@
.container
%h1 Modifier une fiche étudiant
=render :partial => "form"

View File

@ -0,0 +1 @@
show_pane_hover("<%= escape_javascript(render(:partial => "form"))%>",700,900);

View File

@ -0,0 +1,43 @@
= link_to 'Ajouter une action', new_admin_contact_action_path, :class => "btn btn-primary", :style => "float:right;", :remote => true
%h1 Liste des contact_actions
%table.table.table-hover
%thead#Admin_rows_header.rows_header
%tr
%td
%td
Date
%td
Nom
%td
Coordonnées
%td Géré par
%td{:style => "width:150px"}
&nbsp;
%tbody#admin_rows.rows
=render @contact_actions

View File

@ -0,0 +1,2 @@
$('#Admin_index_block').replaceWith("<%= escape_javascript(render(:partial => "index_block")) %>");

View File

@ -0,0 +1,4 @@
.container
%h1 Ajouter une action
=render :partial => "form"

View File

@ -0,0 +1 @@
show_pane_hover("<%= escape_javascript(render(:partial => "form"))%>",700,900);

View File

@ -0,0 +1,6 @@
= link_to i(:pencil), edit_admin_contact_path(@contact), :remote => true
= link_to "retour", admin_contacts_path(), :class => "btn btn-primary"
#show=render :partial => "show"

View File

@ -0,0 +1,2 @@
$('#contact_actions').html("<%= escape_javascript(render(@contact_actions))%>");
close_pane_hover();

View File

@ -1,23 +1,31 @@
%tr.vertical_center.contact#contact{:id => contact.id, :class => ("success" if !contact.readed)}
%tr.vertical_center.contact#contact{:id => contact.id}
%td{:style => "vertical-align:middle;"}
=image_tag "/provenance/#{contact.provenance_id}.png", :style => "width:20px;border-radius:50%;box-shadow:0 0 3px rgba(0,0,0,0.5)"
%td{:style => "vertical-align:middle;"}
-if !contact.readed
%span{:style => "display:inline-block;width:10px;height:10px;border-radius:50%;background:#00B3EC"}
%td
=l contact.created_at
%td
=contact.name
%td
=contact.email
%td
%br
=contact.tel
%td.actions
%td
-if contact.admin
%span{:style => "background:#{contact.admin.color};padding:5px 10px;color:white"}
=contact.admin.username
%td.actions{:style => "width:430px;text-align:right;"}
= link_to i(:"trash-o"), [:admin, contact], :confirm => 'Voulez-vous vraiment supprimer cet utilisateur ?', :method => :delete, :remote => true
= link_to ic(:"trash-o"), [:admin, contact], :confirm => 'Voulez-vous vraiment supprimer cet utilisateur ?', :method => :delete, :remote => true, :class => "btn btn-danger"
= link_to i(:pencil), edit_admin_contact_path(contact), :remote => true
= link_to ic(:pencil)+" modifier / attribuer la fiche", edit_admin_contact_path(contact), :remote => true, :class => "btn btn-warning"
= link_to i(:eye), [:admin, contact]
= link_to ic(:eye)+ " détail de la fiche ", [:admin, contact], :class => "btn btn-primary"

View File

@ -2,6 +2,8 @@
.content
=f.inputs do
= f.input :readed, :label => "Lu ?"
= f.input :admin_id, :label => "Géré par ?", :collection => (Admin.where(:contact_role => true).all.map{|u|[ u.username, u.id]}), :as => :select
= f.input :archived, :label => "Archivé ?"
= f.input :name, :label => "Nom"
= f.input :email, :label => "Email"
= f.input :tel, :label => "Téléphone"

View File

@ -3,22 +3,26 @@
%h1 Liste des contacts
%p
=link_to "Actifs", admin_contacts_path
=link_to "Archivés", admin_contacts_path(:archived => true)
%table.table.table-hover
%thead#Admin_rows_header.rows_header
%tr
%td
%td
%td
Date
%td
Nom
%td
Email
%td
Tel
Coordonnées
%td Géré par
%td{:style => "width:150px"}
&nbsp;

View File

@ -1,6 +1,32 @@
= link_to i(:pencil), edit_admin_contact_path(@contact), :remote => true
= link_to "retour", admin_contacts_path(), :class => "btn btn-primary"
.right
= link_to "retour", admin_contacts_path(), :class => "btn btn-primary"
= link_to ic(:pencil)+" modifier / attribuer la fiche", edit_admin_contact_path(@contact), :remote => true, :class => "btn btn-warning"
%br
%br
#show=render :partial => "show"
= link_to 'Ajouter une action', new_admin_contact_action_path(:contact_id => @contact.id, :test => "test"), :class => "btn btn-success", :style => "float:right;", :remote => true
%h2 Interactions
#contact_actions
=render @contact_actions

BIN
public/provenance/1.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 30 KiB

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

15
test/fixtures/contact_actions.yml vendored Normal file
View File

@ -0,0 +1,15 @@
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
one:
admin_id: 1
action_at: 2016-09-28 23:16:06
contact_id:
action_title: MyString
action_message: MyText
two:
admin_id: 1
action_at: 2016-09-28 23:16:06
contact_id:
action_title: MyString
action_message: MyText

View File

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

View File

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