From c299d88e76c3dc8ef4750ae81e2bac155fb7f68f Mon Sep 17 00:00:00 2001 From: Jeremy Zheng Date: Fri, 7 Jul 2017 17:57:30 -0700 Subject: [PATCH] pos and shop model --- app/controllers/home_controller.rb | 17 ++++++++ app/controllers/mall/home_controller.rb | 4 ++ app/controllers/pos/home_controller.rb | 4 ++ app/controllers/shop/home_controller.rb | 4 ++ app/models/mall/store.rb | 1 + app/policies/mall/store_policy.rb | 40 +++++++++++++++++++ app/views/mall/home/index.html.erb | 2 + app/views/pos/home/index.html.erb | 2 + app/views/shop/home/index.html.erb | 2 + config/locales/mall.en.yml | 2 + config/locales/mall.zh-CN.yml | 2 + config/locales/pos.en.yml | 2 + config/locales/pos.zh-CN.yml | 2 + config/locales/zh-CN.yml | 2 + config/routes.rb | 27 ++++++++++++- .../20170707181427_create_mall_catalogs.rb | 1 + db/schema.rb | 2 + 17 files changed, 114 insertions(+), 2 deletions(-) create mode 100644 app/controllers/mall/home_controller.rb create mode 100644 app/controllers/pos/home_controller.rb create mode 100644 app/controllers/shop/home_controller.rb create mode 100644 app/policies/mall/store_policy.rb create mode 100644 app/views/mall/home/index.html.erb create mode 100644 app/views/pos/home/index.html.erb create mode 100644 app/views/shop/home/index.html.erb create mode 100644 config/locales/mall.en.yml create mode 100644 config/locales/mall.zh-CN.yml create mode 100644 config/locales/pos.en.yml create mode 100644 config/locales/pos.zh-CN.yml diff --git a/app/controllers/home_controller.rb b/app/controllers/home_controller.rb index 135b104..08e3b92 100644 --- a/app/controllers/home_controller.rb +++ b/app/controllers/home_controller.rb @@ -15,6 +15,12 @@ def dashboard {label: 'attachments.index.title', href: attachments_path}, ] }, + { + label: '.shopping', + links: [ + + ], + }, ] forum_links = [ {label: 'forum.articles.new.title', href: new_forum_article_path}, @@ -22,6 +28,13 @@ def dashboard {label: 'forum.comments.index.title', href: forum_comments_path}, ] + mall_card = { + label: '.mall', + links: [ + {label: 'mall.stores.index.title', href: mall_stores_path} + ], + } + if current_user.is_admin? @cards << { label: '.site', @@ -47,7 +60,11 @@ def dashboard ] } + @cards << mall_card + forum_links << {label: 'forum.tags.index.title', href: forum_tags_path} + elsif current_user.is_member? + @cards << mall_card end @cards << {label: '.forum', links: forum_links} diff --git a/app/controllers/mall/home_controller.rb b/app/controllers/mall/home_controller.rb new file mode 100644 index 0000000..a510a04 --- /dev/null +++ b/app/controllers/mall/home_controller.rb @@ -0,0 +1,4 @@ +class Mall::HomeController < ApplicationController + def index + end +end diff --git a/app/controllers/pos/home_controller.rb b/app/controllers/pos/home_controller.rb new file mode 100644 index 0000000..7fe7625 --- /dev/null +++ b/app/controllers/pos/home_controller.rb @@ -0,0 +1,4 @@ +class Pos::HomeController < ApplicationController + def index + end +end diff --git a/app/controllers/shop/home_controller.rb b/app/controllers/shop/home_controller.rb new file mode 100644 index 0000000..af3eab0 --- /dev/null +++ b/app/controllers/shop/home_controller.rb @@ -0,0 +1,4 @@ +class Shop::HomeController < ApplicationController + def index + end +end diff --git a/app/models/mall/store.rb b/app/models/mall/store.rb index 5e8ad7d..cbd36e1 100644 --- a/app/models/mall/store.rb +++ b/app/models/mall/store.rb @@ -1,2 +1,3 @@ class Mall::Store < ApplicationRecord + resourcify end diff --git a/app/policies/mall/store_policy.rb b/app/policies/mall/store_policy.rb new file mode 100644 index 0000000..8d2985c --- /dev/null +++ b/app/policies/mall/store_policy.rb @@ -0,0 +1,40 @@ +module Mall + class StorePolicy + attr_reader :user, :record + + def initialize(user, record) + @user = user + @record = record + end + + def index? + create? + end + + def create? + !user.nil? && user.has_role?(:member) + end + + def new? + create? + end + + def edit? + update? + end + + def update? + !user.nil? && (user.has_role? :manager, record) + end + + def destroy? + update? + end + + def sell? + !user.nil? && (user.has_role? :seller, record) + end + + + end +end diff --git a/app/views/mall/home/index.html.erb b/app/views/mall/home/index.html.erb new file mode 100644 index 0000000..b0709b9 --- /dev/null +++ b/app/views/mall/home/index.html.erb @@ -0,0 +1,2 @@ +

Mall::Home#index

+

Find me in app/views/mall/home/index.html.erb

diff --git a/app/views/pos/home/index.html.erb b/app/views/pos/home/index.html.erb new file mode 100644 index 0000000..c659f14 --- /dev/null +++ b/app/views/pos/home/index.html.erb @@ -0,0 +1,2 @@ +

Pos::Home#index

+

Find me in app/views/pos/home/index.html.erb

diff --git a/app/views/shop/home/index.html.erb b/app/views/shop/home/index.html.erb new file mode 100644 index 0000000..abd6aae --- /dev/null +++ b/app/views/shop/home/index.html.erb @@ -0,0 +1,2 @@ +

Shop::Home#index

+

Find me in app/views/shop/home/index.html.erb

diff --git a/config/locales/mall.en.yml b/config/locales/mall.en.yml new file mode 100644 index 0000000..668cdd3 --- /dev/null +++ b/config/locales/mall.en.yml @@ -0,0 +1,2 @@ +en: + mall: \ No newline at end of file diff --git a/config/locales/mall.zh-CN.yml b/config/locales/mall.zh-CN.yml new file mode 100644 index 0000000..70f499e --- /dev/null +++ b/config/locales/mall.zh-CN.yml @@ -0,0 +1,2 @@ +zh-CN: + mall: \ No newline at end of file diff --git a/config/locales/pos.en.yml b/config/locales/pos.en.yml new file mode 100644 index 0000000..f2bd2eb --- /dev/null +++ b/config/locales/pos.en.yml @@ -0,0 +1,2 @@ +en: + pos: \ No newline at end of file diff --git a/config/locales/pos.zh-CN.yml b/config/locales/pos.zh-CN.yml new file mode 100644 index 0000000..768f7e1 --- /dev/null +++ b/config/locales/pos.zh-CN.yml @@ -0,0 +1,2 @@ +zh-CN: + pos: \ No newline at end of file diff --git a/config/locales/zh-CN.yml b/config/locales/zh-CN.yml index fcafbef..2df34fa 100644 --- a/config/locales/zh-CN.yml +++ b/config/locales/zh-CN.yml @@ -33,6 +33,8 @@ zh-CN: site: 站点设置 forum: 社区 survey: 问卷调查 + mall: 商店 + shopping: 购物 donate: title: 捐赠 admin: diff --git a/config/routes.rb b/config/routes.rb index fc12ab4..b4ad107 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -2,12 +2,35 @@ Rails.application.routes.draw do + # pos + namespace :pos do + root to:'home#index' + resources :orders, except: [:show, :destroy] + resources :returns, except: [:show, :destroy] + end + + # shop + namespace :shop do + root to:'home#index' + resources :stores, only:[:index, :show] + resources :products, only:[:index, :show] + resources :variants, only:[:index, :show] + end # mall namespace :mall do - resources :products resources :stores - resources :variants + resources :catalogs + + # resources :products + # resources :variants + # resources :addresses + # resources :payment_methods + # resources :payments + # resources :shipping_methods + # resources :shipments + + root to: 'home#index' end # survey diff --git a/db/migrate/20170707181427_create_mall_catalogs.rb b/db/migrate/20170707181427_create_mall_catalogs.rb index fbb694b..625b921 100644 --- a/db/migrate/20170707181427_create_mall_catalogs.rb +++ b/db/migrate/20170707181427_create_mall_catalogs.rb @@ -8,6 +8,7 @@ def change t.integer :sort_order, limit:1, null:false + t.belongs_to :mall_store, index: true, null: false t.timestamps end end diff --git a/db/schema.rb b/db/schema.rb index ee6f9d6..d909981 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -112,9 +112,11 @@ t.text "description", null: false t.text "assets" t.integer "sort_order", limit: 2, null: false + t.bigint "mall_store_id", null: false t.datetime "created_at", null: false t.datetime "updated_at", null: false t.index ["format"], name: "index_mall_catalogs_on_format" + t.index ["mall_store_id"], name: "index_mall_catalogs_on_mall_store_id" t.index ["name"], name: "index_mall_catalogs_on_name" end