mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-10 02:02:35 -05:00
Angular Individual Service Injection - Decouple bootstrap service (#1457)
* change services to be individually injected into angular * messing around with injection * change angular bootstrapping to factory style * formatting * formatting * fix imports * fix build errors * fix testsw * fix tests * fix compile errors
This commit is contained in:
@@ -7,32 +7,30 @@ import { DataService } from 'sql/parts/grid/services/dataService';
|
||||
import { IConnectionProfile } from 'sql/parts/connection/common/interfaces';
|
||||
import { IContextKeyService, IContextKey } from 'vs/platform/contextkey/common/contextkey';
|
||||
import { ConnectionContextkey } from 'sql/parts/connection/common/connectionContextKey';
|
||||
import { IBootstrapParams } from './bootstrapService';
|
||||
|
||||
export interface BootstrapParams {
|
||||
}
|
||||
|
||||
export interface QueryComponentParams extends BootstrapParams {
|
||||
export interface IQueryComponentParams extends IBootstrapParams {
|
||||
dataService: DataService;
|
||||
}
|
||||
|
||||
export interface EditDataComponentParams extends BootstrapParams {
|
||||
export interface IEditDataComponentParams extends IBootstrapParams {
|
||||
dataService: DataService;
|
||||
}
|
||||
|
||||
export interface DefaultComponentParams extends BootstrapParams {
|
||||
export interface IDefaultComponentParams extends IBootstrapParams {
|
||||
connection: IConnectionProfile;
|
||||
ownerUri: string;
|
||||
scopedContextService: IContextKeyService;
|
||||
connectionContextKey: ConnectionContextkey;
|
||||
}
|
||||
|
||||
export interface DashboardComponentParams extends DefaultComponentParams {
|
||||
export interface IDashboardComponentParams extends IDefaultComponentParams {
|
||||
}
|
||||
|
||||
export interface TaskDialogComponentParams extends BootstrapParams {
|
||||
export interface ITaskDialogComponentParams extends IBootstrapParams {
|
||||
ownerUri: string;
|
||||
}
|
||||
|
||||
export interface QueryPlanParams extends BootstrapParams {
|
||||
export interface IQueryPlanParams extends IBootstrapParams {
|
||||
planXml: string;
|
||||
}
|
||||
|
||||
@@ -3,20 +3,21 @@
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import { NgModuleRef, InjectionToken } from '@angular/core';
|
||||
import { BootstrapParams } from 'sql/services/bootstrap/bootstrapParams';
|
||||
import { NgModuleRef, enableProdMode, InjectionToken, ReflectiveInjector, Type, PlatformRef } from '@angular/core';
|
||||
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
|
||||
|
||||
import { IConnectionManagementService, IConnectionDialogService, IErrorMessageService }
|
||||
from 'sql/parts/connection/common/connectionManagement';
|
||||
import { IMetadataService } from 'sql/services/metadata/metadataService';
|
||||
import { IObjectExplorerService } from 'sql/parts/objectExplorer/common/objectExplorerService';
|
||||
import { IQueryEditorService } from 'sql/parts/query/common/queryEditorService';
|
||||
import { IAngularEventingService } from 'sql/services/angularEventing/angularEventingService';
|
||||
import { IScriptingService } from 'sql/services/scripting/scriptingService';
|
||||
import { IQueryModelService } from 'sql/parts/query/execution/queryModel';
|
||||
import { IQueryManagementService } from 'sql/parts/query/common/queryManagement';
|
||||
import { IQueryModelService } from 'sql/parts/query/execution/queryModel';
|
||||
import { IAdminService } from 'sql/parts/admin/common/adminService';
|
||||
import { IRestoreDialogController, IRestoreService } from 'sql/parts/disasterRecovery/restore/common/restoreService';
|
||||
import { IBackupService, IBackupUiService } from 'sql/parts/disasterRecovery/backup/common/backupService';
|
||||
import { IAngularEventingService } from 'sql/services/angularEventing/angularEventingService';
|
||||
import { IInsightsDialogService } from 'sql/parts/insights/common/interfaces';
|
||||
import { ISqlOAuthService } from 'sql/common/sqlOAuthService';
|
||||
import { IFileBrowserService, IFileBrowserDialogController } from 'sql/parts/fileBrowser/common/interfaces';
|
||||
@@ -24,105 +25,122 @@ import { IClipboardService } from 'sql/platform/clipboard/common/clipboardServic
|
||||
import { ICapabilitiesService } from 'sql/services/capabilities/capabilitiesService';
|
||||
import { IDashboardViewService } from 'sql/services/dashboard/common/dashboardViewService';
|
||||
import { IModelViewService } from 'sql/services/modelComponents/modelViewService';
|
||||
import { IJobManagementService } from 'sql/parts/jobManagement/common/interfaces';
|
||||
|
||||
import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding';
|
||||
import { IContextKeyService } from 'vs/platform/contextkey/common/contextkey';
|
||||
import { IContextMenuService, IContextViewService } from 'vs/platform/contextview/browser/contextView';
|
||||
import { IEditorInput } from 'vs/platform/editor/common/editor';
|
||||
import { createDecorator, IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
|
||||
import { IWorkbenchThemeService } from 'vs/workbench/services/themes/common/workbenchThemeService';
|
||||
import { IWorkbenchEditorService } from 'vs/workbench/services/editor/common/editorService';
|
||||
import { IPartService } from 'vs/workbench/services/part/common/partService';
|
||||
import { IEditorInput } from 'vs/platform/editor/common/editor';
|
||||
import { IInstantiationService, ServicesAccessor, ServiceIdentifier } from 'vs/platform/instantiation/common/instantiation';
|
||||
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
|
||||
import { IWorkspaceContextService } from 'vs/platform/workspace/common/workspace';
|
||||
import { IAccountManagementService } from 'sql/services/accountManagement/interfaces';
|
||||
import { IWindowsService, IWindowService } from 'vs/platform/windows/common/windows';
|
||||
import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
|
||||
import { IStorageService } from 'vs/platform/storage/common/storage';
|
||||
import { ConfigurationEditingService } from 'vs/workbench/services/configuration/node/configurationEditingService';
|
||||
import { ICommandService } from 'vs/platform/commands/common/commands';
|
||||
import { IJobManagementService } from 'sql/parts/jobManagement/common/interfaces';
|
||||
import { IEnvironmentService } from 'vs/platform/environment/common/environment';
|
||||
import { INotificationService } from 'vs/platform/notification/common/notification';
|
||||
import { IWorkbenchThemeService } from 'vs/workbench/services/themes/common/workbenchThemeService';
|
||||
import { IClipboardService as vsIClipboardService } from 'vs/platform/clipboard/common/clipboardService';
|
||||
|
||||
export const BOOTSTRAP_SERVICE_ID = 'bootstrapService';
|
||||
export const IBootstrapService = createDecorator<IBootstrapService>(BOOTSTRAP_SERVICE_ID);
|
||||
const selectorCounter = new Map<string, number>();
|
||||
|
||||
/*
|
||||
* Handles logic for bootstrapping and passing singleton services to Angular components.
|
||||
*/
|
||||
export interface IBootstrapService {
|
||||
|
||||
_serviceBrand: any;
|
||||
|
||||
connectionManagementService: IConnectionManagementService;
|
||||
metadataService: IMetadataService;
|
||||
objectExplorerService: IObjectExplorerService;
|
||||
scriptingService: IScriptingService;
|
||||
queryEditorService: IQueryEditorService;
|
||||
connectionDialogService: IConnectionDialogService;
|
||||
queryModelService: IQueryModelService;
|
||||
adminService: IAdminService;
|
||||
backupService: IBackupService;
|
||||
backupUiService: IBackupUiService;
|
||||
restoreService: IRestoreService;
|
||||
keybindingService: IKeybindingService;
|
||||
contextKeyService: IContextKeyService;
|
||||
contextMenuService: IContextMenuService;
|
||||
themeService: IWorkbenchThemeService;
|
||||
editorService: IWorkbenchEditorService;
|
||||
errorMessageService: IErrorMessageService;
|
||||
partService: IPartService;
|
||||
queryManagementService: IQueryManagementService;
|
||||
instantiationService: IInstantiationService;
|
||||
angularEventingService: IAngularEventingService;
|
||||
configurationService: IConfigurationService;
|
||||
insightsDialogService: IInsightsDialogService;
|
||||
contextViewService: IContextViewService;
|
||||
restoreDialogService: IRestoreDialogController;
|
||||
notificationService: INotificationService;
|
||||
workspaceContextService: IWorkspaceContextService;
|
||||
accountManagementService: IAccountManagementService;
|
||||
windowsService: IWindowsService;
|
||||
sqlOAuthService: ISqlOAuthService;
|
||||
windowService: IWindowService;
|
||||
fileBrowserService: IFileBrowserService;
|
||||
fileBrowserDialogService: IFileBrowserDialogController;
|
||||
telemetryService: ITelemetryService;
|
||||
storageService: IStorageService;
|
||||
clipboardService: IClipboardService;
|
||||
capabilitiesService: ICapabilitiesService;
|
||||
configurationEditorService: ConfigurationEditingService;
|
||||
commandService: ICommandService;
|
||||
dashboardViewService: IDashboardViewService;
|
||||
modelViewService: IModelViewService;
|
||||
jobManagementService: IJobManagementService;
|
||||
environmentService: IEnvironmentService;
|
||||
|
||||
/*
|
||||
* Bootstraps the Angular module described. Components that need singleton services should inject the
|
||||
* 'BootstrapService' dependency to obtain a reference to this class. Components that need dynamic parameters
|
||||
* should wrap them in an object and pass them in through the "params" parameter.
|
||||
*
|
||||
* moduleType: The TypeScript type of the module to bootstrap
|
||||
* container: The HTML container to append the selector HTMLElement
|
||||
* selectorString: The tag name and class used to create the element, e.g. 'tagName.cssClassName'
|
||||
* params: The parameters to be associated with the given id
|
||||
* input: Optional editor input. If specified, will listen to its onDispose event and destroy the module when this happens
|
||||
* callbackSetModule:Optional. If specified, will be used to set the moduleRef
|
||||
* Returns the unique selector string that this module will bootstrap with.
|
||||
*/
|
||||
bootstrap(moduleType: any, container: HTMLElement, selectorString: string, params: BootstrapParams, input?: IEditorInput, callbackSetModule?: (value: NgModuleRef<{}>) => void): string;
|
||||
|
||||
/*
|
||||
* Gets the "params" entry associated with the given id and unassociates the id/entry pair.
|
||||
* Returns undefined if no entry is found.
|
||||
*/
|
||||
getBootstrapParams<T extends BootstrapParams>(id: string): T;
|
||||
|
||||
/*
|
||||
* Gets the next unique selector given the baseSelectorString. A unique selector is the baseSelectorString with a
|
||||
* number appended. E.g. if baseSelectorString='query', valid unique selectors could be query0, query1, query2, etc.
|
||||
*/
|
||||
getUniqueSelector(baseSelectorString: string): string;
|
||||
export const IBootstrapParams = new InjectionToken('bootstrap_params');
|
||||
export interface IBootstrapParams {
|
||||
}
|
||||
|
||||
export type IModuleFactory<T> = (params: IBootstrapParams, selector: string) => Type<T>;
|
||||
|
||||
function createUniqueSelector(selector: string): string {
|
||||
let num: number;
|
||||
if (selectorCounter.has(selector)) {
|
||||
num = selectorCounter.get(selector);
|
||||
} else {
|
||||
num = 0;
|
||||
}
|
||||
selectorCounter.set(selector, num + 1);
|
||||
return `${selector}_${num}`;
|
||||
}
|
||||
|
||||
let platform: PlatformRef;
|
||||
|
||||
export function bootstrapAngular<T>(collection: ServicesAccessor, moduleType: IModuleFactory<T>, container: HTMLElement, selectorString: string, params: IBootstrapParams, input?: IEditorInput, callbackSetModule?: (value: NgModuleRef<T>) => void): string {
|
||||
// Create the uniqueSelectorString
|
||||
let uniqueSelectorString = createUniqueSelector(selectorString);
|
||||
let selector = document.createElement(uniqueSelectorString);
|
||||
container.appendChild(selector);
|
||||
|
||||
if (!platform) {
|
||||
// Perform the bootsrap
|
||||
const providers: { provide: ServiceIdentifier<any> | InjectionToken<any>, useValue: any }[] = [
|
||||
// sql services
|
||||
{ provide: IConnectionManagementService, useValue: collection.get(IConnectionManagementService) },
|
||||
{ provide: IConnectionDialogService, useValue: collection.get(IConnectionDialogService) },
|
||||
{ provide: IErrorMessageService, useValue: collection.get(IErrorMessageService) },
|
||||
{ provide: IMetadataService, useValue: collection.get(IMetadataService) },
|
||||
{ provide: IObjectExplorerService, useValue: collection.get(IObjectExplorerService) },
|
||||
{ provide: IQueryEditorService, useValue: collection.get(IQueryEditorService) },
|
||||
{ provide: IScriptingService, useValue: collection.get(IScriptingService) },
|
||||
{ provide: IQueryManagementService, useValue: collection.get(IQueryManagementService) },
|
||||
{ provide: IQueryModelService, useValue: collection.get(IQueryModelService) },
|
||||
{ provide: IAdminService, useValue: collection.get(IAdminService) },
|
||||
{ provide: IRestoreDialogController, useValue: collection.get(IRestoreDialogController) },
|
||||
{ provide: IRestoreService, useValue: collection.get(IRestoreService) },
|
||||
{ provide: IBackupService, useValue: collection.get(IBackupService) },
|
||||
{ provide: IBackupUiService, useValue: collection.get(IBackupUiService) },
|
||||
{ provide: IAngularEventingService, useValue: collection.get(IAngularEventingService) },
|
||||
{ provide: IInsightsDialogService, useValue: collection.get(IInsightsDialogService) },
|
||||
{ provide: ISqlOAuthService, useValue: collection.get(ISqlOAuthService) },
|
||||
{ provide: IFileBrowserService, useValue: collection.get(IFileBrowserService) },
|
||||
{ provide: IFileBrowserDialogController, useValue: collection.get(IFileBrowserDialogController) },
|
||||
{ provide: IClipboardService, useValue: collection.get(IClipboardService) },
|
||||
{ provide: ICapabilitiesService, useValue: collection.get(ICapabilitiesService) },
|
||||
{ provide: IDashboardViewService, useValue: collection.get(IDashboardViewService) },
|
||||
{ provide: IModelViewService, useValue: collection.get(IModelViewService) },
|
||||
|
||||
// vscode services
|
||||
{ provide: vsIClipboardService, useValue: collection.get(vsIClipboardService) },
|
||||
{ provide: IKeybindingService, useValue: collection.get(IKeybindingService) },
|
||||
{ provide: IContextKeyService, useValue: collection.get(IContextKeyService) },
|
||||
{ provide: IContextMenuService, useValue: collection.get(IContextMenuService) },
|
||||
{ provide: IContextViewService, useValue: collection.get(IContextViewService) },
|
||||
{ provide: IWorkbenchEditorService, useValue: collection.get(IWorkbenchEditorService) },
|
||||
{ provide: IPartService, useValue: collection.get(IPartService) },
|
||||
{ provide: IInstantiationService, useValue: collection.get(IInstantiationService) },
|
||||
{ provide: IConfigurationService, useValue: collection.get(IConfigurationService) },
|
||||
{ provide: IWorkspaceContextService, useValue: collection.get(IWorkspaceContextService) },
|
||||
{ provide: IAccountManagementService, useValue: collection.get(IAccountManagementService) },
|
||||
{ provide: IWindowsService, useValue: collection.get(IWindowsService) },
|
||||
{ provide: IWindowService, useValue: collection.get(IWindowService) },
|
||||
{ provide: ITelemetryService, useValue: collection.get(ITelemetryService) },
|
||||
{ provide: IStorageService, useValue: collection.get(IStorageService) },
|
||||
{ provide: ICommandService, useValue: collection.get(ICommandService) },
|
||||
{ provide: IJobManagementService, useValue: collection.get(IJobManagementService) },
|
||||
{ provide: IEnvironmentService, useValue: collection.get(IEnvironmentService) },
|
||||
{ provide: INotificationService, useValue: collection.get(INotificationService) },
|
||||
{ provide: IWorkbenchThemeService, useValue: collection.get(IWorkbenchThemeService) }
|
||||
];
|
||||
|
||||
platform = platformBrowserDynamic(providers);
|
||||
}
|
||||
|
||||
platform.bootstrapModule(moduleType(params, uniqueSelectorString)).then(moduleRef => {
|
||||
if (input) {
|
||||
input.onDispose(() => {
|
||||
moduleRef.destroy();
|
||||
});
|
||||
}
|
||||
if (callbackSetModule) {
|
||||
callbackSetModule(moduleRef);
|
||||
}
|
||||
});
|
||||
|
||||
return uniqueSelectorString;
|
||||
}
|
||||
|
||||
if (!process.env['VSCODE_DEV']) {
|
||||
enableProdMode();
|
||||
}
|
||||
|
||||
@@ -1,199 +0,0 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import { NgModuleRef, enableProdMode } from '@angular/core';
|
||||
import { platformBrowserDynamic, } from '@angular/platform-browser-dynamic';
|
||||
|
||||
import { BootstrapParams } from 'sql/services/bootstrap/bootstrapParams';
|
||||
import { IConnectionManagementService, IConnectionDialogService, IErrorMessageService }
|
||||
from 'sql/parts/connection/common/connectionManagement';
|
||||
import { IMetadataService } from 'sql/services/metadata/metadataService';
|
||||
import { IObjectExplorerService } from 'sql/parts/objectExplorer/common/objectExplorerService';
|
||||
import { IQueryEditorService } from 'sql/parts/query/common/queryEditorService';
|
||||
import { IScriptingService } from 'sql/services/scripting/scriptingService';
|
||||
import { IQueryManagementService } from 'sql/parts/query/common/queryManagement';
|
||||
import { IQueryModelService } from 'sql/parts/query/execution/queryModel';
|
||||
import { IAdminService } from 'sql/parts/admin/common/adminService';
|
||||
import { IRestoreDialogController, IRestoreService } from 'sql/parts/disasterRecovery/restore/common/restoreService';
|
||||
import { IBackupService, IBackupUiService } from 'sql/parts/disasterRecovery/backup/common/backupService';
|
||||
import { IAngularEventingService } from 'sql/services/angularEventing/angularEventingService';
|
||||
import { IInsightsDialogService } from 'sql/parts/insights/common/interfaces';
|
||||
import { ISqlOAuthService } from 'sql/common/sqlOAuthService';
|
||||
import { IFileBrowserService, IFileBrowserDialogController } from 'sql/parts/fileBrowser/common/interfaces';
|
||||
import { IClipboardService } from 'sql/platform/clipboard/common/clipboardService';
|
||||
import { ICapabilitiesService } from 'sql/services/capabilities/capabilitiesService';
|
||||
import { IDashboardViewService } from 'sql/services/dashboard/common/dashboardViewService';
|
||||
import { IModelViewService } from 'sql/services/modelComponents/modelViewService';
|
||||
|
||||
import { $ } from 'vs/base/browser/dom';
|
||||
import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding';
|
||||
import { IContextKeyService } from 'vs/platform/contextkey/common/contextkey';
|
||||
import { IContextMenuService, IContextViewService } from 'vs/platform/contextview/browser/contextView';
|
||||
import { IWorkbenchEditorService } from 'vs/workbench/services/editor/common/editorService';
|
||||
import { IPartService } from 'vs/workbench/services/part/common/partService';
|
||||
import { IEditorInput } from 'vs/platform/editor/common/editor';
|
||||
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
|
||||
import { IBootstrapService, BOOTSTRAP_SERVICE_ID } from './bootstrapService';
|
||||
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
|
||||
import { IWorkspaceContextService } from 'vs/platform/workspace/common/workspace';
|
||||
import { IAccountManagementService } from 'sql/services/accountManagement/interfaces';
|
||||
import { IWindowsService, IWindowService } from 'vs/platform/windows/common/windows';
|
||||
import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
|
||||
import { IStorageService } from 'vs/platform/storage/common/storage';
|
||||
import { ConfigurationEditingService } from 'vs/workbench/services/configuration/node/configurationEditingService';
|
||||
import { ICommandService } from 'vs/platform/commands/common/commands';
|
||||
import { IJobManagementService } from 'sql/parts/jobManagement/common/interfaces';
|
||||
import { IEnvironmentService } from 'vs/platform/environment/common/environment';
|
||||
import { INotificationService } from 'vs/platform/notification/common/notification';
|
||||
import { IThemeService } from 'vs/platform/theme/common/themeService';
|
||||
import { IWorkbenchThemeService } from 'vs/workbench/services/themes/common/workbenchThemeService';
|
||||
|
||||
export class BootstrapService implements IBootstrapService {
|
||||
|
||||
public _serviceBrand: any;
|
||||
|
||||
// Maps uniqueSelectors (as opposed to selectors) to BootstrapParams
|
||||
private _bootstrapParameterMap: Map<string, BootstrapParams>;
|
||||
|
||||
// Maps selectors (as opposed to uniqueSelectors) to a queue of uniqueSelectors
|
||||
private _selectorQueueMap: Map<string, string[]>;
|
||||
|
||||
// Maps selectors (as opposed to uniqueSelectors) to the next available uniqueSelector ID number
|
||||
private _selectorCountMap: Map<string, number>;
|
||||
|
||||
public configurationEditorService: ConfigurationEditingService;
|
||||
|
||||
constructor(
|
||||
@IConnectionManagementService public connectionManagementService: IConnectionManagementService,
|
||||
@IMetadataService public metadataService: IMetadataService,
|
||||
@IObjectExplorerService public objectExplorerService: IObjectExplorerService,
|
||||
@IScriptingService public scriptingService: IScriptingService,
|
||||
@IQueryEditorService public queryEditorService: IQueryEditorService,
|
||||
@IAdminService public adminService: IAdminService,
|
||||
@IWorkbenchThemeService public themeService: IWorkbenchThemeService,
|
||||
@IWorkbenchEditorService public editorService: IWorkbenchEditorService,
|
||||
@IBackupService public backupService: IBackupService,
|
||||
@IBackupUiService public backupUiService: IBackupUiService,
|
||||
@IRestoreDialogController public restoreDialogService: IRestoreDialogController,
|
||||
@IRestoreService public restoreService: IRestoreService,
|
||||
@IConnectionDialogService public connectionDialogService: IConnectionDialogService,
|
||||
@IQueryModelService public queryModelService: IQueryModelService,
|
||||
@IKeybindingService public keybindingService: IKeybindingService,
|
||||
@IContextKeyService public contextKeyService: IContextKeyService,
|
||||
@IContextMenuService public contextMenuService: IContextMenuService,
|
||||
@IErrorMessageService public errorMessageService: IErrorMessageService,
|
||||
@IPartService public partService: IPartService,
|
||||
@IQueryManagementService public queryManagementService: IQueryManagementService,
|
||||
@IInstantiationService public instantiationService: IInstantiationService,
|
||||
@IAngularEventingService public angularEventingService: IAngularEventingService,
|
||||
@IConfigurationService public configurationService: IConfigurationService,
|
||||
@IInsightsDialogService public insightsDialogService: IInsightsDialogService,
|
||||
@IContextViewService public contextViewService: IContextViewService,
|
||||
@INotificationService public notificationService: INotificationService,
|
||||
@IWorkspaceContextService public workspaceContextService: IWorkspaceContextService,
|
||||
@IAccountManagementService public accountManagementService: IAccountManagementService,
|
||||
@IWindowsService public windowsService: IWindowsService,
|
||||
@ISqlOAuthService public sqlOAuthService: ISqlOAuthService,
|
||||
@IFileBrowserService public fileBrowserService: IFileBrowserService,
|
||||
@IFileBrowserDialogController public fileBrowserDialogService: IFileBrowserDialogController,
|
||||
@IWindowService public windowService: IWindowService,
|
||||
@ITelemetryService public telemetryService: ITelemetryService,
|
||||
@IStorageService public storageService: IStorageService,
|
||||
@IClipboardService public clipboardService: IClipboardService,
|
||||
@ICapabilitiesService public capabilitiesService: ICapabilitiesService,
|
||||
@ICommandService public commandService: ICommandService,
|
||||
@IDashboardViewService public dashboardViewService: IDashboardViewService,
|
||||
@IModelViewService public modelViewService: IModelViewService,
|
||||
@IJobManagementService public jobManagementService: IJobManagementService,
|
||||
@IEnvironmentService public environmentService: IEnvironmentService
|
||||
) {
|
||||
this.configurationEditorService = this.instantiationService.createInstance(ConfigurationEditingService);
|
||||
this._bootstrapParameterMap = new Map<string, BootstrapParams>();
|
||||
this._selectorQueueMap = new Map<string, string[]>();
|
||||
this._selectorCountMap = new Map<string, number>();
|
||||
}
|
||||
|
||||
public bootstrap(moduleType: any, container: HTMLElement, selectorString: string, params: BootstrapParams, input?: IEditorInput, callbackSetModule?: (value: NgModuleRef<{}>) => void): string {
|
||||
// Create the uniqueSelectorString
|
||||
let uniqueSelectorString: string = this._getUniqueSelectorString(selectorString);
|
||||
let selector: HTMLElement = $(uniqueSelectorString);
|
||||
container.appendChild(selector);
|
||||
|
||||
// Associate the elementId
|
||||
this._setUniqueSelector(selectorString, uniqueSelectorString);
|
||||
|
||||
// Associate the params
|
||||
this._bootstrapParameterMap.set(uniqueSelectorString, params);
|
||||
|
||||
// Perform the bootsrap
|
||||
let providers = [
|
||||
{ provide: BOOTSTRAP_SERVICE_ID, useValue: this },
|
||||
{ provide: IWorkbenchThemeService, useValue: this.themeService },
|
||||
{ provide: IContextViewService, useValue: this.contextViewService }
|
||||
];
|
||||
|
||||
platformBrowserDynamic(providers).bootstrapModule(moduleType).then(moduleRef => {
|
||||
if (input) {
|
||||
input.onDispose(() => {
|
||||
moduleRef.destroy();
|
||||
});
|
||||
}
|
||||
if (callbackSetModule) {
|
||||
callbackSetModule(moduleRef);
|
||||
}
|
||||
});
|
||||
|
||||
return uniqueSelectorString;
|
||||
}
|
||||
|
||||
public getBootstrapParams(id: string): any {
|
||||
let idLowercase = id.toLowerCase();
|
||||
let params: BootstrapParams = this._bootstrapParameterMap.get(idLowercase);
|
||||
this._bootstrapParameterMap.delete(idLowercase);
|
||||
return params;
|
||||
}
|
||||
|
||||
public getUniqueSelector(selectorString: string): string {
|
||||
let idArray = this._selectorQueueMap.get(selectorString);
|
||||
if (!idArray) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
let id: string = idArray.shift();
|
||||
|
||||
if (idArray.length === 0) {
|
||||
this._selectorQueueMap.delete(selectorString);
|
||||
} else {
|
||||
this._selectorQueueMap.set(selectorString, idArray);
|
||||
}
|
||||
|
||||
return id;
|
||||
}
|
||||
|
||||
private _getUniqueSelectorString(selectorString: string): string {
|
||||
let count: number = this._selectorCountMap.get(selectorString);
|
||||
if (!count) {
|
||||
this._selectorCountMap.set(selectorString, 1);
|
||||
count = 0;
|
||||
} else {
|
||||
this._selectorCountMap.set(selectorString, count + 1);
|
||||
}
|
||||
let casedString = selectorString + count.toString();
|
||||
return casedString.toLowerCase();
|
||||
}
|
||||
|
||||
private _setUniqueSelector(selectorString: string, elementId: string) {
|
||||
let idArray = this._selectorQueueMap.get(selectorString);
|
||||
if (!idArray) {
|
||||
idArray = [];
|
||||
}
|
||||
idArray.push(elementId);
|
||||
this._selectorQueueMap.set(selectorString, idArray);
|
||||
}
|
||||
}
|
||||
|
||||
if (!process.env['VSCODE_DEV']) {
|
||||
enableProdMode();
|
||||
}
|
||||
Reference in New Issue
Block a user