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

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

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 { 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<IDashboardContainerRegistry>(DashboardContainerExtensions.dashboardContainerContributions);
const containerTypes = [
@@ -90,14 +91,8 @@ export function initExtensionConfigs(configurations: WidgetConfig[]): Array<Widg
let insightConfig = widgetRegistry.getRegisteredExtensionInsights(key);
if (insightConfig !== undefined) {
// Setup the default properties for this extension if needed
if (!config.provider && insightConfig.provider) {
config.provider = insightConfig.provider;
}
if (!config.name && insightConfig.name) {
config.name = insightConfig.name;
}
if (!config.edition && insightConfig.edition) {
config.edition = insightConfig.edition;
if (!config.when && insightConfig.when) {
config.when = insightConfig.when;
}
if (!config.gridItemConfig && insightConfig.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
* @param config widgets to filter
*/
export function filterConfigs<T extends { provider?: string | string[], edition?: number | number[] }>(config: T[], dashboardService: DashboardServiceInterface): Array<T> {
let connectionInfo: ConnectionManagementInfo = dashboardService.connectionManagementService.connectionInfo;
let edition = connectionInfo.serverInfo.engineEditionId;
let provider = connectionInfo.providerId;
// filter by provider
export function filterConfigs<T extends { when?: string }>(config: T[], dashboardService: DashboardServiceInterface): Array<T> {
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));
}
});
}

View File

@@ -66,7 +66,6 @@ export abstract class DashboardPage extends Disposable implements OnDestroy {
private _editEnabled = new Emitter<boolean>();
public readonly editEnabled: Event<boolean> = 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);
}
}

View File

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

View File

@@ -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'
}
}
};

View File

@@ -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<void>();
@@ -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<DashboardComponentParams>(this._uniqueSelector);
this.uri = this._bootstrapParams.ownerUri;
this._contextKeyService = this._bootstrapParams.scopedContextService;
}
/**

View File

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

View File

@@ -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;

View File

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

View File

@@ -93,15 +93,15 @@ export class BackupUiService implements IBackupUiService {
private _connectionUri: string;
private static _connectionUniqueId: number = 0;
private _onShowBackupEvent: Emitter<DashboardComponentParams>;
public get onShowBackupEvent(): Event<DashboardComponentParams> { 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<DashboardComponentParams>();
this._onShowBackupEvent = new Emitter<{ connection: IConnectionProfile, ownerUri: string }>();
}
public showBackup(connection: IConnectionProfile): Promise<any> {