Skip to content

Commit

Permalink
Factor dashboard helper methods.
Browse files Browse the repository at this point in the history
  • Loading branch information
cirosantilli committed Oct 2, 2014
1 parent b034991 commit 94e8e1e
Showing 1 changed file with 13 additions and 22 deletions.
35 changes: 13 additions & 22 deletions app/helpers/dashboard_helper.rb
Expand Up @@ -37,40 +37,31 @@ def projects_dashboard_filter_path(options={})
end

def assigned_entities_count(current_user, entity, scope = nil)
items = current_user.send("assigned_" + entity.pluralize).opened

if scope.kind_of?(Group)
items = items.of_group(scope)
elsif scope.kind_of?(Project)
items = items.of_projects(scope)
end

items.count
items = current_user.send('assigned_' + entity.pluralize)
get_count(items, scope, 'assigned_')
end

def authored_entities_count(current_user, entity, scope = nil)
items = current_user.send(entity.pluralize).opened

if scope.kind_of?(Group)
items = items.of_group(scope)
elsif scope.kind_of?(Project)
items = items.of_projects(scope)
end

items.count
items = current_user.send(entity.pluralize)
get_count(items, scope)
end

def authorized_entities_count(current_user, entity, scope = nil)
items = entity.classify.constantize.opened
items = entity.classify.constantize
get_count(items, scope, '', true)
end

protected

def get_items(items, scope, prefix = '', get_authorized = false)
items = items.opened
if scope.kind_of?(Group)
items = items.of_group(scope)
elsif scope.kind_of?(Project)
items = items.of_projects(scope)
else
items = items.of_projects(current_user.authorized_projects)
elsif get_authorized
items.of_projects(current_user.authorized_projects)
end

items.count
end
end

0 comments on commit 94e8e1e

Please sign in to comment.