Skip to content

Commit

Permalink
Nov fixes - fast html preview overhaul (#74)
Browse files Browse the repository at this point in the history
* rebuilt fast webview

* better onConnect terminal mgmt

* update change log

* working fast render

* wrapping up fast html preview enhancements
  • Loading branch information
DumpySquare authored Sep 30, 2020
1 parent 6f0bb8f commit 3d26f35
Show file tree
Hide file tree
Showing 9 changed files with 321 additions and 399 deletions.
20 changes: 20 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,26 @@ Check [Keep a Changelog](http://keepachangelog.com/) for recommendations on how

---

## [2.4.0] - (10-5-2020)


### Modified
- FAST Template Render HTML preview
- now respects tab settings like other windows
- Re-renders appropriately when sending new content (like changing template params)
- this required a complete rework of the class object
- Re-scoped fast templates to yaml files only (it's really just the best way to go)
- added right click options in explorer view to render template html preview
- added right click option in editor view to render template html preview
- added right click option in Fast view for connected device
- added `Submit` button to bottom of html preview which produces a rendered template output in new json editor

- onConnect/onDisconnect terminal settings
- updated to only execute if settings are actaully present to be executed
- added logic to track created terminals, use existing terminals (created by extension), and dispose terminals onDisconnect

---

## [2.3.0] - (9-8-2020)

### Added
Expand Down
28 changes: 21 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"displayName": "F5 Networks FAST",
"description": "(F)5 Networks (A)pplication (S)ervices (T)emplate engine extension",
"publisher": "DumpySquare",
"version": "2.3.0",
"version": "2.4.0",
"keywords": [
"f5",
"f5networks",
Expand Down Expand Up @@ -49,6 +49,12 @@
"path": "./snippets.json"
}
],
"yamlValidation": [
{
"fileMatch": "*.fast.yml",
"url": "https://github.com/f5devcentral/f5-fast-core/blob/master/schema/template.json"
}
],
"jsonValidation": [
{
"fileMatch": "*.as3.json",
Expand Down Expand Up @@ -416,14 +422,9 @@
"category": "F5-Fast",
"enablement": "f5.fastInstalled"
},
{
"command": "f5-fast.renderYmlTemplate",
"title": "Render YAML Template",
"category": "F5-Fast"
},
{
"command": "f5-fast.renderHtmlPreview",
"title": "Render HTML Preview",
"title": "Render Fast Template HTML Preview",
"category": "F5-Fast"
},
{
Expand Down Expand Up @@ -563,6 +564,10 @@
"command": "f5-fast.deployApp",
"group": "F5"
},
{
"command": "f5-fast.renderHtmlPreview",
"group": "F5"
},
{
"when": "editorHasSelection",
"command": "f5-as3.postDec",
Expand Down Expand Up @@ -641,6 +646,11 @@
"when": "f5.fastInstalled && resourceExtname =~ /\\.(mst|ya?ml|fast)/",
"command": "f5-fast.postTemplate",
"group": "F5-Fast"
},
{
"when": "resourceExtname =~ /\\.(ya?ml)/",
"command": "f5-fast.renderHtmlPreview",
"group": "F5-Fast"
}
],
"view/title": [
Expand Down Expand Up @@ -910,6 +920,10 @@
"command": "f5-fast.deleteFastTempSet",
"when": "view == fastView && viewItem == fastTemplateSet"
},
{
"command": "f5-fast.renderHtmlPreview",
"when": "view == fastView && viewItem == fastTemplate"
},
{
"command": "f5-as3.fullTenant",
"when": "view == as3Tenants && viewItem == as3Tenant"
Expand Down
8 changes: 4 additions & 4 deletions src/editorViews/editorView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,10 @@ export class TextDocumentView {
const newEditorColumn = ext.settings.previewColumn;


/**
* bool, default = false
*/
const enableWebViews = ext.settings.enableWebViews;
// /**
// * bool, default = false
// */
// const enableWebViews = ext.settings.enableWebViews;

/**
* Should the new/updated editor take focus?
Expand Down
161 changes: 161 additions & 0 deletions src/editorViews/fastWebView.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@

import { WebviewPanel, window, commands, ViewColumn, EventEmitter, Event, Uri } from 'vscode';

import { ext } from '../extensionVariables';
import logger from '../utils/logger';

const fast = require('@f5devcentral/f5-fast-core');

type HttpResponse = '';

export class FastWebView {

protected _onDidCloseAllWebviewPanels = new EventEmitter<void>();
protected readonly panels: WebviewPanel[] = [];
private showResponseInDifferentTab = false;
protected activePanel: WebviewPanel | undefined;
protected fastTemplateYml: string | undefined;
protected fastEngine: any | undefined;

private readonly panelResponses: Map<WebviewPanel, HttpResponse>;

public constructor() {
this.panelResponses = new Map<WebviewPanel, HttpResponse>();
}

public get onDidCloseAllWebviewPanels(): Event<void> {

return this._onDidCloseAllWebviewPanels.event;
}

protected get previewActiveContextKey(): string {
return 'httpResponsePreviewFocus';
}

protected setPreviewActiveContext(value: boolean) {
commands.executeCommand('setContext', this.previewActiveContextKey, value);
}

protected displayRenderedTemplate (tempParams: string) {
/**
* take params from panel submit button
* process through fast with template
* then display in new editor to the right...
*/

// const final = this.fastEngine.template.render(tempParams);

// ext.panel.render('text');
}

protected async renderHTML(fastYml: string) {

/**
* add checking for YAML format since we only want to support yaml
*
*/
try {
this.fastEngine = await fast.Template.loadYaml(fastYml);
} catch (e) {
logger.error(e);
window.showErrorMessage(e.message);
}
const schema = this.fastEngine.getParametersSchema();
const defaultParams = this.fastEngine.getCombinedParameters();
const htmlData = fast.guiUtils.generateHtmlPreview(schema, defaultParams);
return htmlData;
}

public async render(fastYml: string) {

// put the incoming fast template somewhere
this.fastTemplateYml = fastYml;
// create
let html = await this.renderHTML(fastYml);

let title = 'test-title';

const newEditorColumn = ext.settings.previewColumn;
const preserveEditorFocus = ext.settings.preserveEditorFocus;
const newEditorTabForAll = ext.settings.newEditorTabForAll;
let viewColumn: ViewColumn | undefined;

viewColumn = viewColumn ? viewColumn : newEditorColumn;

let panel: WebviewPanel;
if (this.showResponseInDifferentTab || this.panels.length === 0) {
panel = window.createWebviewPanel(
'fast webView',
title,
{ viewColumn: viewColumn, preserveFocus: !preserveEditorFocus },
{
enableFindWidget: true,
enableScripts: true,
retainContextWhenHidden: true
});

panel.onDidDispose(() => {
if (panel === this.activePanel) {
this.setPreviewActiveContext(false);
this.activePanel = undefined;
}

const index = this.panels.findIndex(v => v === panel);
if (index !== -1) {
this.panels.splice(index, 1);
this.panelResponses.delete(panel);
}
if (this.panels.length === 0) {
this._onDidCloseAllWebviewPanels.fire();
}
});

panel.onDidChangeViewState(({ webviewPanel }) => {
const active = this.panels.some(p => p.active);
this.setPreviewActiveContext(active);
this.activePanel = webviewPanel.active ? webviewPanel : undefined;
});

panel.webview.onDidReceiveMessage( async message => {
// console.log( message );

try {
const final = await this.fastEngine.render(message);
ext.panel.render(final);
} catch (e) {
logger.error(e);
// window.showErrorMessage(e.message);
}

});

this.panels.push(panel);
} else {
panel = this.panels[this.panels.length - 1];
panel.title = title;
}


/**
* Appends the necessary stuff for submit button and getting template params
* move the following to it's own function
*/
const htmlSubmitBtn = `
<script>
(function init() {
const vscode = acquireVsCodeApi();
document.vscode = vscode;
})();
</script>
<button onclick="vscode.postMessage(editor.getValue())">Submit</button>
<p></p>
`;

html += htmlSubmitBtn;

panel.webview.html = html;
panel.reveal(viewColumn, !preserveEditorFocus);
this.activePanel = panel;
}

}
Loading

0 comments on commit 3d26f35

Please sign in to comment.