mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-01-24 01:25:37 -05:00
add samples (#920)
This commit is contained in:
16
samples/extensionSamples/src/controllers/button.html
Normal file
16
samples/extensionSamples/src/controllers/button.html
Normal file
@@ -0,0 +1,16 @@
|
||||
<html>
|
||||
<header>
|
||||
</header>
|
||||
<body>
|
||||
<button onclick="count()">Count</button>
|
||||
<button onclick="openFlyout()">Open Flyout</button>
|
||||
<script>
|
||||
function count() {
|
||||
parent.postMessage('count', '*');
|
||||
}
|
||||
function openFlyout() {
|
||||
parent.postMessage('openFlyout', '*');
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
25
samples/extensionSamples/src/controllers/controllerBase.ts
Normal file
25
samples/extensionSamples/src/controllers/controllerBase.ts
Normal file
@@ -0,0 +1,25 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* 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 * as vscode from 'vscode';
|
||||
|
||||
export default abstract class ControllerBase implements vscode.Disposable {
|
||||
protected _context: vscode.ExtensionContext;
|
||||
|
||||
public constructor(context: vscode.ExtensionContext) {
|
||||
this._context = context;
|
||||
}
|
||||
|
||||
abstract activate(): Promise<boolean>;
|
||||
|
||||
abstract deactivate(): void;
|
||||
|
||||
public dispose(): void {
|
||||
this.deactivate();
|
||||
}
|
||||
}
|
||||
|
||||
15
samples/extensionSamples/src/controllers/counter.html
Normal file
15
samples/extensionSamples/src/controllers/counter.html
Normal file
@@ -0,0 +1,15 @@
|
||||
<html>
|
||||
<header>
|
||||
|
||||
</header>
|
||||
<body>
|
||||
<div id="output">Total Counts: 0</div>
|
||||
<script>
|
||||
let output = document.getElementById('output');
|
||||
window.addEventListener("message", receiveMessage, false);
|
||||
function receiveMessage(e) {
|
||||
output.innerText = 'Total Counts: ' + e.data;
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
61
samples/extensionSamples/src/controllers/mainController.ts
Normal file
61
samples/extensionSamples/src/controllers/mainController.ts
Normal file
@@ -0,0 +1,61 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* 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 * as sqlops from 'sqlops';
|
||||
import * as Utils from '../utils';
|
||||
import ControllerBase from './controllerBase';
|
||||
import * as fs from 'fs';
|
||||
import * as path from 'path';
|
||||
|
||||
/**
|
||||
* The main controller class that initializes the extension
|
||||
*/
|
||||
export default class MainController extends ControllerBase {
|
||||
// PUBLIC METHODS //////////////////////////////////////////////////////
|
||||
/**
|
||||
* Deactivates the extension
|
||||
*/
|
||||
public deactivate(): void {
|
||||
Utils.logDebug('Main controller deactivated');
|
||||
}
|
||||
|
||||
public activate(): Promise<boolean> {
|
||||
const webviewExampleHtml = fs.readFileSync(path.join(__dirname, 'webviewExample.html')).toString();
|
||||
const buttonHtml = fs.readFileSync(path.join(__dirname, 'button.html')).toString();
|
||||
const counterHtml = fs.readFileSync(path.join(__dirname, 'counter.html')).toString();
|
||||
|
||||
let countWidget: sqlops.DashboardWebview;
|
||||
let buttonWidget: sqlops.DashboardWebview;
|
||||
let count = 0;
|
||||
|
||||
let dialog: sqlops.ModalDialog = sqlops.window.createDialog('Flyout extension');
|
||||
dialog.html = '<div>This is a flyout extension.</div>';
|
||||
|
||||
sqlops.dashboard.registerWebviewProvider('webview-count', e => {
|
||||
e.html = counterHtml;
|
||||
countWidget = e;
|
||||
});
|
||||
sqlops.dashboard.registerWebviewProvider('webview-button', e => {
|
||||
e.html = buttonHtml;
|
||||
buttonWidget = e;
|
||||
e.onMessage(event => {
|
||||
if (event === 'openFlyout') {
|
||||
dialog.open();
|
||||
} else {
|
||||
count++;
|
||||
countWidget.postMessage(count);
|
||||
}
|
||||
});
|
||||
});
|
||||
sqlops.dashboard.registerWebviewProvider('webviewExample', e => {
|
||||
e.html = webviewExampleHtml;
|
||||
});
|
||||
|
||||
return Promise.resolve(true);
|
||||
}
|
||||
}
|
||||
|
||||
19
samples/extensionSamples/src/controllers/webviewExample.html
Normal file
19
samples/extensionSamples/src/controllers/webviewExample.html
Normal file
@@ -0,0 +1,19 @@
|
||||
<html>
|
||||
<header>
|
||||
<style>
|
||||
html {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
body {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
background-color: skyblue;
|
||||
}
|
||||
</style>
|
||||
</header>
|
||||
<body>
|
||||
Hello :)
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user