import type { IComponentController, IComponentOptions } from 'angular'; import { module } from 'angular'; import { SETTINGS } from '../config/settings'; import type { IPagerDutyService } from './pagerDuty.read.service'; import { PagerDutyReader } from './pagerDuty.read.service'; import { SchedulerFactory } from '../scheduler/SchedulerFactory'; export class PagerDutySelectFieldController implements IComponentController { public component: any; public pagerDutyServices: IPagerDutyService[]; public servicesLoaded: boolean; private scheduler: any; public helpContents = `
Make sure your service exists in Pager Duty and includes the "Generic API" integration.
Note: it can take up to five minutes for the service to appear in Spinnaker
`; public required = (SETTINGS.pagerDuty && SETTINGS.pagerDuty.required) || false; public label = `PagerDuty${this.required ? ' *' : ''}`; public $onInit() { this.scheduler = SchedulerFactory.createScheduler(10000); this.scheduler.subscribe(() => this.loadPagerDutyServices()); this.loadPagerDutyServices(); } public $onDestroy(): void { this.scheduler.unsubscribe(); } private loadPagerDutyServices(): void { PagerDutyReader.listServices().subscribe((pagerDutyServices: IPagerDutyService[]) => { this.pagerDutyServices = pagerDutyServices.filter((service) => service.integration_key); this.servicesLoaded = true; }); } } const pagerDutySelectField: IComponentOptions = { bindings: { component: '=', }, controller: PagerDutySelectFieldController, template: `