diff --git a/back-office/app/controllers/item_in_groups_controller.rb b/back-office/app/controllers/item_in_groups_controller.rb new file mode 100644 index 0000000..0c63975 --- /dev/null +++ b/back-office/app/controllers/item_in_groups_controller.rb @@ -0,0 +1,4 @@ +class ItemInGroupsController < ApplicationController + active_scaffold :"item_in_group" do |conf| + end +end diff --git a/back-office/app/helpers/item_in_groups_helper.rb b/back-office/app/helpers/item_in_groups_helper.rb new file mode 100644 index 0000000..a8c3fdb --- /dev/null +++ b/back-office/app/helpers/item_in_groups_helper.rb @@ -0,0 +1,2 @@ +module ItemInGroupsHelper +end \ No newline at end of file diff --git a/back-office/app/models/item.rb b/back-office/app/models/item.rb index b84b34f..62110b2 100644 --- a/back-office/app/models/item.rb +++ b/back-office/app/models/item.rb @@ -5,7 +5,7 @@ class Item < ActiveRecord::Base belongs_to :supplier belongs_to :brand belongs_to :delivery_time_estimation - 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/back-office/app/models/item_group.rb b/back-office/app/models/item_group.rb index b6c50aa..844927f 100644 --- a/back-office/app/models/item_group.rb +++ b/back-office/app/models/item_group.rb @@ -1,5 +1,5 @@ class ItemGroup < ActiveRecord::Base - has_and_belongs_to_many :items, :join_table => 'item_item_groups' + end diff --git a/back-office/app/models/item_in_group.rb b/back-office/app/models/item_in_group.rb new file mode 100644 index 0000000..86d5596 --- /dev/null +++ b/back-office/app/models/item_in_group.rb @@ -0,0 +1,8 @@ +class ItemInGroup < ActiveRecord::Base + belongs_to :item_group + belongs_to :item + + validates_presence_of :item_group_id + validates_presence_of :item_id + validates_presence_of :position +end diff --git a/back-office/config/routes.rb b/back-office/config/routes.rb index b210e89..3375f60 100644 --- a/back-office/config/routes.rb +++ b/back-office/config/routes.rb @@ -1,5 +1,6 @@ Rails.application.routes.draw do + resources :item_in_groups do as_routes end resources :item_groups do as_routes end resources :link_banners do as_routes end resources :delivery_time_estimations do as_routes end diff --git a/back-office/test/controllers/item_in_groups_controller_test.rb b/back-office/test/controllers/item_in_groups_controller_test.rb new file mode 100644 index 0000000..36438fc --- /dev/null +++ b/back-office/test/controllers/item_in_groups_controller_test.rb @@ -0,0 +1,49 @@ +require 'test_helper' + +class ItemInGroupsControllerTest < ActionController::TestCase + setup do + @item_in_group = item_in_groups(:one) + end + + test "should get index" do + get :index + assert_response :success + assert_not_nil assigns(:item_in_groups) + end + + test "should get new" do + get :new + assert_response :success + end + + test "should create item_in_group" do + assert_difference('ItemInGroup.count') do + post :create, item_in_group: { item_group_id: @item_in_group.item_group_id, item_id: @item_in_group.item_id, position: @item_in_group.position } + end + + assert_redirected_to item_in_group_path(assigns(:item_in_group)) + end + + test "should show item_in_group" do + get :show, id: @item_in_group + assert_response :success + end + + test "should get edit" do + get :edit, id: @item_in_group + assert_response :success + end + + test "should update item_in_group" do + patch :update, id: @item_in_group, item_in_group: { item_group_id: @item_in_group.item_group_id, item_id: @item_in_group.item_id, position: @item_in_group.position } + assert_redirected_to item_in_group_path(assigns(:item_in_group)) + end + + test "should destroy item_in_group" do + assert_difference('ItemInGroup.count', -1) do + delete :destroy, id: @item_in_group + end + + assert_redirected_to item_in_groups_path + end +end diff --git a/back-office/test/fixtures/item_in_groups.yml b/back-office/test/fixtures/item_in_groups.yml new file mode 100644 index 0000000..92d8c02 --- /dev/null +++ b/back-office/test/fixtures/item_in_groups.yml @@ -0,0 +1,11 @@ +# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html + +one: + item_id: 1 + item_group_id: 1 + position: 1 + +two: + item_id: 1 + item_group_id: 1 + position: 1 diff --git a/back-office/test/models/item_in_group_test.rb b/back-office/test/models/item_in_group_test.rb new file mode 100644 index 0000000..5f8c419 --- /dev/null +++ b/back-office/test/models/item_in_group_test.rb @@ -0,0 +1,7 @@ +require 'test_helper' + +class ItemInGroupTest < ActiveSupport::TestCase + # test "the truth" do + # assert true + # end +end diff --git a/front-api/db/migrate/20150420044444_create_item_in_groups.rb b/front-api/db/migrate/20150420044444_create_item_in_groups.rb new file mode 100644 index 0000000..98fc3cd --- /dev/null +++ b/front-api/db/migrate/20150420044444_create_item_in_groups.rb @@ -0,0 +1,13 @@ +class CreateItemInGroups < ActiveRecord::Migration + def change + create_table :item_in_groups do |t| + t.integer :item_id + t.integer :item_group_id + t.integer :position + + t.timestamps null: false + end + + drop_table "item_item_groups" + end +end diff --git a/front-api/db/schema.rb b/front-api/db/schema.rb index 2c52d13..9443ceb 100644 --- a/front-api/db/schema.rb +++ b/front-api/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: 20150414214540) do +ActiveRecord::Schema.define(version: 20150420044444) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -106,9 +106,12 @@ ActiveRecord::Schema.define(version: 20150414214540) do t.decimal "price" end - create_table "item_item_groups", id: false, force: :cascade do |t| - t.integer "item_id", null: false - t.integer "item_group_id", null: false + create_table "item_in_groups", force: :cascade do |t| + t.integer "item_id" + t.integer "item_group_id" + t.integer "position" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false end create_table "items", force: :cascade do |t| diff --git a/front-api/models/item.rb b/front-api/models/item.rb index 8368e63..087ab53 100644 --- a/front-api/models/item.rb +++ b/front-api/models/item.rb @@ -4,6 +4,9 @@ class Item < ActiveRecord::Base has_many :multi_media_descriptions belongs_to :sub_category + has_many :item_groups, through: :item_in_groups + + attr_accessor :count # used for cart def attributes super.merge('count' => self.count) diff --git a/front-api/models/item_group.rb b/front-api/models/item_group.rb index edc5619..72fc716 100644 --- a/front-api/models/item_group.rb +++ b/front-api/models/item_group.rb @@ -1,8 +1,10 @@ class ItemGroup < ActiveRecord::Base - has_and_belongs_to_many :items, :join_table => 'item_item_groups' + + has_many :item_in_groups + has_many :items, through: :item_in_groups def all_items(offset, limit) - self.items.where(on_display: true).order(:created_at).limit(limit).offset(offset).all + self.items.where(on_display: true).order("item_in_groups.position").limit(limit).offset(offset).all end end diff --git a/front-api/models/item_in_group.rb b/front-api/models/item_in_group.rb new file mode 100644 index 0000000..e4e79de --- /dev/null +++ b/front-api/models/item_in_group.rb @@ -0,0 +1,4 @@ +class ItemInGroup < ActiveRecord::Base + belongs_to :item_group + belongs_to :item +end diff --git a/front-ui/app/components/startPage/startPage.js b/front-ui/app/components/startPage/startPage.js index 68ab8df..7c2b509 100644 --- a/front-ui/app/components/startPage/startPage.js +++ b/front-ui/app/components/startPage/startPage.js @@ -2,7 +2,8 @@ var React = require('react'), Router = require('react-router'), RouteHandler = Router.RouteHandler, AllItems = require('../items/allItems'), - LinkBanner = require('../linkBanner/linkBanner'); + LinkBanner = require('../linkBanner/linkBanner'), + AllItemsInGroup = require('../items/allItemsInGroup'); var StartPage = React.createClass({ render : function() { @@ -11,7 +12,7 @@ var StartPage = React.createClass({