import type { IController , IScope } from 'angular' ; import { extend } from 'lodash' ; import { $q } from 'ngimport' ; import type { IAccountDetails , IArtifact , IExpectedArtifact } from '@spinnaker/core' ; import { AccountService , ExpectedArtifactSelectorViewController , NgGenericArtifactDelegate } from '@spinnaker/core' ; export class DeployCloudFormationStackConfigController implements IController { public state = { loaded : false , } ; public textSource = 'text' ; public artifactSource = 'artifact' ; public sources = [ this . textSource , this . artifactSource ] ; public showClusterSelect = false ; public accounts : IAccountDetails [ ] ; public cloudFormationStackArtifactDelegate : NgGenericArtifactDelegate ; public cloudFormationStackArtifactController : ExpectedArtifactSelectorViewController ; public static $inject = [ '$scope' ] ; constructor ( private $scope ) { const dataToFetch = { accounts : AccountService . getAllAccountDetailsForProvider ( 'aws' ) , artifactAccounts : AccountService . getArtifactAccounts ( ) , } ; $q . all ( dataToFetch ) . then ( ( backingData ) => { const { accounts , artifactAccounts } = backingData ; this . accounts = accounts ; this . state . loaded = true ; this . cloudFormationStackArtifactDelegate . setAccounts ( artifactAccounts ) ; this . cloudFormationStackArtifactController . updateAccounts ( this . cloudFormationStackArtifactDelegate . getSelectedExpectedArtifact ( ) ) ; } ) ; this . cloudFormationStackArtifactDelegate = new NgGenericArtifactDelegate ( $scope , 'stack' ) ; this . cloudFormationStackArtifactController = new ExpectedArtifactSelectorViewController ( this . cloudFormationStackArtifactDelegate ) ; } public canShowAccountSelect ( ) { return ( this . $scope . stage . source === this . artifactSource && ! this . $scope . showCreateArtifactForm && this . cloudFormationStackArtifactController . accountsForArtifact . length > 1 ) ; } public toggleChangeSet ( ) { this . $scope . stage . isChangeSet = ! this . $scope . stage . isChangeSet ; } public onStackArtifactEdited = ( artifact ) => { this . $scope . $applyAsync ( ( ) => { this . $scope . stage . stackArtifactId = null ; this . $scope . stage . stackArtifact = artifact ; } ) ; } ; public onStackArtifactSelected = ( expectedArtifact ) => { this . onChangeStackArtifactId ( expectedArtifact . id ) ; } ; public onChangeStackArtifactId = ( artifactId ) => { this . $scope . $applyAsync ( ( ) => { this . $scope . stage . stackArtifactId = artifactId ; this . $scope . stage . stackArtifact = null ; } ) ; } ; public onStackArtifactAccountSelected = ( stackArtifactAccount ) => { this . $scope . $applyAsync ( ( ) => { this . $scope . stage . stackArtifactAccount = stackArtifactAccount ; } ) ; } ; public updatePipeline = ( changes ) => { this . $scope . $applyAsync ( ( ) => { extend ( this . $scope . pipeline , changes ) ; } ) ; } ; }