Skip to content

Commit

Permalink
route to pipeline config if no executions or configurations
Browse files Browse the repository at this point in the history
  • Loading branch information
anotherchrisberry committed Feb 12, 2015
1 parent 2b9e465 commit de67419
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ angular.module('deckApp.delivery.pipelineExecutions.controller', [
'deckApp.pipelines.config.service',
'deckApp.utils.scrollTo'
])
.controller('pipelineExecutions', function($scope, $q, executionsService, d3Service, pipelineConfigService, scrollToService) {
.controller('pipelineExecutions', function($scope, $q, $state, executionsService, d3Service, pipelineConfigService, scrollToService) {
var controller = this;

$scope.viewState = {
Expand Down Expand Up @@ -122,6 +122,11 @@ angular.module('deckApp.delivery.pipelineExecutions.controller', [
if ($scope.detailsTarget) {
scrollToService.scrollTo('execution-' + $scope.detailsTarget, 250);
}
var noExecutions = !results.executions || !results.executions.length;
var noConfigurations = !results.configurations.length;
if(noExecutions && noConfigurations) {
$state.go('^.pipelineConfig');
}
}

function dataInitializationFailure() {
Expand Down
32 changes: 26 additions & 6 deletions app/scripts/modules/delivery/pipelineExecutions.controller.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,43 @@ describe('Controller: pipelineExecutions', function () {

var controller;
var scope;
var $state;
var pipelineConfigService;
var executionsService;
var $q;

beforeEach(
module('deckApp.delivery.pipelineExecutions.controller')
);

beforeEach(
inject(function ($rootScope, $controller) {
inject(function ($rootScope, $controller, _$state_, _pipelineConfigService_, _executionsService_, _$q_) {
scope = $rootScope.$new();
$state = { go: angular.noop };
pipelineConfigService = _pipelineConfigService_;
executionsService = _executionsService_;
$q = _$q_;
scope.application = {name: 'foo'};
controller = $controller('pipelineExecutions', {
$scope: scope
});

this.initializeController = function() {
controller = $controller('pipelineExecutions', {
$scope: scope,
$state: $state,
pipelineConfigService: pipelineConfigService,
executionsService: executionsService,
});
};
})
);

it('should instantiate the controller', function () {
expect(controller).toBeDefined();
it('should reroute to pipeline config when no execution history or configurations', function () {
spyOn($state, 'go');
spyOn(pipelineConfigService, 'getPipelinesForApplication').and.returnValue($q.when({ plain: angular.noop, length: 0 }));
spyOn(executionsService, 'getAll').and.returnValue($q.when([]));
this.initializeController();
scope.$digest();

expect($state.go).toHaveBeenCalledWith('^.pipelineConfig');
});
});

4 changes: 2 additions & 2 deletions app/scripts/modules/pipelines/config/pipelineConfig.html
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<div class="row" ng-if="application.pipelines.length">
<div class="col-md-4">
<a class="btn btn-link" ui-sref="^.executions">
<span class="glyphicon glyphicon-arrow-left"></span>
Back to Executions
<span class="small glyphicon glyphicon glyphicon-circle-arrow-left"></span>
Pipeline Executions
</a>
</div>
<div class="col-md-4 text-right">
Expand Down

0 comments on commit de67419

Please sign in to comment.