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
ee4072cf
Commit
ee4072cf
authored
Oct 10, 2017
by
ivan Lan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add column_has_children to JsonColumn & Add info_input to customer snapshots controller
parent
326c0cb3
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
39 additions
and
28 deletions
+39
-28
product_snapshots_controller.rb
...engai/controller/customer/product_snapshots_controller.rb
+2
-1
json_column.rb
lib/shotengai/json_column.rb
+30
-0
product.rb
lib/shotengai/product.rb
+0
-2
snapshot.rb
lib/shotengai/snapshot.rb
+7
-25
No files found.
lib/shotengai/controller/customer/product_snapshots_controller.rb
View file @
ee4072cf
...
@@ -31,9 +31,10 @@ module Shotengai
...
@@ -31,9 +31,10 @@ module Shotengai
private
private
def
resource_params
def
resource_params
remark_input
=
params
.
require
(
resource_key
).
fetch
(
:remark_input
,
nil
)
&
.
map
(
&
:permit!
)
remark_input
=
params
.
require
(
resource_key
).
fetch
(
:remark_input
,
nil
)
&
.
map
(
&
:permit!
)
info_input
=
params
.
require
(
resource_key
).
fetch
(
:info_input
,
nil
)
&
.
map
(
&
:permit!
)
params
.
require
(
resource_key
).
permit
(
params
.
require
(
resource_key
).
permit
(
:count
,
:shotengai_series_id
:count
,
:shotengai_series_id
).
merge
({
remark_input:
remark_input
})
).
merge
({
remark_input:
remark_input
,
info_input:
info_input
})
end
end
def
edit_only_unpaid
def
edit_only_unpaid
...
...
lib/shotengai/json_column.rb
View file @
ee4072cf
...
@@ -28,6 +28,35 @@ module Shotengai
...
@@ -28,6 +28,35 @@ module Shotengai
def
hash_column
def
hash_column
# like meta, detail these json using for code development
# like meta, detail these json using for code development
end
end
def
column_has_children
column
,
options
ArgumentError
.
new
(
"Please give
#{
column
}
one child at least."
)
unless
options
[
:children
]
children_names
=
options
[
:children
].
map
(
&
:to_s
)
self_name
=
options
[
:as
]
||
self
.
model_name
.
singular
class_eval
%Q{
define_method('full_
#{
column
}
') do
read_attribute(:
#{
column
}
) || {}
end
define_method('full_
#{
column
}
=') do |val|
write_attribute(:
#{
column
}
, val)
end
define_method('
#{
column
}
') do
full_
#{
column
}
['
#{
self_name
}
'] || {}
end
define_method('
#{
column
}
=') do |val|
self.full_
#{
column
}
= full_
#{
column
}
.merge('snapshot' => val)
end
#{
children_names
}
.each do |child|
define_method(
\"\#
{child}_
#{
column
}
\"
) do
full_
#{
column
}
[child]
end
end
}
end
end
end
end
end
end
end
\ No newline at end of file
lib/shotengai/product.rb
View file @
ee4072cf
...
@@ -61,8 +61,6 @@ module Shotengai
...
@@ -61,8 +61,6 @@ module Shotengai
transitions
from: :deleted
,
to: :not_on
transitions
from: :deleted
,
to: :not_on
end
end
end
end
scope
:alive
,
->
{
where
.
not
(
status:
'deleted'
)
}
def
status_zh
def
status_zh
{
{
...
...
lib/shotengai/snapshot.rb
View file @
ee4072cf
...
@@ -37,6 +37,8 @@ module Shotengai
...
@@ -37,6 +37,8 @@ module Shotengai
validates
:count
,
numericality:
{
only_integer:
true
,
greater_than:
0
}
validates
:count
,
numericality:
{
only_integer:
true
,
greater_than:
0
}
custom_hash_columns
:spec
,
:info
,
:remark
custom_hash_columns
:spec
,
:info
,
:remark
column_has_children
:meta
,
children:
[
'product'
,
'snapshot'
],
as: :snapshot
column_has_children
:info
,
children:
[
'product'
,
'snapshot'
],
as: :snapshot
validate
:cannot_edit
,
if: :order_was_paid
validate
:cannot_edit
,
if: :order_was_paid
before_destroy
:cannot_edit
,
if: :order_was_paid
before_destroy
:cannot_edit
,
if: :order_was_paid
...
@@ -80,31 +82,6 @@ module Shotengai
...
@@ -80,31 +82,6 @@ module Shotengai
define_method
(
column
)
{
read_attribute
(
column
)
||
self
.
series
.
send
(
column
)
}
define_method
(
column
)
{
read_attribute
(
column
)
||
self
.
series
.
send
(
column
)
}
end
end
def
full_meta
read_attribute
(
:meta
)
||
{}
end
def
full_meta
=
val
write_attribute
(
:meta
,
val
)
end
def
meta
full_meta
[
'snapshot'
]
||
{}
end
def
product_meta
full_meta
[
'product'
]
end
def
series_meta
full_meta
[
'series'
]
end
def
meta
=
val
self
.
full_meta
=
full_meta
.
merge
(
'snapshot'
=>
val
)
end
def
already_disable
def
already_disable
series
.
deleted?
||
product
.
on_sale?
.!
series
.
deleted?
||
product
.
on_sale?
.!
end
end
...
@@ -137,6 +114,11 @@ module Shotengai
...
@@ -137,6 +114,11 @@ module Shotengai
product:
product
.
meta
,
product:
product
.
meta
,
series:
series
.
meta
,
series:
series
.
meta
,
snapshot:
meta
,
snapshot:
meta
,
},
full_info:
{
product:
product
.
info
,
series:
series
.
info
,
snapshot:
info
,
}
}
)
)
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