diff options
author | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2014-01-15 16:32:56 +0200 |
---|---|---|
committer | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2014-01-15 16:32:56 +0200 |
commit | 46997c6a89c6115c64f6e0c8836bb3b598fcd433 (patch) | |
tree | 6fde006df9c518de051b830b78440659f829cb06 /app | |
parent | 234b86c97fa576d406201a032d2cb72e60ee21b7 (diff) | |
download | gitlab-ce-46997c6a89c6115c64f6e0c8836bb3b598fcd433.tar.gz |
Remove unnecessary contexts
Signed-off-by: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
Diffstat (limited to 'app')
-rw-r--r-- | app/contexts/filter_context.rb | 58 | ||||
-rw-r--r-- | app/contexts/issues/list_context.rb | 39 | ||||
-rw-r--r-- | app/contexts/merge_requests_load_context.rb | 38 |
3 files changed, 0 insertions, 135 deletions
diff --git a/app/contexts/filter_context.rb b/app/contexts/filter_context.rb deleted file mode 100644 index fb0d42cf87d..00000000000 --- a/app/contexts/filter_context.rb +++ /dev/null @@ -1,58 +0,0 @@ -class FilterContext - attr_accessor :klass, :current_user, :params - - def initialize(klass, current_user, params) - @klass = klass - @current_user = current_user - @params = params - end - - def execute - items = by_scope - items = by_state(items) - items = by_project(items) - items = by_search(items) - end - - private - - def by_scope - table_name = klass.table_name - - case params[:scope] - when 'authored' then - current_user.send(table_name) - when 'all' then - klass.of_projects(current_user.authorized_projects.pluck(:id)) - else - current_user.send("assigned_#{table_name}") - end - end - - def by_state(items) - case params[:status] - when 'closed' - items.closed - when 'all' - items - else - items.opened - end - end - - def by_project(items) - if params[:project_id].present? - items = items.of_projects(params[:project_id]) - end - - items - end - - def by_search(items) - if params[:search].present? - items = items.search(params[:search]) - end - - items - end -end diff --git a/app/contexts/issues/list_context.rb b/app/contexts/issues/list_context.rb deleted file mode 100644 index 6de14d8cd4f..00000000000 --- a/app/contexts/issues/list_context.rb +++ /dev/null @@ -1,39 +0,0 @@ -module Issues - class ListContext < BaseContext - attr_accessor :issues - - def execute - @issues = @project.issues - - @issues = case params[:state] - when 'all' then @issues - when 'closed' then @issues.closed - else @issues.opened - end - - @issues = case params[:scope] - when 'assigned-to-me' then @issues.assigned_to(current_user) - when 'created-by-me' then @issues.authored(current_user) - else @issues - end - - @issues = @issues.tagged_with(params[:label_name]) if params[:label_name].present? - @issues = @issues.includes(:author, :project) - - # Filter by specific assignee_id (or lack thereof)? - if params[:assignee_id].present? - @issues = @issues.where(assignee_id: (params[:assignee_id] == '0' ? nil : params[:assignee_id])) - end - - # Filter by specific milestone_id (or lack thereof)? - if params[:milestone_id].present? - @issues = @issues.where(milestone_id: (params[:milestone_id] == '0' ? nil : params[:milestone_id])) - end - - # Sort by :sort param - @issues = @issues.sort(params[:sort]) - - @issues - end - end -end diff --git a/app/contexts/merge_requests_load_context.rb b/app/contexts/merge_requests_load_context.rb deleted file mode 100644 index 3559ebf7a36..00000000000 --- a/app/contexts/merge_requests_load_context.rb +++ /dev/null @@ -1,38 +0,0 @@ -# Build collection of Merge Requests -# based on filtering passed via params for @project -class MergeRequestsLoadContext < BaseContext - def execute - merge_requests = @project.merge_requests - - merge_requests = case params[:state] - when 'all' then merge_requests - when 'closed' then merge_requests.closed - else merge_requests.opened - end - - merge_requests = case params[:scope] - when 'assigned-to-me' then merge_requests.assigned_to(current_user) - when 'created-by-me' then merge_requests.authored(current_user) - else merge_requests - end - - - merge_requests = merge_requests.page(params[:page]).per(20) - merge_requests = merge_requests.includes(:author, :source_project, :target_project).order("created_at desc") - - # Filter by specific assignee_id (or lack thereof)? - if params[:assignee_id].present? - merge_requests = merge_requests.where(assignee_id: (params[:assignee_id] == '0' ? nil : params[:assignee_id])) - end - - # Filter by specific milestone_id (or lack thereof)? - if params[:milestone_id].present? - merge_requests = merge_requests.where(milestone_id: (params[:milestone_id] == '0' ? nil : params[:milestone_id])) - end - - # Sort by :sort param - merge_requests = merge_requests.sort(params[:sort]) - - merge_requests - end -end |