From e4fd20b80725c77f258c44bea6faea118477f843 Mon Sep 17 00:00:00 2001 From: Andrew Spinks Date: Sun, 29 Apr 2012 16:32:38 +1000 Subject: [PATCH] Add default supplier view and relationship to address. --- app/models/spree/product_decorator.rb | 5 +++ app/models/spree/supplier.rb | 10 +---- .../distributors/{show.html => show.html.erb} | 0 .../spree/admin/suppliers/_form.html.haml | 16 ++++++++ .../spree/admin/suppliers/edit.html.haml | 5 +++ .../spree/admin/suppliers/index.html.erb | 37 ------------------- .../spree/admin/suppliers/index.html.haml | 22 +++++++++++ app/views/spree/admin/suppliers/new.html.haml | 6 +++ .../spree/admin/suppliers/show.html.haml | 21 +++++++++++ .../20120425065453_add_supplier_to_product.rb | 5 +++ spec/models/product_spec.rb | 9 +++++ spec/models/suppliers_spec.rb | 9 +++++ 12 files changed, 99 insertions(+), 46 deletions(-) create mode 100644 app/models/spree/product_decorator.rb rename app/views/spree/admin/distributors/{show.html => show.html.erb} (100%) create mode 100644 app/views/spree/admin/suppliers/_form.html.haml create mode 100644 app/views/spree/admin/suppliers/edit.html.haml delete mode 100644 app/views/spree/admin/suppliers/index.html.erb create mode 100644 app/views/spree/admin/suppliers/index.html.haml create mode 100644 app/views/spree/admin/suppliers/new.html.haml create mode 100644 app/views/spree/admin/suppliers/show.html.haml create mode 100644 db/migrate/20120425065453_add_supplier_to_product.rb create mode 100644 spec/models/product_spec.rb diff --git a/app/models/spree/product_decorator.rb b/app/models/spree/product_decorator.rb new file mode 100644 index 0000000000..635430d163 --- /dev/null +++ b/app/models/spree/product_decorator.rb @@ -0,0 +1,5 @@ +Spree::Product.class_eval do + attr_accessible :supplier_id + + belongs_to :supplier +end \ No newline at end of file diff --git a/app/models/spree/supplier.rb b/app/models/spree/supplier.rb index df73a6c630..2710cfd4e6 100644 --- a/app/models/spree/supplier.rb +++ b/app/models/spree/supplier.rb @@ -2,16 +2,8 @@ module Spree class Supplier < ActiveRecord::Base set_table_name 'suppliers' belongs_to :address - # has_many :orders - # belongs_to :country - # belongs_to :state + has_many :products # validates :name, :pickup_address, :country_id, :state_id, :city, :post_code, :presence => true - - # after_initialize :initialize_country - - # def initialize_country - # self.country = Spree::Country.find_by_id(Spree::Config[:default_country_id]) - # end end end diff --git a/app/views/spree/admin/distributors/show.html b/app/views/spree/admin/distributors/show.html.erb similarity index 100% rename from app/views/spree/admin/distributors/show.html rename to app/views/spree/admin/distributors/show.html.erb diff --git a/app/views/spree/admin/suppliers/_form.html.haml b/app/views/spree/admin/suppliers/_form.html.haml new file mode 100644 index 0000000000..79880a9b93 --- /dev/null +++ b/app/views/spree/admin/suppliers/_form.html.haml @@ -0,0 +1,16 @@ +%table{'data-hook' => "suppliers"} + %tr{'data-hook' => "name"} + %td Name: + %td= f.text_field :name + %tr{'data-hook' => "description"} + %td Description: + %td= f.text_field :description + %tr{'data-hook' => "email"} + %td Email: + %td= f.text_field :email + %tr{'data-hook' => "website"} + %td Website: + %td= f.text_field :website + %tr{'data-hook' => "twitter"} + %td Twitter: + %td= f.text_field :twitter \ No newline at end of file diff --git a/app/views/spree/admin/suppliers/edit.html.haml b/app/views/spree/admin/suppliers/edit.html.haml new file mode 100644 index 0000000000..b51781dede --- /dev/null +++ b/app/views/spree/admin/suppliers/edit.html.haml @@ -0,0 +1,5 @@ + += render :partial => 'spree/shared/error_messages', :locals => { :target => @supplier } += form_for [:admin, @supplier] do |f| + = render :partial => 'form', :locals => { :f => f } + = render :partial => 'spree/admin/shared/edit_resource_links' diff --git a/app/views/spree/admin/suppliers/index.html.erb b/app/views/spree/admin/suppliers/index.html.erb deleted file mode 100644 index 82e5bc927c..0000000000 --- a/app/views/spree/admin/suppliers/index.html.erb +++ /dev/null @@ -1,37 +0,0 @@ - -
- -
-
- - - - - - - - - - - <% @suppliers.each do |supplier| %> - - - - - - <% end %> - <% if @suppliers.empty? %> - - <% end %> - -
Name - Description - -
<%= link_to supplier.name, spree.admin_supplier_path(supplier) %><%=supplier.description %> - <%= link_to_edit supplier, :class => 'edit' %>   - <%= link_to_delete supplier %> -
<%= t(:none) %>
\ No newline at end of file diff --git a/app/views/spree/admin/suppliers/index.html.haml b/app/views/spree/admin/suppliers/index.html.haml new file mode 100644 index 0000000000..eb4c9f4ee9 --- /dev/null +++ b/app/views/spree/admin/suppliers/index.html.haml @@ -0,0 +1,22 @@ +.toolbar{'data-hook' => "suppliers"} + %ul.actions + %li= button_link_to "New Supplier", spree.new_admin_supplier_path, :icon => 'add', :id => 'admin_new_supplier_link' + %br.clear +%table#listing_suppliers.index + %thead + %tr{'data-hook' => "suppliers_header"} + %th Name + %th Description + %th + %tbody + - @suppliers.each do |supplier| + %tr + %td= link_to supplier.name, spree.admin_supplier_path(supplier) + %td= supplier.description + %td{'data-hook' => "admin_supplier_index_row_actions"} + = link_to_edit supplier, :class => 'edit' +   + = link_to_delete supplier + - if @suppliers.empty? + %tr + %td{:colspan => "2"}= t(:none) diff --git a/app/views/spree/admin/suppliers/new.html.haml b/app/views/spree/admin/suppliers/new.html.haml new file mode 100644 index 0000000000..d048b04975 --- /dev/null +++ b/app/views/spree/admin/suppliers/new.html.haml @@ -0,0 +1,6 @@ + += render :partial => 'spree/shared/error_messages', :locals => { :target => @supplier } + += form_for [:admin, @supplier] do |f| + = render :partial => 'form', :locals => { :f => f } + = render :partial => 'spree/admin/shared/new_resource_links' diff --git a/app/views/spree/admin/suppliers/show.html.haml b/app/views/spree/admin/suppliers/show.html.haml new file mode 100644 index 0000000000..795b0ed261 --- /dev/null +++ b/app/views/spree/admin/suppliers/show.html.haml @@ -0,0 +1,21 @@ +%h1 Supplier +%table + %tr + %th Name + %td= @supplier.name + %tr + %th Description + %td= @supplier.description + %tr + %th Email + %td= @supplier.email + %tr + %th Website + %td= @supplier.website + %tr + %th Twitter + %td= @supplier.twitter +%p + = link_to :Edit, spree.edit_admin_supplier_path(@supplier), :class => 'edit_supplier' + = t(:or) + = link_to t(:back), spree.admin_suppliers_path diff --git a/db/migrate/20120425065453_add_supplier_to_product.rb b/db/migrate/20120425065453_add_supplier_to_product.rb new file mode 100644 index 0000000000..41653e7857 --- /dev/null +++ b/db/migrate/20120425065453_add_supplier_to_product.rb @@ -0,0 +1,5 @@ +class AddSupplierToProduct < ActiveRecord::Migration + def change + add_column :spree_products, :supplier_id, :integer + end +end diff --git a/spec/models/product_spec.rb b/spec/models/product_spec.rb new file mode 100644 index 0000000000..c7d9c776e0 --- /dev/null +++ b/spec/models/product_spec.rb @@ -0,0 +1,9 @@ +require 'spec_helper' + +describe Spree::Product do + + describe "associations" do + it { should belong_to(:supplier) } + end + +end diff --git a/spec/models/suppliers_spec.rb b/spec/models/suppliers_spec.rb index 15672d666f..36b06aef61 100644 --- a/spec/models/suppliers_spec.rb +++ b/spec/models/suppliers_spec.rb @@ -2,8 +2,17 @@ require 'spec_helper' describe Spree::Supplier do + describe "associations" do + it { should have_many(:products) } + it { should belong_to(:address) } + end + it "should have an address" it "should add an address on save" + describe 'validations' do + # it{ should validate_presence_of(:comment) } + end + end