gitlab_routing_helper.rb 2.83 KB
Newer Older
1
# Shorter routing method for project and project items
2 3 4 5 6 7 8 9 10 11 12 13 14
# Since update to rails 4.1.9 we are now allowed to use `/` in project routing
# so we use nested routing for project resources which include project and
# project namespace. To avoid writing long methods every time we define shortcuts for
# some of routing.
#
# For example instead of this:
#
#   namespace_project_merge_request_path(merge_request.project.namespace, merge_request.projects, merge_request)
#
# We can simply use shortcut:
#
#   merge_request_path(merge_request)
#
15 16 17 18 19
module GitlabRoutingHelper
  def project_path(project, *args)
    namespace_project_path(project.namespace, project, *args)
  end

20 21 22 23 24 25 26 27
  def project_files_path(project, *args)
    namespace_project_tree_path(project.namespace, project, @ref || project.repository.root_ref)
  end

  def project_commits_path(project, *args)
    namespace_project_commits_path(project.namespace, project, @ref || project.repository.root_ref)
  end

Kamil Trzcinski's avatar
Kamil Trzcinski committed
28 29 30 31
  def project_builds_path(project, *args)
    namespace_project_builds_path(project.namespace, project, *args)
  end

32 33 34 35
  def activity_project_path(project, *args)
    activity_namespace_project_path(project.namespace, project, *args)
  end

36 37 38 39
  def edit_project_path(project, *args)
    edit_namespace_project_path(project.namespace, project, *args)
  end

40 41 42 43 44 45 46 47
  def runners_path(project, *args)
    namespace_project_runners_path(project.namespace, project, *args)
  end

  def runner_path(runner, *args)
    namespace_project_runner_path(@project.namespace, @project, runner, *args)
  end

48 49 50 51 52 53 54
  def issue_path(entity, *args)
    namespace_project_issue_path(entity.project.namespace, entity.project, entity, *args)
  end

  def merge_request_path(entity, *args)
    namespace_project_merge_request_path(entity.project.namespace, entity.project, entity, *args)
  end
55

56 57 58 59
  def milestone_path(entity, *args)
    namespace_project_milestone_path(entity.project.namespace, entity.project, entity, *args)
  end

60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
  def project_url(project, *args)
    namespace_project_url(project.namespace, project, *args)
  end

  def edit_project_url(project, *args)
    edit_namespace_project_url(project.namespace, project, *args)
  end

  def issue_url(entity, *args)
    namespace_project_issue_url(entity.project.namespace, entity.project, entity, *args)
  end

  def merge_request_url(entity, *args)
    namespace_project_merge_request_url(entity.project.namespace, entity.project, entity, *args)
  end
75

76
  def project_snippet_url(entity, *args)
77 78
    namespace_project_snippet_url(entity.project.namespace, entity.project, entity, *args)
  end
79 80 81 82 83 84 85 86

  def toggle_subscription_path(entity, *args)
    if entity.is_a?(Issue)
      toggle_subscription_namespace_project_issue_path(entity.project.namespace, entity.project, entity)
    else
      toggle_subscription_namespace_project_merge_request_path(entity.project.namespace, entity.project, entity)
    end
  end
87
end