added brands

This commit is contained in:
Edin Dazdarevic
2015-03-28 14:38:15 +01:00
parent 6c7a1b962f
commit 71fbde93de
11 changed files with 35 additions and 5 deletions

View File

@@ -0,0 +1,3 @@
class Brand < ActiveRecord::Base
has_many :items
end

View File

@@ -3,6 +3,7 @@ class Item < ActiveRecord::Base
has_many :multi_media_descriptions
belongs_to :sub_category
belongs_to :supplier
belongs_to :brand
has_and_belongs_to_many :item_groups, :join_table => 'item_item_groups'
validates_presence_of :name, :description, :list_price, :current_input_price, :tags, :unit_id, :code, :sub_category_id, :weight, :supplier_id

View File

@@ -4,7 +4,8 @@ def prepare_items_for_mass_display(items)
:include => [
:unit ,
:multi_media_descriptions ,
:sub_category
:sub_category,
:brand
])
end
@@ -94,4 +95,4 @@ get '/item/item_group/:item_group_id/offset/:offset/limit/:limit' do |item_group
items = ItemGroup.find(item_group_id).all_items(offset, limit)
prepare_items_for_mass_display(items)
end
end

View File

@@ -0,0 +1,9 @@
class CreateBrands < ActiveRecord::Migration
def change
create_table :brands do |t|
t.string :name
end
add_column :items, :brand_id, :integer
end
end

View File

@@ -11,11 +11,15 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20150324044314) do
ActiveRecord::Schema.define(version: 20150328132019) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
create_table "brands", force: :cascade do |t|
t.string "name"
end
create_table "carts", force: :cascade do |t|
t.integer "user_id"
t.boolean "ordered", default: false
@@ -125,6 +129,7 @@ ActiveRecord::Schema.define(version: 20150324044314) do
t.decimal "weight", precision: 5, scale: 3
t.integer "supplier_id"
t.integer "delivery_time_estimation_id"
t.integer "brand_id"
end
create_table "link_banners", force: :cascade do |t|

View File

@@ -0,0 +1,3 @@
class Brand < ActiveRecord::Base
has_many :items
end

View File

@@ -1,5 +1,6 @@
class Item < ActiveRecord::Base
belongs_to :unit
belongs_to :brand
has_many :multi_media_descriptions
belongs_to :sub_category

View File

@@ -29,6 +29,7 @@ var ItemWithDetailsPage = React.createClass({
<div className="col-md-7">
<h3> {this.state.item.get('name')}</h3>
<div>
<div className='h4'> {this.state.item.get('brand').name}</div>
<div className='h4'> {this.state.item.get('list_price')} KM</div>
<div className='h5'>{this.state.item.get('pricePerUnit')}</div>
<div> {this.state.item.get('description')}</div>

View File

@@ -25,6 +25,7 @@ var SingleItem = React.createClass({
<div className="single_item" onClick={itemClick}>
<img src={firstImage.url} className="item_list_image" />
<h1> { this.props.item.get('name') }</h1>
<div>{ this.props.item.get('brand')? this.props.item.get('brand').name : '' } </div>
<div> { this.props.item.get('list_price') } KM </div>
</div>
);

View File

@@ -2,8 +2,10 @@ var Backbone = require('backbone');
var Globals = require('../globals');
var Item = Backbone.Model.extend({
urlRoot : Globals.ApiUrl + '/item',
urlRoot : Globals.ApiUrl + '/item',
defaults : {
brand: {}
}

View File

@@ -15,6 +15,9 @@ var ItemWithDetails = Backbone.Model.extend({
var descriptionSuffix = this.get('unit').description_suffix;
return (+pricePerUnit).toString() + " KM " + descriptionSuffix;
}
},
defaults : {
brand: {}
}
});