Common filtering for dashboard and group. Share partial search result partial
This commit is contained in:
parent
0a16039924
commit
cc64f2a814
11 changed files with 214 additions and 207 deletions
31
app/contexts/filter_context.rb
Normal file
31
app/contexts/filter_context.rb
Normal file
|
@ -0,0 +1,31 @@
|
|||
class FilterContext
|
||||
attr_accessor :items, :params
|
||||
|
||||
def initialize(items, params)
|
||||
@items = items
|
||||
@params = params
|
||||
end
|
||||
|
||||
def execute
|
||||
apply_filter(items)
|
||||
end
|
||||
|
||||
def apply_filter items
|
||||
if params[:project_id]
|
||||
items = items.where(project_id: params[:project_id])
|
||||
end
|
||||
|
||||
if params[:search].present?
|
||||
items = items.search(params[:search])
|
||||
end
|
||||
|
||||
case params[:status]
|
||||
when 'closed'
|
||||
items.closed
|
||||
when 'all'
|
||||
items
|
||||
else
|
||||
items.opened
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue