Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
S
shotengai
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
open-source
shotengai
Commits
cc41041e
Commit
cc41041e
authored
Jan 18, 2018
by
ivan Lan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Change product column :need_express to :express_way
parent
6421bb70
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
93 additions
and
6 deletions
+93
-6
1_create_shotengai_products_and_orders.rb
db/migrate/1_create_shotengai_products_and_orders.rb
+1
-1
shotengai_products.rb
...generators/templates/spec/factories/shotengai_products.rb
+1
-1
_product.json.jbuilder
lib/generators/templates/views/share/_product.json.jbuilder
+1
-1
_product_simple.json.jbuilder
...ators/templates/views/share/_product_simple.json.jbuilder
+1
-1
base.rb
lib/shotengai/controller/base.rb
+3
-0
products_controller.rb
lib/shotengai/controller/merchant/products_controller.rb
+1
-1
product.rb
lib/shotengai/product.rb
+9
-1
taggable.rb
lib/shotengai/taggable.rb
+76
-0
No files found.
db/migrate/1_create_shotengai_products_and_orders.rb
View file @
cc41041e
...
...
@@ -11,7 +11,7 @@ class CreateShotengaiProductsAndOrders < ActiveRecord::Migration[5.1]
t
.
string
:title
t
.
string
:status
t
.
integer
:default_series_id
t
.
boolean
:need_express
t
.
integer
:express_way
t
.
boolean
:need_time_attr
t
.
string
:cover_image
t
.
json
:banners
...
...
lib/generators/templates/spec/factories/shotengai_products.rb
View file @
cc41041e
...
...
@@ -36,7 +36,7 @@ FactoryGirl.define do
}
}
# default_series_id ''
need_express
true
express_way
'no_need'
# need_time_attr true
cover_image
'cover_image.image'
banners
{
[
'image1'
,
'image2'
]
}
...
...
lib/generators/templates/views/share/_product.json.jbuilder
View file @
cc41041e
json.extract! product, :id, :title, :status, :status_zh,
:
need_express
, :need_time_attr,
:
express_way
, :need_time_attr,
:cover_image, :banners, :detail, :meta
json.spec product.spec_output
# TODO: NOTE: catalog_list is only vaild in the template example
...
...
lib/generators/templates/views/share/_product_simple.json.jbuilder
View file @
cc41041e
json.extract! product, :id, :title, :status, :status_zh,
:
need_express
, :cover_image
:
express_way
, :cover_image
json.catalog_list product.catalog_list if product.respond_to?(:catalog_list)
json.default_series product.default_series, partial: 'shotengai/share/series_simple', as: :series
lib/shotengai/controller/base.rb
View file @
cc41041e
...
...
@@ -18,6 +18,9 @@ module Shotengai
# The view template dir
# respond_with @products, template: "#{self.class.template_dir}/index"
# Use method instead of instance variable in order to
# let the value could be delegated to superclass when you do not set the subclass value.
# 确保可继承 且 多个子类间不影响(类变量会出现)
def
template_dir
=
template_dir
class_eval
%Q{
def add_template_dir
...
...
lib/shotengai/controller/merchant/products_controller.rb
View file @
cc41041e
...
...
@@ -70,7 +70,7 @@ module Shotengai
# NOTE: :catalog_list is a default catalog list for template example, maybe should move it to the template controller, but it need add controller template for every controller
params
.
require
(
resource_key
).
permit
(
:title
,
:default_series_id
,
:
need_express
,
:need_time_attr
,
:cover_image
,
catalog_ids:
[],
:
express_way
,
:need_time_attr
,
:cover_image
,
catalog_ids:
[],
banners:
[],
# spec_template: [:key, val: []],
# remark_template: [:key, :val],
...
...
lib/shotengai/product.rb
View file @
cc41041e
...
...
@@ -8,7 +8,6 @@ module Shotengai
# status :string(255)
# spec_template :json
# default_series_id :integer
# need_express :boolean
# need_time_attr :boolean
# cover_image :string(255)
# banners :json
...
...
@@ -20,6 +19,7 @@ module Shotengai
# created_at :datetime not null
# updated_at :datetime not null
# remark_template :json
# express_way :integer
#
# Indexes
#
...
...
@@ -70,6 +70,14 @@ module Shotengai
}[
status
.
to_sym
]
end
enum
express_way:
{
no_need:
0
,
delivery:
1
,
pick_up:
2
,
both:
3
,
custom:
4
}
def
default_series
Shotengai
::
Series
.
alive
.
find_by_id
(
default_series_id
)
||
series
.
alive
.
first
end
...
...
lib/shotengai/taggable.rb
0 → 100644
View file @
cc41041e
module
Shotengai
module
Taggable
extend
ActiveSupport
::
Concern
included
do
has_many
:taggings
,
->
{
order
(
order: :asc
)},
as: :tagged
end
class_methods
do
def
join_catalog_system
catalog_class_name
,
self_as:
nil
catalog_class
=
catalog_class_name
.
constantize
raise
ArgumentError
.
new
(
'Wrong catalog class required.'
)
unless
Shotengai
::
Catalog
===
catalog_class
self_as
||=
self
.
class_name
.
model_name
.
collection
# catalog_class.class_eval %Q{
# has_many :#{self_as}, class_name:
# }
catalog_class_collection
=
'catalogs'
# 交集
self
.
scope
:catalogs_intersection
,
->
(
catalogs
){
join
(
:taggings
).
where
(
taggings:
{
catalog_id:
catalogs
.
map
(
&
:id
)
})
}
# 并集
self
.
scope
:catalogs_union
,
->
(
catalogs
){
join
(
:taggings
).
where
(
taggings:
{
catalog_id:
catalogs
.
map
(
&
:id
)
}).
distant
}
end
def
tagged_with
class_name
,
as:
nil
# Let target class to has_many :taggings
tag
=
class_name
.
constantize
ArgumentError
.
new
(
"
#{
class_name
}
do not inherit from ActiveRecord::Base"
)
unless
ActiveRecord
::
Base
===
tag
tag
.
class_eval
do
has_many
:taggings
,
as: :tag
end
as
||=
class_name
.
downcase
.
pluralize
# Query with tag
# Use tag_ids to avoid another querying
self
.
scope
"have_
#{
as
}
"
.
to_sym
,
->
(
tag_ids
)
{
joins
(
:taggings
).
where
(
taggings:
{
tag_type:
tag
.
base_class
.
name
,
tag_id:
tag_ids
}
).
distinct
}
# Add update method
self
.
class_eval
%Q{
def
#{
as
}
#{
tag
}
.joins(:taggings).where(taggings: { tagged: self }).distinct
end
def
#{
as
}
_tags
Tagging.where(tagged: self, tag_type:
#{
tag
.
base_class
.
name
}
)
end
# Update by id array
def
#{
as
}
_ids= id_ary
ActiveRecord::Base.transaction do
#{
as
}
_tags.destroy_all
Array(id_ary).each_with_index do |id, i|
#{
as
}
_tags.create!(tag:
#{
tag
}
.find(id), order: i)
end
end
end
# Update by tags array
def
#{
as
}
= tags
ActiveRecord::Base.transaction do
#{
as
}
_tags.destroy_all
Array(tags).each_with_index do |tag, i|
#{
as
}
_tags.create!(tag: tag, order: i)
end
end
end
}
end
end
end
end
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment