Skip to content

Commit d1ae61c

Browse files
#182 moved data view html template, styles and scripts to new /web folder
1 parent 8571518 commit d1ae61c

16 files changed

+50
-51
lines changed

β€Žsrc/data.preview.tsβ€Ž

Lines changed: 49 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -175,9 +175,9 @@ export class DataPreview {
175175
\n dataUrl:`, this._dataUrl);
176176

177177
// create html template for data preview with local scripts, styles and theme params replaced
178-
const scriptsPath: string = Uri.file(path.join(this._extensionPath, 'scripts'))
178+
const scriptsPath: string = Uri.file(path.join(this._extensionPath, 'web/scripts'))
179179
.with({scheme: 'vscode-resource'}).toString(true);
180-
const stylesPath: string = Uri.file(path.join(this._extensionPath, 'styles'))
180+
const stylesPath: string = Uri.file(path.join(this._extensionPath, 'web/styles'))
181181
.with({scheme: 'vscode-resource'}).toString(true);
182182
this._html = htmlTemplate.replace({
183183
title: this._fileName,
@@ -194,6 +194,16 @@ export class DataPreview {
194194
this.configure();
195195
} // end of constructor()
196196

197+
/**
198+
* Configures webview html for preview.
199+
*/
200+
public configure(): void {
201+
this.webview.html = this.html;
202+
// NOTE: let webview fire refresh message
203+
// when data view DOM content is initialized
204+
// see: data.view.html/refresh();
205+
}
206+
197207
/**
198208
* Updates data preview status bar item text.
199209
*/
@@ -308,6 +318,43 @@ export class DataPreview {
308318
}, null, this._disposables);
309319
} // end of initWebview()
310320

321+
/**
322+
* Creates webview options with local resource roots, etc
323+
* for data preview webview display.
324+
*/
325+
private getWebviewOptions(): any {
326+
return {
327+
enableScripts: true,
328+
enableCommandUris: true,
329+
retainContextWhenHidden: true,
330+
localResourceRoots: this.getLocalResourceRoots()
331+
};
332+
}
333+
334+
/**
335+
* Creates local resource roots for loading assets in data preview webview.
336+
*/
337+
private getLocalResourceRoots(): Uri[] {
338+
const localResourceRoots: Uri[] = [];
339+
const workspaceFolder: WorkspaceFolder = workspace.getWorkspaceFolder(this.uri);
340+
if (workspaceFolder && workspaceFolder !== undefined) {
341+
localResourceRoots.push(Uri.file(workspaceFolder.uri.fsPath));
342+
}
343+
else if (!this.uri.scheme || this.uri.scheme === 'file') {
344+
localResourceRoots.push(Uri.file(path.dirname(this.uri.fsPath)));
345+
}
346+
347+
// add web view styles and scripts folders
348+
localResourceRoots.push(Uri.file(path.join(this._extensionPath, './web/styles')));
349+
localResourceRoots.push(Uri.file(path.join(this._extensionPath, './web/scripts')));
350+
351+
if (config.logLevel === LogLevel.Debug) {
352+
this._logger.debug('getLocalResourceRoots():',
353+
localResourceRoots.map(uri => uri.path));
354+
}
355+
return localResourceRoots;
356+
}
357+
311358
/**
312359
* Sends initial data info to data view.
313360
*/
@@ -427,54 +474,6 @@ export class DataPreview {
427474
}
428475
} // end of loadView()
429476

430-
/**
431-
* Creates webview options with local resource roots, etc
432-
* for data preview webview display.
433-
*/
434-
private getWebviewOptions(): any {
435-
return {
436-
enableScripts: true,
437-
enableCommandUris: true,
438-
retainContextWhenHidden: true,
439-
localResourceRoots: this.getLocalResourceRoots()
440-
};
441-
}
442-
443-
/**
444-
* Creates local resource roots for loading assets in data preview webview.
445-
*/
446-
private getLocalResourceRoots(): Uri[] {
447-
const localResourceRoots: Uri[] = [];
448-
const workspaceFolder: WorkspaceFolder = workspace.getWorkspaceFolder(this.uri);
449-
if (workspaceFolder && workspaceFolder !== undefined) {
450-
localResourceRoots.push(Uri.file(workspaceFolder.uri.fsPath));
451-
}
452-
else if (!this.uri.scheme || this.uri.scheme === 'file') {
453-
localResourceRoots.push(Uri.file(path.dirname(this.uri.fsPath)));
454-
}
455-
456-
// add data preview js scripts
457-
localResourceRoots.push(Uri.file(path.join(this._extensionPath, 'scripts')));
458-
459-
// add data preview styles
460-
localResourceRoots.push(Uri.file(path.join(this._extensionPath, 'styles')));
461-
if (config.logLevel === LogLevel.Debug) {
462-
this._logger.debug('getLocalResourceRoots():',
463-
localResourceRoots.map(uri => uri.path));
464-
}
465-
return localResourceRoots;
466-
}
467-
468-
/**
469-
* Configures webview html for preview.
470-
*/
471-
public configure(): void {
472-
this.webview.html = this.html;
473-
// NOTE: let webview fire refresh message
474-
// when data view DOM content is initialized
475-
// see: data.view.html/refresh();
476-
}
477-
478477
/**
479478
* Saves updated data viewer config for restore on vscode reload.
480479
*/

β€Žsrc/extension.tsβ€Ž

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ export function activate(context: ExtensionContext) {
3333
logger.debug('activate(): activating from extPath:', context.extensionPath);
3434

3535
// initialize data preview webview panel html template
36-
const templateManager: ITemplateManager = new TemplateManager(context.asAbsolutePath('templates'));
36+
const templateManager: ITemplateManager = new TemplateManager(context.asAbsolutePath('web'));
3737
const dataViewTemplate: Template = templateManager.getTemplate('data.view.html');
3838

3939
// create extension status bar items
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
Β (0)