Factor dashboard helper methods.
This commit is contained in:
parent
b0349915e2
commit
da99560ecb
|
@ -37,40 +37,31 @@ module DashboardHelper
|
||||||
end
|
end
|
||||||
|
|
||||||
def assigned_entities_count(current_user, entity, scope = nil)
|
def assigned_entities_count(current_user, entity, scope = nil)
|
||||||
items = current_user.send("assigned_" + entity.pluralize).opened
|
items = current_user.send('assigned_' + entity.pluralize)
|
||||||
|
get_count(items, scope)
|
||||||
if scope.kind_of?(Group)
|
|
||||||
items = items.of_group(scope)
|
|
||||||
elsif scope.kind_of?(Project)
|
|
||||||
items = items.of_projects(scope)
|
|
||||||
end
|
|
||||||
|
|
||||||
items.count
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def authored_entities_count(current_user, entity, scope = nil)
|
def authored_entities_count(current_user, entity, scope = nil)
|
||||||
items = current_user.send(entity.pluralize).opened
|
items = current_user.send(entity.pluralize)
|
||||||
|
get_count(items, scope)
|
||||||
if scope.kind_of?(Group)
|
|
||||||
items = items.of_group(scope)
|
|
||||||
elsif scope.kind_of?(Project)
|
|
||||||
items = items.of_projects(scope)
|
|
||||||
end
|
|
||||||
|
|
||||||
items.count
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def authorized_entities_count(current_user, entity, scope = nil)
|
def authorized_entities_count(current_user, entity, scope = nil)
|
||||||
items = entity.classify.constantize.opened
|
items = entity.classify.constantize
|
||||||
|
get_count(items, scope, true, current_user)
|
||||||
|
end
|
||||||
|
|
||||||
|
protected
|
||||||
|
|
||||||
|
def get_count(items, scope, get_authorized = false, current_user = nil)
|
||||||
|
items = items.opened
|
||||||
if scope.kind_of?(Group)
|
if scope.kind_of?(Group)
|
||||||
items = items.of_group(scope)
|
items = items.of_group(scope)
|
||||||
elsif scope.kind_of?(Project)
|
elsif scope.kind_of?(Project)
|
||||||
items = items.of_projects(scope)
|
items = items.of_projects(scope)
|
||||||
else
|
elsif get_authorized
|
||||||
items = items.of_projects(current_user.authorized_projects)
|
items = items.of_projects(current_user.authorized_projects)
|
||||||
end
|
end
|
||||||
|
|
||||||
items.count
|
items.count
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue