|
@@ -1,17 +1,25 @@
|
|
|
let creatingVariable = false;
|
|
|
+let variables = [];
|
|
|
|
|
|
/*
|
|
|
-* Workspace position modal attributes
|
|
|
-*/
|
|
|
+ * Workspace position modal attributes
|
|
|
+ */
|
|
|
let $workspacePositionModal = $("#workspacePositionModal");
|
|
|
let $workspacePositionModalBody = $("#workspacePositionModalBody");
|
|
|
-let $workspacePositionModalPositionsSelect = $("#workspacePositionModalPositionsSelect");
|
|
|
+let $workspacePositionModalPositionsSelect = $(
|
|
|
+ "#workspacePositionModalPositionsSelect"
|
|
|
+);
|
|
|
|
|
|
let workspaceToBeAddId = null;
|
|
|
let workspaceToBeAddVariable = null;
|
|
|
let workspaceToBeAddAfterComponent = null;
|
|
|
|
|
|
-function addVariable(variable = {name: "", type: dataTypes.String, value: ""}, id = null) {
|
|
|
+function addVariable(
|
|
|
+ variable = {name: "", type: dataTypes.String, value: ""},
|
|
|
+ id = null
|
|
|
+) {
|
|
|
+ subMenuOptions.style.display = "none";
|
|
|
+
|
|
|
if (creatingVariable === false) {
|
|
|
// Blocking future variable creation until finish the current creation
|
|
|
creatingVariable = true;
|
|
@@ -78,7 +86,7 @@ function addVariableToCode({id = null}) {
|
|
|
let variable = {
|
|
|
name: $("#variableName").val(),
|
|
|
type: $("#variableType").val(),
|
|
|
- value: $("#variableValue").val()
|
|
|
+ value: $("#variableValue").val(),
|
|
|
};
|
|
|
|
|
|
code = mountCodeFromVariable(variable);
|
|
@@ -97,75 +105,122 @@ function cancelAddVariable(id = null) {
|
|
|
// Removing div form for variable creation
|
|
|
$("#variableCreationDiv").remove();
|
|
|
|
|
|
- if (id != null)
|
|
|
- $(`#variableDiv${id}`).show();
|
|
|
+ if (id != null) $(`#variableDiv${id}`).show();
|
|
|
|
|
|
// Enabling future variable creation
|
|
|
creatingVariable = false;
|
|
|
}
|
|
|
|
|
|
-function editVariable(id = null, variable = {name: "", type: dataTypes.String, value: ""}) {
|
|
|
+function editVariable(
|
|
|
+ id = null,
|
|
|
+ variable = {name: "", type: dataTypes.String, value: ""}
|
|
|
+) {
|
|
|
$(`#variableDiv${id}`).hide();
|
|
|
addVariable(variable, id);
|
|
|
}
|
|
|
|
|
|
-function deleteVariable(id = null) {
|
|
|
- if (id != null)
|
|
|
- $(`#variableDiv${id}`).remove();
|
|
|
+function deleteVariable(variableIndex = null, subMenuOptionId) {
|
|
|
+ trashSound.play();
|
|
|
+
|
|
|
+ document.getElementById(subMenuOptionId).remove();
|
|
|
+
|
|
|
+ for (let i = 0; i < variables[variableIndex].attributions.length; i++) {
|
|
|
+ variables[variableIndex].attributions[i].parentElement.parentElement.remove();
|
|
|
+ }
|
|
|
+
|
|
|
+ for (let i = 0; i < variables[variableIndex].usages.length; i++) {
|
|
|
+ variables[variableIndex].usages[i].remove();
|
|
|
+ }
|
|
|
+
|
|
|
+ variables.splice(variableIndex, 1);
|
|
|
+ // Refresh variables sub menu
|
|
|
+ buildVariablesSubmenu();
|
|
|
}
|
|
|
|
|
|
function addCodeToScreen({
|
|
|
id = null,
|
|
|
code = "Some code",
|
|
|
- variable = {name: "", type: "String", value: ""}
|
|
|
+ variable = {name: "", type: "String", value: ""},
|
|
|
}) {
|
|
|
let html = ``;
|
|
|
|
|
|
if (id != null) {
|
|
|
$(`#mainCode${id}`).html(`<span>${code}</span>`);
|
|
|
$(`#globalMenu${id}`).val(code);
|
|
|
- $(`#positionCode${id}`).html(`<button type="button" class="btn btn-dark" id="positionCode${id}" onclick='askWhereToPlaceTheVariable(${id}, ${JSON.stringify(variable)})'>Posicionar</button>`);
|
|
|
- $(`#editCode${id}`).html(`<button type="button" class="btn btn-info" id="editCodeButton${id}" onclick='editVariable(${id}, ${JSON.stringify(variable)})'>Editar</button>`);
|
|
|
+ $(`#positionCode${id}`).html(
|
|
|
+ `<button type="button" class="btn btn-dark" id="positionCode${id}" onclick='askWhereToPlaceTheVariable(${id}, ${JSON.stringify(
|
|
|
+ variable
|
|
|
+ )})'>Posicionar</button>`
|
|
|
+ );
|
|
|
+ $(`#editCode${id}`).html(
|
|
|
+ `<button type="button" class="btn btn-info" id="editCodeButton${id}" onclick='editVariable(${id}, ${JSON.stringify(
|
|
|
+ variable
|
|
|
+ )})'>Editar</button>`
|
|
|
+ );
|
|
|
$(`#variableDiv${id}`).show();
|
|
|
+
|
|
|
+ updateVariable({
|
|
|
+ id: id,
|
|
|
+ name: variable.name,
|
|
|
+ type: variable.type,
|
|
|
+ value: variable.value,
|
|
|
+ code: code,
|
|
|
+ element: document.getElementById(`variableDiv${id}`),
|
|
|
+ });
|
|
|
} else {
|
|
|
- html += `<div class="col-3 p-2" id="variableDiv${universalId}">`;
|
|
|
- html += ` <input type="hidden" id="globalMenu${universalId}" value="${code}"/>`;
|
|
|
- html += ` <div class="card" id="variableCard${universalId}">`;
|
|
|
- html += ` <div class="card-header" id="variableCardHeader${universalId}">`;
|
|
|
+ id = universalId.next();
|
|
|
+ html += `<div class="col-3 p-2" id="variableDiv${id}">`;
|
|
|
+ html += ` <input type="hidden" id="globalMenu${id}" value="${code}"/>`;
|
|
|
+ html += ` <div class="card" id="variableCard${id}">`;
|
|
|
+ html += ` <div class="card-header" id="variableCardHeader${id}">`;
|
|
|
html += ` <h4>Variável</h4>`;
|
|
|
html += ` </div>`;
|
|
|
- html += ` <div class="card-body" id="variableCardBody${universalId}">`;
|
|
|
- html += ` <div class="row code-line" id="codeLine${universalId}">`;
|
|
|
- html += ` <div class="col-2 line-number" id="mainLine${universalId}"><span>${getCurrentMainLineNumber()}</span></div>`;
|
|
|
- html += ` <div class="col-10 line-code" id="mainCode${universalId}"><span>${code}</span></div>`;
|
|
|
+ html += ` <div class="card-body" id="variableCardBody${id}">`;
|
|
|
+ html += ` <div class="row code-line" id="codeLine${id}">`;
|
|
|
+ html += ` <div class="col-2 line-number" id="mainLine${id}"><span>${getCurrentMainLineNumber()}</span></div>`;
|
|
|
+ html += ` <div class="col-10 line-code" id="mainCode${id}"><span>${code}</span></div>`;
|
|
|
html += ` </div>`;
|
|
|
html += ` </div>`;
|
|
|
- html += ` <div class="card-footer" id="variableCardFooter${universalId}">`;
|
|
|
+ html += ` <div class="card-footer" id="variableCardFooter${id}">`;
|
|
|
html += ` <div class="row">`;
|
|
|
- html += ` <div class="col-4" id="deleteCode${universalId}">`;
|
|
|
- html += ` <button type="button" class="btn btn-danger" id="deleteCodeButton${universalId}" onclick="deleteVariable(${universalId})">Remover</button>`;
|
|
|
+ html += ` <div class="col-4" id="deleteCode${id}">`;
|
|
|
+ html += ` <button type="button" class="btn btn-danger" id="deleteCodeButton${id}" onclick="deleteVariable(${id})">Remover</button>`;
|
|
|
html += ` </div>`;
|
|
|
- html += ` <div class="col-4 align-self-center" id="positionCode${universalId}">`;
|
|
|
- html += ` <button type="button" class="btn btn-dark" id="positionCodeButton${universalId}" onclick='askWhereToPlaceTheVariable(${universalId}, ${JSON.stringify(variable)})'>Posicionar</button>`;
|
|
|
+ html += ` <div class="col-4 align-self-center" id="positionCode${id}">`;
|
|
|
+ html += ` <button type="button" class="btn btn-dark" id="positionCodeButton${id}" onclick='askWhereToPlaceTheVariable(${id}, ${JSON.stringify(
|
|
|
+ variable
|
|
|
+ )})'>Posicionar</button>`;
|
|
|
html += ` </div>`;
|
|
|
- html += ` <div class="col-3" id="editCode${universalId}">`;
|
|
|
- html += ` <button type="button" class="btn btn-info" id="editCodeButton${universalId}" onclick='editVariable(${universalId}, ${JSON.stringify(variable)})'>Editar</button>`;
|
|
|
+ html += ` <div class="col-3" id="editCode${id}">`;
|
|
|
+ html += ` <button type="button" class="btn btn-info" id="editCodeButton${id}" onclick='editVariable(${id}, ${JSON.stringify(
|
|
|
+ variable
|
|
|
+ )})'>Editar</button>`;
|
|
|
html += ` </div>`;
|
|
|
html += ` </div>`;
|
|
|
html += ` </div>`;
|
|
|
html += ` </div>`;
|
|
|
html += `</div>`;
|
|
|
|
|
|
- $workspace.append(html);
|
|
|
+ // Saving reference to variable in variables array
|
|
|
+ variables.push({
|
|
|
+ id: id,
|
|
|
+ name: variable.name,
|
|
|
+ type: variable.type,
|
|
|
+ value: variable.value,
|
|
|
+ code: code,
|
|
|
+ element: document.getElementById(`variableDiv${universalId.next()}`),
|
|
|
+ attributions: [],
|
|
|
+ usages: []
|
|
|
+ });
|
|
|
}
|
|
|
-
|
|
|
- // Increasing universal id
|
|
|
- universalId += 1;
|
|
|
}
|
|
|
|
|
|
-function askWhereToPlaceTheVariable(id = null, variable = {name: "", type: "String", value: ""}) {
|
|
|
+function askWhereToPlaceTheVariable(
|
|
|
+ id = null,
|
|
|
+ variable = {name: "", type: "String", value: ""}
|
|
|
+) {
|
|
|
if (buildAllWorkspaceComponentsSelect()) {
|
|
|
- $workspacePositionModal.modal('toggle');
|
|
|
+ $workspacePositionModal.modal("toggle");
|
|
|
$workspacePositionModalPositionsSelect.focus();
|
|
|
|
|
|
workspaceToBeAddId = id;
|
|
@@ -176,19 +231,22 @@ function askWhereToPlaceTheVariable(id = null, variable = {name: "", type: "Stri
|
|
|
}
|
|
|
|
|
|
function buildAllWorkspaceComponentsSelect() {
|
|
|
- let allWorkspaceComponents = $(`input[type="hidden"][name="${WORKSPACE_COMPONENTS_NAME}"]`);
|
|
|
+ let allWorkspaceComponents = $(
|
|
|
+ `input[type="hidden"][name="${WORKSPACE_COMPONENTS_NAME}"]`
|
|
|
+ );
|
|
|
let selectOptions = [];
|
|
|
|
|
|
if (allWorkspaceComponents.length > 0) {
|
|
|
for (let i = 0; i < allWorkspaceComponents.length; i++) {
|
|
|
- console.log(allWorkspaceComponents[i].attributes);
|
|
|
- selectOptions.push(`<option value="${allWorkspaceComponents[i].attributes.universalworkspaceid.value}">${allWorkspaceComponents[i].value}</option>`);
|
|
|
+ selectOptions.push(
|
|
|
+ `<option value="${allWorkspaceComponents[i].attributes.universalworkspaceid.value}">${allWorkspaceComponents[i].value}</option>`
|
|
|
+ );
|
|
|
}
|
|
|
|
|
|
$workspacePositionModalPositionsSelect.empty(); // remove old options
|
|
|
selectOptions.forEach((object, index, array) => {
|
|
|
$workspacePositionModalPositionsSelect.append($(object));
|
|
|
- })
|
|
|
+ });
|
|
|
|
|
|
return true;
|
|
|
} else {
|
|
@@ -197,12 +255,38 @@ function buildAllWorkspaceComponentsSelect() {
|
|
|
}
|
|
|
|
|
|
$("#workspacePositionModalAddButton").click(() => {
|
|
|
- addVariableToMain({id: workspaceToBeAddId, variable: workspaceToBeAddVariable, afterComponentWithId: $workspacePositionModalPositionsSelect.val()})
|
|
|
+ addVariableToMain({
|
|
|
+ id: workspaceToBeAddId,
|
|
|
+ variable: workspaceToBeAddVariable,
|
|
|
+ afterComponentWithId: $workspacePositionModalPositionsSelect.val(),
|
|
|
+ });
|
|
|
|
|
|
// Reset variables for future use
|
|
|
workspaceToBeAddId = null;
|
|
|
workspaceToBeAddVariable = null;
|
|
|
|
|
|
// Hide position modal
|
|
|
- $workspacePositionModal.modal('toggle');
|
|
|
-});
|
|
|
+ $workspacePositionModal.modal("toggle");
|
|
|
+});
|
|
|
+
|
|
|
+function updateVariable(
|
|
|
+ variable = {
|
|
|
+ id: 0,
|
|
|
+ name: "Name",
|
|
|
+ type: "String",
|
|
|
+ value: "Value",
|
|
|
+ code: 'String Name = "value"',
|
|
|
+ element: document.getElementById("body"),
|
|
|
+ }
|
|
|
+) {
|
|
|
+ for (let i = 0; i < variables.length; i++) {
|
|
|
+ if (variables[i].id === variable.id) {
|
|
|
+ variables[i] = variable;
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ console.warn(
|
|
|
+ `Can't find variable with id: ${variable.id} to update, please verify the variable universalId`
|
|
|
+ );
|
|
|
+}
|