mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-01-23 01:25:38 -05:00
Inital platform relayering (#6385)
* moving test files and inital refactoring * relayer extension host code * fix imports * make insights work * relayer dashboard * relayer notebooks * moveing more code around * formatting * accept angular as browser * fix serializer * add missing files * remove declarations from extensions * fix build errors * more relayering * change urls to relative to help code relayering * remove layering to prep for merge * fix hygiene errors * fix hygiene errors * fix tests
This commit is contained in:
93
src/sql/workbench/api/common/extHostDashboardWebview.ts
Normal file
93
src/sql/workbench/api/common/extHostDashboardWebview.ts
Normal file
@@ -0,0 +1,93 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import { SqlMainContext, ExtHostDashboardWebviewsShape, MainThreadDashboardWebviewShape } from 'sql/workbench/api/common/sqlExtHost.protocol';
|
||||
|
||||
import { IMainContext } from 'vs/workbench/api/common/extHost.protocol';
|
||||
import { Emitter } from 'vs/base/common/event';
|
||||
import { deepClone } from 'vs/base/common/objects';
|
||||
|
||||
import * as vscode from 'vscode';
|
||||
import * as azdata from 'azdata';
|
||||
|
||||
class ExtHostDashboardWebview implements azdata.DashboardWebview {
|
||||
|
||||
private _html: string;
|
||||
public onMessageEmitter = new Emitter<any>();
|
||||
public onClosedEmitter = new Emitter<any>();
|
||||
|
||||
constructor(
|
||||
private readonly _proxy: MainThreadDashboardWebviewShape,
|
||||
private readonly _handle: number,
|
||||
private readonly _connection: azdata.connection.Connection,
|
||||
private readonly _serverInfo: azdata.ServerInfo
|
||||
) { }
|
||||
|
||||
public postMessage(message: any): Thenable<any> {
|
||||
return this._proxy.$sendMessage(this._handle, message);
|
||||
}
|
||||
|
||||
public get onMessage(): vscode.Event<any> {
|
||||
return this.onMessageEmitter.event;
|
||||
}
|
||||
|
||||
public get onClosed(): vscode.Event<any> {
|
||||
return this.onClosedEmitter.event;
|
||||
}
|
||||
|
||||
public get connection(): azdata.connection.Connection {
|
||||
return deepClone(this._connection);
|
||||
}
|
||||
|
||||
public get serverInfo(): azdata.ServerInfo {
|
||||
return deepClone(this._serverInfo);
|
||||
}
|
||||
|
||||
get html(): string {
|
||||
return this._html;
|
||||
}
|
||||
|
||||
set html(value: string) {
|
||||
if (this._html !== value) {
|
||||
this._html = value;
|
||||
this._proxy.$setHtml(this._handle, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export class ExtHostDashboardWebviews implements ExtHostDashboardWebviewsShape {
|
||||
private readonly _proxy: MainThreadDashboardWebviewShape;
|
||||
|
||||
private readonly _webviews = new Map<number, ExtHostDashboardWebview>();
|
||||
private readonly _handlers = new Map<string, (webview: azdata.DashboardWebview) => void>();
|
||||
|
||||
constructor(
|
||||
mainContext: IMainContext
|
||||
) {
|
||||
this._proxy = mainContext.getProxy(SqlMainContext.MainThreadDashboardWebview);
|
||||
}
|
||||
|
||||
$onMessage(handle: number, message: any): void {
|
||||
const webview = this._webviews.get(handle);
|
||||
webview.onMessageEmitter.fire(message);
|
||||
}
|
||||
|
||||
$onClosed(handle: number): void {
|
||||
const webview = this._webviews.get(handle);
|
||||
webview.onClosedEmitter.fire(undefined);
|
||||
this._webviews.delete(handle);
|
||||
}
|
||||
|
||||
$registerProvider(widgetId: string, handler: (webview: azdata.DashboardWebview) => void): void {
|
||||
this._handlers.set(widgetId, handler);
|
||||
this._proxy.$registerProvider(widgetId);
|
||||
}
|
||||
|
||||
$registerWidget(handle: number, id: string, connection: azdata.connection.Connection, serverInfo: azdata.ServerInfo): void {
|
||||
let webview = new ExtHostDashboardWebview(this._proxy, handle, connection, serverInfo);
|
||||
this._webviews.set(handle, webview);
|
||||
this._handlers.get(id)(webview);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user