From 71fbde93dec3c9879758eede198a09d0167e4fec Mon Sep 17 00:00:00 2001 From: Edin Dazdarevic Date: Sat, 28 Mar 2015 14:38:15 +0100 Subject: [PATCH] added brands --- back-office/app/models/brand.rb | 3 +++ back-office/app/models/item.rb | 1 + front-api/controllers/item.rb | 5 +++-- front-api/db/migrate/20150328132019_create_brands.rb | 9 +++++++++ front-api/db/schema.rb | 7 ++++++- front-api/models/brand.rb | 3 +++ front-api/models/item.rb | 1 + front-ui/app/components/items/itemWithDetailsPage.js | 1 + front-ui/app/components/items/singleItem.js | 1 + front-ui/app/models/item.js | 6 ++++-- front-ui/app/models/itemWithDetails.js | 3 +++ 11 files changed, 35 insertions(+), 5 deletions(-) create mode 100644 back-office/app/models/brand.rb create mode 100644 front-api/db/migrate/20150328132019_create_brands.rb create mode 100644 front-api/models/brand.rb diff --git a/back-office/app/models/brand.rb b/back-office/app/models/brand.rb new file mode 100644 index 0000000..c7ebc71 --- /dev/null +++ b/back-office/app/models/brand.rb @@ -0,0 +1,3 @@ +class Brand < ActiveRecord::Base + has_many :items +end diff --git a/back-office/app/models/item.rb b/back-office/app/models/item.rb index 016389e..a59816b 100644 --- a/back-office/app/models/item.rb +++ b/back-office/app/models/item.rb @@ -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 diff --git a/front-api/controllers/item.rb b/front-api/controllers/item.rb index d491405..4cdfc54 100644 --- a/front-api/controllers/item.rb +++ b/front-api/controllers/item.rb @@ -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 \ No newline at end of file +end diff --git a/front-api/db/migrate/20150328132019_create_brands.rb b/front-api/db/migrate/20150328132019_create_brands.rb new file mode 100644 index 0000000..200961b --- /dev/null +++ b/front-api/db/migrate/20150328132019_create_brands.rb @@ -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 diff --git a/front-api/db/schema.rb b/front-api/db/schema.rb index 59ad6a6..f4a1995 100644 --- a/front-api/db/schema.rb +++ b/front-api/db/schema.rb @@ -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| diff --git a/front-api/models/brand.rb b/front-api/models/brand.rb new file mode 100644 index 0000000..c7ebc71 --- /dev/null +++ b/front-api/models/brand.rb @@ -0,0 +1,3 @@ +class Brand < ActiveRecord::Base + has_many :items +end diff --git a/front-api/models/item.rb b/front-api/models/item.rb index 25a6904..dbba0c2 100644 --- a/front-api/models/item.rb +++ b/front-api/models/item.rb @@ -1,5 +1,6 @@ class Item < ActiveRecord::Base belongs_to :unit + belongs_to :brand has_many :multi_media_descriptions belongs_to :sub_category diff --git a/front-ui/app/components/items/itemWithDetailsPage.js b/front-ui/app/components/items/itemWithDetailsPage.js index 3361fc5..63ef7f1 100644 --- a/front-ui/app/components/items/itemWithDetailsPage.js +++ b/front-ui/app/components/items/itemWithDetailsPage.js @@ -29,6 +29,7 @@ var ItemWithDetailsPage = React.createClass({

{this.state.item.get('name')}

+
{this.state.item.get('brand').name}
{this.state.item.get('list_price')} KM
{this.state.item.get('pricePerUnit')}
{this.state.item.get('description')}
diff --git a/front-ui/app/components/items/singleItem.js b/front-ui/app/components/items/singleItem.js index 4a56217..0aeb1bb 100644 --- a/front-ui/app/components/items/singleItem.js +++ b/front-ui/app/components/items/singleItem.js @@ -25,6 +25,7 @@ var SingleItem = React.createClass({

{ this.props.item.get('name') }

+
{ this.props.item.get('brand')? this.props.item.get('brand').name : '' }
{ this.props.item.get('list_price') } KM
); diff --git a/front-ui/app/models/item.js b/front-ui/app/models/item.js index 7534dfe..861df83 100644 --- a/front-ui/app/models/item.js +++ b/front-ui/app/models/item.js @@ -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: {} + } diff --git a/front-ui/app/models/itemWithDetails.js b/front-ui/app/models/itemWithDetails.js index 8840940..56648fa 100644 --- a/front-ui/app/models/itemWithDetails.js +++ b/front-ui/app/models/itemWithDetails.js @@ -15,6 +15,9 @@ var ItemWithDetails = Backbone.Model.extend({ var descriptionSuffix = this.get('unit').description_suffix; return (+pricePerUnit).toString() + " KM " + descriptionSuffix; } + }, + defaults : { + brand: {} } });