diff --git a/extensions/insights-default/package.json b/extensions/insights-default/package.json index 1ba5fc4ac0..3acfa15a75 100644 --- a/extensions/insights-default/package.json +++ b/extensions/insights-default/package.json @@ -11,7 +11,7 @@ "id": "query-data-store-db-insight", "contrib": { "name": "Top 5 Slowest Queries", - "provider": "MSSQL", + "when": "connectionProvider == 'MSSQL'", "gridItemConfig": { "x": 2, "y": 1 @@ -41,7 +41,7 @@ "id": "table-space-db-insight", "contrib": { "name": "Space used per table", - "provider": "MSSQL", + "when": "connectionProvider == 'MSSQL'", "gridItemConfig": { "x": 2, "y": 1 @@ -62,8 +62,7 @@ "id": "all-database-size-server-insight", "contrib": { "name": "Database Size (MB)", - "provider": "MSSQL", - "edition": [0,1,2,3,4], + "when": "connectionProvider == 'MSSQL' && !mssql:iscloud", "gridItemConfig": { "x": 2, "y": 2 @@ -84,8 +83,7 @@ "contrib": { "cacheId": "backup-history-server-insight", "name": "Backup Status", - "provider": "MSSQL", - "edition": [0,1,2,3,4], + "when": "connectionProvider == 'MSSQL' && !mssql:iscloud", "gridItemConfig": { "x": 1, "y": 1 diff --git a/extensions/mssql/client/src/contextProvider.ts b/extensions/mssql/client/src/contextProvider.ts new file mode 100644 index 0000000000..5ac4fd2c1e --- /dev/null +++ b/extensions/mssql/client/src/contextProvider.ts @@ -0,0 +1,52 @@ +/*--------------------------------------------------------------------------------------------- + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the Source EULA. See License.txt in the project root for license information. + *--------------------------------------------------------------------------------------------*/ +'use strict'; +import * as vscode from 'vscode'; +import * as sqlops from 'sqlops'; + +export enum BuiltInCommands { + SetContext = 'setContext', +} + +export enum ContextKeys { + ISCLOUD = 'mssql:iscloud' +} + +const isCloudEditions = [ + 5, + 6 +]; + +export function setCommandContext(key: ContextKeys | string, value: any) { + return vscode.commands.executeCommand(BuiltInCommands.SetContext, key, value); +} + +export default class ContextProvider { + private _disposables = new Array(); + + constructor() { + this._disposables.push(sqlops.workspace.onDidOpenDashboard(this.onDashboardOpen, this)); + this._disposables.push(sqlops.workspace.onDidChangeToDashboard(this.onDashboardOpen, this)); + } + + public onDashboardOpen(e: sqlops.DashboardDocument): void { + let iscloud: boolean; + if (e.profile.providerName.toLowerCase() === 'mssql' && e.serverInfo.engineEditionId) { + if (isCloudEditions.some(i => i === e.serverInfo.engineEditionId)) { + iscloud = true; + } else { + iscloud = false; + } + } + + if (iscloud === true || iscloud === false) { + setCommandContext(ContextKeys.ISCLOUD, iscloud); + } + } + + dispose(): void { + this._disposables = this._disposables.map(i => i.dispose()); + } +} diff --git a/extensions/mssql/client/src/main.ts b/extensions/mssql/client/src/main.ts index 3fc96be21b..9dd999f5a3 100644 --- a/extensions/mssql/client/src/main.ts +++ b/extensions/mssql/client/src/main.ts @@ -6,12 +6,15 @@ import vscode = require('vscode'); import MainController from './controllers/mainController'; +import ContextProvider from './contextProvider'; export let controller: MainController; export function activate(context: vscode.ExtensionContext) { controller = new MainController(context); + let contextProvider = new ContextProvider(); context.subscriptions.push(controller); + context.subscriptions.push(contextProvider); controller.activate(); } diff --git a/src/sql/parts/admin/security/createLoginEditor.ts b/src/sql/parts/admin/security/createLoginEditor.ts index 83329e11e3..376dad5683 100644 --- a/src/sql/parts/admin/security/createLoginEditor.ts +++ b/src/sql/parts/admin/security/createLoginEditor.ts @@ -18,7 +18,7 @@ import { IMetadataService } from 'sql/services/metadata/metadataService'; import { IScriptingService } from 'sql/services/scripting/scriptingService'; import { IQueryEditorService } from 'sql/parts/query/common/queryEditorService'; import { IBootstrapService } from 'sql/services/bootstrap/bootstrapService'; -import { DashboardComponentParams } from 'sql/services/bootstrap/bootstrapParams'; +import { BootstrapParams } from 'sql/services/bootstrap/bootstrapParams'; import { CREATELOGIN_SELECTOR } from 'sql/parts/admin/security/createLogin.component'; export class CreateLoginEditor extends BaseEditor { @@ -96,7 +96,7 @@ export class CreateLoginEditor extends BaseEditor { private bootstrapAngular(input: CreateLoginInput): void { // Get the bootstrap params and perform the bootstrap - let params: DashboardComponentParams = { + let params: BootstrapParams = { connection: input.getConnectionProfile(), ownerUri: input.getUri() }; diff --git a/src/sql/parts/connection/common/connectionContextKey.ts b/src/sql/parts/connection/common/connectionContextKey.ts new file mode 100644 index 0000000000..cf7d5e0fe9 --- /dev/null +++ b/src/sql/parts/connection/common/connectionContextKey.ts @@ -0,0 +1,49 @@ +/*--------------------------------------------------------------------------------------------- + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the Source EULA. See License.txt in the project root for license information. + *--------------------------------------------------------------------------------------------*/ + +'use strict'; + +import { RawContextKey, IContextKeyService, IContextKey } from 'vs/platform/contextkey/common/contextkey'; +import { IConnectionProfile } from 'sqlops'; + +export class ConnectionContextkey implements IContextKey { + + static Provider = new RawContextKey('connectionProvider', undefined); + static Server = new RawContextKey('serverName', undefined); + static Database = new RawContextKey('databasename', undefined); + static Connection = new RawContextKey('connection', undefined); + + private _providerKey: IContextKey; + private _serverKey: IContextKey; + private _databaseKey: IContextKey; + private _connectionKey: IContextKey; + + constructor( + @IContextKeyService contextKeyService: IContextKeyService + ) { + this._providerKey = ConnectionContextkey.Provider.bindTo(contextKeyService); + this._serverKey = ConnectionContextkey.Server.bindTo(contextKeyService); + this._databaseKey = ConnectionContextkey.Database.bindTo(contextKeyService); + this._connectionKey = ConnectionContextkey.Connection.bindTo(contextKeyService); + } + + set(value: IConnectionProfile) { + this._connectionKey.set(value); + this._providerKey.set(value && value.providerName); + this._serverKey.set(value && value.serverName); + this._databaseKey.set(value && value.databaseName); + } + + reset(): void { + this._providerKey.reset(); + this._serverKey.reset(); + this._databaseKey.reset(); + this._connectionKey.reset(); + } + + public get(): IConnectionProfile { + return this._connectionKey.get(); + } +} diff --git a/src/sql/parts/dashboard/common/dashboardHelper.ts b/src/sql/parts/dashboard/common/dashboardHelper.ts index ea4be725de..0bd824b672 100644 --- a/src/sql/parts/dashboard/common/dashboardHelper.ts +++ b/src/sql/parts/dashboard/common/dashboardHelper.ts @@ -19,6 +19,7 @@ import { WEBVIEW_CONTAINER } from 'sql/parts/dashboard/containers/dashboardWebvi import { NAV_SECTION } from 'sql/parts/dashboard/containers/dashboardNavSection.contribution'; import { IDashboardContainerRegistry, Extensions as DashboardContainerExtensions, IDashboardContainer, registerContainerType } from 'sql/platform/dashboard/common/dashboardContainerRegistry'; import { IDashboardTab } from 'sql/platform/dashboard/common/dashboardRegistry'; +import { ContextKeyExpr } from 'vs/platform/contextkey/common/contextkey'; const dashboardcontainerRegistry = Registry.as(DashboardContainerExtensions.dashboardContainerContributions); const containerTypes = [ @@ -90,14 +91,8 @@ export function initExtensionConfigs(configurations: WidgetConfig[]): Array(config: T[], dashboardService: DashboardServiceInterface): Array { - let connectionInfo: ConnectionManagementInfo = dashboardService.connectionManagementService.connectionInfo; - let edition = connectionInfo.serverInfo.engineEditionId; - let provider = connectionInfo.providerId; - - // filter by provider +export function filterConfigs(config: T[], dashboardService: DashboardServiceInterface): Array { return config.filter((item) => { - if (item.provider) { - return stringOrStringArrayCompare(item.provider, provider); - } else { + if (!item.when) { return true; - } - }).filter((item) => { - if (item.edition) { - if (edition) { - return stringOrStringArrayCompare(isNumberArray(item.edition) ? item.edition.map(item => item.toString()) : item.edition.toString(), edition.toString()); - } else { - dashboardService.messageService.show(Severity.Warning, nls.localize('providerMissingEdition', 'Widget filters based on edition, but the provider does not have an edition')); - return true; - } } else { - return true; + return dashboardService.contextKeyService.contextMatchesRules(ContextKeyExpr.deserialize(item.when)); } }); } diff --git a/src/sql/parts/dashboard/common/dashboardPage.component.ts b/src/sql/parts/dashboard/common/dashboardPage.component.ts index 957a5b21fb..93a7f98902 100644 --- a/src/sql/parts/dashboard/common/dashboardPage.component.ts +++ b/src/sql/parts/dashboard/common/dashboardPage.component.ts @@ -66,7 +66,6 @@ export abstract class DashboardPage extends Disposable implements OnDestroy { private _editEnabled = new Emitter(); public readonly editEnabled: Event = this._editEnabled.event; - // tslint:disable:no-unused-variable private readonly homeTabTitle: string = nls.localize('home', 'Home'); @@ -113,7 +112,6 @@ export abstract class DashboardPage extends Disposable implements OnDestroy { this.propertiesWidget = properties ? properties[0] : undefined; this.createTabs(tempWidgets); - } } diff --git a/src/sql/parts/dashboard/common/dashboardWidget.ts b/src/sql/parts/dashboard/common/dashboardWidget.ts index e3ea6b72fa..dbe4c8546d 100644 --- a/src/sql/parts/dashboard/common/dashboardWidget.ts +++ b/src/sql/parts/dashboard/common/dashboardWidget.ts @@ -24,6 +24,7 @@ export interface WidgetConfig { context: string; provider: string | Array; edition: number | Array; + when?: string; gridItemConfig?: NgGridItemConfig; widget: Object; background_color?: string; diff --git a/src/sql/parts/dashboard/dashboardEditor.ts b/src/sql/parts/dashboard/dashboardEditor.ts index 53a83a96bd..68a660c3d0 100644 --- a/src/sql/parts/dashboard/dashboardEditor.ts +++ b/src/sql/parts/dashboard/dashboardEditor.ts @@ -11,12 +11,18 @@ import { BaseEditor } from 'vs/workbench/browser/parts/editor/baseEditor'; import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry'; import { IWorkbenchThemeService } from 'vs/workbench/services/themes/common/workbenchThemeService'; import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation'; +import { IContextKeyService } from 'vs/platform/contextkey/common/contextkey'; import { DashboardInput } from './dashboardInput'; import { DashboardModule } from './dashboard.module'; import { IBootstrapService } from 'sql/services/bootstrap/bootstrapService'; import { DashboardComponentParams } from 'sql/services/bootstrap/bootstrapParams'; import { DASHBOARD_SELECTOR } from 'sql/parts/dashboard/dashboard.component'; +import { ConnectionContextkey } from 'sql/parts/connection/common/connectionContextKey'; +import { IDashboardService } from 'sql/services/dashboard/common/dashboardService'; +import { ConnectionProfile } from '../connection/common/connectionProfile'; +import { IConnectionProfile } from 'sqlops'; +import { IConnectionManagementService } from 'sql/parts/connection/common/connectionManagement'; export class DashboardEditor extends BaseEditor { @@ -28,7 +34,10 @@ export class DashboardEditor extends BaseEditor { @ITelemetryService telemetryService: ITelemetryService, @IWorkbenchThemeService themeService: IWorkbenchThemeService, @IInstantiationService private instantiationService: IInstantiationService, - @IBootstrapService private _bootstrapService: IBootstrapService + @IBootstrapService private _bootstrapService: IBootstrapService, + @IContextKeyService private _contextKeyService: IContextKeyService, + @IDashboardService private _dashboardService: IDashboardService, + @IConnectionManagementService private _connMan: IConnectionManagementService ) { super(DashboardEditor.ID, telemetryService, themeService); } @@ -47,6 +56,15 @@ export class DashboardEditor extends BaseEditor { * Sets focus on this editor. Specifically, it sets the focus on the hosted text editor. */ public focus(): void { + + let profile: IConnectionProfile; + if (this.input.connectionProfile instanceof ConnectionProfile) { + profile = this.input.connectionProfile.toIConnectionProfile(); + } else { + profile = this.input.connectionProfile; + } + let serverInfo = this._connMan.getConnectionInfo(this.input.uri).serverInfo; + this._dashboardService.changeToDashboard({ profile, serverInfo }); } /** @@ -84,9 +102,22 @@ export class DashboardEditor extends BaseEditor { */ private bootstrapAngular(input: DashboardInput): void { // Get the bootstrap params and perform the bootstrap + let profile: IConnectionProfile; + if (input.connectionProfile instanceof ConnectionProfile) { + profile = input.connectionProfile.toIConnectionProfile(); + } else { + profile = this.input.connectionProfile; + } + let serverInfo = this._connMan.getConnectionInfo(this.input.uri).serverInfo; + this._dashboardService.changeToDashboard({ profile, serverInfo }); + let scopedContextService = this._contextKeyService.createScoped(input.container); + let connectionContextKey = new ConnectionContextkey(scopedContextService); + connectionContextKey.set(input.connectionProfile); + let params: DashboardComponentParams = { connection: input.connectionProfile, - ownerUri: input.uri + ownerUri: input.uri, + scopedContextService: scopedContextService }; input.hasBootstrapped = true; diff --git a/src/sql/parts/dashboard/pages/dashboardPageContribution.ts b/src/sql/parts/dashboard/pages/dashboardPageContribution.ts index 3ad7679f01..67136d2190 100644 --- a/src/sql/parts/dashboard/pages/dashboardPageContribution.ts +++ b/src/sql/parts/dashboard/pages/dashboardPageContribution.ts @@ -30,31 +30,9 @@ export function generateDashboardWidgetSchema(type?: 'database' | 'server', exte icon: { type: 'string' }, - provider: { - anyOf: [ - { - type: 'string' - }, - { - type: 'array', - items: { - type: 'string' - } - } - ] - }, - edition: { - anyOf: [ - { - type: 'number' - }, - { - type: 'array', - items: { - type: 'number' - } - } - ] + when: { + description: localize('sqlops.extension.contributes.widget.when', 'Condition which must be true to show this item'), + type: 'string' }, gridItemConfig: { type: 'object', @@ -102,31 +80,9 @@ export function generateDashboardGridLayoutSchema(type?: 'database' | 'server', icon: { type: 'string' }, - provider: { - anyOf: [ - { - type: 'string' - }, - { - type: 'array', - items: { - type: 'string' - } - } - ] - }, - edition: { - anyOf: [ - { - type: 'number' - }, - { - type: 'array', - items: { - type: 'number' - } - } - ] + when: { + description: localize('sqlops.extension.contributes.widget.when', 'Condition which must be true to show this item'), + type: 'string' } } }; diff --git a/src/sql/parts/dashboard/services/dashboardServiceInterface.service.ts b/src/sql/parts/dashboard/services/dashboardServiceInterface.service.ts index efde92d62c..5e7b63e5bd 100644 --- a/src/sql/parts/dashboard/services/dashboardServiceInterface.service.ts +++ b/src/sql/parts/dashboard/services/dashboardServiceInterface.service.ts @@ -23,6 +23,7 @@ import { IConnectionProfile } from 'sql/parts/connection/common/interfaces'; import { AngularEventType, IAngularEvent, IAngularEventingService } from 'sql/services/angularEventing/angularEventingService'; import { IDashboardTab } from 'sql/platform/dashboard/common/dashboardRegistry'; import { PinConfig } from 'sql/parts/dashboard/common/dashboardWidget'; +import { IDashboardWebviewService } from 'sql/services/dashboardWebview/common/dashboardWebviewService'; import { ProviderMetadata, DatabaseInfo, SimpleExecuteResult } from 'sqlops'; @@ -42,8 +43,7 @@ import * as nls from 'vs/nls'; import { IPartService } from 'vs/workbench/services/part/common/partService'; import { deepClone } from 'vs/base/common/objects'; import { ICommandService } from 'vs/platform/commands/common/commands'; - -import { IDashboardWebviewService } from 'sql/services/dashboardWebview/common/dashboardWebviewService'; +import { IContextKeyService } from 'vs/platform/contextkey/common/contextkey'; const DASHBOARD_SETTINGS = 'dashboard'; @@ -137,6 +137,7 @@ export class DashboardServiceInterface implements OnDestroy { private _commandService: ICommandService; private _dashboardWebviewService: IDashboardWebviewService; private _partService: IPartService; + private _contextKeyService: IContextKeyService; private _angularEventingService: IAngularEventingService; private _updatePage = new Emitter(); @@ -219,6 +220,10 @@ export class DashboardServiceInterface implements OnDestroy { return this._partService; } + public get contextKeyService(): IContextKeyService { + return this._contextKeyService; + } + public get adminService(): SingleAdminService { return this._adminService; } @@ -256,8 +261,9 @@ export class DashboardServiceInterface implements OnDestroy { } private _getbootstrapParams(): void { - this._bootstrapParams = this._bootstrapService.getBootstrapParams(this._uniqueSelector); + this._bootstrapParams = this._bootstrapService.getBootstrapParams(this._uniqueSelector); this.uri = this._bootstrapParams.ownerUri; + this._contextKeyService = this._bootstrapParams.scopedContextService; } /** diff --git a/src/sql/parts/dashboard/widgets/insights/interfaces.ts b/src/sql/parts/dashboard/widgets/insights/interfaces.ts index cb1371bae4..6ca459c339 100644 --- a/src/sql/parts/dashboard/widgets/insights/interfaces.ts +++ b/src/sql/parts/dashboard/widgets/insights/interfaces.ts @@ -51,8 +51,7 @@ export interface IInsightsConfig { cacheId?: string; type: any; name?: string; - provider?: string; - edition?: number | Array; + when?: string; gridItemConfig?: ISize; query?: string | Array; queryFile?: string; diff --git a/src/sql/parts/disasterRecovery/backup/backup.component.ts b/src/sql/parts/disasterRecovery/backup/backup.component.ts index 8dd05e0b38..ce7689447e 100644 --- a/src/sql/parts/disasterRecovery/backup/backup.component.ts +++ b/src/sql/parts/disasterRecovery/backup/backup.component.ts @@ -323,7 +323,7 @@ export class BackupComponent { this._backupUiService.onShowBackupDialog(); } - private onGetBackupConfigInfo(param: DashboardComponentParams) { + private onGetBackupConfigInfo(param: { connection: IConnectionProfile, ownerUri: string }) { // Show spinner this.showSpinner(); this.backupEnabled = false; diff --git a/src/sql/parts/disasterRecovery/backup/common/backupService.ts b/src/sql/parts/disasterRecovery/backup/common/backupService.ts index a65a888e29..f7680a3eb5 100644 --- a/src/sql/parts/disasterRecovery/backup/common/backupService.ts +++ b/src/sql/parts/disasterRecovery/backup/common/backupService.ts @@ -35,7 +35,7 @@ export interface IBackupUiService { /** * On show backup event */ - onShowBackupEvent: Event; + onShowBackupEvent: Event<{ connection: IConnectionProfile, ownerUri: string }>; /** * Close backup wizard diff --git a/src/sql/parts/disasterRecovery/backup/common/backupServiceImp.ts b/src/sql/parts/disasterRecovery/backup/common/backupServiceImp.ts index 518efb61c4..a00586b6c0 100644 --- a/src/sql/parts/disasterRecovery/backup/common/backupServiceImp.ts +++ b/src/sql/parts/disasterRecovery/backup/common/backupServiceImp.ts @@ -93,15 +93,15 @@ export class BackupUiService implements IBackupUiService { private _connectionUri: string; private static _connectionUniqueId: number = 0; - private _onShowBackupEvent: Emitter; - public get onShowBackupEvent(): Event { return this._onShowBackupEvent.event; } + private _onShowBackupEvent: Emitter<{ connection: IConnectionProfile, ownerUri: string }>; + public get onShowBackupEvent(): Event<{ connection: IConnectionProfile, ownerUri: string }> { return this._onShowBackupEvent.event; } constructor( @IInstantiationService private _instantiationService: IInstantiationService, @IPartService private _partService: IPartService, @ICapabilitiesService private _capabilitiesService: ICapabilitiesService, @IBackupService private _disasterRecoveryService: IBackupService, @IConnectionManagementService private _connectionManagementService: IConnectionManagementService) { - this._onShowBackupEvent = new Emitter(); + this._onShowBackupEvent = new Emitter<{ connection: IConnectionProfile, ownerUri: string }>(); } public showBackup(connection: IConnectionProfile): Promise { diff --git a/src/sql/platform/dashboard/common/dashboardRegistry.ts b/src/sql/platform/dashboard/common/dashboardRegistry.ts index a5dd77a59a..c4bf5cb75a 100644 --- a/src/sql/platform/dashboard/common/dashboardRegistry.ts +++ b/src/sql/platform/dashboard/common/dashboardRegistry.ts @@ -27,6 +27,7 @@ export interface IDashboardTab { container?: object; provider?: string | string[]; edition?: number | number[]; + when?: string; alwaysShow?: boolean; } diff --git a/src/sql/services/bootstrap/bootstrapParams.ts b/src/sql/services/bootstrap/bootstrapParams.ts index 9a69b43dd0..e035024676 100644 --- a/src/sql/services/bootstrap/bootstrapParams.ts +++ b/src/sql/services/bootstrap/bootstrapParams.ts @@ -5,6 +5,7 @@ import { DataService } from 'sql/parts/grid/services/dataService'; import { IConnectionProfile } from 'sql/parts/connection/common/interfaces'; +import { IContextKeyService } from 'vs/platform/contextkey/common/contextkey'; export interface BootstrapParams { } @@ -20,6 +21,7 @@ export interface EditDataComponentParams extends BootstrapParams { export interface DashboardComponentParams extends BootstrapParams { connection: IConnectionProfile; ownerUri: string; + scopedContextService: IContextKeyService; } export interface TaskDialogComponentParams extends BootstrapParams { diff --git a/src/sql/services/bootstrap/bootstrapService.ts b/src/sql/services/bootstrap/bootstrapService.ts index 11a9810746..bb2f82c6dd 100644 --- a/src/sql/services/bootstrap/bootstrapService.ts +++ b/src/sql/services/bootstrap/bootstrapService.ts @@ -112,7 +112,7 @@ export interface IBootstrapService { * Gets the "params" entry associated with the given id and unassociates the id/entry pair. * Returns undefined if no entry is found. */ - getBootstrapParams(id: string): any; + getBootstrapParams(id: string): T; /* * Gets the next unique selector given the baseSelectorString. A unique selector is the baseSelectorString with a diff --git a/src/sql/services/dashboard/common/dashboardService.ts b/src/sql/services/dashboard/common/dashboardService.ts new file mode 100644 index 0000000000..936a72434c --- /dev/null +++ b/src/sql/services/dashboard/common/dashboardService.ts @@ -0,0 +1,23 @@ +/*--------------------------------------------------------------------------------------------- + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the Source EULA. See License.txt in the project root for license information. + *--------------------------------------------------------------------------------------------*/ +'use strict'; + +import { createDecorator } from 'vs/platform/instantiation/common/instantiation'; +import Event from 'vs/base/common/event'; + +import * as sqlops from 'sqlops'; + +export const IDashboardService = createDecorator('dashboardService'); + +export interface IDashboardService { + + _serviceBrand: any; + readonly onDidOpenDashboard: Event; + readonly onDidChangeToDashboard: Event; + + openDashboard(document: sqlops.DashboardDocument): void; + + changeToDashboard(document: sqlops.DashboardDocument): void; +} diff --git a/src/sql/services/dashboard/common/dashboardServiceImpl.ts b/src/sql/services/dashboard/common/dashboardServiceImpl.ts new file mode 100644 index 0000000000..75a2d6e9fd --- /dev/null +++ b/src/sql/services/dashboard/common/dashboardServiceImpl.ts @@ -0,0 +1,28 @@ +/*--------------------------------------------------------------------------------------------- + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the Source EULA. See License.txt in the project root for license information. + *--------------------------------------------------------------------------------------------*/ +'use strict'; + +import { IDashboardService } from './dashboardService'; + +import Event, { Emitter } from 'vs/base/common/event'; + +import * as sqlops from 'sqlops'; + +export class DashboardService implements IDashboardService { + public _serviceBrand: any; + private _onDidOpenDashboard = new Emitter(); + public readonly onDidOpenDashboard: Event = this._onDidOpenDashboard.event; + + private _onDidChangeToDashboard = new Emitter(); + public readonly onDidChangeToDashboard: Event = this._onDidChangeToDashboard.event; + + public openDashboard(document: sqlops.DashboardDocument): void { + this._onDidOpenDashboard.fire(document); + } + + public changeToDashboard(document: sqlops.DashboardDocument): void { + this._onDidChangeToDashboard.fire(document); + } +} diff --git a/src/sql/sqlops.d.ts b/src/sql/sqlops.d.ts index fe4eccc480..7f899d0b27 100644 --- a/src/sql/sqlops.d.ts +++ b/src/sql/sqlops.d.ts @@ -1507,6 +1507,23 @@ declare module 'sqlops' { ): ModalDialog; } + export namespace workspace { + /** + * An event that is emitted when a [dashboard](#DashboardDocument) is opened. + */ + export const onDidOpenDashboard: vscode.Event; + + /** + * An event that is emitted when a [dashboard](#DashboardDocument) is focused. + */ + export const onDidChangeToDashboard: vscode.Event; + } + + export interface DashboardDocument { + profile: IConnectionProfile; + serverInfo: ServerInfo; + } + export namespace tasks { export interface ITaskHandler { diff --git a/src/sql/workbench/api/electron-browser/mainThreadDashboard.ts b/src/sql/workbench/api/electron-browser/mainThreadDashboard.ts new file mode 100644 index 0000000000..3359b18cd3 --- /dev/null +++ b/src/sql/workbench/api/electron-browser/mainThreadDashboard.ts @@ -0,0 +1,33 @@ + +/*--------------------------------------------------------------------------------------------- + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for license information. + *--------------------------------------------------------------------------------------------*/ +'use strict'; +import { extHostNamedCustomer } from 'vs/workbench/api/electron-browser/extHostCustomers'; +import { SqlMainContext, MainThreadDashboardShape, ExtHostDashboardShape, SqlExtHostContext } from 'sql/workbench/api/node/sqlExtHost.protocol'; +import { IExtHostContext } from 'vs/workbench/api/node/extHost.protocol'; +import { IDashboardService } from 'sql/services/dashboard/common/dashboardService'; + +@extHostNamedCustomer(SqlMainContext.MainThreadDashboard) +export class MainThreadDashboard implements MainThreadDashboardShape { + private _proxy: ExtHostDashboardShape; + + constructor( + context: IExtHostContext, + @IDashboardService private _dashboardService: IDashboardService + ) { + this._proxy = context.get(SqlExtHostContext.ExtHostDashboard); + _dashboardService.onDidChangeToDashboard(e => { + this._proxy.$onDidChangeToDashboard(e); + }); + + _dashboardService.onDidOpenDashboard(e => { + this._proxy.$onDidOpenDashboard(e); + }); + } + + public dispose(): void { + + } +} diff --git a/src/sql/workbench/api/node/extHostDashboard.ts b/src/sql/workbench/api/node/extHostDashboard.ts new file mode 100644 index 0000000000..3fdbdb72f6 --- /dev/null +++ b/src/sql/workbench/api/node/extHostDashboard.ts @@ -0,0 +1,34 @@ +/*--------------------------------------------------------------------------------------------- + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the Source EULA. See License.txt in the project root for license information. + *--------------------------------------------------------------------------------------------*/ +'use strict'; + +import { IThreadService } from 'vs/workbench/services/thread/common/threadService'; +import Event, { Emitter } from 'vs/base/common/event'; + +import * as sqlops from 'sqlops'; + +import { ExtHostDashboardShape, MainThreadDashboardShape, SqlMainContext } from './sqlExtHost.protocol'; + +export class ExtHostDashboard implements ExtHostDashboardShape { + private _onDidOpenDashboard = new Emitter(); + public readonly onDidOpenDashboard: Event = this._onDidOpenDashboard.event; + + private _onDidChangeToDashboard = new Emitter(); + public readonly onDidChangeToDashboard: Event = this._onDidChangeToDashboard.event; + + private _proxy: MainThreadDashboardShape; + + constructor(threadService: IThreadService) { + this._proxy = threadService.get(SqlMainContext.MainThreadDashboard); + } + + $onDidOpenDashboard(dashboard: sqlops.DashboardDocument) { + this._onDidOpenDashboard.fire(dashboard); + } + + $onDidChangeToDashboard(dashboard: sqlops.DashboardDocument) { + this._onDidChangeToDashboard.fire(dashboard); + } +} diff --git a/src/sql/workbench/api/node/sqlExtHost.api.impl.ts b/src/sql/workbench/api/node/sqlExtHost.api.impl.ts index f0fe0a4e23..92b2d0a1f7 100644 --- a/src/sql/workbench/api/node/sqlExtHost.api.impl.ts +++ b/src/sql/workbench/api/node/sqlExtHost.api.impl.ts @@ -31,6 +31,7 @@ import { ILogService } from 'vs/platform/log/common/log'; import { IExtensionApiFactory } from 'vs/workbench/api/node/extHost.api.impl'; import { ExtHostDashboardWebviews } from 'sql/workbench/api/node/extHostDashboardWebview'; import { ExtHostConnectionManagement } from 'sql/workbench/api/node/extHostConnectionManagement'; +import { ExtHostDashboard } from 'sql/workbench/api/node/extHostDashboard'; export interface ISqlExtensionApiFactory { vsCodeFactory(extension: IExtensionDescription): typeof vscode; @@ -60,6 +61,7 @@ export function createApiFactory( const extHostModalDialogs = threadService.set(SqlExtHostContext.ExtHostModalDialogs, new ExtHostModalDialogs(threadService)); const extHostTasks = threadService.set(SqlExtHostContext.ExtHostTasks, new ExtHostTasks(threadService, logService)); const extHostWebviewWidgets = threadService.set(SqlExtHostContext.ExtHostDashboardWebviews, new ExtHostDashboardWebviews(threadService)); + const extHostDashboard = threadService.set(SqlExtHostContext.ExtHostDashboard, new ExtHostDashboard(threadService)); return { vsCodeFactory: vsCodeFactory, @@ -269,6 +271,11 @@ export function createApiFactory( } }; + const workspace: typeof sqlops.workspace = { + onDidOpenDashboard: extHostDashboard.onDidOpenDashboard, + onDidChangeToDashboard: extHostDashboard.onDidChangeToDashboard + }; + const dashboard = { registerWebviewProvider(widgetId: string, handler: (webview: sqlops.DashboardWebview) => void) { extHostWebviewWidgets.$registerProvider(widgetId, handler); @@ -291,7 +298,8 @@ export function createApiFactory( ScriptOperation: sqlExtHostTypes.ScriptOperation, window, tasks, - dashboard + dashboard, + workspace }; } }; diff --git a/src/sql/workbench/api/node/sqlExtHost.contribution.ts b/src/sql/workbench/api/node/sqlExtHost.contribution.ts index 9b7a1552a4..295972905d 100644 --- a/src/sql/workbench/api/node/sqlExtHost.contribution.ts +++ b/src/sql/workbench/api/node/sqlExtHost.contribution.ts @@ -16,6 +16,7 @@ import 'sql/workbench/api/node/mainThreadDataProtocol'; import 'sql/workbench/api/node/mainThreadSerializationProvider'; import 'sql/workbench/api/node/mainThreadResourceProvider'; import 'sql/workbench/api/electron-browser/mainThreadTasks'; +import 'sql/workbench/api/electron-browser/mainThreadDashboard'; import 'sql/workbench/api/node/mainThreadDashboardWebview'; import './mainThreadAccountManagement'; import { LifecyclePhase } from 'vs/platform/lifecycle/common/lifecycle'; diff --git a/src/sql/workbench/api/node/sqlExtHost.protocol.ts b/src/sql/workbench/api/node/sqlExtHost.protocol.ts index 8e2bf0fca7..a5a859684b 100644 --- a/src/sql/workbench/api/node/sqlExtHost.protocol.ts +++ b/src/sql/workbench/api/node/sqlExtHost.protocol.ts @@ -423,7 +423,8 @@ export const SqlMainContext = { MainThreadResourceProvider: createMainId('MainThreadResourceProvider'), MainThreadModalDialog: createMainId('MainThreadModalDialog'), MainThreadTasks: createMainId('MainThreadTasks'), - MainThreadDashboardWebview: createMainId('MainThreadDashboardWebview') + MainThreadDashboardWebview: createMainId('MainThreadDashboardWebview'), + MainThreadDashboard: createMainId('MainThreadDashboard') }; export const SqlExtHostContext = { @@ -435,9 +436,19 @@ export const SqlExtHostContext = { ExtHostResourceProvider: createExtId('ExtHostResourceProvider'), ExtHostModalDialogs: createExtId('ExtHostModalDialogs'), ExtHostTasks: createExtId('ExtHostTasks'), - ExtHostDashboardWebviews: createExtId('ExtHostDashboardWebviews') + ExtHostDashboardWebviews: createExtId('ExtHostDashboardWebviews'), + ExtHostDashboard: createExtId('ExtHostDashboard') }; +export interface MainThreadDashboardShape extends IDisposable { + +} + +export interface ExtHostDashboardShape { + $onDidOpenDashboard(dashboard: sqlops.DashboardDocument): void; + $onDidChangeToDashboard(dashboard: sqlops.DashboardDocument): void; +} + export interface MainThreadModalDialogShape extends IDisposable { $createDialog(handle: number): void; $disposeDialog(handle: number): void; diff --git a/src/vs/workbench/electron-browser/workbench.ts b/src/vs/workbench/electron-browser/workbench.ts index 791d3a64a2..9adcbc5bb8 100644 --- a/src/vs/workbench/electron-browser/workbench.ts +++ b/src/vs/workbench/electron-browser/workbench.ts @@ -147,6 +147,8 @@ import { ResourceProviderService } from 'sql/parts/accountManagement/common/reso import { AccountPickerService } from 'sql/parts/accountManagement/accountPicker/accountPickerService'; import { IDashboardWebviewService } from 'sql/services/dashboardWebview/common/dashboardWebviewService'; import { DashboardWebviewService } from 'sql/services/dashboardWebview/common/dashboardWebviewServiceImpl'; +import { IDashboardService } from 'sql/services/dashboard/common/dashboardService'; +import { DashboardService } from 'sql/services/dashboard/common/dashboardServiceImpl'; export const MessagesVisibleContext = new RawContextKey('globalMessageVisible', false); export const EditorsVisibleContext = new RawContextKey('editorIsOpen', false); @@ -674,6 +676,7 @@ export class Workbench implements IPartService { // {{SQL CARBON EDIT}} // SQL Tools services + serviceCollection.set(IDashboardService, this.instantiationService.createInstance(DashboardService)); serviceCollection.set(IDashboardWebviewService, this.instantiationService.createInstance(DashboardWebviewService)); serviceCollection.set(IAngularEventingService, this.instantiationService.createInstance(AngularEventingService)); serviceCollection.set(INewDashboardTabDialogService, this.instantiationService.createInstance(NewDashboardTabDialogService));