<commit_before>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, DELIVERY_KEY } from 'core/application';
import { IManagedApplicationSummary } from 'core/domain';
import { ManagedReader } from './ManagedReader';
import {
  addManagedResourceMetadataToServerGroups,
  addManagedResourceMetadataToLoadBalancers,
  addManagedResourceMetadataToSecurityGroups,
} from './managedResourceDecorators';

export const MANAGED_RESOURCES_DATA_SOURCE = 'spinnaker.core.managed.dataSource';
module(MANAGED_RESOURCES_DATA_SOURCE, []).run([
  '$q',
  ($q: IQService) => {
    if (!SETTINGS.feature.managedResources) {
      return;
    }
    const loadManagedResources = (application: Application) => {
      return ManagedReader.getApplicationSummary(application.name);
    };

    const addManagedResources = (application: Application, data: IManagedApplicationSummary) => {
      application.isManagementPaused = data.applicationPaused;
      return $q.when(data);
    };

    const addManagedMetadataToResources = (application: Application) => {
      application.serverGroups.ready().then(() => addManagedResourceMetadataToServerGroups(application), noop);
      application.loadBalancers.ready().then(() => addManagedResourceMetadataToLoadBalancers(application), noop);
      application.securityGroups.ready().then(() => addManagedResourceMetadataToSecurityGroups(application), noop);
    };

    const loadEnvironments = (application: Application) => {
      return ManagedReader.getEnvironmentsSummary(application.name);
    };

    const addEnvironments = (
      _application: Application,
      data: IManagedApplicationSummary<'resources' | 'artifacts' | 'environments'>,
    ) => {
      return $q.when(data);
    };

    ApplicationDataSourceRegistry.registerDataSource({
      key: 'managedResources',
      visible: false,
      loader: loadManagedResources,
      onLoad: addManagedResources,
      afterLoad: addManagedMetadataToResources,
      defaultData: { applicationPaused: false, hasManagedResources: false, resources: [] },
    });

    ApplicationDataSourceRegistry.registerDataSource({
      key: 'environments',
      sref: '.environments',
      category: DELIVERY_KEY,
      optional: true,
      optIn: true,
      label: 'Environments',
      icon: 'fa fa-fw fa-xs fa-code-branch',
      iconName: 'spCIBranch',
      description: '[beta] Artifacts and environments managed by Spinnaker',
      loader: loadEnvironments,
      onLoad: addEnvironments,
      defaultData: {
        applicationPaused: false,
        hasManagedResources: false,
        environments: [],
        artifacts: [],
        resources: [],
      },
    });
  },
]);<commit_msg>feat(core): Add environment views new icon to data source config (#8320)<commit_after>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, DELIVERY_KEY } from 'core/application';
import { IManagedApplicationSummary } from 'core/domain';
import { ManagedReader } from './ManagedReader';
import {
  addManagedResourceMetadataToServerGroups,
  addManagedResourceMetadataToLoadBalancers,
  addManagedResourceMetadataToSecurityGroups,
} from './managedResourceDecorators';

export const MANAGED_RESOURCES_DATA_SOURCE = 'spinnaker.core.managed.dataSource';
module(MANAGED_RESOURCES_DATA_SOURCE, []).run([
  '$q',
  ($q: IQService) => {
    if (!SETTINGS.feature.managedResources) {
      return;
    }
    const loadManagedResources = (application: Application) => {
      return ManagedReader.getApplicationSummary(application.name);
    };

    const addManagedResources = (application: Application, data: IManagedApplicationSummary) => {
      application.isManagementPaused = data.applicationPaused;
      return $q.when(data);
    };

    const addManagedMetadataToResources = (application: Application) => {
      application.serverGroups.ready().then(() => addManagedResourceMetadataToServerGroups(application), noop);
      application.loadBalancers.ready().then(() => addManagedResourceMetadataToLoadBalancers(application), noop);
      application.securityGroups.ready().then(() => addManagedResourceMetadataToSecurityGroups(application), noop);
    };

    const loadEnvironments = (application: Application) => {
      return ManagedReader.getEnvironmentsSummary(application.name);
    };

    const addEnvironments = (
      _application: Application,
      data: IManagedApplicationSummary<'resources' | 'artifacts' | 'environments'>,
    ) => {
      return $q.when(data);
    };

    ApplicationDataSourceRegistry.registerDataSource({
      key: 'managedResources',
      visible: false,
      loader: loadManagedResources,
      onLoad: addManagedResources,
      afterLoad: addManagedMetadataToResources,
      defaultData: { applicationPaused: false, hasManagedResources: false, resources: [] },
    });

    ApplicationDataSourceRegistry.registerDataSource({
      key: 'environments',
      sref: '.environments',
      category: DELIVERY_KEY,
      optional: true,
      optIn: true,
      label: 'Environments',
      icon: 'fa fa-fw fa-xs fa-code-branch',
      iconName: 'spEnvironments',
      description: '[beta] Artifacts and environments managed by Spinnaker',
      loader: loadEnvironments,
      onLoad: addEnvironments,
      defaultData: {
        applicationPaused: false,
        hasManagedResources: false,
        environments: [],
        artifacts: [],
        resources: [],
      },
    });
  },
]);
{'fraction_non_alphanumeric': 0.1124677558039553, 'fraction_numerical': 0.0006878761822871883, 'mean_word_length': 4.14235190097259, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1369292', 'n_tokens_mistral': 1559, 'n_tokens_neox': 1511, 'n_words': 310}