2012-11-21 00:24:05 -05:00
|
|
|
module DashboardHelper
|
2013-08-06 14:12:01 -04:00
|
|
|
def filter_path(entity, options={})
|
2012-11-26 23:29:11 -05:00
|
|
|
exist_opts = {
|
2014-01-15 09:16:45 -05:00
|
|
|
state: params[:state],
|
2013-12-25 02:08:56 -05:00
|
|
|
scope: params[:scope],
|
2012-11-26 23:29:11 -05:00
|
|
|
project_id: params[:project_id],
|
|
|
|
}
|
|
|
|
|
|
|
|
options = exist_opts.merge(options)
|
|
|
|
|
2013-08-06 14:12:01 -04:00
|
|
|
path = request.path
|
|
|
|
path << "?#{options.to_param}"
|
|
|
|
path
|
2012-11-21 00:24:05 -05:00
|
|
|
end
|
2012-11-21 01:14:05 -05:00
|
|
|
|
2013-12-25 02:08:56 -05:00
|
|
|
def entities_per_project(project, entity)
|
2013-12-25 02:19:51 -05:00
|
|
|
case entity.to_sym
|
|
|
|
when :issue then @issues.where(project_id: project.id)
|
|
|
|
when :merge_request then @merge_requests.where(target_project_id: project.id)
|
|
|
|
else
|
|
|
|
[]
|
|
|
|
end.count
|
2012-11-21 01:14:05 -05:00
|
|
|
end
|
2013-12-29 05:58:00 -05:00
|
|
|
|
|
|
|
def projects_dashboard_filter_path(options={})
|
|
|
|
exist_opts = {
|
|
|
|
sort: params[:sort],
|
|
|
|
scope: params[:scope],
|
|
|
|
group: params[:group],
|
|
|
|
}
|
|
|
|
|
|
|
|
options = exist_opts.merge(options)
|
|
|
|
|
|
|
|
path = request.path
|
|
|
|
path << "?#{options.to_param}"
|
|
|
|
path
|
|
|
|
end
|
2014-07-10 10:54:31 -04:00
|
|
|
|
|
|
|
def assigned_entities_count(current_user, entity, scope = nil)
|
2014-10-02 05:38:21 -04:00
|
|
|
items = current_user.send('assigned_' + entity.pluralize)
|
|
|
|
get_count(items, scope)
|
2014-07-10 10:54:31 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def authored_entities_count(current_user, entity, scope = nil)
|
2014-10-02 05:38:21 -04:00
|
|
|
items = current_user.send(entity.pluralize)
|
|
|
|
get_count(items, scope)
|
2014-07-10 10:54:31 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def authorized_entities_count(current_user, entity, scope = nil)
|
2014-10-02 05:38:21 -04:00
|
|
|
items = entity.classify.constantize
|
|
|
|
get_count(items, scope, true, current_user)
|
|
|
|
end
|
|
|
|
|
|
|
|
protected
|
2014-07-10 10:54:31 -04:00
|
|
|
|
2014-10-02 05:38:21 -04:00
|
|
|
def get_count(items, scope, get_authorized = false, current_user = nil)
|
|
|
|
items = items.opened
|
2014-07-10 10:54:31 -04:00
|
|
|
if scope.kind_of?(Group)
|
|
|
|
items = items.of_group(scope)
|
|
|
|
elsif scope.kind_of?(Project)
|
|
|
|
items = items.of_projects(scope)
|
2014-10-02 05:38:21 -04:00
|
|
|
elsif get_authorized
|
2014-07-10 10:54:31 -04:00
|
|
|
items = items.of_projects(current_user.authorized_projects)
|
|
|
|
end
|
|
|
|
items.count
|
|
|
|
end
|
2012-11-21 00:24:05 -05:00
|
|
|
end
|