Commit 3c2a6174 authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Merge branch 'ci-nav-changes' into 'master'

Integrate CI navigation more tightly with project

![Screen_Shot_2015-09-17_at_09.51.56](https://gitlab.com/gitlab-org/gitlab-ce/uploads/013807ad9f89a35a4af988199c2ee92f/Screen_Shot_2015-09-17_at_09.51.56.png)
![Screen_Shot_2015-09-17_at_09.52.14](https://gitlab.com/gitlab-org/gitlab-ce/uploads/8f9bdaafeef62fa451ee3699f003cbc4/Screen_Shot_2015-09-17_at_09.52.14.png)
![Screen_Shot_2015-09-17_at_09.52.07](https://gitlab.com/gitlab-org/gitlab-ce/uploads/cb726bf0651ddb74c10fd7bae9a333fb/Screen_Shot_2015-09-17_at_09.52.07.png)

/cc @dzaporozhets

See merge request !1324
parents 591f2e1d e960b3ad
......@@ -13,7 +13,9 @@ module ApplicationHelper
# current_controller?(:commits) # => false
# current_controller?(:commits, :tree) # => true
def current_controller?(*args)
args.any? { |v| v.to_s.downcase == controller.controller_name }
args.any? do |v|
v.to_s.downcase == controller.controller_name || v.to_s.downcase == controller.controller_path
end
end
# Check if a particular action is the current one
......
......@@ -4,118 +4,10 @@ module Ci
image_tag 'ci/loader.gif', alt: 'Loading'
end
# Navigation link helper
#
# Returns an `li` element with an 'active' class if the supplied
# controller(s) and/or action(s) are currently active. The content of the
# element is the value passed to the block.
#
# options - The options hash used to determine if the element is "active" (default: {})
# :controller - One or more controller names to check (optional).
# :action - One or more action names to check (optional).
# :path - A shorthand path, such as 'dashboard#index', to check (optional).
# :html_options - Extra options to be passed to the list element (optional).
# block - An optional block that will become the contents of the returned
# `li` element.
#
# When both :controller and :action are specified, BOTH must match in order
# to be marked as active. When only one is given, either can match.
#
# Examples
#
# # Assuming we're on TreeController#show
#
# # Controller matches, but action doesn't
# nav_link(controller: [:tree, :refs], action: :edit) { "Hello" }
# # => '<li>Hello</li>'
#
# # Controller matches
# nav_link(controller: [:tree, :refs]) { "Hello" }
# # => '<li class="active">Hello</li>'
#
# # Shorthand path
# nav_link(path: 'tree#show') { "Hello" }
# # => '<li class="active">Hello</li>'
#
# # Supplying custom options for the list element
# nav_link(controller: :tree, html_options: {class: 'home'}) { "Hello" }
# # => '<li class="home active">Hello</li>'
#
# Returns a list item element String
def nav_link(options = {}, &block)
if path = options.delete(:path)
if path.respond_to?(:each)
c = path.map { |p| p.split('#').first }
a = path.map { |p| p.split('#').last }
else
c, a, _ = path.split('#')
end
else
c = options.delete(:controller)
a = options.delete(:action)
end
if c && a
# When given both options, make sure BOTH are active
klass = current_controller?(*c) && current_action?(*a) ? 'active' : ''
else
# Otherwise check EITHER option
klass = current_controller?(*c) || current_action?(*a) ? 'active' : ''
end
# Add our custom class into the html_options, which may or may not exist
# and which may or may not already have a :class key
o = options.delete(:html_options) || {}
o[:class] ||= ''
o[:class] += ' ' + klass
o[:class].strip!
if block_given?
content_tag(:li, capture(&block), o)
else
content_tag(:li, nil, o)
end
end
# Check if a particular controller is the current one
#
# args - One or more controller names to check
#
# Examples
#
# # On TreeController
# current_controller?(:tree) # => true
# current_controller?(:commits) # => false
# current_controller?(:commits, :tree) # => true
def current_controller?(*args)
args.any? { |v| v.to_s.downcase == controller.controller_name }
end
# Check if a particular action is the current one
#
# args - One or more action names to check
#
# Examples
#
# # On Projects#new
# current_action?(:new) # => true
# current_action?(:create) # => false
# current_action?(:new, :create) # => true
def current_action?(*args)
args.any? { |v| v.to_s.downcase == action_name }
end
def date_from_to(from, to)
"#{from.to_s(:short)} - #{to.to_s(:short)}"
end
def body_data_page
path = controller.controller_path.split('/')
namespace = path.first if path.second
[namespace, controller.controller_name, controller.action_name].compact.join(":")
end
def duration_in_words(finished_at, started_at)
if finished_at && started_at
interval_in_seconds = finished_at.to_i - started_at.to_i
......
%ul.nav.nav-sidebar
= nav_link do
= link_to ci_root_path, title: 'Back to dashboard', data: {placement: 'right'}, class: 'back-link' do
= link_to admin_root_path, title: 'Back to dashboard', data: {placement: 'right'}, class: 'back-link' do
= icon('caret-square-o-left fw')
%span
Back to Dashboard
Back to Admin
%li.separate-item
= nav_link path: 'projects#index' do
......
%ul.nav.nav-sidebar
= nav_link do
= link_to root_path, title: 'Back to dashboard', data: {placement: 'right'}, class: 'back-link' do
= icon('caret-square-o-left fw')
%span
Back to GitLab
%li.separate-item
= nav_link path: 'projects#index' do
= link_to ci_root_path do
%i.fa.fa-home
%span
Projects
- if current_user && current_user.is_admin?
%li
= link_to ci_admin_projects_path do
%i.fa.fa-cogs
%span
Admin
%li
= link_to ci_help_path do
%i.fa.fa-info
%span
Help
......@@ -8,4 +8,4 @@
- else
= render "layouts/header/public", title: header_title
= render 'layouts/ci/page', sidebar: 'nav_dashboard'
= render 'layouts/ci/page'
......@@ -4,7 +4,7 @@
= icon('dashboard fw')
%span
Overview
= nav_link(controller: :projects) do
= nav_link(controller: [:admin, :projects]) do
= link_to admin_namespaces_projects_path, title: 'Projects', data: {placement: 'right'} do
= icon('cube fw')
%span
......@@ -24,6 +24,11 @@
= icon('key fw')
%span
Deploy Keys
= nav_link do
= link_to ci_admin_projects_path, title: 'Continuous Integration', data: {placement: 'right'} do
= icon('building fw')
%span
Continuous Integration
= nav_link(controller: :logs) do
= link_to admin_logs_path, title: 'Logs', data: {placement: 'right'} do
= icon('file-text fw')
......
%ul.nav.nav-sidebar
= nav_link(path: ['root#index', 'projects#trending', 'projects#starred', 'projects#index'], html_options: {class: 'home'}) do
= nav_link(path: ['root#index', 'projects#trending', 'projects#starred', 'dashboard/projects#index'], html_options: {class: 'home'}) do
= link_to root_path, title: 'Projects', data: {placement: 'right'} do
= icon('home fw')
%span
......@@ -31,6 +31,11 @@
%span
Merge Requests
%span.count= current_user.assigned_merge_requests.opened.count
= nav_link(path: 'ci/projects#index') do
= link_to ci_projects_path, title: 'Continuous Integration', data: {placement: 'right'} do
= icon('building fw')
%span
Continuous Integration
= nav_link(controller: :snippets) do
= link_to dashboard_snippets_path, title: 'Your snippets', data: {placement: 'right'} do
= icon('clipboard fw')
......@@ -46,8 +51,3 @@
= icon('user fw')
%span
Profile Settings
= nav_link(controller: :ci) do
= link_to ci_root_path, title: 'Continuous Integration', data: {placement: 'right'} do
= icon('building fw')
%span
CI
......@@ -76,6 +76,13 @@
Merge Requests
%span.count.merge_counter= @project.merge_requests.opened.count
- if @project.gitlab_ci?
= nav_link(controller: [:ci, :project]) do
= link_to ci_project_path(@project.gitlab_ci_project), title: 'Continuous Integration', data: {placement: 'right'} do
= icon('building fw')
%span
Continuous Integration
- if project_nav_tab? :settings
= nav_link(controller: [:project_members, :teams]) do
= link_to namespace_project_project_members_path(@project.namespace, @project), title: 'Members', class: 'team-tab tab', data: {placement: 'right'} do
......
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