diff --git a/app/assets/stylesheets/admin.css.scss b/app/assets/stylesheets/admin.css.scss index 59ad8a1..4dc6367 100644 --- a/app/assets/stylesheets/admin.css.scss +++ b/app/assets/stylesheets/admin.css.scss @@ -11,6 +11,7 @@ @import "vendor/select2"; @import "admin/topics"; +@import "admin/contacts"; #admin_navbar{ border-radius:0px; diff --git a/app/assets/stylesheets/admin/contacts.scss b/app/assets/stylesheets/admin/contacts.scss new file mode 100644 index 0000000..57761f5 --- /dev/null +++ b/app/assets/stylesheets/admin/contacts.scss @@ -0,0 +1,15 @@ +#contact_actions{ + margin-top:50px; + + .contact_action{ + margin-bottom:50px; + padding:20px; + border:2px solid black; + + .name{ + float:right; + + } + } + +} \ No newline at end of file diff --git a/app/controllers/admin/contact_actions_controller.rb b/app/controllers/admin/contact_actions_controller.rb new file mode 100644 index 0000000..caa6917 --- /dev/null +++ b/app/controllers/admin/contact_actions_controller.rb @@ -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 diff --git a/app/controllers/admin/contacts_controller.rb b/app/controllers/admin/contacts_controller.rb index 0acb1bc..d1602ae 100644 --- a/app/controllers/admin/contacts_controller.rb +++ b/app/controllers/admin/contacts_controller.rb @@ -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 diff --git a/app/models/contact.rb b/app/models/contact.rb index ea4833f..08b528e 100644 --- a/app/models/contact.rb +++ b/app/models/contact.rb @@ -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 diff --git a/app/models/contact_action.rb b/app/models/contact_action.rb new file mode 100644 index 0000000..831d5b6 --- /dev/null +++ b/app/models/contact_action.rb @@ -0,0 +1,5 @@ +class ContactAction < ActiveRecord::Base + belongs_to :contact + belongs_to :admin + belongs_to :contact_action_pattern +end diff --git a/app/models/contact_action_pattern.rb b/app/models/contact_action_pattern.rb new file mode 100644 index 0000000..01118c8 --- /dev/null +++ b/app/models/contact_action_pattern.rb @@ -0,0 +1,2 @@ +class ContactActionPattern < ActiveRecord::Base +end diff --git a/app/views/admin/contact_actions/_contact_action.html.haml b/app/views/admin/contact_actions/_contact_action.html.haml new file mode 100644 index 0000000..801d5be --- /dev/null +++ b/app/views/admin/contact_actions/_contact_action.html.haml @@ -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 + + + + diff --git a/app/views/admin/contact_actions/_form.haml b/app/views/admin/contact_actions/_form.haml new file mode 100644 index 0000000..45bb293 --- /dev/null +++ b/app/views/admin/contact_actions/_form.haml @@ -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" + + \ No newline at end of file diff --git a/app/views/admin/contact_actions/_show.html.haml b/app/views/admin/contact_actions/_show.html.haml new file mode 100644 index 0000000..7478512 --- /dev/null +++ b/app/views/admin/contact_actions/_show.html.haml @@ -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 \ No newline at end of file diff --git a/app/views/admin/contact_actions/create.js.erb b/app/views/admin/contact_actions/create.js.erb new file mode 100644 index 0000000..7586aaf --- /dev/null +++ b/app/views/admin/contact_actions/create.js.erb @@ -0,0 +1,2 @@ +$('#contact_actions').html("<%= escape_javascript(render(@contact_actions))%>"); +close_pane_hover(); \ No newline at end of file diff --git a/app/views/admin/contact_actions/destroy.js.erb b/app/views/admin/contact_actions/destroy.js.erb new file mode 100644 index 0000000..e112011 --- /dev/null +++ b/app/views/admin/contact_actions/destroy.js.erb @@ -0,0 +1 @@ +$('#contact_action_<%= @contact_action.id %>').remove(); \ No newline at end of file diff --git a/app/views/admin/contact_actions/edit.haml b/app/views/admin/contact_actions/edit.haml new file mode 100644 index 0000000..015bb4e --- /dev/null +++ b/app/views/admin/contact_actions/edit.haml @@ -0,0 +1,4 @@ +.container + %h1 Modifier une fiche étudiant + + =render :partial => "form" \ No newline at end of file diff --git a/app/views/admin/contact_actions/edit.js.erb b/app/views/admin/contact_actions/edit.js.erb new file mode 100644 index 0000000..6c8f015 --- /dev/null +++ b/app/views/admin/contact_actions/edit.js.erb @@ -0,0 +1 @@ +show_pane_hover("<%= escape_javascript(render(:partial => "form"))%>",700,900); \ No newline at end of file diff --git a/app/views/admin/contact_actions/index.html.haml b/app/views/admin/contact_actions/index.html.haml new file mode 100644 index 0000000..f151858 --- /dev/null +++ b/app/views/admin/contact_actions/index.html.haml @@ -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"} +   + + + + + %tbody#admin_rows.rows + + =render @contact_actions + + + + + + + + + + + + + diff --git a/app/views/admin/contact_actions/index.js.erb b/app/views/admin/contact_actions/index.js.erb new file mode 100644 index 0000000..6a4e08d --- /dev/null +++ b/app/views/admin/contact_actions/index.js.erb @@ -0,0 +1,2 @@ + +$('#Admin_index_block').replaceWith("<%= escape_javascript(render(:partial => "index_block")) %>"); \ No newline at end of file diff --git a/app/views/admin/contact_actions/new.haml b/app/views/admin/contact_actions/new.haml new file mode 100644 index 0000000..198f5a5 --- /dev/null +++ b/app/views/admin/contact_actions/new.haml @@ -0,0 +1,4 @@ +.container + %h1 Ajouter une action + + =render :partial => "form" \ No newline at end of file diff --git a/app/views/admin/contact_actions/new.js.erb b/app/views/admin/contact_actions/new.js.erb new file mode 100644 index 0000000..6c8f015 --- /dev/null +++ b/app/views/admin/contact_actions/new.js.erb @@ -0,0 +1 @@ +show_pane_hover("<%= escape_javascript(render(:partial => "form"))%>",700,900); \ No newline at end of file diff --git a/app/views/admin/contact_actions/show.html.haml b/app/views/admin/contact_actions/show.html.haml new file mode 100644 index 0000000..dc76093 --- /dev/null +++ b/app/views/admin/contact_actions/show.html.haml @@ -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" + + + diff --git a/app/views/admin/contact_actions/update.js.erb b/app/views/admin/contact_actions/update.js.erb new file mode 100644 index 0000000..7586aaf --- /dev/null +++ b/app/views/admin/contact_actions/update.js.erb @@ -0,0 +1,2 @@ +$('#contact_actions').html("<%= escape_javascript(render(@contact_actions))%>"); +close_pane_hover(); \ No newline at end of file diff --git a/app/views/admin/contacts/_contact.html.haml b/app/views/admin/contacts/_contact.html.haml index d8f17ed..d30753f 100644 --- a/app/views/admin/contacts/_contact.html.haml +++ b/app/views/admin/contacts/_contact.html.haml @@ -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" diff --git a/app/views/admin/contacts/_form.haml b/app/views/admin/contacts/_form.haml index 5fc4cb3..975f03e 100644 --- a/app/views/admin/contacts/_form.haml +++ b/app/views/admin/contacts/_form.haml @@ -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" diff --git a/app/views/admin/contacts/index.html.haml b/app/views/admin/contacts/index.html.haml index de753b7..238a958 100644 --- a/app/views/admin/contacts/index.html.haml +++ b/app/views/admin/contacts/index.html.haml @@ -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"}   diff --git a/app/views/admin/contacts/show.html.haml b/app/views/admin/contacts/show.html.haml index dc76093..c332ad9 100644 --- a/app/views/admin/contacts/show.html.haml +++ b/app/views/admin/contacts/show.html.haml @@ -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 + + + + + + + + + + + + + + + diff --git a/public/provenance/1.png b/public/provenance/1.png new file mode 100644 index 0000000..21a1073 Binary files /dev/null and b/public/provenance/1.png differ diff --git a/test/fixtures/contact_action_patterns.yml b/test/fixtures/contact_action_patterns.yml new file mode 100644 index 0000000..97fbfc4 --- /dev/null +++ b/test/fixtures/contact_action_patterns.yml @@ -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 diff --git a/test/fixtures/contact_actions.yml b/test/fixtures/contact_actions.yml new file mode 100644 index 0000000..f8c1bc2 --- /dev/null +++ b/test/fixtures/contact_actions.yml @@ -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 diff --git a/test/models/contact_action_pattern_test.rb b/test/models/contact_action_pattern_test.rb new file mode 100644 index 0000000..6f8c5b6 --- /dev/null +++ b/test/models/contact_action_pattern_test.rb @@ -0,0 +1,7 @@ +require 'test_helper' + +class ContactActionPatternTest < ActiveSupport::TestCase + # test "the truth" do + # assert true + # end +end diff --git a/test/models/contact_action_test.rb b/test/models/contact_action_test.rb new file mode 100644 index 0000000..8234f3c --- /dev/null +++ b/test/models/contact_action_test.rb @@ -0,0 +1,7 @@ +require 'test_helper' + +class ContactActionTest < ActiveSupport::TestCase + # test "the truth" do + # assert true + # end +end