33let angular = require ( 'angular' ) ;
44
55module . exports = angular . module ( 'spinnaker.core.delivery.manualPipelineExecution.controller' , [
6+ require ( 'angular-ui-bootstrap' ) ,
67 require ( '../../utils/lodash.js' ) ,
78 require ( '../../pipeline/config/triggers/jenkins/jenkinsTrigger.module.js' ) ,
9+ require ( '../../ci/jenkins/igor.service.js' ) ,
810] )
9- . controller ( 'ManualPipelineExecutionCtrl' , function ( $scope , $filter , _ , igorService , $modalInstance , pipeline , application ) {
11+ . controller ( 'ManualPipelineExecutionCtrl' , function ( _ , igorService , $modalInstance , pipeline , application ) {
1012
11- $scope . pipeline = pipeline ;
12-
13- $scope . application = application ;
14-
15- if ( ! pipeline ) {
16- $scope . pipelineOptions = application . pipelineConfigs ;
17- }
18-
19- $scope . command = {
13+ this . command = {
2014 pipeline : pipeline ,
2115 trigger : null ,
2216 selectedBuild : null ,
2317 } ;
2418
19+ this . viewState = {
20+ buildsLoading : true ,
21+ } ;
22+
2523 let addTriggers = ( ) => {
26- if ( ! $scope . command . pipeline ) {
27- $scope . command . trigger = null ;
24+ if ( ! this . command . pipeline ) {
25+ this . command . trigger = null ;
2826 return ;
2927 }
3028
31- $scope . triggers = _ . chain ( $scope . command . pipeline . triggers )
29+ this . triggers = _ . chain ( this . command . pipeline . triggers )
3230 . filter ( 'type' , 'jenkins' )
3331 . sortBy ( 'enabled' )
34- . map ( function ( trigger ) {
32+ . reverse ( )
33+ . map ( ( trigger ) => {
3534 var copy = _ . clone ( trigger ) ;
3635 copy . buildNumber = null ;
3736 copy . type = 'manual' ;
@@ -40,81 +39,90 @@ module.exports = angular.module('spinnaker.core.delivery.manualPipelineExecution
4039 } )
4140 . value ( ) ;
4241
43- $scope . command . trigger = _ . first ( $scope . triggers ) ;
44- $scope . builds = [ ] ;
42+ this . command . trigger = _ . first ( this . triggers ) ;
43+ this . builds = [ ] ;
4544 } ;
4645
47- $scope . viewState = {
48- triggering : false ,
49- buildsLoading : true ,
50- } ;
5146
52- $scope . triggerUpdated = function ( trigger ) {
53- $scope . viewState . buildsLoading = true ;
54- let command = $scope . command ;
47+ /**
48+ * Controller API
49+ */
50+
51+ this . triggerUpdated = ( trigger ) => {
52+ this . viewState . buildsLoading = true ;
53+ let command = this . command ;
5554
5655 if ( trigger !== undefined ) {
5756 command . trigger = trigger ;
5857 }
5958
6059 if ( command . trigger ) {
61- $scope . viewState . buildsLoading = true ;
62- igorService . listBuildsForJob ( command . trigger . master , command . trigger . job ) . then ( function ( builds ) {
63- $scope . builds = _ . filter ( builds , { building : false , result : 'SUCCESS' } ) ;
60+ this . viewState . buildsLoading = true ;
61+ igorService . listBuildsForJob ( command . trigger . master , command . trigger . job ) . then ( ( builds ) => {
62+ this . builds = _ . filter ( builds , { building : false , result : 'SUCCESS' } ) ;
6463 if ( ! angular . isDefined ( command . trigger . build ) ) {
65- command . selectedBuild = $scope . builds [ 0 ] ;
64+ command . selectedBuild = this . builds [ 0 ] ;
6665 }
67- $scope . viewState . buildsLoading = false ;
66+ this . viewState . buildsLoading = false ;
6867 } ) ;
6968 } else {
70- $scope . builds = [ ] ;
71- $scope . viewState . buildsLoading = false ;
69+ this . builds = [ ] ;
70+ this . viewState . buildsLoading = false ;
7271 }
7372 } ;
7473
75- $scope . pipelineSelected = ( ) => {
76- let pipeline = $scope . command . pipeline ,
74+ this . pipelineSelected = ( ) => {
75+ let pipeline = this . command . pipeline ,
7776 executions = application . executions || [ ] ;
78- $scope . currentlyRunningExecutions = executions
77+ this . currentlyRunningExecutions = executions
7978 . filter ( ( execution ) => execution . pipelineConfigId === pipeline . id && execution . isActive ) ;
8079 addTriggers ( ) ;
81- $scope . triggerUpdated ( ) ;
82- if ( pipeline . parameterConfig !== undefined && pipeline . parameterConfig . length ) {
83- $scope . parameters = { } ;
84- _ . each ( pipeline . parameterConfig , function ( parameter ) {
85- $scope . parameters [ parameter . name ] = parameter . default ;
86- } ) ;
87- }
80+ this . triggerUpdated ( ) ;
8881
89- } ;
82+ this . showRebakeOption = pipeline . stages . some ( ( stage ) => stage . type === 'bake' ) ;
9083
84+ if ( pipeline . parameterConfig !== undefined && pipeline . parameterConfig . length ) {
85+ this . parameters = { } ;
86+ pipeline . parameterConfig . forEach ( ( parameter ) => {
87+ this . parameters [ parameter . name ] = parameter . default ;
88+ } ) ;
89+ }
9190
92- $scope . updateSelectedBuild = function ( item ) {
93- $scope . command . selectedBuild = item ;
9491 } ;
9592
96- this . cancel = function ( ) {
97- $modalInstance . dismiss ( ) ;
93+ this . updateSelectedBuild = ( item ) => {
94+ this . command . selectedBuild = item ;
9895 } ;
9996
100- this . execute = function ( ) {
101- let selectedTrigger = $scope . command . trigger || { } ,
97+ this . execute = ( ) => {
98+ let selectedTrigger = this . command . trigger || { } ,
10299 command = { trigger : selectedTrigger } ,
103- pipeline = $scope . command . pipeline ;
100+ pipeline = this . command . pipeline ;
104101
105102 command . pipelineName = pipeline . name ;
106103
107- if ( selectedTrigger && $scope . command . selectedBuild ) {
108- selectedTrigger . buildNumber = $scope . command . selectedBuild . number ;
104+ if ( selectedTrigger && this . command . selectedBuild ) {
105+ selectedTrigger . buildNumber = this . command . selectedBuild . number ;
109106 }
110107 if ( pipeline . parameterConfig !== undefined && pipeline . parameterConfig . length ) {
111- selectedTrigger . parameters = $scope . parameters ;
108+ selectedTrigger . parameters = this . parameters ;
112109 }
113110 $modalInstance . close ( command ) ;
114111 } ;
115112
113+ this . cancel = $modalInstance . dismiss ;
114+
115+
116+ /**
117+ * Initialization
118+ */
119+
116120 if ( pipeline ) {
117- $scope . pipelineSelected ( ) ;
121+ this . pipelineSelected ( ) ;
122+ }
123+
124+ if ( ! pipeline ) {
125+ this . pipelineOptions = application . pipelineConfigs ;
118126 }
119127
120128 } ) . name ;
0 commit comments