From aadb77cf5600812377428e353cf47faa35076d25 Mon Sep 17 00:00:00 2001 From: Vokhmin Alexey V Date: Thu, 18 Jul 2013 21:20:22 +0400 Subject: [PATCH] #214: Fixed: Cannot read property from_ref of null --- .../angularjs/controllers/pull_request_controller.js | 8 ++++++-- app/views/projects/pull_requests/_status.html.haml | 2 +- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/app/assets/javascripts/angularjs/controllers/pull_request_controller.js b/app/assets/javascripts/angularjs/controllers/pull_request_controller.js index 0ee096af7..dce9d49b5 100644 --- a/app/assets/javascripts/angularjs/controllers/pull_request_controller.js +++ b/app/assets/javascripts/angularjs/controllers/pull_request_controller.js @@ -30,14 +30,18 @@ RosaABF.controller('PullRequestController',['$scope', '$http', 'ApiPullRequest', ); } - $scope.getBranch = function() { + // @param [from_ref] - sets only at first time + $scope.getBranch = function(from_ref) { if (!$scope.project_resource) { $scope.project_resource = ApiProject.resource.get({id: $scope.project_id}); } + // Fix: at first load + // Cannot read property 'from_ref' of null + if (!from_ref) { from_ref = $scope.pull.from_ref.ref; } $scope.project_resource.$refs({id: $scope.project_id}, function(results) { _.each(results.refs_list, function(ref){ var result = new ProjectRef(ref); - if (!result.isTag && result.ref == $scope.pull.from_ref.ref) { + if (!result.isTag && result.ref == from_ref) { $scope.branch = result; return true; } diff --git a/app/views/projects/pull_requests/_status.html.haml b/app/views/projects/pull_requests/_status.html.haml index 5b31777af..cfb843693 100644 --- a/app/views/projects/pull_requests/_status.html.haml +++ b/app/views/projects/pull_requests/_status.html.haml @@ -20,7 +20,7 @@ - if !@pull.cross_pull? && can?(:write, @project) - %div{'ng-init' => 'getBranch()', 'ng-show' => "pull.status == 'closed' || pull.status == 'merged'"} + %div{'ng-init' => "getBranch('#{@pull.from_ref}')", '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"}