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
Hide 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
self
.
base_resources
=
ProductSeries
self
.
template_dir
=
'shotengai/merchant/series/'
skip_before_action
:set_resource
,
only: :batch_event
# add_actions :batch_event
skip_before_action
:set_resource
,
only:
[
:batch_event
,
:recycle_bin
]
def
default_query
resources
resources
.
alive
.
where
(
params
[
:product_id
]
&&
{
shotengai_product_id:
params
[
:product_id
]
}
)
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
@resource
.
soft_delete!
...
...
@@ -23,12 +27,15 @@ module Shotengai
def
batch_event
# params[ids] params[:event]
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
# :relive only work for products in recycle_bin
resources
=
event
.
eql?
(
:relive
)
?
default_resources
.
recycle_bin
:
default_resources
ActiveRecord
::
Base
.
transaction
do
default_
resources
.
where
(
id:
params
[
:ids
]).
each
(
&
"
#{
event
}
!"
.
to_sym
)
resources
.
where
(
id:
params
[
:ids
]).
each
(
&
"
#{
event
}
!"
.
to_sym
)
end
head
200
end
private
def
resource_params
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
self
.
base_resources
=
Product
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
def
default_query
resources
resources
.
where
(
@manager
&&
{
manager:
@manager
})
resources
.
alive
.
where
(
@manager
&&
{
manager:
@manager
})
end
def
index_query
resources
...
...
@@ -31,6 +31,7 @@ module Shotengai
end
def
relive
@resource
=
default_resources
.
recycle_bin
.
find
(
params
[
:id
])
@resource
.
relive!
respond_with
@resource
,
template:
"
#{
@template_dir
}
/show"
,
status:
200
end
...
...
@@ -43,12 +44,21 @@ module Shotengai
def
batch_event
# params[ids] params[:event]
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
# :relive only work for products in recycle_bin
resources
=
event
.
eql?
(
:relive
)
?
default_resources
.
recycle_bin
:
default_resources
ActiveRecord
::
Base
.
transaction
do
default_
resources
.
where
(
id:
params
[
:ids
]).
each
(
&
"
#{
event
}
!"
.
to_sym
)
resources
.
where
(
id:
params
[
:ids
]).
each
(
&
"
#{
event
}
!"
.
to_sym
)
end
head
200
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
def
resource_params
# QUESTION: need these ?
...
...
lib/shotengai/product.rb
View file @
b3fde4f2
...
...
@@ -32,6 +32,9 @@ module Shotengai
belongs_to
:manager
,
polymorphic:
true
,
optional:
true
#, touch: true
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
aasm
column: :status
do
...
...
lib/shotengai/series.rb
View file @
b3fde4f2
...
...
@@ -7,7 +7,7 @@ module Shotengai
# original_price :decimal(9, 2)
# price :decimal(9, 2)
# stock :integer default(-1)
#
state
:string(255)
#
aasm_state
:string(255)
# spec :json
# type :string(255)
# meta :json
...
...
@@ -31,6 +31,9 @@ module Shotengai
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)
scope
:query_spec_with_product
,
->
(
val
,
product
)
{
if
val
.
keys
.
sort
==
product
.
spec
.
keys
.
sort
...
...
@@ -111,7 +114,7 @@ module Shotengai
end
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.'
)
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