diff --git a/app/scripts/modules/core/src/domain/IManagedEntity.ts b/app/scripts/modules/core/src/domain/IManagedEntity.ts index 26b790b72eb..6c560ab24f1 100644 --- a/app/scripts/modules/core/src/domain/IManagedEntity.ts +++ b/app/scripts/modules/core/src/domain/IManagedEntity.ts @@ -24,12 +24,60 @@ export interface IManagedResourceSummary { }; } -export interface IManagedApplicationSummary { - applicationPaused: boolean; - hasManagedResources: boolean; +export interface IManagedEnviromentSummary { + name: string; + resources: string[]; + artifacts: Array<{ + name: string; + type: string; + statuses: string[]; + versions: { + current?: string; + deploying?: string; + pending: string[]; + approved: string[]; + previous: string[]; + vetoed: string[]; + }; + }>; +} + +export interface IManagedArtifactVersion { + version: string; + environments: Array<{ + name: string; + state: string; + deployedAt?: string; + replacedAt?: string; + replacedBy?: string; + }>; +} + +export interface IManagedArtifactSummary { + name: string; + type: string; + versions: IManagedArtifactVersion[]; +} + +export interface IManagedApplicationEnvironmentsSummary extends IManagedApplicationSummary { + environments: IManagedEnviromentSummary[]; + artifacts: IManagedArtifactSummary[]; +} + +export interface IManagedApplicationEntities { resources: IManagedResourceSummary[]; + environments: IManagedEnviromentSummary[]; + artifacts: IManagedArtifactSummary[]; } +export type IManagedApplicationSummary = Pick< + IManagedApplicationEntities, + T +> & { + applicationPaused: boolean; + hasManagedResources: boolean; +}; + export interface IManagedResource { managedResourceSummary?: IManagedResourceSummary; isManaged?: boolean; diff --git a/app/scripts/modules/core/src/managed/ManagedReader.ts b/app/scripts/modules/core/src/managed/ManagedReader.ts index b37c8041d6e..3fd83acf400 100644 --- a/app/scripts/modules/core/src/managed/ManagedReader.ts +++ b/app/scripts/modules/core/src/managed/ManagedReader.ts @@ -69,22 +69,34 @@ const transformManagedResourceDiff = (diff: IManagedResourceEventHistoryResponse }, {} as IManagedResourceDiff); export class ManagedReader { - public static getApplicationSummary(app: string): IPromise { + private static decorateResources(response: IManagedApplicationSummary) { + // Individual resources don't update their status when an application is paused/resumed, + // so for now let's swap to a PAUSED status and keep things simpler in downstream components. + if (response.applicationPaused) { + response.resources.forEach(resource => (resource.status = ManagedResourceStatus.PAUSED)); + } + + response.resources.forEach(resource => (resource.isPaused = resource.status === ManagedResourceStatus.PAUSED)); + + return response; + } + + public static getApplicationSummary(app: string): IPromise> { return API.one('managed') .one('application', app) - .withParams({ includeDetails: true }) + .withParams({ includeDetails: true, entities: 'resources' }) .get() - .then((response: IManagedApplicationSummary) => { - // Individual resources don't update their status when an application is paused/resumed, - // so for now let's swap to a PAUSED status and keep things simpler in downstream components. - if (response.applicationPaused) { - response.resources.forEach(resource => (resource.status = ManagedResourceStatus.PAUSED)); - } - - response.resources.forEach(resource => (resource.isPaused = resource.status === ManagedResourceStatus.PAUSED)); + .then(this.decorateResources); + } - return response; - }); + public static getEnvironmentsSummary( + app: string, + ): IPromise> { + return API.one('managed') + .one('application', app) + .withParams({ includeDetails: true, entities: ['resources', 'artifacts', 'environments'] }) + .get() + .then(this.decorateResources); } public static getResourceHistory(resourceId: string): IPromise { diff --git a/app/scripts/modules/core/src/managed/managed.dataSource.ts b/app/scripts/modules/core/src/managed/managed.dataSource.ts index 43dcecb6aee..8ce13000536 100644 --- a/app/scripts/modules/core/src/managed/managed.dataSource.ts +++ b/app/scripts/modules/core/src/managed/managed.dataSource.ts @@ -3,7 +3,7 @@ import { IQService, module } from 'angular'; import { noop } from 'core/utils'; import { SETTINGS } from 'core/config/settings'; import { ApplicationDataSourceRegistry } from 'core/application/service/ApplicationDataSourceRegistry'; -import { Application } from 'core/application'; +import { Application, DELIVERY_KEY } from 'core/application'; import { IManagedApplicationSummary } from 'core/domain'; import { ManagedReader } from './ManagedReader'; import { @@ -34,6 +34,14 @@ module(MANAGED_RESOURCES_DATA_SOURCE, []).run([ application.securityGroups.ready().then(() => addManagedResourceMetadataToSecurityGroups(application), noop); }; + const loadEnvironments = (application: Application) => { + return ManagedReader.getEnvironmentsSummary(application.name); + }; + + const addEnvironments = (_application: Application, data: IManagedApplicationSummary) => { + return $q.when(data); + }; + ApplicationDataSourceRegistry.registerDataSource({ key: 'managedResources', visible: false, @@ -42,5 +50,24 @@ module(MANAGED_RESOURCES_DATA_SOURCE, []).run([ afterLoad: addManagedMetadataToResources, defaultData: { applicationPaused: false, hasManagedResources: false, resources: [] }, }); + + ApplicationDataSourceRegistry.registerDataSource({ + key: 'environments', + sref: '.environments', + category: DELIVERY_KEY, + optional: true, + optIn: true, + hidden: true, + icon: 'fa fa-fw fa-xs fa-code-branch', + loader: loadEnvironments, + onLoad: addEnvironments, + defaultData: { + applicationPaused: false, + hasManagedResources: false, + environments: [], + artifacts: [], + resources: [], + }, + }); }, ]);