mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-01-19 17:22:48 -05:00
SQL Operations Studio Public Preview 1 (0.23) release source code
This commit is contained in:
19
src/sql/platform/clipboard/common/clipboardService.ts
Normal file
19
src/sql/platform/clipboard/common/clipboardService.ts
Normal file
@@ -0,0 +1,19 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* 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 { IClipboardService as vsIClipboardService } from 'vs/platform/clipboard/common/clipboardService';
|
||||
|
||||
import { createDecorator } from 'vs/platform/instantiation/common/instantiation';
|
||||
|
||||
export const IClipboardService = createDecorator<IClipboardService>('sqlclipboardService');
|
||||
|
||||
export interface IClipboardService extends vsIClipboardService {
|
||||
/**
|
||||
* Writes the input image as a dataurl to the clipbaord
|
||||
*/
|
||||
writeImageDataUrl(data: string): void;
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* 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 { IClipboardService } from 'sql/platform/clipboard/common/clipboardService';
|
||||
import { IClipboardService as vsIClipboardService } from 'vs/platform/clipboard/common/clipboardService';
|
||||
import { clipboard, nativeImage } from 'electron';
|
||||
|
||||
export class ClipboardService implements IClipboardService {
|
||||
_serviceBrand: any;
|
||||
|
||||
constructor(
|
||||
@vsIClipboardService private _vsClipboardService: vsIClipboardService
|
||||
) { }
|
||||
|
||||
/**
|
||||
* Writes the input image as a dataurl to the clipbaord
|
||||
*/
|
||||
writeImageDataUrl(data: string): void {
|
||||
let image = nativeImage.createFromDataURL(data);
|
||||
clipboard.writeImage(image);
|
||||
}
|
||||
|
||||
writeText(text: string): void {
|
||||
this._vsClipboardService.writeText(text);
|
||||
}
|
||||
}
|
||||
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);
|
||||
}
|
||||
85
src/sql/platform/tasks/taskRegistry.ts
Normal file
85
src/sql/platform/tasks/taskRegistry.ts
Normal file
@@ -0,0 +1,85 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import * as platform from 'vs/platform/registry/common/platform';
|
||||
import { IJSONSchema, IJSONSchemaMap } from 'vs/base/common/jsonSchema';
|
||||
import { Action } from 'vs/base/common/actions';
|
||||
import { IConstructorSignature3 } from 'vs/platform/instantiation/common/instantiation';
|
||||
import * as nls from 'vs/nls';
|
||||
|
||||
export type TaskIdentifier = string;
|
||||
|
||||
export interface ActionICtor extends IConstructorSignature3<string, string, string, Action> {
|
||||
ID: string;
|
||||
LABEL: string;
|
||||
ICON: string;
|
||||
}
|
||||
|
||||
export const Extensions = {
|
||||
TaskContribution: 'workbench.contributions.tasks'
|
||||
};
|
||||
|
||||
export interface ITaskRegistry {
|
||||
/**
|
||||
* Returns a map of action ids to their contructors;
|
||||
*/
|
||||
idToCtorMap: { [id: string]: ActionICtor };
|
||||
|
||||
/**
|
||||
* Returns array of registered ids
|
||||
*/
|
||||
ids: Array<string>;
|
||||
|
||||
/**
|
||||
* Schemas of the tasks registered
|
||||
*/
|
||||
taskSchemas: IJSONSchemaMap;
|
||||
|
||||
/**
|
||||
* Registers an action as a task which can be ran given the schema as an input
|
||||
* @param id id of the task
|
||||
* @param description desciption of the task
|
||||
* @param schema schema of expected input
|
||||
* @param ctor contructor of the action
|
||||
*/
|
||||
registerTask(id: string, description: string, schema: IJSONSchema, ctor: ActionICtor): TaskIdentifier;
|
||||
}
|
||||
|
||||
class TaskRegistry implements ITaskRegistry {
|
||||
private _idCtorMap: { [id: string]: ActionICtor } = {};
|
||||
private _taskSchema: IJSONSchema = { type: 'object', description: nls.localize('schema.taskSchema', 'Task actions specific for sql'), properties: {}, additionalProperties: false };
|
||||
|
||||
get idToCtorMap(): { [id: string]: ActionICtor } {
|
||||
return this._idCtorMap;
|
||||
}
|
||||
|
||||
get ids(): Array<string> {
|
||||
return Object.keys(this._idCtorMap);
|
||||
}
|
||||
|
||||
get taskSchemas(): IJSONSchemaMap {
|
||||
return this._taskSchema.properties;
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers an action as a task which can be ran given the schema as an input
|
||||
* @param id id of the task
|
||||
* @param description desciption of the task
|
||||
* @param schema schema of expected input
|
||||
* @param ctor contructor of the action
|
||||
*/
|
||||
registerTask(id: string, description: string, schema: IJSONSchema, ctor: ActionICtor): TaskIdentifier {
|
||||
this._idCtorMap[id] = ctor;
|
||||
this._taskSchema.properties[id] = schema;
|
||||
return id;
|
||||
}
|
||||
}
|
||||
|
||||
const taskRegistry = new TaskRegistry();
|
||||
platform.Registry.add(Extensions.TaskContribution, taskRegistry);
|
||||
|
||||
export function registerTask(id: string, description: string, schema: IJSONSchema, ctor: ActionICtor): TaskIdentifier {
|
||||
return taskRegistry.registerTask(id, description, schema, ctor);
|
||||
}
|
||||
38
src/sql/platform/views/fixedCollapsibleView.ts
Normal file
38
src/sql/platform/views/fixedCollapsibleView.ts
Normal file
@@ -0,0 +1,38 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import types = require('vs/base/common/types');
|
||||
import objects = require('vs/base/common/objects');
|
||||
|
||||
import {
|
||||
ICollapsibleViewOptions, AbstractCollapsibleView, ViewSizing, CollapsibleState
|
||||
} from 'vs/base/browser/ui/splitview/splitview';
|
||||
|
||||
export interface IFixedCollapsibleViewOptions extends ICollapsibleViewOptions {
|
||||
expandedBodySize?: number;
|
||||
}
|
||||
|
||||
export abstract class FixedCollapsibleView extends AbstractCollapsibleView {
|
||||
private _expandedBodySize: number;
|
||||
|
||||
constructor(initialSize: number, opts: IFixedCollapsibleViewOptions) {
|
||||
super(initialSize, objects.mixin({ sizing: ViewSizing.Fixed }, opts));
|
||||
this._expandedBodySize = types.isUndefined(opts.expandedBodySize) ? 22 : opts.expandedBodySize;
|
||||
}
|
||||
|
||||
get fixedSize(): number { return this.state === CollapsibleState.EXPANDED ? this.expandedSize : this.headerSize; }
|
||||
private get expandedSize(): number { return this.expandedBodySize + this.headerSize; }
|
||||
|
||||
get expandedBodySize(): number { return this._expandedBodySize; }
|
||||
set expandedBodySize(size: number) {
|
||||
this._expandedBodySize = size;
|
||||
this.setFixed(this.fixedSize);
|
||||
}
|
||||
|
||||
protected changeState(state: CollapsibleState): void {
|
||||
super.changeState(state);
|
||||
this.setFixed(this.fixedSize);
|
||||
}
|
||||
}
|
||||
102
src/sql/platform/views/fixedListView.ts
Normal file
102
src/sql/platform/views/fixedListView.ts
Normal file
@@ -0,0 +1,102 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* 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 { CollapsibleView, ICollapsibleViewOptions } from 'vs/workbench/parts/views/browser/views';
|
||||
import { List } from 'vs/base/browser/ui/list/listWidget';
|
||||
import { IAction, ActionRunner } from 'vs/base/common/actions';
|
||||
import { IContextMenuService } from 'vs/platform/contextview/browser/contextView';
|
||||
import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding';
|
||||
import { $ } from 'vs/base/browser/builder';
|
||||
import { CountBadge } from 'vs/base/browser/ui/countBadge/countBadge';
|
||||
import { IDisposable, dispose } from 'vs/base/common/lifecycle';
|
||||
import { IThemeService } from 'vs/platform/theme/common/themeService';
|
||||
import { attachBadgeStyler } from 'vs/platform/theme/common/styler';
|
||||
import { CollapsibleState } from 'vs/base/browser/ui/splitview/splitview';
|
||||
|
||||
export class FixedListView<T> extends CollapsibleView {
|
||||
private _badge: CountBadge;
|
||||
private _disposables: IDisposable[] = [];
|
||||
|
||||
constructor(
|
||||
initialSize: number,
|
||||
initiallyCollapsed: boolean,
|
||||
private _viewTitle: string,
|
||||
private _list: List<T>,
|
||||
private _bodyContainer: HTMLElement,
|
||||
headerSize: number,
|
||||
private _actions: IAction[],
|
||||
actionRunner: ActionRunner,
|
||||
contextMenuService: IContextMenuService,
|
||||
keybindingService: IKeybindingService,
|
||||
private _themeService: IThemeService
|
||||
) {
|
||||
super(initialSize, <ICollapsibleViewOptions>{
|
||||
id: _viewTitle,
|
||||
name: _viewTitle,
|
||||
actionRunner: actionRunner,
|
||||
collapsed: initiallyCollapsed,
|
||||
ariaHeaderLabel: _viewTitle,
|
||||
sizing: headerSize,
|
||||
initialBodySize: undefined
|
||||
}, keybindingService, contextMenuService);
|
||||
}
|
||||
|
||||
// RENDER METHODS //////////////////////////////////////////////////////
|
||||
public renderBody(container: HTMLElement): void {
|
||||
container.appendChild(this._bodyContainer);
|
||||
}
|
||||
|
||||
public renderHeader(container: HTMLElement): void {
|
||||
const titleDiv = $('div.title').appendTo(container);
|
||||
$('span').text(this._viewTitle).appendTo(titleDiv);
|
||||
super.renderHeader(container);
|
||||
|
||||
// show the badge
|
||||
this._badge = new CountBadge($('.count-badge-wrapper').appendTo(container).getHTMLElement());
|
||||
this._disposables.push(attachBadgeStyler(this._badge, this._themeService));
|
||||
}
|
||||
|
||||
public updateList(content: T[]) {
|
||||
this._list.splice(0, this._list.length, content);
|
||||
this._badge.setCount(this._list.length);
|
||||
this._list.layout(this._list.contentHeight);
|
||||
this.setFixed(this.fixedSize);
|
||||
}
|
||||
|
||||
public listContentHeight(): number {
|
||||
return this._list.contentHeight;
|
||||
}
|
||||
|
||||
public get fixedSize(): number {
|
||||
return this.state === CollapsibleState.EXPANDED ? this.expandedSize : this.headerSize;
|
||||
}
|
||||
|
||||
private get expandedSize(): number {
|
||||
if (this._list && this._list.contentHeight) {
|
||||
return this._list.contentHeight + this.headerSize;
|
||||
}
|
||||
|
||||
return this.headerSize;
|
||||
}
|
||||
|
||||
protected changeState(state: CollapsibleState): void {
|
||||
super.changeState(state);
|
||||
this.setFixed(this.fixedSize);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return actions for the view
|
||||
*/
|
||||
public getActions(): IAction[] {
|
||||
return this._actions;
|
||||
}
|
||||
|
||||
public dispose(): void {
|
||||
this._disposables = dispose(this._disposables);
|
||||
super.dispose();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user