Created the gear settings entry and created a way to initialize both sections with one controller

Changed views to partials, created the repository view,
created a repository_helper to further aid the creation of variables
across different controllers
This commit is contained in:
Jose Ivan Vargas 2017-01-23 18:28:40 -06:00
parent c51d720366
commit 0b74ae849d
10 changed files with 68 additions and 27 deletions

View file

@ -7,12 +7,11 @@ class Projects::DeployKeysController < Projects::ApplicationController
layout "project_settings"
def index
@key = DeployKey.new
set_index_vars
redirect_to namespace_project_settings_repository_path(@project.namespace, @project)
end
def new
redirect_to namespace_project_deploy_keys_path(@project.namespace, @project)
redirect_to namespace_project_settings_repository_path(@project.namespace, @project)
end
def create
@ -20,7 +19,7 @@ class Projects::DeployKeysController < Projects::ApplicationController
set_index_vars
if @key.valid? && @project.deploy_keys << @key
redirect_to namespace_project_deploy_keys_path(@project.namespace, @project)
redirect_to namespace_project_settings_repository_path(@project.namespace, @project)
else
render "index"
end
@ -29,7 +28,7 @@ class Projects::DeployKeysController < Projects::ApplicationController
def enable
Projects::EnableDeployKeyService.new(@project, current_user, params).execute
redirect_to namespace_project_deploy_keys_path(@project.namespace, @project)
redirect_to namespace_project_settings_repository_path(@project.namespace, @project)
end
def disable

View file

@ -8,14 +8,13 @@ class Projects::ProtectedBranchesController < Projects::ApplicationController
layout "project_settings"
def index
@protected_branch = @project.protected_branches.new
load_gon_index
redirect_to namespace_project_settings_repository_path(@project.namespace, @project)
end
def create
@protected_branch = ::ProtectedBranches::CreateService.new(@project, current_user, protected_branch_params).execute
if @protected_branch.persisted?
redirect_to namespace_project_protected_branches_path(@project.namespace, @project)
redirect_to namespace_project_settings_repository_path(@project.namespace, @project)
else
load_protected_branches
load_gon_index
@ -45,7 +44,7 @@ class Projects::ProtectedBranchesController < Projects::ApplicationController
@protected_branch.destroy
respond_to do |format|
format.html { redirect_to namespace_project_protected_branches_path }
format.html { redirect_to namespace_project_settings_repository_path }
format.js { head :ok }
end
end

View file

@ -1,8 +1,42 @@
module Projects
module Settings
class RepositoryController < Projects::ApplicationController
def show
include RepositoryHelper
before_action :authorize_admin_project!
before_action :load_protected_branches, only: [:show]
def show
define_deploy_keys_variables
define_protected_branches_controller
end
def load_protected_branches
@protected_branches = @project.protected_branches.order(:name).page(params[:page])
end
def set_index_vars
@enabled_keys ||= @project.deploy_keys
@available_keys ||= current_user.accessible_deploy_keys - @enabled_keys
@available_project_keys ||= current_user.project_deploy_keys - @enabled_keys
@available_public_keys ||= DeployKey.are_public - @enabled_keys
# Public keys that are already used by another accessible project are already
# in @available_project_keys.
@available_public_keys -= @available_project_keys
end
private
def define_deploy_keys_variables
@key = DeployKey.new
set_index_vars
end
def define_protected_branches_controller
@protected_branch = @project.protected_branches.new
load_gon_index(@project)
end
end
end

View file

@ -0,0 +1,13 @@
module RepositoryHelper
def access_levels_options
{
push_access_levels: ProtectedBranch::PushAccessLevel.human_access_levels.map { |id, text| { id: id, text: text, before_divider: true } },
merge_access_levels: ProtectedBranch::MergeAccessLevel.human_access_levels.map { |id, text| { id: id, text: text, before_divider: true } }
}
end
def load_gon_index(project)
params = { open_branches: project.open_branches.map { |br| { text: br.name, id: br.name, title: br.name } } }
gon.push(params.merge(access_levels_options))
end
end

View file

@ -4,18 +4,14 @@
%span
Members
- if can_edit
= nav_link(controller: :deploy_keys) do
= link_to namespace_project_deploy_keys_path(@project.namespace, @project), title: 'Deploy Keys' do
= nav_link(controller: :repository) do
= link_to namespace_project_settings_repository_path(@project.namespace, @project), title: 'Repository' do
%span
Deploy Keys
Repository
= nav_link(controller: :integrations) do
= link_to namespace_project_settings_integrations_path(@project.namespace, @project), title: 'Integrations' do
%span
Integrations
= nav_link(controller: :protected_branches) do
= link_to namespace_project_protected_branches_path(@project.namespace, @project), title: 'Protected Branches' do
%span
Protected Branches
- if @project.feature_available?(:builds, current_user)
= nav_link(controller: :ci_cd) do

View file

@ -1,15 +1,13 @@
- page_title "Deploy Keys"
.row.prepend-top-default
.col-lg-3.profile-settings-sidebar
%h4.prepend-top-0
= page_title
Deploy Keys
%p
Deploy keys allow read-only access to your repository. Deploy keys can be used for CI, staging or production servers. You can create a deploy key or add an existing one.
.col-lg-9
%h5.prepend-top-0
Create a new deploy key for this project
= render "form"
= render "projects/deploy_keys/form"
.col-lg-9.col-lg-offset-3
%hr
.col-lg-9.col-lg-offset-3.append-bottom-default.deploy-keys

View file

@ -23,6 +23,6 @@
- if can_admin_project
%th
%tbody
= render partial: @protected_branches, locals: { can_admin_project: can_admin_project }
= render partial: 'projects/protected_branches/protected_branch', collection: @protected_branches, locals: { can_admin_project: can_admin_project}
= paginate @protected_branches, theme: 'gitlab'

View file

@ -10,7 +10,7 @@
= f.label :name, class: 'col-md-2 text-right' do
Branch:
.col-md-10
= render partial: "dropdown", locals: { f: f }
= render partial: "projects/protected_branches/dropdown", locals: { f: f }
.help-block
= link_to 'Wildcards', help_page_path('user/project/protected_branches', anchor: 'wildcard-protected-branches')
such as

View file

@ -17,6 +17,6 @@
%p.append-bottom-0 Read more about #{link_to "protected branches", help_page_path("user/project/protected_branches"), class: "underlined-link"} and #{link_to "project permissions", help_page_path("user/permissions"), class: "underlined-link"}.
.col-lg-9
- if can? current_user, :admin_project, @project
= render 'create_protected_branch'
= render 'projects/protected_branches/create_protected_branch'
= render "branches_list"
= render "projects/protected_branches/branches_list"

View file

@ -1,2 +1,4 @@
%h1
Hello World
- page_title "Repository"
= render "projects/deploy_keys/index"
= render "projects/protected_branches/index"