integrate with contextkeyservice (#804)

* commting .d.ts changes

* added serverinfo to .d.ts

* maybe its working?

* works

* updated contrib

* remove unnecessary code

* fix compile errors

* change back sqlops engine for merge
This commit is contained in:
Anthony Dresser
2018-03-06 13:56:04 -08:00
committed by GitHub
parent 0bba972657
commit 9f5268101d
27 changed files with 336 additions and 103 deletions

View File

@@ -11,7 +11,7 @@
"id": "query-data-store-db-insight", "id": "query-data-store-db-insight",
"contrib": { "contrib": {
"name": "Top 5 Slowest Queries", "name": "Top 5 Slowest Queries",
"provider": "MSSQL", "when": "connectionProvider == 'MSSQL'",
"gridItemConfig": { "gridItemConfig": {
"x": 2, "x": 2,
"y": 1 "y": 1
@@ -41,7 +41,7 @@
"id": "table-space-db-insight", "id": "table-space-db-insight",
"contrib": { "contrib": {
"name": "Space used per table", "name": "Space used per table",
"provider": "MSSQL", "when": "connectionProvider == 'MSSQL'",
"gridItemConfig": { "gridItemConfig": {
"x": 2, "x": 2,
"y": 1 "y": 1
@@ -62,8 +62,7 @@
"id": "all-database-size-server-insight", "id": "all-database-size-server-insight",
"contrib": { "contrib": {
"name": "Database Size (MB)", "name": "Database Size (MB)",
"provider": "MSSQL", "when": "connectionProvider == 'MSSQL' && !mssql:iscloud",
"edition": [0,1,2,3,4],
"gridItemConfig": { "gridItemConfig": {
"x": 2, "x": 2,
"y": 2 "y": 2
@@ -84,8 +83,7 @@
"contrib": { "contrib": {
"cacheId": "backup-history-server-insight", "cacheId": "backup-history-server-insight",
"name": "Backup Status", "name": "Backup Status",
"provider": "MSSQL", "when": "connectionProvider == 'MSSQL' && !mssql:iscloud",
"edition": [0,1,2,3,4],
"gridItemConfig": { "gridItemConfig": {
"x": 1, "x": 1,
"y": 1 "y": 1

View File

@@ -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<vscode.Disposable>();
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());
}
}

View File

@@ -6,12 +6,15 @@
import vscode = require('vscode'); import vscode = require('vscode');
import MainController from './controllers/mainController'; import MainController from './controllers/mainController';
import ContextProvider from './contextProvider';
export let controller: MainController; export let controller: MainController;
export function activate(context: vscode.ExtensionContext) { export function activate(context: vscode.ExtensionContext) {
controller = new MainController(context); controller = new MainController(context);
let contextProvider = new ContextProvider();
context.subscriptions.push(controller); context.subscriptions.push(controller);
context.subscriptions.push(contextProvider);
controller.activate(); controller.activate();
} }

View File

@@ -18,7 +18,7 @@ import { IMetadataService } from 'sql/services/metadata/metadataService';
import { IScriptingService } from 'sql/services/scripting/scriptingService'; import { IScriptingService } from 'sql/services/scripting/scriptingService';
import { IQueryEditorService } from 'sql/parts/query/common/queryEditorService'; import { IQueryEditorService } from 'sql/parts/query/common/queryEditorService';
import { IBootstrapService } from 'sql/services/bootstrap/bootstrapService'; 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'; import { CREATELOGIN_SELECTOR } from 'sql/parts/admin/security/createLogin.component';
export class CreateLoginEditor extends BaseEditor { export class CreateLoginEditor extends BaseEditor {
@@ -96,7 +96,7 @@ export class CreateLoginEditor extends BaseEditor {
private bootstrapAngular(input: CreateLoginInput): void { private bootstrapAngular(input: CreateLoginInput): void {
// Get the bootstrap params and perform the bootstrap // Get the bootstrap params and perform the bootstrap
let params: DashboardComponentParams = { let params: BootstrapParams = {
connection: input.getConnectionProfile(), connection: input.getConnectionProfile(),
ownerUri: input.getUri() ownerUri: input.getUri()
}; };

View File

@@ -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<IConnectionProfile> {
static Provider = new RawContextKey<string>('connectionProvider', undefined);
static Server = new RawContextKey<string>('serverName', undefined);
static Database = new RawContextKey<string>('databasename', undefined);
static Connection = new RawContextKey<IConnectionProfile>('connection', undefined);
private _providerKey: IContextKey<string>;
private _serverKey: IContextKey<string>;
private _databaseKey: IContextKey<string>;
private _connectionKey: IContextKey<IConnectionProfile>;
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();
}
}

View File

@@ -19,6 +19,7 @@ import { WEBVIEW_CONTAINER } from 'sql/parts/dashboard/containers/dashboardWebvi
import { NAV_SECTION } from 'sql/parts/dashboard/containers/dashboardNavSection.contribution'; import { NAV_SECTION } from 'sql/parts/dashboard/containers/dashboardNavSection.contribution';
import { IDashboardContainerRegistry, Extensions as DashboardContainerExtensions, IDashboardContainer, registerContainerType } from 'sql/platform/dashboard/common/dashboardContainerRegistry'; import { IDashboardContainerRegistry, Extensions as DashboardContainerExtensions, IDashboardContainer, registerContainerType } from 'sql/platform/dashboard/common/dashboardContainerRegistry';
import { IDashboardTab } from 'sql/platform/dashboard/common/dashboardRegistry'; import { IDashboardTab } from 'sql/platform/dashboard/common/dashboardRegistry';
import { ContextKeyExpr } from 'vs/platform/contextkey/common/contextkey';
const dashboardcontainerRegistry = Registry.as<IDashboardContainerRegistry>(DashboardContainerExtensions.dashboardContainerContributions); const dashboardcontainerRegistry = Registry.as<IDashboardContainerRegistry>(DashboardContainerExtensions.dashboardContainerContributions);
const containerTypes = [ const containerTypes = [
@@ -90,14 +91,8 @@ export function initExtensionConfigs(configurations: WidgetConfig[]): Array<Widg
let insightConfig = widgetRegistry.getRegisteredExtensionInsights(key); let insightConfig = widgetRegistry.getRegisteredExtensionInsights(key);
if (insightConfig !== undefined) { if (insightConfig !== undefined) {
// Setup the default properties for this extension if needed // Setup the default properties for this extension if needed
if (!config.provider && insightConfig.provider) { if (!config.when && insightConfig.when) {
config.provider = insightConfig.provider; config.when = insightConfig.when;
}
if (!config.name && insightConfig.name) {
config.name = insightConfig.name;
}
if (!config.edition && insightConfig.edition) {
config.edition = insightConfig.edition;
} }
if (!config.gridItemConfig && insightConfig.gridItemConfig) { if (!config.gridItemConfig && insightConfig.gridItemConfig) {
config.gridItemConfig = { config.gridItemConfig = {
@@ -163,28 +158,12 @@ export function addContext(config: WidgetConfig[], dashboardServer: DashboardSer
* Returns a filtered version of the widgets passed based on edition and provider * Returns a filtered version of the widgets passed based on edition and provider
* @param config widgets to filter * @param config widgets to filter
*/ */
export function filterConfigs<T extends { provider?: string | string[], edition?: number | number[] }>(config: T[], dashboardService: DashboardServiceInterface): Array<T> { export function filterConfigs<T extends { when?: string }>(config: T[], dashboardService: DashboardServiceInterface): Array<T> {
let connectionInfo: ConnectionManagementInfo = dashboardService.connectionManagementService.connectionInfo;
let edition = connectionInfo.serverInfo.engineEditionId;
let provider = connectionInfo.providerId;
// filter by provider
return config.filter((item) => { return config.filter((item) => {
if (item.provider) { if (!item.when) {
return stringOrStringArrayCompare(item.provider, provider);
} else {
return true; 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 { } else {
return true; return dashboardService.contextKeyService.contextMatchesRules(ContextKeyExpr.deserialize(item.when));
} }
}); });
} }

View File

@@ -66,7 +66,6 @@ export abstract class DashboardPage extends Disposable implements OnDestroy {
private _editEnabled = new Emitter<boolean>(); private _editEnabled = new Emitter<boolean>();
public readonly editEnabled: Event<boolean> = this._editEnabled.event; public readonly editEnabled: Event<boolean> = this._editEnabled.event;
// tslint:disable:no-unused-variable // tslint:disable:no-unused-variable
private readonly homeTabTitle: string = nls.localize('home', 'Home'); 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.propertiesWidget = properties ? properties[0] : undefined;
this.createTabs(tempWidgets); this.createTabs(tempWidgets);
} }
} }

View File

@@ -24,6 +24,7 @@ export interface WidgetConfig {
context: string; context: string;
provider: string | Array<string>; provider: string | Array<string>;
edition: number | Array<number>; edition: number | Array<number>;
when?: string;
gridItemConfig?: NgGridItemConfig; gridItemConfig?: NgGridItemConfig;
widget: Object; widget: Object;
background_color?: string; background_color?: string;

View File

@@ -11,12 +11,18 @@ import { BaseEditor } from 'vs/workbench/browser/parts/editor/baseEditor';
import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry'; import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
import { IWorkbenchThemeService } from 'vs/workbench/services/themes/common/workbenchThemeService'; import { IWorkbenchThemeService } from 'vs/workbench/services/themes/common/workbenchThemeService';
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation'; import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
import { IContextKeyService } from 'vs/platform/contextkey/common/contextkey';
import { DashboardInput } from './dashboardInput'; import { DashboardInput } from './dashboardInput';
import { DashboardModule } from './dashboard.module'; import { DashboardModule } from './dashboard.module';
import { IBootstrapService } from 'sql/services/bootstrap/bootstrapService'; import { IBootstrapService } from 'sql/services/bootstrap/bootstrapService';
import { DashboardComponentParams } from 'sql/services/bootstrap/bootstrapParams'; import { DashboardComponentParams } from 'sql/services/bootstrap/bootstrapParams';
import { DASHBOARD_SELECTOR } from 'sql/parts/dashboard/dashboard.component'; 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 { export class DashboardEditor extends BaseEditor {
@@ -28,7 +34,10 @@ export class DashboardEditor extends BaseEditor {
@ITelemetryService telemetryService: ITelemetryService, @ITelemetryService telemetryService: ITelemetryService,
@IWorkbenchThemeService themeService: IWorkbenchThemeService, @IWorkbenchThemeService themeService: IWorkbenchThemeService,
@IInstantiationService private instantiationService: IInstantiationService, @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); 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. * Sets focus on this editor. Specifically, it sets the focus on the hosted text editor.
*/ */
public focus(): void { 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 { private bootstrapAngular(input: DashboardInput): void {
// Get the bootstrap params and perform the bootstrap // 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 = { let params: DashboardComponentParams = {
connection: input.connectionProfile, connection: input.connectionProfile,
ownerUri: input.uri ownerUri: input.uri,
scopedContextService: scopedContextService
}; };
input.hasBootstrapped = true; input.hasBootstrapped = true;

View File

@@ -30,31 +30,9 @@ export function generateDashboardWidgetSchema(type?: 'database' | 'server', exte
icon: { icon: {
type: 'string' type: 'string'
}, },
provider: { when: {
anyOf: [ description: localize('sqlops.extension.contributes.widget.when', 'Condition which must be true to show this item'),
{ type: 'string'
type: 'string'
},
{
type: 'array',
items: {
type: 'string'
}
}
]
},
edition: {
anyOf: [
{
type: 'number'
},
{
type: 'array',
items: {
type: 'number'
}
}
]
}, },
gridItemConfig: { gridItemConfig: {
type: 'object', type: 'object',
@@ -102,31 +80,9 @@ export function generateDashboardGridLayoutSchema(type?: 'database' | 'server',
icon: { icon: {
type: 'string' type: 'string'
}, },
provider: { when: {
anyOf: [ description: localize('sqlops.extension.contributes.widget.when', 'Condition which must be true to show this item'),
{ type: 'string'
type: 'string'
},
{
type: 'array',
items: {
type: 'string'
}
}
]
},
edition: {
anyOf: [
{
type: 'number'
},
{
type: 'array',
items: {
type: 'number'
}
}
]
} }
} }
}; };

View File

@@ -23,6 +23,7 @@ import { IConnectionProfile } from 'sql/parts/connection/common/interfaces';
import { AngularEventType, IAngularEvent, IAngularEventingService } from 'sql/services/angularEventing/angularEventingService'; import { AngularEventType, IAngularEvent, IAngularEventingService } from 'sql/services/angularEventing/angularEventingService';
import { IDashboardTab } from 'sql/platform/dashboard/common/dashboardRegistry'; import { IDashboardTab } from 'sql/platform/dashboard/common/dashboardRegistry';
import { PinConfig } from 'sql/parts/dashboard/common/dashboardWidget'; import { PinConfig } from 'sql/parts/dashboard/common/dashboardWidget';
import { IDashboardWebviewService } from 'sql/services/dashboardWebview/common/dashboardWebviewService';
import { ProviderMetadata, DatabaseInfo, SimpleExecuteResult } from 'sqlops'; 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 { IPartService } from 'vs/workbench/services/part/common/partService';
import { deepClone } from 'vs/base/common/objects'; import { deepClone } from 'vs/base/common/objects';
import { ICommandService } from 'vs/platform/commands/common/commands'; import { ICommandService } from 'vs/platform/commands/common/commands';
import { IContextKeyService } from 'vs/platform/contextkey/common/contextkey';
import { IDashboardWebviewService } from 'sql/services/dashboardWebview/common/dashboardWebviewService';
const DASHBOARD_SETTINGS = 'dashboard'; const DASHBOARD_SETTINGS = 'dashboard';
@@ -137,6 +137,7 @@ export class DashboardServiceInterface implements OnDestroy {
private _commandService: ICommandService; private _commandService: ICommandService;
private _dashboardWebviewService: IDashboardWebviewService; private _dashboardWebviewService: IDashboardWebviewService;
private _partService: IPartService; private _partService: IPartService;
private _contextKeyService: IContextKeyService;
private _angularEventingService: IAngularEventingService; private _angularEventingService: IAngularEventingService;
private _updatePage = new Emitter<void>(); private _updatePage = new Emitter<void>();
@@ -219,6 +220,10 @@ export class DashboardServiceInterface implements OnDestroy {
return this._partService; return this._partService;
} }
public get contextKeyService(): IContextKeyService {
return this._contextKeyService;
}
public get adminService(): SingleAdminService { public get adminService(): SingleAdminService {
return this._adminService; return this._adminService;
} }
@@ -256,8 +261,9 @@ export class DashboardServiceInterface implements OnDestroy {
} }
private _getbootstrapParams(): void { private _getbootstrapParams(): void {
this._bootstrapParams = this._bootstrapService.getBootstrapParams(this._uniqueSelector); this._bootstrapParams = this._bootstrapService.getBootstrapParams<DashboardComponentParams>(this._uniqueSelector);
this.uri = this._bootstrapParams.ownerUri; this.uri = this._bootstrapParams.ownerUri;
this._contextKeyService = this._bootstrapParams.scopedContextService;
} }
/** /**

View File

@@ -51,8 +51,7 @@ export interface IInsightsConfig {
cacheId?: string; cacheId?: string;
type: any; type: any;
name?: string; name?: string;
provider?: string; when?: string;
edition?: number | Array<number>;
gridItemConfig?: ISize; gridItemConfig?: ISize;
query?: string | Array<string>; query?: string | Array<string>;
queryFile?: string; queryFile?: string;

View File

@@ -323,7 +323,7 @@ export class BackupComponent {
this._backupUiService.onShowBackupDialog(); this._backupUiService.onShowBackupDialog();
} }
private onGetBackupConfigInfo(param: DashboardComponentParams) { private onGetBackupConfigInfo(param: { connection: IConnectionProfile, ownerUri: string }) {
// Show spinner // Show spinner
this.showSpinner(); this.showSpinner();
this.backupEnabled = false; this.backupEnabled = false;

View File

@@ -35,7 +35,7 @@ export interface IBackupUiService {
/** /**
* On show backup event * On show backup event
*/ */
onShowBackupEvent: Event<DashboardComponentParams>; onShowBackupEvent: Event<{ connection: IConnectionProfile, ownerUri: string }>;
/** /**
* Close backup wizard * Close backup wizard

View File

@@ -93,15 +93,15 @@ export class BackupUiService implements IBackupUiService {
private _connectionUri: string; private _connectionUri: string;
private static _connectionUniqueId: number = 0; private static _connectionUniqueId: number = 0;
private _onShowBackupEvent: Emitter<DashboardComponentParams>; private _onShowBackupEvent: Emitter<{ connection: IConnectionProfile, ownerUri: string }>;
public get onShowBackupEvent(): Event<DashboardComponentParams> { return this._onShowBackupEvent.event; } public get onShowBackupEvent(): Event<{ connection: IConnectionProfile, ownerUri: string }> { return this._onShowBackupEvent.event; }
constructor( @IInstantiationService private _instantiationService: IInstantiationService, constructor( @IInstantiationService private _instantiationService: IInstantiationService,
@IPartService private _partService: IPartService, @IPartService private _partService: IPartService,
@ICapabilitiesService private _capabilitiesService: ICapabilitiesService, @ICapabilitiesService private _capabilitiesService: ICapabilitiesService,
@IBackupService private _disasterRecoveryService: IBackupService, @IBackupService private _disasterRecoveryService: IBackupService,
@IConnectionManagementService private _connectionManagementService: IConnectionManagementService) { @IConnectionManagementService private _connectionManagementService: IConnectionManagementService) {
this._onShowBackupEvent = new Emitter<DashboardComponentParams>(); this._onShowBackupEvent = new Emitter<{ connection: IConnectionProfile, ownerUri: string }>();
} }
public showBackup(connection: IConnectionProfile): Promise<any> { public showBackup(connection: IConnectionProfile): Promise<any> {

View File

@@ -27,6 +27,7 @@ export interface IDashboardTab {
container?: object; container?: object;
provider?: string | string[]; provider?: string | string[];
edition?: number | number[]; edition?: number | number[];
when?: string;
alwaysShow?: boolean; alwaysShow?: boolean;
} }

View File

@@ -5,6 +5,7 @@
import { DataService } from 'sql/parts/grid/services/dataService'; import { DataService } from 'sql/parts/grid/services/dataService';
import { IConnectionProfile } from 'sql/parts/connection/common/interfaces'; import { IConnectionProfile } from 'sql/parts/connection/common/interfaces';
import { IContextKeyService } from 'vs/platform/contextkey/common/contextkey';
export interface BootstrapParams { export interface BootstrapParams {
} }
@@ -20,6 +21,7 @@ export interface EditDataComponentParams extends BootstrapParams {
export interface DashboardComponentParams extends BootstrapParams { export interface DashboardComponentParams extends BootstrapParams {
connection: IConnectionProfile; connection: IConnectionProfile;
ownerUri: string; ownerUri: string;
scopedContextService: IContextKeyService;
} }
export interface TaskDialogComponentParams extends BootstrapParams { export interface TaskDialogComponentParams extends BootstrapParams {

View File

@@ -112,7 +112,7 @@ export interface IBootstrapService {
* Gets the "params" entry associated with the given id and unassociates the id/entry pair. * Gets the "params" entry associated with the given id and unassociates the id/entry pair.
* Returns undefined if no entry is found. * Returns undefined if no entry is found.
*/ */
getBootstrapParams(id: string): any; getBootstrapParams<T extends BootstrapParams>(id: string): T;
/* /*
* Gets the next unique selector given the baseSelectorString. A unique selector is the baseSelectorString with a * Gets the next unique selector given the baseSelectorString. A unique selector is the baseSelectorString with a

View File

@@ -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<IDashboardService>('dashboardService');
export interface IDashboardService {
_serviceBrand: any;
readonly onDidOpenDashboard: Event<sqlops.DashboardDocument>;
readonly onDidChangeToDashboard: Event<sqlops.DashboardDocument>;
openDashboard(document: sqlops.DashboardDocument): void;
changeToDashboard(document: sqlops.DashboardDocument): void;
}

View File

@@ -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<sqlops.DashboardDocument>();
public readonly onDidOpenDashboard: Event<sqlops.DashboardDocument> = this._onDidOpenDashboard.event;
private _onDidChangeToDashboard = new Emitter<sqlops.DashboardDocument>();
public readonly onDidChangeToDashboard: Event<sqlops.DashboardDocument> = this._onDidChangeToDashboard.event;
public openDashboard(document: sqlops.DashboardDocument): void {
this._onDidOpenDashboard.fire(document);
}
public changeToDashboard(document: sqlops.DashboardDocument): void {
this._onDidChangeToDashboard.fire(document);
}
}

17
src/sql/sqlops.d.ts vendored
View File

@@ -1507,6 +1507,23 @@ declare module 'sqlops' {
): ModalDialog; ): ModalDialog;
} }
export namespace workspace {
/**
* An event that is emitted when a [dashboard](#DashboardDocument) is opened.
*/
export const onDidOpenDashboard: vscode.Event<DashboardDocument>;
/**
* An event that is emitted when a [dashboard](#DashboardDocument) is focused.
*/
export const onDidChangeToDashboard: vscode.Event<DashboardDocument>;
}
export interface DashboardDocument {
profile: IConnectionProfile;
serverInfo: ServerInfo;
}
export namespace tasks { export namespace tasks {
export interface ITaskHandler { export interface ITaskHandler {

View File

@@ -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 {
}
}

View File

@@ -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<sqlops.DashboardDocument>();
public readonly onDidOpenDashboard: Event<sqlops.DashboardDocument> = this._onDidOpenDashboard.event;
private _onDidChangeToDashboard = new Emitter<sqlops.DashboardDocument>();
public readonly onDidChangeToDashboard: Event<sqlops.DashboardDocument> = 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);
}
}

View File

@@ -31,6 +31,7 @@ import { ILogService } from 'vs/platform/log/common/log';
import { IExtensionApiFactory } from 'vs/workbench/api/node/extHost.api.impl'; import { IExtensionApiFactory } from 'vs/workbench/api/node/extHost.api.impl';
import { ExtHostDashboardWebviews } from 'sql/workbench/api/node/extHostDashboardWebview'; import { ExtHostDashboardWebviews } from 'sql/workbench/api/node/extHostDashboardWebview';
import { ExtHostConnectionManagement } from 'sql/workbench/api/node/extHostConnectionManagement'; import { ExtHostConnectionManagement } from 'sql/workbench/api/node/extHostConnectionManagement';
import { ExtHostDashboard } from 'sql/workbench/api/node/extHostDashboard';
export interface ISqlExtensionApiFactory { export interface ISqlExtensionApiFactory {
vsCodeFactory(extension: IExtensionDescription): typeof vscode; vsCodeFactory(extension: IExtensionDescription): typeof vscode;
@@ -60,6 +61,7 @@ export function createApiFactory(
const extHostModalDialogs = threadService.set(SqlExtHostContext.ExtHostModalDialogs, new ExtHostModalDialogs(threadService)); const extHostModalDialogs = threadService.set(SqlExtHostContext.ExtHostModalDialogs, new ExtHostModalDialogs(threadService));
const extHostTasks = threadService.set(SqlExtHostContext.ExtHostTasks, new ExtHostTasks(threadService, logService)); const extHostTasks = threadService.set(SqlExtHostContext.ExtHostTasks, new ExtHostTasks(threadService, logService));
const extHostWebviewWidgets = threadService.set(SqlExtHostContext.ExtHostDashboardWebviews, new ExtHostDashboardWebviews(threadService)); const extHostWebviewWidgets = threadService.set(SqlExtHostContext.ExtHostDashboardWebviews, new ExtHostDashboardWebviews(threadService));
const extHostDashboard = threadService.set(SqlExtHostContext.ExtHostDashboard, new ExtHostDashboard(threadService));
return { return {
vsCodeFactory: vsCodeFactory, vsCodeFactory: vsCodeFactory,
@@ -269,6 +271,11 @@ export function createApiFactory(
} }
}; };
const workspace: typeof sqlops.workspace = {
onDidOpenDashboard: extHostDashboard.onDidOpenDashboard,
onDidChangeToDashboard: extHostDashboard.onDidChangeToDashboard
};
const dashboard = { const dashboard = {
registerWebviewProvider(widgetId: string, handler: (webview: sqlops.DashboardWebview) => void) { registerWebviewProvider(widgetId: string, handler: (webview: sqlops.DashboardWebview) => void) {
extHostWebviewWidgets.$registerProvider(widgetId, handler); extHostWebviewWidgets.$registerProvider(widgetId, handler);
@@ -291,7 +298,8 @@ export function createApiFactory(
ScriptOperation: sqlExtHostTypes.ScriptOperation, ScriptOperation: sqlExtHostTypes.ScriptOperation,
window, window,
tasks, tasks,
dashboard dashboard,
workspace
}; };
} }
}; };

View File

@@ -16,6 +16,7 @@ import 'sql/workbench/api/node/mainThreadDataProtocol';
import 'sql/workbench/api/node/mainThreadSerializationProvider'; import 'sql/workbench/api/node/mainThreadSerializationProvider';
import 'sql/workbench/api/node/mainThreadResourceProvider'; import 'sql/workbench/api/node/mainThreadResourceProvider';
import 'sql/workbench/api/electron-browser/mainThreadTasks'; import 'sql/workbench/api/electron-browser/mainThreadTasks';
import 'sql/workbench/api/electron-browser/mainThreadDashboard';
import 'sql/workbench/api/node/mainThreadDashboardWebview'; import 'sql/workbench/api/node/mainThreadDashboardWebview';
import './mainThreadAccountManagement'; import './mainThreadAccountManagement';
import { LifecyclePhase } from 'vs/platform/lifecycle/common/lifecycle'; import { LifecyclePhase } from 'vs/platform/lifecycle/common/lifecycle';

View File

@@ -423,7 +423,8 @@ export const SqlMainContext = {
MainThreadResourceProvider: createMainId<MainThreadResourceProviderShape>('MainThreadResourceProvider'), MainThreadResourceProvider: createMainId<MainThreadResourceProviderShape>('MainThreadResourceProvider'),
MainThreadModalDialog: createMainId<MainThreadModalDialogShape>('MainThreadModalDialog'), MainThreadModalDialog: createMainId<MainThreadModalDialogShape>('MainThreadModalDialog'),
MainThreadTasks: createMainId<MainThreadTasksShape>('MainThreadTasks'), MainThreadTasks: createMainId<MainThreadTasksShape>('MainThreadTasks'),
MainThreadDashboardWebview: createMainId<MainThreadDashboardWebviewShape>('MainThreadDashboardWebview') MainThreadDashboardWebview: createMainId<MainThreadDashboardWebviewShape>('MainThreadDashboardWebview'),
MainThreadDashboard: createMainId<MainThreadDashboardShape>('MainThreadDashboard')
}; };
export const SqlExtHostContext = { export const SqlExtHostContext = {
@@ -435,9 +436,19 @@ export const SqlExtHostContext = {
ExtHostResourceProvider: createExtId<ExtHostResourceProviderShape>('ExtHostResourceProvider'), ExtHostResourceProvider: createExtId<ExtHostResourceProviderShape>('ExtHostResourceProvider'),
ExtHostModalDialogs: createExtId<ExtHostModalDialogsShape>('ExtHostModalDialogs'), ExtHostModalDialogs: createExtId<ExtHostModalDialogsShape>('ExtHostModalDialogs'),
ExtHostTasks: createExtId<ExtHostTasksShape>('ExtHostTasks'), ExtHostTasks: createExtId<ExtHostTasksShape>('ExtHostTasks'),
ExtHostDashboardWebviews: createExtId<ExtHostDashboardWebviewsShape>('ExtHostDashboardWebviews') ExtHostDashboardWebviews: createExtId<ExtHostDashboardWebviewsShape>('ExtHostDashboardWebviews'),
ExtHostDashboard: createExtId<ExtHostDashboardShape>('ExtHostDashboard')
}; };
export interface MainThreadDashboardShape extends IDisposable {
}
export interface ExtHostDashboardShape {
$onDidOpenDashboard(dashboard: sqlops.DashboardDocument): void;
$onDidChangeToDashboard(dashboard: sqlops.DashboardDocument): void;
}
export interface MainThreadModalDialogShape extends IDisposable { export interface MainThreadModalDialogShape extends IDisposable {
$createDialog(handle: number): void; $createDialog(handle: number): void;
$disposeDialog(handle: number): void; $disposeDialog(handle: number): void;

View File

@@ -147,6 +147,8 @@ import { ResourceProviderService } from 'sql/parts/accountManagement/common/reso
import { AccountPickerService } from 'sql/parts/accountManagement/accountPicker/accountPickerService'; import { AccountPickerService } from 'sql/parts/accountManagement/accountPicker/accountPickerService';
import { IDashboardWebviewService } from 'sql/services/dashboardWebview/common/dashboardWebviewService'; import { IDashboardWebviewService } from 'sql/services/dashboardWebview/common/dashboardWebviewService';
import { DashboardWebviewService } from 'sql/services/dashboardWebview/common/dashboardWebviewServiceImpl'; 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<boolean>('globalMessageVisible', false); export const MessagesVisibleContext = new RawContextKey<boolean>('globalMessageVisible', false);
export const EditorsVisibleContext = new RawContextKey<boolean>('editorIsOpen', false); export const EditorsVisibleContext = new RawContextKey<boolean>('editorIsOpen', false);
@@ -674,6 +676,7 @@ export class Workbench implements IPartService {
// {{SQL CARBON EDIT}} // {{SQL CARBON EDIT}}
// SQL Tools services // SQL Tools services
serviceCollection.set(IDashboardService, this.instantiationService.createInstance(DashboardService));
serviceCollection.set(IDashboardWebviewService, this.instantiationService.createInstance(DashboardWebviewService)); serviceCollection.set(IDashboardWebviewService, this.instantiationService.createInstance(DashboardWebviewService));
serviceCollection.set(IAngularEventingService, this.instantiationService.createInstance(AngularEventingService)); serviceCollection.set(IAngularEventingService, this.instantiationService.createInstance(AngularEventingService));
serviceCollection.set(INewDashboardTabDialogService, this.instantiationService.createInstance(NewDashboardTabDialogService)); serviceCollection.set(INewDashboardTabDialogService, this.instantiationService.createInstance(NewDashboardTabDialogService));