/*--------------------------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the Source EULA. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation'; import { Event, Emitter } from 'vs/base/common/event'; import * as azdata from 'azdata'; import { IAccountPickerService } from 'sql/workbench/services/accountManagement/browser/accountPicker'; import { AccountPicker } from 'sql/workbench/services/accountManagement/browser/accountPickerImpl'; export class AccountPickerService implements IAccountPickerService { _serviceBrand: undefined; private _accountPicker?: AccountPicker; // EVENTING //////////////////////////////////////////////////////////// private _addAccountCompleteEmitter: Emitter; public get addAccountCompleteEvent(): Event { return this._addAccountCompleteEmitter.event; } private _addAccountErrorEmitter: Emitter; public get addAccountErrorEvent(): Event { return this._addAccountErrorEmitter.event; } private _addAccountStartEmitter: Emitter; public get addAccountStartEvent(): Event { return this._addAccountStartEmitter.event; } private _onAccountSelectionChangeEvent: Emitter; public get onAccountSelectionChangeEvent(): Event { return this._onAccountSelectionChangeEvent.event; } private _onTenantSelectionChangeEvent: Emitter; public get onTenantSelectionChangeEvent(): Event { return this._onTenantSelectionChangeEvent.event; } constructor( @IInstantiationService private _instantiationService: IInstantiationService ) { // Create event emitters this._addAccountCompleteEmitter = new Emitter(); this._addAccountErrorEmitter = new Emitter(); this._addAccountStartEmitter = new Emitter(); this._onAccountSelectionChangeEvent = new Emitter(); this._onTenantSelectionChangeEvent = new Emitter(); } /** * Get selected account */ public get selectedAccount(): azdata.Account | undefined { if (this._accountPicker) { return this._accountPicker.viewModel.selectedAccount; } else { return undefined; } } /** * Render account picker */ public renderAccountPicker(rootContainer: HTMLElement): void { if (!this._accountPicker) { // TODO: expand support to multiple providers const providerId: string = 'azure_publicCloud'; this._accountPicker = this._instantiationService.createInstance(AccountPicker, providerId); this._accountPicker.createAccountPickerComponent(); } this._accountPicker.addAccountCompleteEvent(() => this._addAccountCompleteEmitter.fire()); this._accountPicker.addAccountErrorEvent((msg) => this._addAccountErrorEmitter.fire(msg)); this._accountPicker.addAccountStartEvent(() => this._addAccountStartEmitter.fire()); this._accountPicker.onAccountSelectionChangeEvent((account) => this._onAccountSelectionChangeEvent.fire(account)); this._accountPicker.onTenantSelectionChangeEvent((tenantId) => this._onTenantSelectionChangeEvent.fire(tenantId)); this._accountPicker.render(rootContainer); } }