import './index.scss' ; import { EuiIcon } from '@elastic/eui' ; import angular , { IModule } from 'angular' ; import 'angular-sanitize' ; import { i18nDirective , i18nFilter , I18nProvider } from '@osd/i18n/angular' ; import { ChromeStart , IUiSettingsClient , CoreStart , SavedObjectsClientContract , PluginInitializerContext , ScopedHistory , AppMountParameters , } from 'opensearch-dashboards/public' ; import { UsageCollectionSetup } from 'src/plugins/usage_collection/public' ; import { Storage } from '../../../opensearch_dashboards_utils/public' ; import { initDashboardApp } from './legacy_app' ; import { EmbeddableStart } from '../../../embeddable/public' ; import { NavigationPublicPluginStart as NavigationStart } from '../../../navigation/public' ; import { DataPublicPluginStart } from '../../../data/public' ; import { SharePluginStart } from '../../../share/public' ; import { OpenSearchDashboardsLegacyStart , configureAppAngularModule , } from '../../../opensearch_dashboards_legacy/public' ; import { UrlForwardingStart } from '../../../url_forwarding/public' ; import { SavedObjectLoader , SavedObjectsStart } from '../../../saved_objects/public' ; import 'angular-sanitize' ; import 'angular-route' ; export interface RenderDeps { pluginInitializerContext : PluginInitializerContext ; core : CoreStart ; data : DataPublicPluginStart ; navigation : NavigationStart ; savedObjectsClient : SavedObjectsClientContract ; savedDashboards : SavedObjectLoader ; dashboardConfig : OpenSearchDashboardsLegacyStart [ 'dashboardConfig' ] ; dashboardCapabilities : any ; embeddableCapabilities : { visualizeCapabilities : any ; mapsCapabilities : any ; } ; uiSettings : IUiSettingsClient ; chrome : ChromeStart ; addBasePath : ( path : string ) => string ; savedQueryService : DataPublicPluginStart [ 'query' ] [ 'savedQueries' ] ; embeddable : EmbeddableStart ; localStorage : Storage ; share ? : SharePluginStart ; usageCollection ? : UsageCollectionSetup ; navigateToDefaultApp : UrlForwardingStart [ 'navigateToDefaultApp' ] ; navigateToLegacyOpenSearchDashboardsUrl : UrlForwardingStart [ 'navigateToLegacyOpenSearchDashboardsUrl' ] ; scopedHistory : ( ) => ScopedHistory ; setHeaderActionMenu : AppMountParameters [ 'setHeaderActionMenu' ] ; savedObjects : SavedObjectsStart ; restorePreviousUrl : ( ) => void ; } let angularModuleInstance = null ; export const renderApp = ( element , appBasePath , deps ) => { if ( ! angularModuleInstance ) { angularModuleInstance = createLocalAngularModule ( ) ; configureAppAngularModule ( angularModuleInstance , { core : deps . core , env : deps . pluginInitializerContext . env } , true , deps . scopedHistory ) ; initDashboardApp ( angularModuleInstance , deps ) ; } const $injector = mountDashboardApp ( appBasePath , element ) ; return ( ) => { ( $injector . get ( 'osdUrlStateStorage' ) as any ) . cancel ( ) ; $injector . get ( '$rootScope' ) . $destroy ( ) ; } ; } ; const mainTemplate = ( basePath ) => `<div ng-view class="dshAppContainer">
  <base href="${ basePath }" />
</div>` ; const moduleName = 'app/dashboard' ; const thirdPartyAngularDependencies = [ 'ngSanitize' , 'ngRoute' , 'react' ] ; function mountDashboardApp ( appBasePath , element ) { const mountpoint = document . createElement ( 'div' ) ; mountpoint . setAttribute ( 'class' , 'dshAppContainer' ) ; mountpoint . innerHTML = mainTemplate ( appBasePath ) ; const $injector = angular . bootstrap ( mountpoint , [ moduleName ] ) ; element . appendChild ( mountpoint ) ; return $injector ; } function createLocalAngularModule ( ) { createLocalI18nModule ( ) ; createLocalIconModule ( ) ; const dashboardAngularModule = angular . module ( moduleName , [ ... thirdPartyAngularDependencies , 'app/dashboard/I18n' , 'app/dashboard/icon' , ] ) ; return dashboardAngularModule ; } function createLocalIconModule ( ) { angular . module ( 'app/dashboard/icon' , [ 'react' ] ) . directive ( 'icon' , ( reactDirective ) => reactDirective ( EuiIcon ) ) ; } function createLocalI18nModule ( ) { angular . module ( 'app/dashboard/I18n' , [ ] ) . provider ( 'i18n' , I18nProvider ) . filter ( 'i18n' , i18nFilter ) . directive ( 'i18nId' , i18nDirective ) ; }