mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-01-14 09:59:47 -05:00
This is an initial PR for a new model-driven UI where extensions can provide definitions of the components & how they're laid out using Containers. #1140, #1141, #1142, #1143 and #1144 are all tracking additional work needed to improve the initial implementation and fix some issues with the implementation. Features: - Supports defining a FlexContainer that maps to a flexbox-based layout. - Supports creating a card component, which is a key-value pair based control that will lay out simple information to a user. Eventually this will have an optional set of actions associated with it. - Has a sample project which shows how to use the API and was used for verification
53 lines
1.7 KiB
TypeScript
53 lines
1.7 KiB
TypeScript
/*---------------------------------------------------------------------------------------------
|
|
* 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 * as fs from 'fs-extra';
|
|
import * as handlebars from 'handlebars';
|
|
import * as path from 'path';
|
|
import * as vscode from 'vscode';
|
|
|
|
import * as Constants from './constants';
|
|
import * as nls from 'vscode-nls';
|
|
|
|
const localize = nls.loadMessageBundle();
|
|
|
|
/**
|
|
* Helper to log messages to the developer console if enabled
|
|
* @param msg Message to log to the console
|
|
*/
|
|
export function logDebug(msg: any): void {
|
|
let config = vscode.workspace.getConfiguration(Constants.extensionConfigSectionName);
|
|
let logDebugInfo = config[Constants.configLogDebugInfo];
|
|
if (logDebugInfo === true) {
|
|
let currentTime = new Date().toLocaleTimeString();
|
|
let outputMsg = '[' + currentTime + ']: ' + msg ? msg.toString() : '';
|
|
console.log(outputMsg);
|
|
}
|
|
}
|
|
|
|
export function renderTemplateHtml(extensionPath: string, templateName: string, templateValues: object): Thenable<string> {
|
|
let templatePath = path.join(extensionPath, 'resources', templateName);
|
|
|
|
// 1) Read the template from the disk
|
|
// 2) Compile it as a handlebars template and render the HTML
|
|
// 3) On failure, return a simple string as an error
|
|
return fs.readFile(templatePath, 'utf-8')
|
|
.then(templateText => {
|
|
let template = handlebars.compile(templateText);
|
|
return template(templateValues);
|
|
})
|
|
.then(
|
|
undefined,
|
|
error => {
|
|
logDebug(error);
|
|
return localize('errorLoadingTab', 'An error occurred while loading the tab');
|
|
}
|
|
);
|
|
}
|
|
|
|
|