add samples (#920)

This commit is contained in:
Abbie Petchtes
2018-03-16 11:05:40 -07:00
committed by GitHub
parent 3d7c081068
commit 75ab5c1a36
27 changed files with 10284 additions and 0 deletions

View 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>

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

View 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>

View 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);
}
}

View 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>