#214: some refactoring of JS, added comments
This commit is contained in:
parent
bc89c873ba
commit
2b423e6a6e
|
@ -46,7 +46,10 @@ RosaABF.controller('ProjectRefsController', function($scope, $http, ApiProject)
|
|||
$scope.destroy = function(branch) {
|
||||
$scope.project_resource.$delete_branch(
|
||||
{owner: $scope.project.owner.uname, project: $scope.project.name, ref: branch.ref},
|
||||
function() { $scope.getRefs(); }
|
||||
function() {
|
||||
var i = $scope.branches.indexOf(branch);
|
||||
if(i != -1) { $scope.branches.splice(i, 1); }
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -12,7 +12,6 @@ RosaABF.controller('PullRequestController', function($scope, $http, ApiPullReque
|
|||
$scope.branch = null;
|
||||
|
||||
$scope.can_delete_branch = false;
|
||||
$scope.check_branch = false;
|
||||
|
||||
$scope.init = function(project_id, serial_id) {
|
||||
$scope.project_id = project_id;
|
||||
|
@ -27,7 +26,6 @@ RosaABF.controller('PullRequestController', function($scope, $http, ApiPullReque
|
|||
$scope.pull = results.pull_request;
|
||||
if ($scope.pull.merged_at) { $scope.merged_at = DateTimeFormatter.utc($scope.pull.merged_at); }
|
||||
if ($scope.pull.closed_at) { $scope.closed_at = DateTimeFormatter.utc($scope.pull.closed_at); }
|
||||
if ($scope.check_branch && ($scope.pull.status == 'closed' || $scope.pull.status == 'merged')) { $scope.getBranch(); }
|
||||
}
|
||||
);
|
||||
}
|
||||
|
@ -40,8 +38,7 @@ RosaABF.controller('PullRequestController', function($scope, $http, ApiPullReque
|
|||
_.each(results.refs_list, function(ref){
|
||||
var result = new ProjectRef(ref);
|
||||
if (!result.isTag && result.ref == $scope.pull.from_ref.ref) {
|
||||
$scope.can_delete_branch = result.object.sha == $scope.pull.from_ref.sha;
|
||||
$scope.branch = true;
|
||||
$scope.branch = result;
|
||||
return true;
|
||||
}
|
||||
});
|
||||
|
@ -70,13 +67,13 @@ RosaABF.controller('PullRequestController', function($scope, $http, ApiPullReque
|
|||
|
||||
$scope.deleteBranch = function() {
|
||||
$scope.project_resource.$delete_branch($scope.branch_params(), function() {
|
||||
$scope.branch = false;
|
||||
$scope.branch = null;
|
||||
});
|
||||
}
|
||||
|
||||
$scope.restoreBranch = function() {
|
||||
$scope.project_resource.$restore_branch($scope.branch_params(), function() {
|
||||
$scope.branch = true;
|
||||
$scope.getBranch();
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -35,14 +35,16 @@ class Projects::Git::TreesController < Projects::Git::BaseController
|
|||
end
|
||||
|
||||
def restore_branch
|
||||
sha = params[:sha]
|
||||
@project.restore_branch @treeish, sha if @treeish.present? && sha.present?
|
||||
@project.restore_branch @treeish, params[:sha] if @treeish.present? && params[:sha].present?
|
||||
render :nothing => true
|
||||
end
|
||||
|
||||
def destroy
|
||||
@project.delete_branch @branch, current_user if @branch && @project.default_branch != @branch.name
|
||||
render :nothing => true
|
||||
if @branch && @project.default_branch != @branch.name && @project.delete_branch(@branch, current_user).present?
|
||||
render :nothing => true
|
||||
else
|
||||
render :nothing => true, :status => 422
|
||||
end
|
||||
end
|
||||
|
||||
def branches
|
||||
|
|
|
@ -20,8 +20,8 @@
|
|||
|
||||
|
||||
- if !@pull.cross_pull? && can?(:write, @project)
|
||||
%div{'ng-init' => 'check_branch = true', 'ng-show' => "pull.status == 'closed' || pull.status == 'merged'"}
|
||||
%a.button{:href => '', 'ng-click' => 'deleteBranch()', 'ng-show' => "branch && can_delete_branch"}
|
||||
%div{'ng-init' => 'getBranch()', 'ng-show' => "pull.status == 'closed' || pull.status == 'merged'"}
|
||||
%a.button{:href => '', 'ng-click' => 'deleteBranch()', 'ng-show' => "branch && branch.object.sha == pull.from_ref.sha"}
|
||||
= t('layout.projects.delete_branch')
|
||||
%a.button{:href => '', 'ng-click' => 'restoreBranch()', 'ng-hide' => "branch"}
|
||||
= t('layout.projects.restore_branch')
|
||||
|
|
|
@ -33,6 +33,7 @@ module Modules
|
|||
repo.tags.map(&:name) + repo.branches.map(&:name)
|
||||
end
|
||||
|
||||
# TODO: return something else instead of empty string on success and error
|
||||
def restore_branch(branch, sha)
|
||||
repo.git.native(:branch, {}, branch, sha)
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue