diff --git a/app/assets/stylesheets/admin.css.scss b/app/assets/stylesheets/admin.css.scss index 5a588a3..5438d6f 100644 --- a/app/assets/stylesheets/admin.css.scss +++ b/app/assets/stylesheets/admin.css.scss @@ -121,7 +121,11 @@ body.admin{ } - +.message-item{ + padding:10px; + background: #eeeded; + margin-bottom:20px; +} padding:0px; diff --git a/app/controllers/admin/messages_controller.rb b/app/controllers/admin/messages_controller.rb new file mode 100644 index 0000000..83a249f --- /dev/null +++ b/app/controllers/admin/messages_controller.rb @@ -0,0 +1,23 @@ +class Admin::MessagesController < ApplicationController + layout "admin" + before_filter :auth_admin + + + def index + @need = Need.find(params[:need_id]) + @comments = @need.messages.order(created_at: :desc).page params[:page] + + end + + def destroy + @message = Message.find(params['id']) + if @message.destroy + flash[:notice] = "Commentaire supprimé" + else + flash[:error] = "Impossible de supprimer ce commentaire" + end + + redirect_to :back + end + +end diff --git a/app/controllers/admin/needs_controller.rb b/app/controllers/admin/needs_controller.rb index 35383c4..d75c50e 100644 --- a/app/controllers/admin/needs_controller.rb +++ b/app/controllers/admin/needs_controller.rb @@ -1,21 +1,87 @@ class Admin::NeedsController < ApplicationController layout "admin" before_filter :auth_admin - before_action :build_category_tree, only:[:new, :update, :create, :edit] + before_action :build_category_tree, only:[:new, :update, :create, :edit, :index] 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) + + @needs = Need.shared + + # filters default value + params[:o] ||= 'created-desc' + params[:r] ||= 10 + + # Include search in the query + if(params[:q] != '') + @needs = @needs.search(params[:q]) + end + + if(params[:c] and params[:c] != '') + @category = NeedCategory.find(params[:c]) + ids = @category.child_ids + @needs = @needs.where(category_id: ids) + end + + # Include order in the query + case params[:o] + when 'alpha-asc' + @needs = @needs.order(title: :asc) + when 'alpha-desc' + @needs = @needs.order(title: :desc) + when 'wishes-asc' + @needs = @needs.with_wishes_count.order('wishes_count ASC') + when 'wishes-desc' + @needs = @needs.with_wishes_count.order('wishes_count DESC') + when 'created-asc' + @needs = @needs.order(created_at: :asc) + when 'created-desc' + @needs = @needs.order(created_at: :desc) + when 'comments-asc' + @needs = @needs.with_messages_count.order('messages_count ASC') + when 'comments-desc' + @needs = @needs.with_messages_count.order('messages_count DESC') + end + + # Paginate + @needs = @needs.page(params[:page]).per(params[:r]) + + + # Define order select options + @orders = { + "Les plus récents" => 'created-desc', + "Les plus populaires" => 'wishes-desc', + "Les plus commentés" => 'comments-desc', + "Alphabétique (de A à Z)" => 'alpha-asc', + "Alphabétique (de Z à A)" => 'alpha-desc' + } + + end + + def new + @need = Need.new() + @comments = @need.messages.order(created_at: :desc).page params[:page] + end + + def create + @need = Need.new(need_params) + + if @need.update_attributes(need_params) + flash[:notice] = "Besoin créé avec succès." + @need.validate! + redirect_to admin_needs_path + else + render :action => "new" + end end def edit + @need = Need.find(params[:id]) + end def update @@ -61,7 +127,7 @@ class Admin::NeedsController < ApplicationController private def need_params - params.require(:need).permit(:title, :description, :category_id) + params.require(:need).permit(:title, :description, :category_id, :author_id) end def build_category_tree diff --git a/app/controllers/admin/wishes_controller.rb b/app/controllers/admin/wishes_controller.rb new file mode 100644 index 0000000..5ab8541 --- /dev/null +++ b/app/controllers/admin/wishes_controller.rb @@ -0,0 +1,22 @@ +class Admin::WishesController < ApplicationController + layout "admin" + before_filter :auth_admin + + + def index + @need = Need.find(params[:need_id]) + @wishes = @need.wishes.order(created_at: :desc).page params[:page] + + end + + def destroy + @wish = Wish.find(params[:id]) + if(@wish.destroy) + flash[:notice] = "Intérêt supprimé avec succès." + end + redirect_to :back + end + + + +end diff --git a/app/views/admin/customers/index.html.haml b/app/views/admin/customers/index.html.haml index 85bf8f6..268959e 100644 --- a/app/views/admin/customers/index.html.haml +++ b/app/views/admin/customers/index.html.haml @@ -2,45 +2,33 @@ - + %table.table.table-hover.table-striped.customer_table %thead#customer_rows_header.rows_header - + %tr - %td + %th Société - %td + %th Nom - - %td + + %th Ville - %td + %th Email confirmé ? - %td + %th Email - - - - %td{:style => "width:100px"} + + + + %th{:style => "width:100px"}   - - - - + + + + %tbody#customer_rows.rows - + =render @customers - + .pagination= paginate @customers - - - - - - - - - - - - diff --git a/app/views/admin/messages/_message.html.haml b/app/views/admin/messages/_message.html.haml new file mode 100644 index 0000000..2917573 --- /dev/null +++ b/app/views/admin/messages/_message.html.haml @@ -0,0 +1,9 @@ +.white.padding.message-item + + %h4=message.customer.anonyme_nick + %p.info="Posté le #{message.created_at.strftime('%d/%m/%Y à %H:%M')}, il y a #{time_ago_in_words(message.created_at)}" + + + %p= message.content + + =link_to "Supprimer", [:admin, @need, message], class: "btn btn-danger", method: "delete" diff --git a/app/views/admin/messages/index.html.haml b/app/views/admin/messages/index.html.haml new file mode 100644 index 0000000..e98cf3f --- /dev/null +++ b/app/views/admin/messages/index.html.haml @@ -0,0 +1,7 @@ +%h1= "Commentaires du besoin #{@need.title}" + +%h4= " #{pluralize(@need.messages.count, 'Commentaire')} pour ce besoin" + +=render collection: @comments, partial: 'message' + +.pagination= paginate @comments diff --git a/app/views/admin/needs/_form.html.haml b/app/views/admin/needs/_form.html.haml index 0965c35..08be0de 100644 --- a/app/views/admin/needs/_form.html.haml +++ b/app/views/admin/needs/_form.html.haml @@ -2,9 +2,15 @@ .content + + + =f.inputs do =f.input :title, :label => "Titre : " - =f.input :category, :as => :select, :collection => @tree.map{|c| [(c.level > 0 ? ('   ' * (c.level - 1)) + "|- ": "").html_safe + c.name, c.id]}, label: "Catégorie de besoin" + =f.input :category, include_blank: "Toute catégorie", :as => :select, :collection => @tree.map{|c| [(c.level > 0 ? ('   ' * (c.level - 1)) + "|- ": "").html_safe + c.name, c.id]}, label: "Catégorie de besoin" =f.input :description, :label => "Description : ", :rows => 5, :input_html => {:style => "height:100px;"} + =f.input :author, :label => "Auteur", include_blank: "Administrateur" + =f.input :created_at, :label => "Créé le", disabled: true + =f.input :updated_at, :label => "Dernière modification le", disabled: true .actions= f.submit "Sauvegarder", :class => "btn btn-primary" diff --git a/app/views/admin/needs/_need.html.haml b/app/views/admin/needs/_need.html.haml index 24b4824..320ffb7 100644 --- a/app/views/admin/needs/_need.html.haml +++ b/app/views/admin/needs/_need.html.haml @@ -1,11 +1,21 @@ %tr{:id => need.id} %td - =need.title + =link_to need.title, edit_admin_need_path(need) %td - =link_to need.author.organisation, edit_admin_customer_path(need.author) + -if need.category + =link_to need.category.name, edit_admin_need_category_path(need.category) + %td - Il y a #{time_ago_in_words( need.created_at)} + -if need.author + =link_to need.author.organisation, edit_admin_customer_path(need.author) + -else + Administrateur + + %td{style: 'text-align:center' } + =link_to i(:"hand-paper-o") + " " + need.wishes.length.to_s, admin_need_wishes_path(need) +    + =link_to i(:"comment-o") + " " + need.messages.length.to_s, admin_need_messages_path(need) %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) diff --git a/app/views/admin/needs/_need_to_validate.html.haml b/app/views/admin/needs/_need_to_validate.html.haml new file mode 100644 index 0000000..9207097 --- /dev/null +++ b/app/views/admin/needs/_need_to_validate.html.haml @@ -0,0 +1,22 @@ + +%tr{:id => need.id} + %td + =link_to need.title, edit_admin_need_path(need) + %td + -if need.category + =link_to need.category.name, edit_admin_need_category_path(need.category) + + %td + -if need.author + =link_to need.author.organisation, edit_admin_customer_path(need.author) + -else + Administrateur + %td + Il y a #{time_ago_in_words( need.created_at)} + + %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) + -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 0a3745f..48db7ea 100644 --- a/app/views/admin/needs/index.html.haml +++ b/app/views/admin/needs/index.html.haml @@ -13,39 +13,68 @@ %thead.rows_header %tr - %td + %th Titre - %td + %th + Catégorie + %th Émetteur - %td + %th Créé - %td{:style => "width:100px"} + %th{:style => "width:100px"}   %tbody.rows - =render @needs_to_validate + =render collection: @needs_to_validate, partial: 'need_to_validate', as: :need + %br + + +%h2 Liste des besoins +.row + .col-md-2 + + = semantic_form_for :search, :html => {id: :search_form, :method => :get } do |f| + = f.inputs do + =f.input :q, :as => :search, label: "Recherche", input_html: {value: params[:q], :name => 'q' }, placeholder: "Rechercher un besoin" + .clear + = f.inputs do + = f.input :o, as: :order, selected: params[:o], input_html: {:name => 'o' }, label: "Ordre d'affichage", :include_blank => false , :as => :select, :collection => @orders + .clear + = f.inputs do + = f.input :r, as: :result, selected: params[:r], input_html: {:name => 'r' }, label: 'Résultats par page', :include_blank => false , :as => :select, :collection => [10,20,50,100] + .clear + = f.inputs do + = f.input :c, as: :category, selected: params[:c], input_html: {:name => 'c' }, label: 'Filtrer par catégorie', :include_blank => "Toute catégorie" , :as => :select, :collection => @tree.map{|c| [(c.level > 0 ? ('   ' * (c.level - 1)) + "|- ": "").html_safe + c.name, c.id]} + .clear + = link_to "Créer un besoin", new_admin_need_path, class:"btn btn-primary" + + .col-md-10 + %table.table.admin_table.table-hover.table-striped + %thead.rows_header + + %tr + %th + Titre + %th + Catégorie + %th + Émetteur + + %th{style: 'text-align:center' } + Commentaires/Intérêts + %th{:style => "width:100px"} +   + + %tbody.rows + + =render @needs + + .pagination.pull-right= paginate @needs - %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 +:javascript + $('#search_o').change(function(){$('#search_form').submit()}) + $('#search_r').change(function(){$('#search_form').submit()}) + $('#search_c').change(function(){$('#search_form').submit()}) diff --git a/app/views/admin/needs/new.html.haml b/app/views/admin/needs/new.html.haml new file mode 100644 index 0000000..54843a2 --- /dev/null +++ b/app/views/admin/needs/new.html.haml @@ -0,0 +1,2 @@ +%h1 Créer un nouveau besoin +=render :partial => "form" diff --git a/app/views/admin/wishes/_wish.html.haml b/app/views/admin/wishes/_wish.html.haml new file mode 100644 index 0000000..f833c7e --- /dev/null +++ b/app/views/admin/wishes/_wish.html.haml @@ -0,0 +1,8 @@ + +%tr{:id => wish.id} + %td + =link_to wish.customer.organisation, edit_admin_customer_path(wish.customer) + %td + =wish.created_at + %td.actions{:style => "width:150px;text-align:right"} + = link_to i(:"remove"), [:admin, @need, wish], :data => {:confirm => "Voulez-vous vraiment supprimer l'intérêt de cet utilisateur pour ce besoin ?"}, :method => :delete diff --git a/app/views/admin/wishes/index.html.haml b/app/views/admin/wishes/index.html.haml new file mode 100644 index 0000000..27b105c --- /dev/null +++ b/app/views/admin/wishes/index.html.haml @@ -0,0 +1,21 @@ +%h1= "Utilisateurs intéressés par le besoin #{@need.title}" + +-if @wishes.length > 0 + %table.table.admin_table.table-hover.table-striped + %thead.rows_header + + %tr + %th + Utilisateur + %th + Intéressé le + %th{:style => "width:100px"} +   + + %tbody.rows + + =render @wishes + + .pagination.pull-right= paginate @wishes +-else + Aucun intérêt enregistré pour ce besoin pour le moment diff --git a/app/views/public/needs/_form.html.haml b/app/views/public/needs/_form.html.haml index 553a321..84aab73 100644 --- a/app/views/public/needs/_form.html.haml +++ b/app/views/public/needs/_form.html.haml @@ -1,7 +1,7 @@ = semantic_form_for [:public, @need] do |f| =f.inputs do = f.input :title, :label => "Titre de votre besoin" - =f.input :category, :as => :select, :collection => @tree.map{|c| [(c.level > 0 ? ('   ' * (c.level - 1)) + "|- ": "").html_safe + c.name, c.id]}, label: "Catégorie de besoin" + = f.input :category, :as => :select, include_blank: "Toute catégorie", :collection => @tree.map{|c| [(c.level > 0 ? ('   ' * (c.level - 1)) + "|- ": "").html_safe + c.name, c.id]}, label: "Catégorie de besoin" = f.input :description, :label => "Description", :rows => 5, :input_html => {:style => "height:100px;"} %br =f.submit "Sauvegarder", :class => "btn btn-primary" diff --git a/app/views/public/needs/_index.html.haml b/app/views/public/needs/_index.html.haml index 6b94ccd..62680f9 100644 --- a/app/views/public/needs/_index.html.haml +++ b/app/views/public/needs/_index.html.haml @@ -3,6 +3,8 @@ %tr %th Titre du besoin + %th + Catégorie %th État %th{:style => "width:100px"} diff --git a/app/views/public/needs/_need.html.haml b/app/views/public/needs/_need.html.haml index 6951c2a..98d3b09 100644 --- a/app/views/public/needs/_need.html.haml +++ b/app/views/public/needs/_need.html.haml @@ -3,6 +3,9 @@ %tr{:id => need.id, class: css_class} %td =link_to need.title, public_need_path(need) + %td + -if need.category + =need.category.name %td =need.human_state %td.actions{:style => "width:150px;text-align:right"} diff --git a/app/views/public/needs/_need_item.html.haml b/app/views/public/needs/_need_item.html.haml index d9cd27f..dbbe475 100644 --- a/app/views/public/needs/_need_item.html.haml +++ b/app/views/public/needs/_need_item.html.haml @@ -4,8 +4,10 @@ %h4 =link_to need.title.upcase, public_need_path(need) - - %p.info=i(:"clock-o") + " Ajouté il y a #{time_ago_in_words(need.created_at)} par #{need.author.anonyme_nick}" + -if need.author + %p.info=i(:"clock-o") + " Ajouté il y a #{time_ago_in_words(need.created_at)} par #{need.author.anonyme_nick}" + -else + %p.info=i(:"clock-o") + " Ajouté il y a #{time_ago_in_words(need.created_at)}" -if need.category diff --git a/app/views/public/needs/_wish.html.haml b/app/views/public/needs/_wish.html.haml index ffbd07e..ffddb8c 100644 --- a/app/views/public/needs/_wish.html.haml +++ b/app/views/public/needs/_wish.html.haml @@ -2,6 +2,9 @@ %tr{:id => wish.id} %td =link_to wish.title, public_need_path(wish) + %td + -if wish.category + =wish.category.name %td =wish.human_state %td{style: 'text-align:center' } diff --git a/app/views/public/needs/_wishes_index.html.haml b/app/views/public/needs/_wishes_index.html.haml index 16045d9..a86192f 100644 --- a/app/views/public/needs/_wishes_index.html.haml +++ b/app/views/public/needs/_wishes_index.html.haml @@ -3,6 +3,8 @@ %tr %th Titre + %th + Catégorie %th État %th{style: 'text-align:center'} @@ -14,5 +16,3 @@ %tbody =render partial: "public/needs/wish", collection: @wishes, as: :wish - - diff --git a/app/views/public/needs/index.html.haml b/app/views/public/needs/index.html.haml index f98fa27..1da8f17 100644 --- a/app/views/public/needs/index.html.haml +++ b/app/views/public/needs/index.html.haml @@ -11,26 +11,17 @@ .row.col-md-3 .white.side-menu = semantic_form_for :search, :html => {id: :search_form, :method => :get } do |f| - = f.inputs do - =f.input :q, :as => :search, label: "Recherche", input_html: {value: params[:q], :name => 'q' }, placeholder: "Rechercher un besoin" - .clear - = f.inputs do = f.input :o, as: :order, selected: params[:o], input_html: {:name => 'o' }, label: "Ordre d'affichage", :include_blank => false , :as => :select, :collection => @orders - .clear - = f.inputs do = f.input :r, as: :result, selected: params[:r], input_html: {:name => 'r' }, label: 'Résultats par page', :include_blank => false , :as => :select, :collection => [6,12,24,48] - .clear - = f.inputs do - = f.input :c, as: :category, selected: params[:c], input_html: {:name => 'c' }, label: 'Filtrer par catégorie', :include_blank => true , :as => :select, :collection => @tree.map{|c| [(c.level > 0 ? ('   ' * (c.level - 1)) + "|- ": "").html_safe + c.name, c.id]} - + = f.input :c, as: :category, selected: params[:c], input_html: {:name => 'c' }, label: 'Filtrer par catégorie', :include_blank => "Toute catégorie" , :as => :select, :collection => @tree.map{|c| [(c.level > 0 ? ('   ' * (c.level - 1)) + "|- ": "").html_safe + c.name, c.id]} .clear :javascript diff --git a/app/views/public/needs/show.html.haml b/app/views/public/needs/show.html.haml index 00378bd..b8082c6 100644 --- a/app/views/public/needs/show.html.haml +++ b/app/views/public/needs/show.html.haml @@ -2,7 +2,12 @@ .show-need %h1= @need.title.upcase + -if @need.author %p.info=i(:"clock-o") + " Ajouté il y a #{time_ago_in_words(@need.created_at)} par #{@need.author.anonyme_nick}" + -else + %p.info=i(:"clock-o") + " Ajouté il y a #{time_ago_in_words(@need.created_at)}" + + %p.info=i(:"tag") + " " + @need.category_path %p.description= @need.description diff --git a/config/routes.rb b/config/routes.rb index 9c102fe..764742f 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -242,11 +242,14 @@ Rails.application.routes.draw do resources :need_categories resources :needs do + resources :messages + resources :wishes member do get :validate get :refuse end end + resources :customers do member do get :validate