mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-01-21 17:22:55 -05:00
SQL Operations Studio Public Preview 1 (0.23) release source code
This commit is contained in:
75
src/sql/platform/dashboard/common/insightRegistry.ts
Normal file
75
src/sql/platform/dashboard/common/insightRegistry.ts
Normal file
@@ -0,0 +1,75 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
import { Type } from '@angular/core';
|
||||
import { IInsightsConfig, IInsightsView } from 'sql/parts/dashboard/widgets/insights/interfaces';
|
||||
|
||||
import * as platform from 'vs/platform/registry/common/platform';
|
||||
import { IJSONSchema } from 'vs/base/common/jsonSchema';
|
||||
import * as nls from 'vs/nls';
|
||||
|
||||
export type InsightIdentifier = string;
|
||||
|
||||
export const Extensions = {
|
||||
InsightContribution: 'dashboard.contributions.insights'
|
||||
};
|
||||
|
||||
export interface IInsightRegistry {
|
||||
insightSchema: IJSONSchema;
|
||||
registerInsight(id: string, description: string, schema: IJSONSchema, ctor: Type<IInsightsView>): InsightIdentifier;
|
||||
registerExtensionInsight(id: string, val: IInsightsConfig): void;
|
||||
getRegisteredExtensionInsights(id: string): IInsightsConfig;
|
||||
getCtorFromId(id: string): Type<IInsightsView>;
|
||||
getAllCtors(): Array<Type<IInsightsView>>;
|
||||
getAllIds(): Array<string>;
|
||||
}
|
||||
|
||||
class InsightRegistry implements IInsightRegistry {
|
||||
private _insightSchema: IJSONSchema = { type: 'object', description: nls.localize('schema.dashboardWidgets', 'Widget used in the dashboards'), properties: {}, additionalProperties: false };
|
||||
private _extensionInsights: { [x: string]: IInsightsConfig } = {};
|
||||
private _idToCtor: { [x: string]: Type<IInsightsView> } = {};
|
||||
|
||||
/**
|
||||
* Register a dashboard widget
|
||||
* @param id id of the widget
|
||||
* @param description description of the widget
|
||||
* @param schema config schema of the widget
|
||||
*/
|
||||
public registerInsight(id: string, description: string, schema: IJSONSchema, ctor: Type<IInsightsView>): InsightIdentifier {
|
||||
this._insightSchema.properties[id] = schema;
|
||||
this._idToCtor[id] = ctor;
|
||||
return id;
|
||||
}
|
||||
|
||||
public registerExtensionInsight(id: string, val: IInsightsConfig): void {
|
||||
this._extensionInsights[id] = val;
|
||||
}
|
||||
|
||||
public getRegisteredExtensionInsights(id: string): IInsightsConfig {
|
||||
return this._extensionInsights[id];
|
||||
}
|
||||
|
||||
public getCtorFromId(id: string): Type<IInsightsView> {
|
||||
return this._idToCtor[id];
|
||||
}
|
||||
|
||||
public getAllCtors(): Array<Type<IInsightsView>> {
|
||||
return Object.values(this._idToCtor);
|
||||
}
|
||||
|
||||
public getAllIds(): Array<string> {
|
||||
return Object.keys(this._idToCtor);
|
||||
}
|
||||
|
||||
public get insightSchema(): IJSONSchema {
|
||||
return this._insightSchema;
|
||||
}
|
||||
}
|
||||
|
||||
const insightRegistry = new InsightRegistry();
|
||||
platform.Registry.add(Extensions.InsightContribution, insightRegistry);
|
||||
|
||||
export function registerInsight(id: string, description: string, schema: IJSONSchema, ctor: Type<IInsightsView>): InsightIdentifier {
|
||||
return insightRegistry.registerInsight(id, description, schema, ctor);
|
||||
}
|
||||
83
src/sql/platform/dashboard/common/widgetRegistry.ts
Normal file
83
src/sql/platform/dashboard/common/widgetRegistry.ts
Normal file
@@ -0,0 +1,83 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
import { IInsightsConfig } from 'sql/parts/dashboard/widgets/insights/interfaces';
|
||||
|
||||
import * as platform from 'vs/platform/registry/common/platform';
|
||||
import { IJSONSchema } from 'vs/base/common/jsonSchema';
|
||||
import * as nls from 'vs/nls';
|
||||
|
||||
export type WidgetIdentifier = string;
|
||||
|
||||
export const Extensions = {
|
||||
DashboardWidgetContribution: 'dashboard.contributions.widgets'
|
||||
};
|
||||
|
||||
export interface IDashboardWidgetRegistry {
|
||||
databaseWidgetSchema: IJSONSchema;
|
||||
serverWidgetSchema: IJSONSchema;
|
||||
registerWidget(id: string, description: string, schema: IJSONSchema, context?: 'database' | 'server'): WidgetIdentifier;
|
||||
registerNonCustomDashboardWidget(id: string, description: string, val: IInsightsConfig, context?: 'database' | 'server'): WidgetIdentifier;
|
||||
}
|
||||
|
||||
class DashboardWidgetRegistry implements IDashboardWidgetRegistry {
|
||||
private _dashboardWidgetSchema: IJSONSchema = { type: 'object', description: nls.localize('schema.dashboardWidgets', 'Widget used in the dashboards'), properties: {}, additionalProperties: false };
|
||||
private _serverWidgetSchema: IJSONSchema = { type: 'object', description: nls.localize('schema.dashboardWidgets', 'Widget used in the dashboards'), properties: {}, additionalProperties: false };
|
||||
/**
|
||||
* Register a dashboard widget
|
||||
* @param id id of the widget
|
||||
* @param description description of the widget
|
||||
* @param schema config schema of the widget
|
||||
* @param context either 'database' or 'server' for what page to register for; if not specified, will register for both
|
||||
*/
|
||||
public registerWidget(id: string, description: string, schema: IJSONSchema, context?: 'database' | 'server'): WidgetIdentifier {
|
||||
if (context === undefined || context === 'database') {
|
||||
this._dashboardWidgetSchema.properties[id] = schema;
|
||||
}
|
||||
|
||||
if (context === undefined || context === 'server') {
|
||||
this._serverWidgetSchema.properties[id] = schema;
|
||||
}
|
||||
|
||||
return id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Register a non custom dashboard widget
|
||||
* @param id id of the widget
|
||||
* @param description description of the widget
|
||||
* @param val cal for default
|
||||
* @param context either 'database' or 'server' for what page to register for; if not specified, will register for both
|
||||
*/
|
||||
registerNonCustomDashboardWidget(id: string, description: string, val: IInsightsConfig, context?: 'database' | 'server'): WidgetIdentifier {
|
||||
if (context === undefined || context === 'database') {
|
||||
this._dashboardWidgetSchema.properties[id] = { type: 'null', default: null };
|
||||
}
|
||||
|
||||
if (context === undefined || context === 'server') {
|
||||
this._serverWidgetSchema.properties[id] = { type: 'null', default: null };
|
||||
}
|
||||
|
||||
return id;
|
||||
}
|
||||
|
||||
public get databaseWidgetSchema(): IJSONSchema {
|
||||
return this._dashboardWidgetSchema;
|
||||
}
|
||||
|
||||
public get serverWidgetSchema(): IJSONSchema {
|
||||
return this._serverWidgetSchema;
|
||||
}
|
||||
}
|
||||
|
||||
const dashboardWidgetRegistry = new DashboardWidgetRegistry();
|
||||
platform.Registry.add(Extensions.DashboardWidgetContribution, dashboardWidgetRegistry);
|
||||
|
||||
export function registerDashboardWidget(id: string, description: string, schema: IJSONSchema, context?: 'database' | 'server'): WidgetIdentifier {
|
||||
return dashboardWidgetRegistry.registerWidget(id, description, schema, context);
|
||||
}
|
||||
|
||||
export function registerNonCustomDashboardWidget(id: string, description: string, val: IInsightsConfig): WidgetIdentifier {
|
||||
return dashboardWidgetRegistry.registerNonCustomDashboardWidget(id, description, val);
|
||||
}
|
||||
Reference in New Issue
Block a user