Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
S
simple_controller
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
simple_controller
Commits
7fe865fa
Commit
7fe865fa
authored
Sep 21, 2021
by
liyijie
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: 重新整理base_controller
parent
5c3341c5
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
36 additions
and
11 deletions
+36
-11
base_controller.rb
lib/simple_controller/base_controller.rb
+36
-11
No files found.
lib/simple_controller/base_controller.rb
View file @
7fe865fa
...
@@ -171,19 +171,12 @@ class SimpleController::BaseController < ::InheritedResources::Base
...
@@ -171,19 +171,12 @@ class SimpleController::BaseController < ::InheritedResources::Base
end
end
end
end
# 可以进行继承实现
def
after_association_chain
association
def
after_association_chain
association
association
association
end
end
# ransack q, 这里主要是为了统计
# 这个方法为了兼容之前的,后面是可以废弃的
def
query_association_chain
if
self
.
class
.
instance_variable_get
(
:@ransack_off
)
||
params
[
:q
].
blank?
end_of_association_chain
else
end_of_association_chain
.
ransack
(
params
[
:q
]).
result
end
end
# 执行sub_q
# 执行sub_q
def
ransack_paginate
(
association
)
def
ransack_paginate
(
association
)
if
params
[
:group_keys
].
present?
if
params
[
:group_keys
].
present?
...
@@ -210,8 +203,21 @@ class SimpleController::BaseController < ::InheritedResources::Base
...
@@ -210,8 +203,21 @@ class SimpleController::BaseController < ::InheritedResources::Base
end
end
end
end
# ransack q, 这里主要是为了统计
def
query_association_chain
if
self
.
class
.
instance_variable_get
(
:@ransack_off
)
||
params
[
:q
].
blank?
policy_association_chain
else
policy_association_chain
.
ransack
(
params
[
:q
]).
result
end
end
def
after_of_asscoaition_chain
after_association_chain
(
query_association_chain
)
end
def
end_of_association_chain
def
end_of_association_chain
_association_chain
=
after_
association_chain
(
policy_association_chain
)
_association_chain
=
after_
of_asscoaition_chain
if
_association_chain
.
respond_to?
(
:order
)
if
_association_chain
.
respond_to?
(
:order
)
_association_chain
.
order
(
id: :desc
)
_association_chain
.
order
(
id: :desc
)
else
else
...
@@ -219,9 +225,28 @@ class SimpleController::BaseController < ::InheritedResources::Base
...
@@ -219,9 +225,28 @@ class SimpleController::BaseController < ::InheritedResources::Base
end
end
end
end
# 执行统计和sub_q
def
ransack_association_chain
association
=
end_of_association_chain
if
params
[
:group_keys
].
present?
statistics_association
=
association
.
unscope
(
:order
).
distinct
@statistics
=
statistics_association
.
group
(
params
[
:group_keys
]).
count
.
merge
(
count:
statistics_association
.
count
)
end
association
=
association
.
ransack
(
params
[
:sub_q
]).
result
unless
self
.
class
.
instance_variable_get
(
:@ransack_off
)
||
params
[
:sub_q
].
blank?
association
=
association
.
distinct
unless
self
.
class
.
instance_variable_get
(
:@distinct_off
)
||
!
association
.
respond_to?
(
:distinct
)
association
end
def
paginate_association_chain
association
=
ransack_association_chain
association
=
association
.
paginate
(
page:
params
[
:page
],
per_page:
params
[
:per_page
])
unless
self
.
class
.
instance_variable_get
(
:@paginate_off
)
association
end
def
collection
def
collection
get_collection_ivar
||
set_collection_ivar
(
get_collection_ivar
||
set_collection_ivar
(
ransack_paginate
(
query_association_chain
)
paginate_association_chain
)
)
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