diff options
| author | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2013-01-07 20:48:57 +0200 |
|---|---|---|
| committer | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2013-01-07 20:52:43 +0200 |
| commit | cc64f2a814802abe9ae3bb8297079b643c8774df (patch) | |
| tree | 5eb20bceb48b9f81093e8734907fe4c9f7b40ada /app/contexts | |
| parent | 0a1603992490d47b3fe676a02dedb5417603a1f2 (diff) | |
| download | gitlab-ce-cc64f2a814802abe9ae3bb8297079b643c8774df.tar.gz | |
Common filtering for dashboard and group. Share partial search result partial
Diffstat (limited to 'app/contexts')
| -rw-r--r-- | app/contexts/filter_context.rb | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/app/contexts/filter_context.rb b/app/contexts/filter_context.rb new file mode 100644 index 00000000000..401d19b31c8 --- /dev/null +++ b/app/contexts/filter_context.rb @@ -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 |
