import type { StateService } from '@uirouter/angularjs' ; import type { IController , IScope } from 'angular' ; import { module } from 'angular' ; import type { IModalService } from 'angular-ui-bootstrap' ; import type { Application , ILoadBalancer , IManifest } from '@spinnaker/core' ; import { ManifestReader , SETTINGS } from '@spinnaker/core' ; import type { IKubernetesLoadBalancer } from '../../interfaces' ; import { KubernetesManifestCommandBuilder } from '../../manifest/manifestCommandBuilder.service' ; import { ManifestWizard } from '../../manifest/wizard/ManifestWizard' ; interface ILoadBalancerFromStateParams { accountId : string ; region : string ; name : string ; } class KubernetesLoadBalancerDetailsController implements IController { public state = { loading : true } ; public manifest : IManifest ; public loadBalancer : IKubernetesLoadBalancer ; public static $inject = [ '$uibModal' , '$state' , '$scope' , 'loadBalancer' , 'app' ] ; constructor ( private $uibModal , private $state , private $scope , loadBalancer , private app ) { const dataSource = this . app . getDataSource ( 'loadBalancers' ) ; dataSource . ready ( ) . then ( ( ) => { this . extractLoadBalancer ( loadBalancer ) ; this . $scope . isDisabled = ! SETTINGS . kubernetesAdHocInfraWritesEnabled ; dataSource . onRefresh ( this . $scope , ( ) => this . extractLoadBalancer ( loadBalancer ) ) ; } ) . catch ( ( ) => this . autoClose ( ) ) ; } public deleteLoadBalancer ( ) { this . $uibModal . open ( { templateUrl : require ( '../../manifest/delete/delete.html' ) , controller : 'kubernetesV2ManifestDeleteCtrl' , controllerAs : 'ctrl' , resolve : { coordinates : { name : this . loadBalancer . name , namespace : this . loadBalancer . namespace , account : this . loadBalancer . account , } , application : this . app , manifestController : ( ) : string => null , } , } ) ; } public editLoadBalancer ( ) { KubernetesManifestCommandBuilder . buildNewManifestCommand ( this . app , this . manifest . manifest , this . loadBalancer . moniker , this . loadBalancer . account ) . then ( ( builtCommand ) => { ManifestWizard . show ( { title : 'Edit Manifest' , application : this . app , command : builtCommand } ) ; } ) ; } private extractLoadBalancer ( { accountId , name , region } ) { const loadBalancer = this . app . getDataSource ( 'loadBalancers' ) . data . find ( ( test ) => { return test . name === name && test . account === accountId && test . region === region ; } ) ; if ( ! loadBalancer ) { return this . autoClose ( ) ; } ManifestReader . getManifest ( accountId , region , name ) . then ( ( manifest ) => { this . manifest = manifest ; this . loadBalancer = loadBalancer ; this . state . loading = false ; } ) ; } private autoClose ( ) { if ( this . $scope . $$destroyed ) { return ; } else { this . $state . params . allowModalToStayOpen = true ; this . $state . go ( '^' , null , { location : 'replace' } ) ; } } } export const KUBERNETES_LOAD_BALANCER_DETAILS_CTRL = 'spinnaker.kubernetes.loadBalancerDetails.controller' ; module ( KUBERNETES_LOAD_BALANCER_DETAILS_CTRL , [ ] ) . controller ( 'kubernetesV2LoadBalancerDetailsCtrl' , KubernetesLoadBalancerDetailsController ) ;