Skip to content
Snippets Groups Projects
Commit 880a0d80 authored by s1995588's avatar s1995588
Browse files

added categories and checkboxes for boolean types

parent efefcae3
No related branches found
No related tags found
No related merge requests found
// This script will be run within the webview itself
// It cannot access the main VS Code APIs directly.
(function () {
const vscode = acquireVsCodeApi();
......@@ -99,115 +100,6 @@
vscode.setState({ tools: tools, documentVars: oldState.documentVars, parameters: oldState.parameters, currentUri: oldState.currentUri, currentTool: oldState.currentTool });
}
function addConstantItem(ul, name, value) {
const li = document.createElement("li");
const nameBox = document.createElement("label");
nameBox.id = "name-" + name;
nameBox.appendChild(document.createTextNode(name));
nameBox.classList.add("name");
li.appendChild(nameBox);
const valueBox = document.createElement("input");
valueBox.id = "value-" + name;
valueBox.type = "text";
valueBox.value = value;
valueBox.classList.add("value");
valueBox.addEventListener("input", event => {
let oldState = vscode.getState();
for (const file of oldState.documentVars) {
if (file.uri === oldState.currentUri) {
for (const constant of file.constants) {
if (constant.name === name) {
constant.value = valueBox.value;
break;
}
}
break;
}
}
vscode.setState({ tools: oldState.tools, documentVars: oldState.documentVars, parameters: oldState.parameters, currentUri: oldState.currentUri, currentTool: oldState.currentTool });
});
li.appendChild(valueBox);
ul.appendChild(li);
}
function addDistributionItem(ul, name, value) {
const li = document.createElement("li");
const nameBox = document.createElement("label");
nameBox.id = "name-" + name;
nameBox.appendChild(document.createTextNode(name));
nameBox.classList.add("name");
li.appendChild(nameBox);
const valueBox = document.createElement("input");
valueBox.id = "value-" + name;
valueBox.type = "text";
valueBox.value = value;
valueBox.classList.add("value");
valueBox.addEventListener("input", event => {
let oldState = vscode.getState();
for (const file of oldState.documentVars) {
if (file.uri === oldState.currentUri) {
for (const distribution of file.distributions) {
if (distribution.name === name) {
distribution.value = valueBox.value;
break;
}
}
break;
}
}
vscode.setState({ tools: oldState.tools, documentVars: oldState.documentVars, parameters: oldState.parameters, currentUri: oldState.currentUri, currentTool: oldState.currentTool });
});
li.appendChild(valueBox);
ul.appendChild(li);
}
function addParameterItem(ul, name, value) {
const li = document.createElement("li");
const nameBox = document.createElement("label");
nameBox.id = "name-" + name;
nameBox.appendChild(document.createTextNode(name));
nameBox.classList.add("name");
li.appendChild(nameBox);
const valueBox = document.createElement("input");
valueBox.id = "value-" + name;
valueBox.type = "text";
valueBox.value = value;
valueBox.classList.add("value");
valueBox.addEventListener("input", event => {
let oldState = vscode.getState();
for (const tool of oldState.parameters) {
if (tool.toolName === oldState.currentTool) {
for (const parameter of tool.parameters) {
if (parameter.id === name) {
parameter.value = valueBox.value;
break;
}
}
break;
}
}
vscode.setState({ tools: oldState.tools, documentVars: oldState.documentVars, parameters: oldState.parameters, currentUri: oldState.currentUri, currentTool: oldState.currentTool });
});
li.appendChild(valueBox);
ul.appendChild(li);
}
/**
*
* @param {Array<{ uri: string, constants: Array<{ name: string, value: string }>, distributions: Array<{ name: string, value: string }> }>} documentVars
......@@ -257,8 +149,8 @@
addDistributionItem(distributionsUl, distribution.name, distribution.value);
}
}
break;
}
break;
}
......@@ -273,7 +165,7 @@
}
/**
* @param {Array<{ toolName: string, parameters: Array<{ id: string, value: string }> }>} parameters
* @param {Array<{ toolName: string, parameters: Array<{ id: string, value: string, type: ParameterType, category: string}> }>} parameters
* @param {string} tool
*/
function updateParameters(parameters, toolName) {
......@@ -305,7 +197,7 @@
for (const tool of parameters) {
if (tool.toolName === toolName) {
for (const parameter of tool.parameters) {
addParameterItem(parametersUl, parameter.id, parameter.value);
addParameterItem(parameter.id, parameter.value, parameter.category, parameter.type);
}
break;
}
......@@ -313,7 +205,7 @@
vscode.setState({ tools: oldState.tools, documentVars: oldState.documentVars, parameters: parameters, currentUri: oldState.currentUri, currentTool: oldState.currentTool });
}
// vscode.setState({ tools: [], documentVars: [], parameters: [], currentUri: "", currentTool: "" });
const oldState = vscode.getState() || { tools: [], documentVars: [], parameters: [], currentUri: "", currentTool: "" };
const tools = oldState.tools;
......@@ -329,4 +221,161 @@
updateParameters(parameters, currentTool);
updateDocumentVars(documentVars, currentUri);
}
//#region help functions
function addConstantItem(ul, name, value) {
const li = document.createElement("li");
const nameBox = document.createElement("label");
nameBox.id = "name-" + name;
nameBox.appendChild(document.createTextNode(name));
nameBox.classList.add("name");
li.appendChild(nameBox);
const valueBox = document.createElement("input");
valueBox.id = "value-" + name;
valueBox.type = "text";
valueBox.value = value;
valueBox.classList.add("value");
valueBox.addEventListener("input", event => {
let oldState = vscode.getState();
for (const file of oldState.documentVars) {
if (file.uri === oldState.currentUri) {
for (const constant of file.constants) {
if (constant.name === name) {
constant.value = valueBox.value;
break;
}
}
break;
}
}
vscode.setState({ tools: oldState.tools, documentVars: oldState.documentVars, parameters: oldState.parameters, currentUri: oldState.currentUri, currentTool: oldState.currentTool });
});
li.appendChild(valueBox);
ul.appendChild(li);
}
function addDistributionItem(ul, name, value) {
const li = document.createElement("li");
const nameBox = document.createElement("label");
nameBox.id = "name-" + name;
nameBox.appendChild(document.createTextNode(name));
nameBox.classList.add("name");
li.appendChild(nameBox);
const valueBox = document.createElement("input");
valueBox.id = "value-" + name;
valueBox.type = "text";
valueBox.value = value;
valueBox.classList.add("value");
valueBox.addEventListener("input", event => {
let oldState = vscode.getState();
for (const file of oldState.documentVars) {
if (file.uri === oldState.currentUri) {
for (const distribution of file.distributions) {
if (distribution.name === name) {
distribution.value = valueBox.value;
break;
}
}
break;
}
}
vscode.setState({ tools: oldState.tools, documentVars: oldState.documentVars, parameters: oldState.parameters, currentUri: oldState.currentUri, currentTool: oldState.currentTool });
});
li.appendChild(valueBox);
ul.appendChild(li);
}
function addCategory(category) {
const outerDiv = document.createElement("div");
outerDiv.classList.add("pane", "vertical");
const firstInnerDiv = document.createElement("div");
firstInnerDiv.classList.add("pane-header");
const codiconDiv = document.createElement("div");
codiconDiv.classList.add("codicon", "codicon-chevron-right");
const h3 = document.createElement("h3");
h3.classList.add("title");
h3.title = "Open Editors";
h3.appendChild(document.createTextNode(category));
const secondInnerDiv = document.createElement("div");
secondInnerDiv.classList.add("pane-body", "hidden");
const categoryUl = document.createElement("ul");
categoryUl.id = "parameter-" + category;
categoryUl.classList.add("option-list");
secondInnerDiv.appendChild(categoryUl);
firstInnerDiv.appendChild(codiconDiv);
firstInnerDiv.appendChild(h3);
outerDiv.appendChild(firstInnerDiv);
outerDiv.appendChild(secondInnerDiv);
const parametersDiv = document.getElementById("parameters");
parametersDiv.appendChild(outerDiv);
addCollapseBehaviour(outerDiv);
return categoryUl;
}
function addParameterItem(name, value, category, type) {
if (category === "") {
category = "Other";
}
let categoryUl = document.getElementById("parameter-" + category);
if (categoryUl === null) {
categoryUl = addCategory(category);
}
const li = document.createElement("li");
const nameBox = document.createElement("label");
nameBox.id = "name-" + name;
nameBox.appendChild(document.createTextNode(name));
nameBox.classList.add("name");
li.appendChild(nameBox);
const valueBox = document.createElement("input");
valueBox.id = "value-" + name;
valueBox.type = type;
valueBox.value = value;
valueBox.classList.add("value");
valueBox.addEventListener("input", event => {
let oldState = vscode.getState();
for (const tool of oldState.parameters) {
if (tool.toolName === oldState.currentTool) {
for (const parameter of tool.parameters) {
if (parameter.id === name) {
parameter.value = valueBox.value;
break;
}
}
break;
}
}
vscode.setState({ tools: oldState.tools, documentVars: oldState.documentVars, parameters: oldState.parameters, currentUri: oldState.currentUri, currentTool: oldState.currentTool });
});
li.appendChild(valueBox);
categoryUl.appendChild(li);
}
//#endregion
}());
......@@ -12,7 +12,11 @@ import { analysisResultsProvider, client, provider } from './extension';
let localToolNames: Array<string> | undefined;
let localDocumentVars: Array<{ uri: string, constants: Array<{ name: string, value: string }>, distributions: Array<{ name: string, value: string }> }> = [];
let localParameters: Array<{ toolName: string, parameters: Array<{ id: string, value: string, type: ParameterType, category: string }> }> = [];
let localParameters: Array<{ toolName: string, parameters: Array<{ id: string, value: string, type: string, category: string }> }> = [];
let typeMap = {
"Boolean": "checkbox"
};
//#region interfaces
interface ParameterDefinitions {
......@@ -84,12 +88,24 @@ export function getDocumentVars(document: TextDocument) {
}
}
// add valid html input types here to change the parameter input field in the sidebar
function getType(type: string) {
switch (type) {
case "Boolean": {
return "checkbox";
}
default: {
return "text";
}
}
}
function getParameters(toolName: string) {
let jsonObject = { "toolName": toolName };
client?.sendRequest<ParameterDefinitions>("modest/getParameters", jsonObject).then(data => {
const index = localParameters.findIndex(x => x.toolName === toolName);
const newParameters = data.parameterDefinitions.map(parameter => {
return { id: parameter.id, value: parameter.defaultValue, type: parameter.type, category: parameter.category };
return { id: parameter.id, value: parameter.defaultValue, type: getType(parameter.type.valueType), category: parameter.category };
});
if (index === -1) {
localParameters.push({ toolName: toolName, parameters: newParameters });
......@@ -281,8 +297,7 @@ export class ModestSidebarProvider implements vscode.WebviewViewProvider {
<div class="codicon codicon-chevron-down"></div>
<h3 class="title" title="Open Editors">Parameters</h3>
</div>
<div class="pane-body">
<ul class="option-list" id="parameters">There are no parameters.</ul>
<div id="parameters"class="pane-body">
</div>
</div>
</div>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment