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
b3fde4f2
Commit
b3fde4f2
authored
Sep 26, 2017
by
ivan Lan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add recycle_bin to Product & Series
parent
b9e60275
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
32 additions
and
9 deletions
+32
-9
product_series_controller.rb
...otengai/controllers/merchant/product_series_controller.rb
+11
-4
products_controller.rb
lib/shotengai/controllers/merchant/products_controller.rb
+13
-3
product.rb
lib/shotengai/product.rb
+3
-0
series.rb
lib/shotengai/series.rb
+5
-2
No files found.
lib/shotengai/controllers/merchant/product_series_controller.rb
View file @
b3fde4f2
...
@@ -5,15 +5,19 @@ module Shotengai
...
@@ -5,15 +5,19 @@ module Shotengai
self
.
base_resources
=
ProductSeries
self
.
base_resources
=
ProductSeries
self
.
template_dir
=
'shotengai/merchant/series/'
self
.
template_dir
=
'shotengai/merchant/series/'
skip_before_action
:set_resource
,
only: :batch_event
skip_before_action
:set_resource
,
only:
[
:batch_event
,
:recycle_bin
]
# add_actions :batch_event
def
default_query
resources
def
default_query
resources
resources
.
alive
.
where
(
resources
.
alive
.
where
(
params
[
:product_id
]
&&
{
shotengai_product_id:
params
[
:product_id
]
}
params
[
:product_id
]
&&
{
shotengai_product_id:
params
[
:product_id
]
}
)
)
end
end
def
recycle_bin
page
=
params
[
:page
]
||
1
per_page
=
params
[
:per_page
]
||
10
@resources
=
default_resources
.
recycle_bin
.
paginate
(
page:
page
,
per_page:
per_page
)
respond_with
@resources
,
template:
"
#{
@template_dir
}
/index"
end
def
destroy
def
destroy
@resource
.
soft_delete!
@resource
.
soft_delete!
...
@@ -23,12 +27,15 @@ module Shotengai
...
@@ -23,12 +27,15 @@ module Shotengai
def
batch_event
# params[ids] params[:event]
def
batch_event
# params[ids] params[:event]
event
=
(
@base_resources
.
where
(
nil
).
klass
.
aasm
.
events
.
map
(
&
:name
)
&
Array
[
params
[
:event
].
to_sym
]).
first
event
=
(
@base_resources
.
where
(
nil
).
klass
.
aasm
.
events
.
map
(
&
:name
)
&
Array
[
params
[
:event
].
to_sym
]).
first
raise
::
Shotengai
::
WebError
.
new
(
'Invaild event'
,
'-1'
,
400
)
unless
event
raise
::
Shotengai
::
WebError
.
new
(
'Invaild event'
,
'-1'
,
400
)
unless
event
# :relive only work for products in recycle_bin
resources
=
event
.
eql?
(
:relive
)
?
default_resources
.
recycle_bin
:
default_resources
ActiveRecord
::
Base
.
transaction
do
ActiveRecord
::
Base
.
transaction
do
default_
resources
.
where
(
id:
params
[
:ids
]).
each
(
&
"
#{
event
}
!"
.
to_sym
)
resources
.
where
(
id:
params
[
:ids
]).
each
(
&
"
#{
event
}
!"
.
to_sym
)
end
end
head
200
head
200
end
end
private
private
def
resource_params
def
resource_params
spec
=
params
.
require
(
resource_key
).
fetch
(
:spec
,
nil
).
try
(
:permit!
)
spec
=
params
.
require
(
resource_key
).
fetch
(
:spec
,
nil
).
try
(
:permit!
)
...
...
lib/shotengai/controllers/merchant/products_controller.rb
View file @
b3fde4f2
...
@@ -5,11 +5,11 @@ module Shotengai
...
@@ -5,11 +5,11 @@ module Shotengai
self
.
base_resources
=
Product
self
.
base_resources
=
Product
self
.
template_dir
=
'shotengai/merchant/products/'
self
.
template_dir
=
'shotengai/merchant/products/'
skip_before_action
:set_resource
,
only:
:batch_event
skip_before_action
:set_resource
,
only:
[
:batch_event
,
:relive
,
:recycle_bin
]
# add_actions :batch_event
# add_actions :batch_event
def
default_query
resources
def
default_query
resources
resources
.
where
(
@manager
&&
{
manager:
@manager
})
resources
.
alive
.
where
(
@manager
&&
{
manager:
@manager
})
end
end
def
index_query
resources
def
index_query
resources
...
@@ -31,6 +31,7 @@ module Shotengai
...
@@ -31,6 +31,7 @@ module Shotengai
end
end
def
relive
def
relive
@resource
=
default_resources
.
recycle_bin
.
find
(
params
[
:id
])
@resource
.
relive!
@resource
.
relive!
respond_with
@resource
,
template:
"
#{
@template_dir
}
/show"
,
status:
200
respond_with
@resource
,
template:
"
#{
@template_dir
}
/show"
,
status:
200
end
end
...
@@ -43,12 +44,21 @@ module Shotengai
...
@@ -43,12 +44,21 @@ module Shotengai
def
batch_event
# params[ids] params[:event]
def
batch_event
# params[ids] params[:event]
event
=
(
@base_resources
.
where
(
nil
).
klass
.
aasm
.
events
.
map
(
&
:name
)
&
Array
[
params
[
:event
].
to_sym
]).
first
event
=
(
@base_resources
.
where
(
nil
).
klass
.
aasm
.
events
.
map
(
&
:name
)
&
Array
[
params
[
:event
].
to_sym
]).
first
raise
::
Shotengai
::
WebError
.
new
(
'Invaild event'
,
'-1'
,
400
)
unless
event
raise
::
Shotengai
::
WebError
.
new
(
'Invaild event'
,
'-1'
,
400
)
unless
event
# :relive only work for products in recycle_bin
resources
=
event
.
eql?
(
:relive
)
?
default_resources
.
recycle_bin
:
default_resources
ActiveRecord
::
Base
.
transaction
do
ActiveRecord
::
Base
.
transaction
do
default_
resources
.
where
(
id:
params
[
:ids
]).
each
(
&
"
#{
event
}
!"
.
to_sym
)
resources
.
where
(
id:
params
[
:ids
]).
each
(
&
"
#{
event
}
!"
.
to_sym
)
end
end
head
200
head
200
end
end
def
recycle_bin
page
=
params
[
:page
]
||
1
per_page
=
params
[
:per_page
]
||
10
@resources
=
default_resources
.
recycle_bin
.
paginate
(
page:
page
,
per_page:
per_page
)
respond_with
@resources
,
template:
"
#{
@template_dir
}
/index"
end
private
private
def
resource_params
def
resource_params
# QUESTION: need these ?
# QUESTION: need these ?
...
...
lib/shotengai/product.rb
View file @
b3fde4f2
...
@@ -33,6 +33,9 @@ module Shotengai
...
@@ -33,6 +33,9 @@ module Shotengai
belongs_to
:manager
,
polymorphic:
true
,
optional:
true
#, touch: true
belongs_to
:manager
,
polymorphic:
true
,
optional:
true
#, touch: true
validate
:check_spec
,
if: :spec
validate
:check_spec
,
if: :spec
scope
:alive
,
->
{
where
.
not
(
status:
'deleted'
)
}
scope
:recycle_bin
,
->
{
unscope
(
where: :status
).
deleted
.
where
(
'updated_at > ?'
,
Time
.
now
-
10
.
day
)}
include
AASM_DLC
include
AASM_DLC
aasm
column: :status
do
aasm
column: :status
do
state
:not_on
,
initial:
true
state
:not_on
,
initial:
true
...
...
lib/shotengai/series.rb
View file @
b3fde4f2
...
@@ -7,7 +7,7 @@ module Shotengai
...
@@ -7,7 +7,7 @@ module Shotengai
# original_price :decimal(9, 2)
# original_price :decimal(9, 2)
# price :decimal(9, 2)
# price :decimal(9, 2)
# stock :integer default(-1)
# stock :integer default(-1)
#
state
:string(255)
#
aasm_state
:string(255)
# spec :json
# spec :json
# type :string(255)
# type :string(255)
# meta :json
# meta :json
...
@@ -31,6 +31,9 @@ module Shotengai
...
@@ -31,6 +31,9 @@ module Shotengai
delegate
:title
,
:detail
,
:banners
,
:cover_image
,
:status
,
:status_zh
,
:manager
,
to: :product
delegate
:title
,
:detail
,
:banners
,
:cover_image
,
:status
,
:status_zh
,
:manager
,
to: :product
scope
:alive
,
->
{
where
.
not
(
aasm_state:
'deleted'
)
}
scope
:recycle_bin
,
->
{
unscope
(
where: :aasm_state
).
deleted
.
where
(
'updated_at < ?'
,
Time
.
now
-
10
.
day
)}
# where("spec->'$.\"颜色\"' = ? and spec->'$.\"大小\"' = ?" ,红色,S)
# where("spec->'$.\"颜色\"' = ? and spec->'$.\"大小\"' = ?" ,红色,S)
scope
:query_spec_with_product
,
->
(
val
,
product
)
{
scope
:query_spec_with_product
,
->
(
val
,
product
)
{
if
val
.
keys
.
sort
==
product
.
spec
.
keys
.
sort
if
val
.
keys
.
sort
==
product
.
spec
.
keys
.
sort
...
@@ -111,7 +114,7 @@ module Shotengai
...
@@ -111,7 +114,7 @@ module Shotengai
end
end
def
uniq_spec
def
uniq_spec
if
self
.
class
.
query_spec_with_product
(
self
.
spec
,
self
.
product
).
where
.
not
(
id:
self
.
id
).
any?
if
self
.
class
.
query_spec_with_product
(
self
.
spec
,
self
.
product
).
alive
.
where
.
not
(
id:
self
.
id
).
any?
errors
.
add
(
:spec
,
'Non uniq spec for the product.'
)
errors
.
add
(
:spec
,
'Non uniq spec for the product.'
)
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