import type { StateService } from '@uirouter/angularjs' ; import UIROUTER_ANGULARJS from '@uirouter/angularjs' ; import type { IController , IQService , IScope } from 'angular' ; import { module } from 'angular' ; import type { Application , ILoadBalancer } from '@spinnaker/core' ; import { MANAGED_RESOURCE_DETAILS_INDICATOR } from '@spinnaker/core' ; import type { IAmazonApplicationLoadBalancer , ITargetGroup } from '../../domain/IAmazonLoadBalancer' ; export interface ITargetGroupFromStateParams { accountId : string ; region : string ; name : string ; loadBalancerName : string ; vpcId : string ; } export class AwsTargetGroupDetailsController implements IController { private targetGroupFromParams : ITargetGroupFromStateParams ; public application : Application ; public state = { loading : true } ; public elbProtocol : string ; public targetGroup : ITargetGroup ; public loadBalancer : IAmazonApplicationLoadBalancer ; public static $inject = [ '$scope' , '$q' , '$state' , 'targetGroup' , 'app' ] ; constructor ( private $scope , private $q , private $state , targetGroup , private app ) { this . application = app ; this . targetGroupFromParams = targetGroup ; this . app . ready ( ) . then ( ( ) => this . extractTargetGroup ( ) ) . then ( ( ) => { if ( ! $scope . $$destroyed ) { app . getDataSource ( 'loadBalancers' ) . onRefresh ( $scope , ( ) => this . extractTargetGroup ( ) ) ; } } ) ; } public autoClose ( ) { if ( this . $scope . $$destroyed ) { return ; } this . $state . params . allowModalToStayOpen = true ; this . $state . go ( '^' , null , { location : 'replace' } ) ; } public extractTargetGroup ( ) { const { loadBalancerName , region , accountId , name } = this . targetGroupFromParams ; const appLoadBalancer = this . app . loadBalancers . data . find ( ( test ) => { return test . name === loadBalancerName && test . region === region && test . account === accountId ; } ) ; if ( ! appLoadBalancer ) { this . autoClose ( ) ; return this . $q . when ( null ) ; } const targetGroup = appLoadBalancer . targetGroups . find ( ( tg ) => tg . name === name ) ; if ( ! targetGroup ) { this . autoClose ( ) ; return this . $q . when ( null ) ; } this . targetGroup = targetGroup ; this . loadBalancer = appLoadBalancer ; this . state . loading = false ; this . elbProtocol = 'http:' ; if ( this . loadBalancer . listeners && this . loadBalancer . listeners . some ( ( l ) => l . protocol === 'HTTPS' ) ) { this . elbProtocol = 'https:' ; } return this . $q . when ( null ) ; } } export const AWS_TARGET_GROUP_DETAILS_CTRL = 'spinnaker.amazon.loadBalancer.details.targetGroupDetails.controller' ; module ( AWS_TARGET_GROUP_DETAILS_CTRL , [ UIROUTER_ANGULARJS , MANAGED_RESOURCE_DETAILS_INDICATOR ] ) . controller ( 'awsTargetGroupDetailsCtrl' , AwsTargetGroupDetailsController ) ;