#222: added form for creating new branch
This commit is contained in:
parent
c33588f620
commit
6f67b580c4
|
@ -7,6 +7,7 @@ RosaABF.controller('ProjectRefsController', ['$scope', '$http', 'ApiProject', fu
|
||||||
$scope.project_id = null;
|
$scope.project_id = null;
|
||||||
$scope.current_ref = null;
|
$scope.current_ref = null;
|
||||||
$scope.project_resource = null;
|
$scope.project_resource = null;
|
||||||
|
$scope.new_branch = false;
|
||||||
|
|
||||||
$scope.init = function(project_id, ref, locale) {
|
$scope.init = function(project_id, ref, locale) {
|
||||||
$scope.project_id = project_id;
|
$scope.project_id = project_id;
|
||||||
|
@ -49,6 +50,22 @@ RosaABF.controller('ProjectRefsController', ['$scope', '$http', 'ApiProject', fu
|
||||||
$scope.singleton.project.branches_count = $scope.branches.length;
|
$scope.singleton.project.branches_count = $scope.branches.length;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$scope.create = function(branch) {
|
||||||
|
branch.ui_container = false;
|
||||||
|
$scope.project_resource.$create_branch(
|
||||||
|
{
|
||||||
|
owner: $scope.project.owner.uname,
|
||||||
|
project: $scope.project.name,
|
||||||
|
from_ref: branch.ref,
|
||||||
|
new_ref: branch.new_ref
|
||||||
|
}, function() { // on success
|
||||||
|
$scope.getRefs();
|
||||||
|
}, function () { // on error
|
||||||
|
$scope.getRefs();
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
$scope.destroy = function(branch) {
|
$scope.destroy = function(branch) {
|
||||||
$scope.project_resource.$delete_branch(
|
$scope.project_resource.$delete_branch(
|
||||||
{owner: $scope.project.owner.uname, project: $scope.project.name, ref: branch.ref},
|
{owner: $scope.project.owner.uname, project: $scope.project.name, ref: branch.ref},
|
||||||
|
|
|
@ -11,6 +11,7 @@ var ProjectRef = function(atts) {
|
||||||
|
|
||||||
//with some logic...
|
//with some logic...
|
||||||
self.isTag = self.object.type == 'tag';
|
self.isTag = self.object.type == 'tag';
|
||||||
|
self.ui_container = false;
|
||||||
|
|
||||||
self.path = function(project) {
|
self.path = function(project) {
|
||||||
return '/' + project.fullname + '/tree/' + self.ref;
|
return '/' + project.fullname + '/tree/' + self.ref;
|
||||||
|
|
|
@ -18,6 +18,11 @@ RosaABF.factory("ApiProject", ['$resource', function($resource) {
|
||||||
url: '/:owner/:project/branches/:ref', // ?sha=<sha>
|
url: '/:owner/:project/branches/:ref', // ?sha=<sha>
|
||||||
method: 'PUT',
|
method: 'PUT',
|
||||||
isArray : false
|
isArray : false
|
||||||
|
},
|
||||||
|
create_branch: {
|
||||||
|
url: '/:owner/:project/branches', // ?new_ref=<new_ref>&from_ref=<from_ref>
|
||||||
|
method: 'POST',
|
||||||
|
isArray : false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
|
@ -75,7 +75,10 @@ header menu ul li a {
|
||||||
td.actions ul {
|
td.actions ul {
|
||||||
float: right;
|
float: right;
|
||||||
}
|
}
|
||||||
.text { font-size: 12px; }
|
.text {
|
||||||
|
font-size: 12px;
|
||||||
|
padding-top: 2px;
|
||||||
|
}
|
||||||
td {
|
td {
|
||||||
border-bottom: 1px solid #a9c6dd;
|
border-bottom: 1px solid #a9c6dd;
|
||||||
padding: 0 20px;
|
padding: 0 20px;
|
||||||
|
|
|
@ -4,8 +4,8 @@ class Projects::Git::TreesController < Projects::Git::BaseController
|
||||||
skip_before_filter :set_branch_and_tree, :set_treeish_and_path, :only => :archive
|
skip_before_filter :set_branch_and_tree, :set_treeish_and_path, :only => :archive
|
||||||
before_filter lambda { raise Grit::NoSuchPathError if params[:treeish] != @branch.try(:name) }, :only => [:branch, :destroy]
|
before_filter lambda { raise Grit::NoSuchPathError if params[:treeish] != @branch.try(:name) }, :only => [:branch, :destroy]
|
||||||
|
|
||||||
skip_authorize_resource :project, :only => [:destroy, :restore_branch]
|
skip_authorize_resource :project, :only => [:destroy, :restore_branch, :create]
|
||||||
before_filter lambda { authorize!(:write, @project) }, :only => [:destroy, :restore_branch]
|
before_filter lambda { authorize!(:write, @project) }, :only => [:destroy, :restore_branch, :create]
|
||||||
|
|
||||||
def show
|
def show
|
||||||
render('empty') and return if @project.is_empty?
|
render('empty') and return if @project.is_empty?
|
||||||
|
@ -39,6 +39,11 @@ class Projects::Git::TreesController < Projects::Git::BaseController
|
||||||
render :nothing => true
|
render :nothing => true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def create
|
||||||
|
status = @project.create_branch(params[:new_ref], params[:from_ref]) ? 200 : 422
|
||||||
|
render :nothing => true, :status => status
|
||||||
|
end
|
||||||
|
|
||||||
def destroy
|
def destroy
|
||||||
status = @branch && @project.delete_branch(@branch, current_user) ? 200 : 422
|
status = @branch && @project.delete_branch(@branch, current_user) ? 200 : 422
|
||||||
render :nothing => true, :status => status
|
render :nothing => true, :status => status
|
||||||
|
|
|
@ -22,13 +22,23 @@
|
||||||
%a{'ng-href' => '{{branch.path(project)}}' } {{branch.ref}}
|
%a{'ng-href' => '{{branch.path(project)}}' } {{branch.ref}}
|
||||||
%td.actions
|
%td.actions
|
||||||
%ul.actions
|
%ul.actions
|
||||||
%li.text{'ng-show' => 'branch.ref == current_ref'}
|
|
||||||
= t('layout.projects.base_branch')
|
|
||||||
- if can?(:write, @project)
|
- if can?(:write, @project)
|
||||||
%li{'ng-hide' => 'branch.ref == current_ref'}
|
%li{'ng-hide' => 'branch.ref == current_ref || branch.ui_container'}
|
||||||
%a{:href => '', 'ng-click' => 'destroy(branch)'}
|
%a{:href => '', 'ng-click' => 'destroy(branch)'}
|
||||||
= t('layout.projects.delete_branch')
|
= t('layout.projects.delete_branch')
|
||||||
%li{'ng-hide' => 'branch.ref == current_ref'}
|
%li{'ng-hide' => 'branch.ui_container'}
|
||||||
|
%a{:href => '', 'ng-click' => 'branch.ui_container = true'}
|
||||||
|
= t('layout.projects.new_branch')
|
||||||
|
%li{'ng-show' => 'branch.ui_container'}
|
||||||
|
%form{'ng-submit' => 'create(branch)'}
|
||||||
|
%input{:name => 'new_ref', 'ng-model' => 'branch.new_ref'}
|
||||||
|
%input{:type => 'submit', :value =>t('layout.create')}
|
||||||
|
%a{:href => '', 'ng-click' => 'branch.ui_container = false'}
|
||||||
|
= t('layout.cancel')
|
||||||
|
%li{'ng-hide' => 'branch.ref == current_ref || branch.ui_container'}
|
||||||
%a{'ng-href' => '{{branch.diff_path(project, current_ref)}}' }
|
%a{'ng-href' => '{{branch.diff_path(project, current_ref)}}' }
|
||||||
= t('layout.projects.compare')
|
= t('layout.projects.compare')
|
||||||
|
%li.text{'ng-show' => 'branch.ref == current_ref && !branch.ui_container'}
|
||||||
|
= t('layout.projects.base_branch')
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -28,6 +28,7 @@ en:
|
||||||
new_build_list: New build
|
new_build_list: New build
|
||||||
confirm_delete: Are you sure you want to delete this project?
|
confirm_delete: Are you sure you want to delete this project?
|
||||||
new: New project
|
new: New project
|
||||||
|
new_branch: New branch
|
||||||
location: Location
|
location: Location
|
||||||
git_repo_location: Path to git repo
|
git_repo_location: Path to git repo
|
||||||
current_project_header: Current project
|
current_project_header: Current project
|
||||||
|
|
|
@ -28,6 +28,7 @@ ru:
|
||||||
new_build_list: Новая сборка
|
new_build_list: Новая сборка
|
||||||
confirm_delete: Вы уверены, что хотите удалить этот проект?
|
confirm_delete: Вы уверены, что хотите удалить этот проект?
|
||||||
new: Новый проект
|
new: Новый проект
|
||||||
|
new_branch: Новая ветка
|
||||||
location: Расположение
|
location: Расположение
|
||||||
git_repo_location: Путь к git-репозиторию
|
git_repo_location: Путь к git-репозиторию
|
||||||
current_project_header: Текущий проект
|
current_project_header: Текущий проект
|
||||||
|
|
|
@ -337,6 +337,7 @@ Rosa::Application.routes.draw do
|
||||||
get '/branches/:treeish' => "git/trees#branches", :as => :branches
|
get '/branches/:treeish' => "git/trees#branches", :as => :branches
|
||||||
delete '/branches/:treeish' => "git/trees#destroy", :as => :branches
|
delete '/branches/:treeish' => "git/trees#destroy", :as => :branches
|
||||||
put '/branches/:treeish' => "git/trees#restore_branch", :as => :branches
|
put '/branches/:treeish' => "git/trees#restore_branch", :as => :branches
|
||||||
|
post '/branches' => "git/trees#create", :as => :branches
|
||||||
# Commits
|
# Commits
|
||||||
get '/commits/:treeish(/*path)' => "git/commits#index", :as => :commits, :format => false
|
get '/commits/:treeish(/*path)' => "git/commits#index", :as => :commits, :format => false
|
||||||
get '/commit/:id(.:format)' => "git/commits#show", :as => :commit
|
get '/commit/:id(.:format)' => "git/commits#show", :as => :commit
|
||||||
|
|
|
@ -36,6 +36,14 @@ module Modules
|
||||||
# TODO: return something else instead of empty string on success and error
|
# TODO: return something else instead of empty string on success and error
|
||||||
def restore_branch(branch, sha)
|
def restore_branch(branch, sha)
|
||||||
repo.git.native(:branch, {}, branch, sha)
|
repo.git.native(:branch, {}, branch, sha)
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
|
||||||
|
def create_branch(new_ref, from_ref)
|
||||||
|
return false if new_ref.blank? || from_ref.blank? ||
|
||||||
|
repo.branches.none?{|b| b.name == from_ref} ||
|
||||||
|
repo.branches.one?{|b| b.name == new_ref}
|
||||||
|
restore_branch new_ref, from_ref
|
||||||
end
|
end
|
||||||
|
|
||||||
def delete_branch(branch, user)
|
def delete_branch(branch, user)
|
||||||
|
|
Loading…
Reference in New Issue