#4 -- Fix js for conventions
All checks were successful
CI fuzzy controller / container-test-job (push) Successful in 1m0s
All checks were successful
CI fuzzy controller / container-test-job (push) Successful in 1m0s
This commit is contained in:
parent
ae309290ff
commit
5e5f9f35c8
@ -1,12 +1,10 @@
|
||||
|
||||
// Rules parsing
|
||||
// antecedent
|
||||
function getAntecedent(rule) {
|
||||
var withoutIf = rule.split('if');
|
||||
let withoutIf = rule.split('if');
|
||||
return withoutIf[1].trim().split('then')[0].trim();
|
||||
}
|
||||
|
||||
|
||||
// TODO: remove duplicate
|
||||
function getAntecedentComponents(antecedent) {
|
||||
return antecedent.split('and').map((i) => i.trim());
|
||||
@ -14,7 +12,7 @@ function getAntecedentComponents(antecedent) {
|
||||
|
||||
// consequent
|
||||
function getConsequent(rule) {
|
||||
var withoutIf = rule.split('if');
|
||||
let withoutIf = rule.split('if');
|
||||
return withoutIf[1].trim().split('then')[1].trim();
|
||||
}
|
||||
|
||||
@ -35,7 +33,7 @@ function getVariableValue(variableComponents) {
|
||||
// Rules creation
|
||||
|
||||
/* exported MessageTypesEnum */
|
||||
var MessageTypesEnum = {
|
||||
let MessageTypesEnum = {
|
||||
INFO: "info",
|
||||
SUCCESS: "success",
|
||||
WARNING: "warning",
|
||||
@ -44,7 +42,7 @@ var MessageTypesEnum = {
|
||||
Object.freeze(MessageTypesEnum);
|
||||
|
||||
function isEmpty(value) {
|
||||
if (typeof value === "function") {
|
||||
if (typeof value === "function") {
|
||||
return false;
|
||||
}
|
||||
return (value == null || value.length === 0);
|
||||
@ -54,6 +52,7 @@ function isEmpty(value) {
|
||||
function showFeedbackMessage(message, type) {
|
||||
alert(type + ' ' + message);
|
||||
}
|
||||
|
||||
/* exported errorHandler */
|
||||
function errorHandler(response, callBack, errorCallBack) {
|
||||
if (!isEmpty(response.error)) {
|
||||
@ -82,11 +81,15 @@ function getFromRest(url, callBack) {
|
||||
}
|
||||
|
||||
/* exported createRule */
|
||||
function createRule() {
|
||||
var ruleString = "if ";
|
||||
var inp = $('.selectpicker.inputVar').children(':selected').map(function() {return $(this).text();}).get();
|
||||
var inpVal = $('.selectpicker.inputVal').children(':selected').map(function() {return $(this).text();}).get();
|
||||
for (var i = 0; i < inp.length; i++) {
|
||||
function createRule() {
|
||||
let ruleString = "if ";
|
||||
let inp = $('.selectpicker.inputVar').children(':selected').map(function () {
|
||||
return $(this).text();
|
||||
}).get();
|
||||
let inpVal = $('.selectpicker.inputVal').children(':selected').map(function () {
|
||||
return $(this).text();
|
||||
}).get();
|
||||
for (let i = 0; i < inp.length; i++) {
|
||||
if (i > 0) {
|
||||
ruleString += ' and ';
|
||||
}
|
||||
@ -101,7 +104,7 @@ function fillSelect(selectElement, values, selectedVal) {
|
||||
$.each(values, function (key, value) {
|
||||
$(selectElement).append($("<option />").val(value.id).text(value.name));
|
||||
});
|
||||
$(selectElement).children().each(function() {
|
||||
$(selectElement).children().each(function () {
|
||||
if ($(this).text() == selectedVal) {
|
||||
$(this).prop('selected', true);
|
||||
}
|
||||
@ -109,33 +112,33 @@ function fillSelect(selectElement, values, selectedVal) {
|
||||
}
|
||||
|
||||
function fillFuzzyTerms(variablesElement, fuzzyTermsElement, termVal) {
|
||||
getFromRest("/rule/getFuzzyTerms/"+$(variablesElement).val(), function (fuzzyTerms) {
|
||||
var fuzzyTermsData = [];
|
||||
$.each(fuzzyTerms, function (key, value) {
|
||||
fuzzyTermsData.push({
|
||||
id: value.id,
|
||||
name: value.description
|
||||
});
|
||||
});
|
||||
fillSelect(fuzzyTermsElement, fuzzyTermsData, termVal);
|
||||
$(fuzzyTermsElement).selectpicker("refresh");
|
||||
$(fuzzyTermsElement).trigger("change");
|
||||
});
|
||||
getFromRest("/rule/getFuzzyTerms/" + $(variablesElement).val(), function (fuzzyTerms) {
|
||||
let fuzzyTermsData = [];
|
||||
$.each(fuzzyTerms, function (key, value) {
|
||||
fuzzyTermsData.push({
|
||||
id: value.id,
|
||||
name: value.description
|
||||
});
|
||||
});
|
||||
fillSelect(fuzzyTermsElement, fuzzyTermsData, termVal);
|
||||
$(fuzzyTermsElement).selectpicker("refresh");
|
||||
$(fuzzyTermsElement).trigger("change");
|
||||
});
|
||||
}
|
||||
|
||||
function fillVariables(projectId, variablesElement, variableVal) {
|
||||
getFromRest("/rule/getVariables/"+projectId, function (variables) {
|
||||
var variablesData = [];
|
||||
$.each(variables, function (key, value) {
|
||||
variablesData.push({
|
||||
id: value.id,
|
||||
name: value.name
|
||||
});
|
||||
});
|
||||
fillSelect(variablesElement, variablesData, variableVal);
|
||||
$(variablesElement).selectpicker("refresh");
|
||||
$(variablesElement).trigger("change");
|
||||
});
|
||||
getFromRest("/rule/getVariables/" + projectId, function (variables) {
|
||||
let variablesData = [];
|
||||
$.each(variables, function (key, value) {
|
||||
variablesData.push({
|
||||
id: value.id,
|
||||
name: value.name
|
||||
});
|
||||
});
|
||||
fillSelect(variablesElement, variablesData, variableVal);
|
||||
$(variablesElement).selectpicker("refresh");
|
||||
$(variablesElement).trigger("change");
|
||||
});
|
||||
}
|
||||
|
||||
function variableValueChanged(variablesElement, fuzzyTermsElement) {
|
||||
@ -147,34 +150,39 @@ function fuzzyTermsValueChanged() {
|
||||
}
|
||||
|
||||
function addVariableSelect(projectId, variableVal) {
|
||||
var variablesElement = $("<select class='selectpicker inputVar m-2' data-live-search='true data-width='70%'></select>");
|
||||
let variablesElement = $("<select class='selectpicker inputVar m-2' data-live-search='true data-width='70%'></select>");
|
||||
fillVariables(projectId, variablesElement, variableVal);
|
||||
return variablesElement;
|
||||
}
|
||||
|
||||
function addFuzzyTermsSelect(variablesElement, termVal) {
|
||||
var fuzzyTermsElement = $("<select class='selectpicker inputVal m-2' data-live-search='true data-width='70%'></select>");
|
||||
let fuzzyTermsElement = $("<select class='selectpicker inputVal m-2' data-live-search='true data-width='70%'></select>");
|
||||
if ($(variablesElement).val()) {
|
||||
fillFuzzyTerms(variablesElement, fuzzyTermsElement, termVal);
|
||||
}
|
||||
return fuzzyTermsElement;
|
||||
}
|
||||
|
||||
function removeAntecedent(buttonElement) {
|
||||
$(buttonElement).parent().remove();
|
||||
fuzzyTermsValueChanged();
|
||||
}
|
||||
|
||||
function addAntecedent(parentElement, projectId, variableVal, termVal) {
|
||||
var rowElement = $("<div class='row'></div>");
|
||||
let rowElement = $("<div class='row'></div>");
|
||||
if ($(parentElement).find('.row').length) {
|
||||
$(rowElement).append("<label class='col col-md-1 m-2'>И</label>");
|
||||
} else {
|
||||
$(rowElement).append("<label class='col col-md-1 m-2'> </label>");
|
||||
}
|
||||
var variablesElement = addVariableSelect(projectId, variableVal);
|
||||
var fuzzyTermsElement = addFuzzyTermsSelect(variablesElement, termVal);
|
||||
$(variablesElement).on( "change", function() {variableValueChanged(variablesElement, fuzzyTermsElement)});
|
||||
$(fuzzyTermsElement).on( "change", function() {fuzzyTermsValueChanged()});
|
||||
let variablesElement = addVariableSelect(projectId, variableVal);
|
||||
let fuzzyTermsElement = addFuzzyTermsSelect(variablesElement, termVal);
|
||||
$(variablesElement).on("change", function () {
|
||||
variableValueChanged(variablesElement, fuzzyTermsElement)
|
||||
});
|
||||
$(fuzzyTermsElement).on("change", function () {
|
||||
fuzzyTermsValueChanged()
|
||||
});
|
||||
$(rowElement).append(variablesElement);
|
||||
$(rowElement).append("<label class='col col-md-1 m-2'>есть</label>");
|
||||
$(rowElement).append(fuzzyTermsElement);
|
||||
@ -185,7 +193,7 @@ function addAntecedent(parentElement, projectId, variableVal, termVal) {
|
||||
}
|
||||
|
||||
function addAntecedentFromRule(parentElement, projectId, ruleContent) {
|
||||
var antecedentComponents = getAntecedentComponents(getAntecedent(ruleContent));
|
||||
let antecedentComponents = getAntecedentComponents(getAntecedent(ruleContent));
|
||||
for (let i = 0; i < antecedentComponents.length; i++) {
|
||||
var a = antecedentComponents[i];
|
||||
addAntecedent(parentElement, projectId, getVariable(a), getVariableValue(a));
|
||||
|
Loading…
x
Reference in New Issue
Block a user