Commit 92fd3cce authored by Douwe Maan's avatar Douwe Maan
Browse files

Add helpers for header title and sidebar, and move setting those from controllers to layouts.

parent 4f266b5ff3b1
......@@ -8,7 +8,6 @@ class Dispatcher
initPageScripts: ->
page = $('body').attr('data-page')
project_id = $('body').attr('data-project-id')
unless page
return false
......
......@@ -3,15 +3,9 @@
# Automatically sets the layout and ensures an administrator is logged in
class Admin::ApplicationController < ApplicationController
before_action :authenticate_admin!
before_action :set_title
layout 'admin'
def authenticate_admin!
return render_404 unless current_user.is_admin?
end
def set_title
@title = "Admin area"
@title_url = admin_root_path
@sidebar = "admin"
end
end
......@@ -3,6 +3,7 @@
class ApplicationController < ActionController::Base
include Gitlab::CurrentSettings
include GitlabRoutingHelper
include PageLayoutHelper
PER_PAGE = 20
......
class Dashboard::ApplicationController < ApplicationController
before_action :set_title
private
def set_title
@title = "Dashboard"
@title_url = root_path
@sidebar = "dashboard"
end
layout 'dashboard'
end
class Explore::ApplicationController < ApplicationController
before_action :set_title
private
def set_title
@title = "Explore GitLab"
@title_url = explore_root_path
@sidebar = "explore"
end
layout 'explore'
end
class Groups::ApplicationController < ApplicationController
before_action :set_title
layout 'group'
private
......@@ -18,10 +18,4 @@ def authorize_admin_group!
return render_404
end
end
def set_title
@title = group.name
@title_url = group_path(group)
@sidebar = "group"
end
end
......@@ -12,6 +12,8 @@ class GroupsController < Groups::ApplicationController
before_action :load_projects, except: [:new, :create, :projects, :edit, :update]
before_action :event_filter, only: :show
layout :determine_layout
def new
@group = Group.new
end
......@@ -116,11 +118,11 @@ def authorize_create_group!
end
end
def set_title
def determine_layout
if [:new, :create].include?(action_name.to_sym)
@title = 'New Group'
'application'
else
super
'group'
end
end
......
class HelpController < ApplicationController
before_action :set_title
layout 'help'
def index
end
......@@ -46,11 +46,6 @@ def ui
private
def set_title
@title = "Help"
@title_url = help_path
end
def path_params
params.require(:category)
params.require(:file)
......
class Oauth::ApplicationsController < Doorkeeper::ApplicationsController
include PageLayoutHelper
before_action :authenticate_user!
before_action :set_title
layout 'profile'
def index
head :forbidden and return
......@@ -36,10 +39,4 @@ def set_application
rescue_from ActiveRecord::RecordNotFound do |exception|
render "errors/not_found", layout: "errors", status: 404
end
def set_title
@title = "Profile"
@title_url = profile_path
@sidebar = "profile"
end
end
class Oauth::AuthorizationsController < Doorkeeper::AuthorizationsController
before_action :authenticate_resource_owner!
before_action :set_title
layout 'profile'
def new
if pre_auth.authorizable?
......@@ -54,10 +55,4 @@ def authorization
def strategy
@strategy ||= server.authorization_request(pre_auth.response_type)
end
def set_title
@title = "Profile"
@title_url = profile_path
@sidebar = "profile"
end
end
class Oauth::AuthorizedApplicationsController < Doorkeeper::AuthorizedApplicationsController
before_action :set_title
include PageLayoutHelper
layout 'profile'
def destroy
Doorkeeper::AccessToken.revoke_all_for(params[:id], current_resource_owner)
redirect_to applications_profile_url, notice: I18n.t(:notice, scope: [:doorkeeper, :flash, :authorized_applications, :destroy])
end
private
def set_title
@title = "Profile"
@title_url = profile_path
@sidebar = "profile"
end
end
class Profiles::ApplicationController < ApplicationController
before_action :set_title
private
def set_title
@title = "Profile"
@title_url = profile_path
@sidebar = "profile"
end
layout 'profile'
end
......@@ -2,9 +2,10 @@ class Profiles::PasswordsController < Profiles::ApplicationController
skip_before_action :check_password_expiration, only: [:new, :create]
before_action :set_user
before_action :set_title
before_action :authorize_change_password!
layout :determine_layout
def new
end
......@@ -64,11 +65,11 @@ def set_user
@user = current_user
end
def set_title
def determine_layout
if [:new, :create].include?(action_name.to_sym)
@title = "New password"
'application'
else
super
'profile'
end
end
......
......@@ -6,7 +6,6 @@ class ProjectsController < ApplicationController
# Authorize
before_action :authorize_admin_project!, only: [:edit, :update, :destroy, :transfer, :archive, :unarchive]
before_action :set_title, only: [:new, :create]
before_action :event_filter, only: :show
layout :determine_layout
......@@ -160,10 +159,6 @@ def markdown_preview
private
def set_title
@title = 'New Project'
end
def determine_layout
if [:new, :create].include?(action_name.to_sym)
'application'
......
class SearchController < ApplicationController
include SearchHelper
before_action :set_title
layout 'search'
def show
return if params[:search].nil? || params[:search].blank?
......@@ -57,11 +57,4 @@ def autocomplete
render json: search_autocomplete_opts(term).to_json
end
private
def set_title
@title = "Search"
@title_url = search_path
end
end
......@@ -7,10 +7,9 @@ class SnippetsController < ApplicationController
# Allow destroy snippet
before_action :authorize_admin_snippet!, only: [:destroy]
before_action :set_title
skip_before_action :authenticate_user!, only: [:index, :user_index, :show, :raw]
layout 'snippets'
respond_to :html
def index
......@@ -96,12 +95,6 @@ def authorize_admin_snippet!
return render_404 unless can?(current_user, :admin_personal_snippet, @snippet)
end
def set_title
@title = 'Snippets'
@title_url = snippets_path
@sidebar = "snippets"
end
def snippet_params
params.require(:personal_snippet).permit(:title, :content, :file_name, :private, :visibility_level)
end
......
......@@ -332,12 +332,4 @@ def state_filters_text_for(entity, project)
end
"#{entity_title}#{count}"
end
def page_title(*titles)
@page_title ||= []
@page_title.push(*titles.compact) if titles.any?
@page_title.join(" | ")
end
end
module PageLayoutHelper
def page_title(*titles)
@page_title ||= []
@page_title.push(*titles.compact) if titles.any?
@page_title.join(" | ")
end
def header_title(title = nil, title_url = nil)
if title
@header_title = title
@header_title_url = title_url
else
@header_title_url ? link_to(@header_title, @header_title_url) : @header_title
end
end
def sidebar(name = nil)
if name
@sidebar = name
else
@sidebar
end
end
end
- page_title 'New Group'
- header_title 'New Group'
= form_for @group, html: { class: 'group-form form-horizontal' } do |f|
- if @group.errors.any?
.alert.alert-danger
......
- page_title "Admin area"
- header_title "Admin area", admin_root_path
- sidebar "admin"
= render template: "layouts/application"
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