#222: added form for creating new branch

This commit is contained in:
Vokhmin Alexey V 2013-07-22 15:27:14 +04:00
parent c33588f620
commit 6f67b580c4
10 changed files with 59 additions and 7 deletions

View File

@ -7,6 +7,7 @@ RosaABF.controller('ProjectRefsController', ['$scope', '$http', 'ApiProject', fu
$scope.project_id = null;
$scope.current_ref = null;
$scope.project_resource = null;
$scope.new_branch = false;
$scope.init = function(project_id, ref, locale) {
$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.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.project_resource.$delete_branch(
{owner: $scope.project.owner.uname, project: $scope.project.name, ref: branch.ref},

View File

@ -11,6 +11,7 @@ var ProjectRef = function(atts) {
//with some logic...
self.isTag = self.object.type == 'tag';
self.ui_container = false;
self.path = function(project) {
return '/' + project.fullname + '/tree/' + self.ref;

View File

@ -18,6 +18,11 @@ RosaABF.factory("ApiProject", ['$resource', function($resource) {
url: '/:owner/:project/branches/:ref', // ?sha=<sha>
method: 'PUT',
isArray : false
},
create_branch: {
url: '/:owner/:project/branches', // ?new_ref=<new_ref>&from_ref=<from_ref>
method: 'POST',
isArray : false
}
}
);

View File

@ -75,7 +75,10 @@ header menu ul li a {
td.actions ul {
float: right;
}
.text { font-size: 12px; }
.text {
font-size: 12px;
padding-top: 2px;
}
td {
border-bottom: 1px solid #a9c6dd;
padding: 0 20px;

View File

@ -4,8 +4,8 @@ class Projects::Git::TreesController < Projects::Git::BaseController
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]
skip_authorize_resource :project, :only => [:destroy, :restore_branch]
before_filter lambda { authorize!(:write, @project) }, :only => [:destroy, :restore_branch]
skip_authorize_resource :project, :only => [:destroy, :restore_branch, :create]
before_filter lambda { authorize!(:write, @project) }, :only => [:destroy, :restore_branch, :create]
def show
render('empty') and return if @project.is_empty?
@ -39,6 +39,11 @@ class Projects::Git::TreesController < Projects::Git::BaseController
render :nothing => true
end
def create
status = @project.create_branch(params[:new_ref], params[:from_ref]) ? 200 : 422
render :nothing => true, :status => status
end
def destroy
status = @branch && @project.delete_branch(@branch, current_user) ? 200 : 422
render :nothing => true, :status => status

View File

@ -22,13 +22,23 @@
%a{'ng-href' => '{{branch.path(project)}}' } {{branch.ref}}
%td.actions
%ul.actions
%li.text{'ng-show' => 'branch.ref == current_ref'}
= t('layout.projects.base_branch')
- 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)'}
= 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)}}' }
= t('layout.projects.compare')
%li.text{'ng-show' => 'branch.ref == current_ref && !branch.ui_container'}
= t('layout.projects.base_branch')

View File

@ -28,6 +28,7 @@ en:
new_build_list: New build
confirm_delete: Are you sure you want to delete this project?
new: New project
new_branch: New branch
location: Location
git_repo_location: Path to git repo
current_project_header: Current project

View File

@ -28,6 +28,7 @@ ru:
new_build_list: Новая сборка
confirm_delete: Вы уверены, что хотите удалить этот проект?
new: Новый проект
new_branch: Новая ветка
location: Расположение
git_repo_location: Путь к git-репозиторию
current_project_header: Текущий проект

View File

@ -337,6 +337,7 @@ Rosa::Application.routes.draw do
get '/branches/:treeish' => "git/trees#branches", :as => :branches
delete '/branches/:treeish' => "git/trees#destroy", :as => :branches
put '/branches/:treeish' => "git/trees#restore_branch", :as => :branches
post '/branches' => "git/trees#create", :as => :branches
# Commits
get '/commits/:treeish(/*path)' => "git/commits#index", :as => :commits, :format => false
get '/commit/:id(.:format)' => "git/commits#show", :as => :commit

View File

@ -36,6 +36,14 @@ module Modules
# TODO: return something else instead of empty string on success and error
def restore_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
def delete_branch(branch, user)