Commit 42387b73 authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Merge branch 'route-helper' into 'master'

Introduce shortcuts for routing helpers

See merge request !1600
parents 5bf492fe 6ac0a021
......@@ -2,6 +2,7 @@ require 'gon'
class ApplicationController < ActionController::Base
include Gitlab::CurrentSettings
include GitlabRoutingHelper
before_filter :authenticate_user_from_token!
before_filter :authenticate_user!
......
......@@ -24,6 +24,6 @@ class Projects::AvatarsController < Projects::ApplicationController
@project.save
@project.reset_events_cache
redirect_to edit_namespace_project_path(@project.namespace, @project)
redirect_to edit_project_path(@project)
end
end
......@@ -60,8 +60,7 @@ class Projects::IssuesController < Projects::ApplicationController
respond_to do |format|
format.html do
if @issue.valid?
redirect_to namespace_project_issue_path(@project.namespace,
@project, @issue)
redirect_to issue_path(@issue)
else
render :new
end
......@@ -79,7 +78,7 @@ class Projects::IssuesController < Projects::ApplicationController
format.js
format.html do
if @issue.valid?
redirect_to [@project.namespace.becomes(Namespace), @project, @issue]
redirect_to issue_path(@issue)
else
render :edit
end
......@@ -129,8 +128,7 @@ class Projects::IssuesController < Projects::ApplicationController
issue = @project.issues.find_by(id: params[:id])
if issue
redirect_to namespace_project_issue_path(@project.namespace, @project,
issue)
redirect_to issue_path(issue)
return
else
raise ActiveRecord::RecordNotFound.new
......
......@@ -79,9 +79,7 @@ class Projects::MergeRequestsController < Projects::ApplicationController
if @merge_request.valid?
redirect_to(
namespace_project_merge_request_path(@merge_request.target_project.namespace,
@merge_request.target_project,
@merge_request),
merge_request_path(@merge_request),
notice: 'Merge request was successfully created.'
)
else
......
......@@ -7,7 +7,7 @@ class Projects::RepositoriesController < Projects::ApplicationController
def create
@project.create_repository
redirect_to namespace_project_path(@project.namespace, @project)
redirect_to project_path(@project)
end
def archive
......
......@@ -23,7 +23,7 @@ class ProjectsController < ApplicationController
if @project.saved?
redirect_to(
namespace_project_path(@project.namespace, @project),
project_path(@project),
notice: 'Project was successfully created.'
)
else
......@@ -39,7 +39,7 @@ class ProjectsController < ApplicationController
flash[:notice] = 'Project was successfully updated.'
format.html do
redirect_to(
edit_namespace_project_path(@project.namespace, @project),
edit_project_path(@project),
notice: 'Project was successfully updated.'
)
end
......@@ -133,7 +133,7 @@ class ProjectsController < ApplicationController
@project.archive!
respond_to do |format|
format.html { redirect_to namespace_project_path(@project.namespace, @project) }
format.html { redirect_to project_path(@project) }
end
end
......@@ -142,7 +142,7 @@ class ProjectsController < ApplicationController
@project.unarchive!
respond_to do |format|
format.html { redirect_to namespace_project_path(@project.namespace, @project) }
format.html { redirect_to project_path(@project) }
end
end
......
# Shorter routing method for project and project items
# 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)
#
module GitlabRoutingHelper
def project_path(project, *args)
namespace_project_path(project.namespace, project, *args)
end
def edit_project_path(project, *args)
edit_namespace_project_path(project.namespace, project, *args)
end
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
end
......@@ -46,7 +46,7 @@ module ProjectsHelper
simple_sanitize(project.group.name), group_path(project.group)
) + ' / ' +
link_to(simple_sanitize(project.name),
namespace_project_path(project.namespace, project))
project_path(project))
end
else
owner = project.namespace.owner
......@@ -55,7 +55,7 @@ module ProjectsHelper
simple_sanitize(owner.name), user_path(owner)
) + ' / ' +
link_to(simple_sanitize(project.name),
namespace_project_path(project.namespace, project))
project_path(project))
end
end
end
......
%h3.page-title
Project: #{@project.name_with_namespace}
= link_to edit_namespace_project_path(@project.namespace, @project), class: "btn pull-right" do
= link_to edit_project_path(@project), class: "btn pull-right" do
%i.fa.fa-pencil-square-o
Edit
%hr
......@@ -13,7 +13,7 @@
%li
%span.light Name:
%strong
= link_to @project.name, namespace_project_path(@project.namespace, @project)
= link_to @project.name, project_path(@project)
%li
%span.light Namespace:
%strong
......
= link_to namespace_project_path(project.namespace, project), class: dom_class(project) do
= link_to project_path(project), class: dom_class(project) do
.dash-project-avatar
= project_icon(project, alt: '', class: 'avatar project-avatar s40')
.dash-project-access-icon
......
......@@ -19,7 +19,7 @@
= project_icon("#{project.namespace.to_param}/#{project.to_param}", alt: '', class: 'avatar project-avatar s60')
.project-access-icon
= visibility_level_icon(project.visibility_level)
= link_to namespace_project_path(project.namespace, project), class: dom_class(project) do
= link_to project_path(project), class: dom_class(project) do
%strong= project.name_with_namespace
- if project.forked_from_project
......
......@@ -11,7 +11,7 @@
.nothing-here-block This group has no projects yet
- projects.each do |project|
%li.project-row
= link_to namespace_project_path(project.namespace, project), class: dom_class(project) do
= link_to project_path(project), class: dom_class(project) do
.dash-project-avatar
= project_icon(project, alt: '', class: 'avatar s40')
.dash-project-access-icon
......
%ul.project-navigation.nav.nav-sidebar
- if @project_settings_nav
= nav_link do
= link_to namespace_project_path(@project.namespace, @project), title: 'Back to project', class: "" do
= link_to project_path(@project), title: 'Back to project', class: "" do
%i.fa.fa-caret-square-o-left
%span
Back to project
......@@ -12,7 +12,7 @@
- else
= nav_link(path: 'projects#show', html_options: {class: "home"}) do
= link_to namespace_project_path(@project.namespace, @project), title: 'Project', class: 'shortcuts-project' do
= link_to project_path(@project), title: 'Project', class: 'shortcuts-project' do
%i.fa.fa-dashboard
%span
Project
......@@ -89,7 +89,7 @@
- if project_nav_tab? :settings
= nav_link(html_options: {class: "#{project_tab_class} separate-item"}) do
= link_to edit_namespace_project_path(@project.namespace, @project), title: 'Settings', class: "stat-tab tab no-highlight" do
= link_to edit_project_path(@project), title: 'Settings', class: "stat-tab tab no-highlight" do
%i.fa.fa-cogs
%span
Settings
%ul.project-settings-nav.sidebar-subnav
= nav_link(path: 'projects#edit') do
= link_to edit_namespace_project_path(@project.namespace, @project), title: 'Project', class: "stat-tab tab " do
= link_to edit_project_path(@project), title: 'Project', class: "stat-tab tab " do
%i.fa.fa-pencil-square-o
%span
Project
......
......@@ -10,8 +10,8 @@
= link_to "Plain diff", namespace_project_commit_path(@project.namespace, @project, @commit, format: :diff), class: "btn btn-warning btn-small"
= link_to "Email patch", namespace_project_commit_path(@project.namespace, @project, @commit, format: :patch), class: "btn btn-warning btn-small"
- elsif @merge_request && @merge_request.persisted?
= link_to "Plain diff", namespace_project_merge_request_path(@project.namespace, @project, @merge_request, format: :diff), class: "btn btn-warning btn-small"
= link_to "Email patch", namespace_project_merge_request_path(@project.namespace, @project, @merge_request, format: :patch), class: "btn btn-warning btn-small"
= link_to "Plain diff", merge_request_path(@merge_request, format: :diff), class: "btn btn-warning btn-small"
= link_to "Email patch", merge_request_path(@merge_request, format: :patch), class: "btn btn-warning btn-small"
%p
To preserve performance only
%strong #{allowed_diff_size} of #{diffs.size}
......
- content_for :note_actions do
- if can?(current_user, :modify_issue, @issue)
- if @issue.closed?
= link_to 'Reopen Issue', namespace_project_issue_path(@project.namespace, @project, @issue, issue: {state_event: :reopen }, status_only: true), method: :put, class: "btn btn-grouped btn-reopen js-note-target-reopen", title: 'Reopen Issue'
= link_to 'Reopen Issue', issue_path(@issue, issue: {state_event: :reopen }, status_only: true), method: :put, class: "btn btn-grouped btn-reopen js-note-target-reopen", title: 'Reopen Issue'
- else
= link_to 'Close Issue', namespace_project_issue_path(@project.namespace, @project, @issue, issue: {state_event: :close }, status_only: true), method: :put, class: "btn btn-grouped btn-close js-note-target-close", title: "Close Issue"
= link_to 'Close Issue', issue_path(@issue, issue: {state_event: :close }, status_only: true), method: :put, class: "btn btn-grouped btn-close js-note-target-close", title: "Close Issue"
.row
%section.col-md-9
.participants
......
%li{ id: dom_id(issue), class: issue_css_classes(issue), url: namespace_project_issue_path(issue.project.namespace, issue.project, issue) }
%li{ id: dom_id(issue), class: issue_css_classes(issue), url: issue_path(issue) }
- if controller.controller_name == 'issues'
.issue-check
= check_box_tag dom_id(issue,"selected"), nil, false, 'data-id' => issue.id, class: "selected_issue", disabled: !can?(current_user, :modify_issue, issue)
.issue-title
%span.str-truncated
= link_to_gfm issue.title, namespace_project_issue_path(issue.project.namespace, issue.project, issue), class: "row_title"
= link_to_gfm issue.title, issue_path(issue), class: "row_title"
.pull-right.light
- if issue.closed?
%span
......@@ -41,9 +41,9 @@
.issue-actions
- if can? current_user, :modify_issue, issue
- if issue.closed?
= link_to 'Reopen', namespace_project_issue_path(issue.project.namespace, issue.project, issue, issue: {state_event: :reopen }, status_only: true), method: :put, class: "btn btn-small btn-grouped reopen_issue btn-reopen", remote: true
= link_to 'Reopen', issue_path(issue, issue: {state_event: :reopen }, status_only: true), method: :put, class: "btn btn-small btn-grouped reopen_issue btn-reopen", remote: true
- else
= link_to 'Close', namespace_project_issue_path(issue.project.namespace, issue.project, issue, issue: {state_event: :close }, status_only: true), method: :put, class: "btn btn-small btn-grouped close_issue btn-close", remote: true
= link_to 'Close', issue_path(issue, issue: {state_event: :close }, status_only: true), method: :put, class: "btn btn-small btn-grouped close_issue btn-close", remote: true
= link_to edit_namespace_project_issue_path(issue.project.namespace, issue.project, issue), class: "btn btn-small edit-issue-link btn-grouped" do
%i.fa.fa-pencil-square-o
Edit
......
......@@ -17,9 +17,9 @@
New Issue
- if can?(current_user, :modify_issue, @issue)
- if @issue.closed?
= link_to 'Reopen', namespace_project_issue_path(@project.namespace, @project, @issue, issue: {state_event: :reopen }, status_only: true), method: :put, class: "btn btn-grouped btn-reopen"
= link_to 'Reopen', issue_path(@issue, issue: {state_event: :reopen }, status_only: true), method: :put, class: "btn btn-grouped btn-reopen"
- else
= link_to 'Close', namespace_project_issue_path(@project.namespace, @project, @issue, issue: {state_event: :close }, status_only: true), method: :put, class: "btn btn-grouped btn-close", title: "Close Issue"
= link_to 'Close', issue_path(@issue, issue: {state_event: :close }, status_only: true), method: :put, class: "btn btn-grouped btn-close", title: "Close Issue"
= link_to edit_namespace_project_issue_path(@project.namespace, @project, @issue), class: "btn btn-grouped issuable-edit" do
%i.fa.fa-pencil-square-o
......
- content_for :note_actions do
- if can?(current_user, :modify_merge_request, @merge_request)
- if @merge_request.open?
= link_to 'Close', namespace_project_merge_request_path(@project.namespace, @project, @merge_request, merge_request: {state_event: :close }), method: :put, class: "btn btn-grouped btn-close close-mr-link js-note-target-close", title: "Close merge request"
= link_to 'Close', merge_request_path(@merge_request, merge_request: {state_event: :close }), method: :put, class: "btn btn-grouped btn-close close-mr-link js-note-target-close", title: "Close merge request"
- if @merge_request.closed?
= link_to 'Reopen', namespace_project_merge_request_path(@project.namespace, @project, @merge_request, merge_request: {state_event: :reopen }), method: :put, class: "btn btn-grouped btn-reopen reopen-mr-link js-note-target-reopen", title: "Reopen merge request"
= link_to 'Reopen', merge_request_path(@merge_request, merge_request: {state_event: :reopen }), method: :put, class: "btn btn-grouped btn-reopen reopen-mr-link js-note-target-reopen", title: "Reopen merge request"
.row
%section.col-md-9
......
%li{ class: mr_css_classes(merge_request) }
.merge-request-title
%span.str-truncated
= link_to_gfm merge_request.title, namespace_project_merge_request_path(merge_request.target_project.namespace, merge_request.target_project, merge_request), class: "row_title"
= link_to_gfm merge_request.title, merge_request_path(merge_request), class: "row_title"
.pull-right.light
- if merge_request.merged?
%span
......
.merge-request{'data-url' => namespace_project_merge_request_path(@project.namespace, @project, @merge_request)}
.merge-request{'data-url' => merge_request_path(@merge_request)}
.merge-request-details
= render "projects/merge_requests/show/mr_title"
%hr
......@@ -28,8 +28,8 @@
Download as
%span.caret
%ul.dropdown-menu
%li= link_to "Email Patches", namespace_project_merge_request_path(@project.namespace, @project, @merge_request, format: :patch)
%li= link_to "Plain Diff", namespace_project_merge_request_path(@project.namespace, @project, @merge_request, format: :diff)
%li= link_to "Email Patches", merge_request_path(@merge_request, format: :patch)
%li= link_to "Plain Diff", merge_request_path(@merge_request, format: :diff)
= render "projects/merge_requests/show/how_to_merge"
= render "projects/merge_requests/show/state_widget"
......@@ -37,12 +37,12 @@
- if @commits.present?
%ul.nav.nav-tabs.merge-request-tabs
%li.notes-tab{data: {action: 'notes'}}
= link_to namespace_project_merge_request_path(@project.namespace, @project, @merge_request) do
= link_to merge_request_path(@merge_request) do
%i.fa.fa-comments
Discussion
%span.badge= @merge_request.mr_and_commit_notes.count
%li.commits-tab{data: {action: 'commits'}}
= link_to namespace_project_merge_request_path(@project.namespace, @project, @merge_request), title: 'Commits' do
= link_to merge_request_path(@merge_request), title: 'Commits' do
%i.fa.fa-history
Commits
%span.badge= @commits.size
......
......@@ -8,5 +8,5 @@
Changes view for this comparison is extremely large.
%p
You can
= link_to "download it", namespace_project_merge_request_path(@merge_request.target_project.namespace, @merge_request.target_project, @merge_request, format: :diff), class: "vlink"
= link_to "download it", merge_request_path(@merge_request, format: :diff), class: "vlink"
instead.
......@@ -14,9 +14,9 @@
.issue-btn-group.pull-right
- if can?(current_user, :modify_merge_request, @merge_request)
- if @merge_request.open?
= link_to 'Close', namespace_project_merge_request_path(@project.namespace, @project, @merge_request, merge_request: { state_event: :close }), method: :put, class: "btn btn-grouped btn-close", title: "Close merge request"
= link_to 'Close', merge_request_path(@merge_request, merge_request: { state_event: :close }), method: :put, class: "btn btn-grouped btn-close", title: "Close merge request"
= link_to edit_namespace_project_merge_request_path(@project.namespace, @project, @merge_request), class: "btn btn-grouped issuable-edit", id: "edit_merge_request" do
%i.fa.fa-pencil-square-o
Edit
- if @merge_request.closed?
= link_to 'Reopen', namespace_project_merge_request_path(@project.namespace, @project, @merge_request, merge_request: {state_event: :reopen }), method: :put, class: "btn btn-grouped btn-reopen reopen-mr-link", title: "Close merge request"
= link_to 'Reopen', merge_request_path(@merge_request, merge_request: {state_event: :reopen }), method: :put, class: "btn btn-grouped btn-reopen reopen-mr-link", title: "Close merge request"
%li{ id: dom_id(issue, 'sortable'), class: 'issue-row', 'data-iid' => issue.iid, 'data-url' => namespace_project_issue_path(@project.namespace, @project, issue) }
%li{ id: dom_id(issue, 'sortable'), class: 'issue-row', 'data-iid' => issue.iid, 'data-url' => issue_path(issue) }
%span.str-truncated
= link_to [@project.namespace.becomes(Namespace), @project, issue] do
%span.cgray ##{issue.iid}
......
%li{ id: dom_id(merge_request, 'sortable'), class: 'mr-row', 'data-iid' => merge_request.iid, 'data-url' => namespace_project_merge_request_path(@project.namespace, @project, merge_request) }
%li{ id: dom_id(merge_request, 'sortable'), class: 'mr-row', 'data-iid' => merge_request.iid, 'data-url' => merge_request_path(merge_request) }
%span.str-truncated
= link_to [@project.namespace.becomes(Namespace), @project, merge_request] do
%span.cgray ##{merge_request.iid}
......
......@@ -19,4 +19,4 @@
- if can? current_user, :remove_project, @project
.prepend-top-20
= link_to 'Remove project', namespace_project_path(@project.namespace, @project), data: { confirm: remove_project_message(@project)}, method: :delete, class: "btn btn-remove pull-right"
= link_to 'Remove project', project_path(@project), data: { confirm: remove_project_message(@project)}, method: :delete, class: "btn btn-remove pull-right"
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment