Skip to content

Instantly share code, notes, and snippets.

@highoncarbs
Created September 23, 2023 07:31
Show Gist options
  • Save highoncarbs/209874d23b28a80e6d09574ef802300f to your computer and use it in GitHub Desktop.
Save highoncarbs/209874d23b28a80e6d09574ef802300f to your computer and use it in GitHub Desktop.
formula_builder.js
checkRule(one, operator, two) {
if (operator == '==') {
return one == two
}
return false
},
getComputedStringFormula() {
let jsondata = this.json_dump_obj
let formula = "";
formula = formula + jsondata.rules[0].first.name + jsondata.rules[0].compare_operator
if (jsondata.rules[0].second_value_type == 'value') {
formula = formula + jsondata.rules[0].second
}
else {
formula = formula + jsondata.rules[0].second.name
}
jsondata.rules[0].rules.forEach(row => {
console.log('Row -- ', row)
let second_value = row.second_value_type == 'value' ? row.second : row.second.name
// let rule_level_one = this.checkRule(row.first.name, row.operator, second_value) // Checks for true or false
formula = formula+ ' if ' + row.first.name +' ' + row.compare_operator + ' '+ second_value
// console.log('Row --2 ',rule_level_one, second_value)
if (true) {
row.rules.forEach(sub_row => {
let second_sub_value = sub_row.second_value_type == 'value' ? sub_row.second : sub_row.second.name
// let rule_level_two = this.checkRule(sub_row.first.name, sub_row.operator, second_sub_value) // Checks for true or false
// if (rule_level_two) {
// formula = formula + sub_row.first.name + sub_row.compare_operator + second_sub_value
// }
formula = formula+ ' : ' + sub_row.first.name +' ' + sub_row.compare_operator + ' '+ second_sub_value
})
}
})
this.json_dump_string = formula
},
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment