admin domain interface
This commit is contained in:
parent
9b801f0a85
commit
eb5a05c328
65
app/controllers/admin/domains_controller.rb
Executable file
65
app/controllers/admin/domains_controller.rb
Executable file
@ -0,0 +1,65 @@
|
||||
class Admin::DomainsController < ApplicationController
|
||||
layout "admin"
|
||||
before_action :build_tree, only:[:new, :edit, :index]
|
||||
|
||||
|
||||
def index
|
||||
@domains = Domain.order(:name)
|
||||
end
|
||||
|
||||
def new
|
||||
@category = Domain.new()
|
||||
|
||||
end
|
||||
|
||||
def create
|
||||
@category = Domain.new(domain_params)
|
||||
|
||||
if @category.save
|
||||
flash[:notice] = "Catégorie créée avec succès."
|
||||
redirect_to admin_domains_path
|
||||
else
|
||||
|
||||
render "new"
|
||||
end
|
||||
end
|
||||
|
||||
def edit
|
||||
@category = Domain.find(params[:id])
|
||||
|
||||
end
|
||||
|
||||
def update
|
||||
@category = Domain.find(params[:id])
|
||||
if @category.update_attributes(domain_params)
|
||||
flash[:notice] = "Catégorie modifiée avec succès."
|
||||
redirect_to admin_domains_path
|
||||
else
|
||||
|
||||
render :action => "edit"
|
||||
end
|
||||
end
|
||||
|
||||
def destroy
|
||||
@category = Domain.find(params[:id])
|
||||
if @category.destroy
|
||||
flash[:notice] = "Catégorie supprimée avec succès."
|
||||
else
|
||||
flash[:error] = "Impossible de supprimer cette catégorie."
|
||||
end
|
||||
|
||||
render "index"
|
||||
end
|
||||
|
||||
def domain_params
|
||||
params.require(:domain).permit(:parent_id, :name)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def build_tree
|
||||
|
||||
|
||||
end
|
||||
|
||||
end
|
@ -52,7 +52,7 @@ class Admin::NeedCategoriesController < ApplicationController
|
||||
end
|
||||
|
||||
def need_category_params
|
||||
params.require(:need_category).permit(:parent_id, :name)
|
||||
params.require(:need_category).permit!
|
||||
end
|
||||
|
||||
private
|
||||
|
@ -165,7 +165,8 @@ class Admin::NeedsController < ApplicationController
|
||||
private
|
||||
|
||||
def need_params
|
||||
params.require(:need).permit(:title, :image_file_id, :description, :category_id, :author_id)
|
||||
params.require(:need).permit!
|
||||
#params.require(:need).permit(:domain_ids, :title, :image_file_id, :description, :category_id, :author_id)
|
||||
end
|
||||
|
||||
def build_category_tree
|
||||
|
@ -13,6 +13,7 @@ class Public::NeedsController < ApplicationController
|
||||
|
||||
# Get only public needs
|
||||
@needs = Need.shared
|
||||
#@needs = @needs.domain_in(current_customer.domain_ids)
|
||||
|
||||
# filters default value
|
||||
params[:o] ||= 'created-desc'
|
||||
|
@ -1,6 +1,7 @@
|
||||
class Customer < ActiveRecord::Base
|
||||
|
||||
|
||||
has_many :domains, :through => :domain_customers
|
||||
has_many :domain_customers, :dependent => :destroy
|
||||
|
||||
scope :search, -> (search) {
|
||||
where('name LIKE ? OR firstname LIKE ? OR organisation LIKE ?', "%#{search}%", "%#{search}%", "%#{search}%")
|
||||
|
10
app/models/domain.rb
Normal file
10
app/models/domain.rb
Normal file
@ -0,0 +1,10 @@
|
||||
class Domain < ActiveRecord::Base
|
||||
has_many :needs, :through => :domain_needs
|
||||
has_many :domain_needs
|
||||
|
||||
has_many :customers, :through => :domain_customers
|
||||
has_many :domain_customers
|
||||
|
||||
has_many :need_categories, :through => :domain_need_categories
|
||||
has_many :domain_need_categories
|
||||
end
|
4
app/models/domain_customer.rb
Normal file
4
app/models/domain_customer.rb
Normal file
@ -0,0 +1,4 @@
|
||||
class DomainCustomer < ActiveRecord::Base
|
||||
belongs_to :domain
|
||||
belongs_to :customer
|
||||
end
|
4
app/models/domain_need.rb
Normal file
4
app/models/domain_need.rb
Normal file
@ -0,0 +1,4 @@
|
||||
class DomainNeed < ActiveRecord::Base
|
||||
belongs_to :domain
|
||||
belongs_to :need
|
||||
end
|
4
app/models/domain_need_category.rb
Normal file
4
app/models/domain_need_category.rb
Normal file
@ -0,0 +1,4 @@
|
||||
class DomainNeedCategory < ActiveRecord::Base
|
||||
belongs_to :domain
|
||||
belongs_to :need_category
|
||||
end
|
@ -2,9 +2,15 @@
|
||||
class Need < ActiveRecord::Base
|
||||
include Workflow
|
||||
|
||||
has_many :domains, :through => :domain_needs
|
||||
has_many :domain_needs, :dependent => :destroy
|
||||
|
||||
scope :shared, -> {
|
||||
where(state: ["verified", "negociating", "negociated", "failed"])
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
scope :with_wishes_count, -> { joins('left join wishes on wishes.need_id = needs.id')
|
||||
.select('needs.*, count(wishes.id) as wishes_count')
|
||||
@ -17,8 +23,14 @@ class Need < ActiveRecord::Base
|
||||
}
|
||||
|
||||
scope :search, -> (search) {
|
||||
where('title LIKE ? OR description LIKE ?', "%#{search}%", "%#{search}%")
|
||||
where('needs.title LIKE ? OR needs.description LIKE ?', "%#{search}%", "%#{search}%")
|
||||
}
|
||||
|
||||
scope :domain_in, -> (domain_ids) {
|
||||
joins(:domains).where('domains.id IN(?)', domain_ids)
|
||||
}
|
||||
|
||||
|
||||
|
||||
after_create :create
|
||||
|
||||
|
@ -1,6 +1,10 @@
|
||||
class NeedCategory < ActiveRecord::Base
|
||||
attr_accessor :level
|
||||
|
||||
|
||||
has_many :domains, :through => :domain_need_categories
|
||||
has_many :domain_need_categories, :dependent => :destroy
|
||||
|
||||
|
||||
scope :top, -> {
|
||||
where(parent_id: nil)
|
||||
}
|
||||
|
@ -6,6 +6,8 @@
|
||||
|
||||
|
||||
=f.inputs do
|
||||
=f.input :domains, :label => "Domaine : ", :collection => Domain.all, :as => :check_boxes
|
||||
|
||||
=f.input :organisation, :label => "Société : "
|
||||
|
||||
=f.input :name, :label => "Nom : "
|
||||
|
7
app/views/admin/domains/_domain.html.haml
Executable file
7
app/views/admin/domains/_domain.html.haml
Executable file
@ -0,0 +1,7 @@
|
||||
|
||||
%tr{:id => domain.id}
|
||||
%td
|
||||
= domain.name
|
||||
%td.actions{:style => "width:150px;text-align:right"}
|
||||
= link_to i(:"trash-o"), [:admin, domain], :data => {:confirm => 'Voulez-vous vraiment supprimer cette catégorie ?'}, :method => :delete
|
||||
= link_to i(:pencil), edit_admin_domain_path(domain)
|
8
app/views/admin/domains/_form.html.haml
Executable file
8
app/views/admin/domains/_form.html.haml
Executable file
@ -0,0 +1,8 @@
|
||||
=semantic_form_for [:admin, @category] do |f|
|
||||
.content
|
||||
|
||||
|
||||
=f.inputs do
|
||||
=f.input :name, :label => "Nom de la catégorie : "
|
||||
|
||||
.actions= f.submit "Sauvegarder", :class => "btn btn-primary"
|
2
app/views/admin/domains/edit.html.haml
Executable file
2
app/views/admin/domains/edit.html.haml
Executable file
@ -0,0 +1,2 @@
|
||||
%h1 Modifier une catégorie
|
||||
=render :partial => "form"
|
15
app/views/admin/domains/index.html.haml
Executable file
15
app/views/admin/domains/index.html.haml
Executable file
@ -0,0 +1,15 @@
|
||||
|
||||
%table.table.admin_table.table-hover.table-striped
|
||||
%thead.rows_header
|
||||
|
||||
%tr
|
||||
%th
|
||||
Nom
|
||||
%th{:style => "width:100px"}
|
||||
|
||||
|
||||
%tbody.rows
|
||||
=render @domains
|
||||
|
||||
%br
|
||||
= link_to "Ajouter un domaine", new_admin_domain_path, class:"btn btn-primary"
|
2
app/views/admin/domains/new.html.haml
Executable file
2
app/views/admin/domains/new.html.haml
Executable file
@ -0,0 +1,2 @@
|
||||
%h1 Ajouter un domaine
|
||||
=render :partial => "admin/domains/form"
|
@ -3,6 +3,8 @@
|
||||
|
||||
|
||||
=f.inputs do
|
||||
=f.input :domains, :label => "Domaine : ", :collection => Domain.all, :as => :check_boxes
|
||||
|
||||
=f.input :parent_id, :as => :select, :collection => @tree.map{|c| [(c.level > 0 ? (' ' * (c.level - 1)) + "|- ": "").html_safe + c.name, c.id]}, label: "Catégorie parente"
|
||||
=f.input :name, :label => "Nom de la catégorie : "
|
||||
|
||||
|
@ -11,6 +11,8 @@
|
||||
=f.input :description, :label => "Description : ", :rows => 5, :input_html => {:style => "height:100px;"}
|
||||
=f.input :image_file_id, :label => "Image", :as => :qi_image_select
|
||||
=f.input :author, :label => "Auteur", include_blank: "Administrateur"
|
||||
|
||||
=f.input :domains, :label => "Domaine : ", :collection => Domain.all, :as => :check_boxes
|
||||
-#= f.input :note, :label => "Informations supplémentaires pour Négos (Si vous n'avez pas attaché de proposition, merci de préciser son prix dans ce champ)", :rows => 5, :input_html => {:style => "height:100px;"}
|
||||
|
||||
.actions
|
||||
|
@ -49,6 +49,7 @@
|
||||
%li= link_to " Besoins", admin_needs_path
|
||||
|
||||
%li= link_to " Catégories", admin_need_categories_path
|
||||
%li= link_to " Domaines", admin_domains_path
|
||||
%li= link_to " Offres", admin_offers_path
|
||||
- unread_messages = ContactMessage.where(read_by_admin: false).count
|
||||
-if unread_messages > 0
|
||||
|
@ -224,7 +224,7 @@ Rails.application.routes.draw do
|
||||
end
|
||||
|
||||
namespace :admin do
|
||||
|
||||
resources :domains
|
||||
resources :annonces do
|
||||
|
||||
end
|
||||
|
48
db/schema.rb
48
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: 20160413101451) do
|
||||
ActiveRecord::Schema.define(version: 20160530213935) do
|
||||
|
||||
create_table "accepted_offers", force: :cascade do |t|
|
||||
t.datetime "created_at", null: false
|
||||
@ -248,6 +248,46 @@ ActiveRecord::Schema.define(version: 20160413101451) do
|
||||
t.datetime "updated_at", null: false
|
||||
end
|
||||
|
||||
create_table "domain_customers", force: :cascade do |t|
|
||||
t.integer "domain_id", limit: 4
|
||||
t.integer "customer_id", limit: 4
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
end
|
||||
|
||||
add_index "domain_customers", ["customer_id"], name: "index_domain_customers_on_customer_id", using: :btree
|
||||
add_index "domain_customers", ["domain_id"], name: "index_domain_customers_on_domain_id", using: :btree
|
||||
|
||||
create_table "domain_need_categories", force: :cascade do |t|
|
||||
t.integer "domain_id", limit: 4
|
||||
t.integer "need_category_id", limit: 4
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
end
|
||||
|
||||
add_index "domain_need_categories", ["domain_id"], name: "index_domain_need_categories_on_domain_id", using: :btree
|
||||
add_index "domain_need_categories", ["need_category_id"], name: "index_domain_need_categories_on_need_category_id", using: :btree
|
||||
|
||||
create_table "domain_needs", force: :cascade do |t|
|
||||
t.integer "domain_id", limit: 4
|
||||
t.integer "need_id", limit: 4
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
end
|
||||
|
||||
add_index "domain_needs", ["domain_id"], name: "index_domain_needs_on_domain_id", using: :btree
|
||||
add_index "domain_needs", ["need_id"], name: "index_domain_needs_on_need_id", using: :btree
|
||||
|
||||
create_table "domains", force: :cascade do |t|
|
||||
t.string "name", limit: 255
|
||||
t.string "slug", limit: 255
|
||||
t.boolean "superadmin", limit: 1
|
||||
t.boolean "enabled", limit: 1
|
||||
t.text "description", limit: 65535
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
end
|
||||
|
||||
create_table "download_contents", force: :cascade do |t|
|
||||
t.string "title", limit: 255
|
||||
t.string "style", limit: 255
|
||||
@ -576,4 +616,10 @@ ActiveRecord::Schema.define(version: 20160413101451) do
|
||||
|
||||
add_foreign_key "customer_newsgroups", "customers"
|
||||
add_foreign_key "customer_newsgroups", "newsgroups"
|
||||
add_foreign_key "domain_customers", "customers"
|
||||
add_foreign_key "domain_customers", "domains"
|
||||
add_foreign_key "domain_need_categories", "domains"
|
||||
add_foreign_key "domain_need_categories", "need_categories"
|
||||
add_foreign_key "domain_needs", "domains"
|
||||
add_foreign_key "domain_needs", "needs"
|
||||
end
|
||||
|
9
test/fixtures/domain_customers.yml
vendored
Normal file
9
test/fixtures/domain_customers.yml
vendored
Normal file
@ -0,0 +1,9 @@
|
||||
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
|
||||
|
||||
one:
|
||||
domain_id:
|
||||
customer_id:
|
||||
|
||||
two:
|
||||
domain_id:
|
||||
customer_id:
|
9
test/fixtures/domain_need_categories.yml
vendored
Normal file
9
test/fixtures/domain_need_categories.yml
vendored
Normal file
@ -0,0 +1,9 @@
|
||||
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
|
||||
|
||||
one:
|
||||
domain_id:
|
||||
need_category_id:
|
||||
|
||||
two:
|
||||
domain_id:
|
||||
need_category_id:
|
9
test/fixtures/domain_needs.yml
vendored
Normal file
9
test/fixtures/domain_needs.yml
vendored
Normal file
@ -0,0 +1,9 @@
|
||||
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
|
||||
|
||||
one:
|
||||
domain_id:
|
||||
need_id:
|
||||
|
||||
two:
|
||||
domain_id:
|
||||
need_id:
|
15
test/fixtures/domains.yml
vendored
Normal file
15
test/fixtures/domains.yml
vendored
Normal file
@ -0,0 +1,15 @@
|
||||
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
|
||||
|
||||
one:
|
||||
name: MyString
|
||||
slug: MyString
|
||||
superadmin: false
|
||||
enabled: false
|
||||
description: MyText
|
||||
|
||||
two:
|
||||
name: MyString
|
||||
slug: MyString
|
||||
superadmin: false
|
||||
enabled: false
|
||||
description: MyText
|
7
test/models/domain_customer_test.rb
Normal file
7
test/models/domain_customer_test.rb
Normal file
@ -0,0 +1,7 @@
|
||||
require 'test_helper'
|
||||
|
||||
class DomainCustomerTest < ActiveSupport::TestCase
|
||||
# test "the truth" do
|
||||
# assert true
|
||||
# end
|
||||
end
|
7
test/models/domain_need_category_test.rb
Normal file
7
test/models/domain_need_category_test.rb
Normal file
@ -0,0 +1,7 @@
|
||||
require 'test_helper'
|
||||
|
||||
class DomainNeedCategoryTest < ActiveSupport::TestCase
|
||||
# test "the truth" do
|
||||
# assert true
|
||||
# end
|
||||
end
|
7
test/models/domain_need_test.rb
Normal file
7
test/models/domain_need_test.rb
Normal file
@ -0,0 +1,7 @@
|
||||
require 'test_helper'
|
||||
|
||||
class DomainNeedTest < ActiveSupport::TestCase
|
||||
# test "the truth" do
|
||||
# assert true
|
||||
# end
|
||||
end
|
7
test/models/domain_test.rb
Normal file
7
test/models/domain_test.rb
Normal file
@ -0,0 +1,7 @@
|
||||
require 'test_helper'
|
||||
|
||||
class DomainTest < ActiveSupport::TestCase
|
||||
# test "the truth" do
|
||||
# assert true
|
||||
# end
|
||||
end
|
Loading…
x
Reference in New Issue
Block a user