class BuildJoin extends React.Component { state = { manualfunction: "", queryfunction: "", functionchecked: false, criticalerror: false, errormsg: "", querytree: [ {tupleextract: null, comparetype: null, comparevalue: null, neighbor: null}, {tupleextract: null, comparetype: null, comparevalue: null, neighbor: null}, {tupleextract: null, comparetype: null, comparevalue: null, neighbor: null}] } handleChange = evt => { this.setState({ [evt.target.id]: evt.target.value }); } setNativeValue = (element, value) => { let lastValue = element.value; element.value = value; let event = new Event("input", { target: element, bubbles: true }); // React 15 event.simulated = true; // React 16 let tracker = element._valueTracker; if (tracker) { tracker.setValue(lastValue); } element.dispatchEvent(event); } handleBuild = (qf) => { const apicall = sspglobals.apiurl + "?cmd=" + "addquery" + "&hash=" + this.props.user.hash + "&function=" + qf // call the server to create this user fetch(apicall).then((response) => { if (response.ok) return response.json(); else this.handleError("Error while using the API!", "danger"); throw new Error("Error while using the API!"); }) .then((json) => { // returns an error if (json.result[0][1] == "success") { this.handleError("Query \n'"+qf+"'\n added!", "success") this.props.onLocationChange("list"); } else { this.handleError("Failed to add Query: \n" + qf, "warning") } }) .catch((err) => { this.handleError("Fetch catched an error!", "danger"); console.log(err); }); } iterateForFunction = (element, index) => { if (element.tupleextract == null) { this.setState((prev) => ({criticalerror: true, errormsg: prev.errormsg + "BREAKING: @" + index + " it's unchoosen what to test. \n"})); return "breaking error"; } if (element.comparetype == null) { this.setState((prev) => ({criticalerror: true, errormsg: prev.errormsg + "BREAKING: @" + index + " it's unchoosen how to test. \n"})); return "breaking error"; } // if (element.comparevalue == null) { // this.setState((prev) => ({criticalerror: true, errormsg: prev.errormsg + "BREAKING: @" + index + " no value was given. \n"})); // return "breaking error"; // } const extract = this.props.user.tupleextracts[element.tupleextract]; const chain = (element.neighbor == null) ? "" : " "; if (extract.type == "string" || extract.type == "text") { if (element.comparevalue == null) element.comparevalue = ""; const regex = /([^a-zA-Z0-9 ÄÜÖäüö@_.,:;+\-*/#~<>|°^!§€$%&()=?{\[\]}])/gm; const value = element.comparevalue.replace(regex, ""); if (value != element.comparevalue) { this.setState((prev) => ({errormsg: prev.errormsg + "String @" + index + " was adjusted. \n"})); this.setNativeValue(document.getElementById("valuebox-"+index), value); } return "(" + extract.name + "_" + element.comparetype + " \"" + value + "\")" + chain; } if (extract.type == "int") { if (element.comparevalue == null) element.comparevalue = 0 const value = parseInt(element.comparevalue); if (isNaN(value)) { this.setState((prev) => ({criticalerror: true, errormsg: prev.errormsg + "BREAKING: Integer @" + index + " could not be parsed. \n"})); return "error"; } return "(" + extract.name + "_" + element.comparetype + " " + value + ")" + chain; } if (extract.type == "real") { if (element.comparevalue == null) element.comparevalue = 0.0; const value = parseFloat(element.comparevalue); if (isNaN(value)) { this.setState((prev) => ({criticalerror: true, errormsg: prev.errormsg + "BREAKING: Real @" + index + " could not be parsed. \n"})); return "error"; } return "(" + extract.name + "_" + element.comparetype + " " + value + ")" + chain; } if (extract.type == "bool") { const value = (element.comparevalue == "TRUE") ? "TRUE" : "FALSE"; return "(" + extract.name + "_" + element.comparetype + " " + value + ")" + chain; } return "error"; } checkFunction = () => { this.setState({criticalerror: false, errormsg: "", queryfunction: "", functionchecked: false}); let index = 0; let fun = "("; do { fun += this.iterateForFunction(this.state.querytree[index], index) index++; console.log(this.state.querytree[index-1].neighbor); } while (this.state.querytree[index-1].neighbor != null); fun += ")"; this.setState({queryfunction: fun, functionchecked: true}); } handleError = (reason, badge) => { this.props.onError(reason, badge); } handleBCSelectExtractChange = (bcId, extractId) => { let qt = this.state.querytree; qt[bcId].tupleextract = (isNaN(parseInt(extractId)) ? null : parseInt(extractId)); qt[bcId].comparetype = null; qt[bcId].comparevalue = null; // this.setNativeValue(document.getElementById("valuebox-"+bcId), ""); this.setState({querytree: qt}); } handleBCSelectComparatorChange = (bcId, comparator) => { let qt = this.state.querytree; qt[bcId].comparetype = comparator; // qt[bcId].comparevalue = null; this.setState({querytree: qt}); } handleBCCompareValueChange = (bcId, value) => { let qt = this.state.querytree; qt[bcId].comparevalue = value; this.setState({querytree: qt}); if (this.props.user.tupleextracts[qt[bcId].tupleextract].type != "bool") { this.setNativeValue(document.getElementById("valuebox-"+bcId), value); } else { this.setNativeValue(document.getElementById("valuebox-"+bcId), ""); } } handleAddAction = (bcId, action) => { let qt = this.state.querytree; if (action == "+") { qt[bcId].neighbor = "and"; qt[bcId+1] = {tupleextract: null, comparetype: null, comparevalue: null, neighbor: null}; } else if (action == "-") { qt[bcId-1].neighbor = null; qt[bcId] = {tupleextract: null, comparetype: null, comparevalue: null, neighbor: null}; } else if (action == "and") { qt[bcId].neighbor = "and"; } else if (action == "or") { qt[bcId].neighbor = "or"; } else { return; } this.setState({querytree: qt}); } render() { return (

Build

Hello {this.props.user.email}

{this.props.user.tupledescr}


this.onDragOver(e)} onDrop={(e)=>this.onDrop(e, "root")} > {this.state.querytree[0].neighbor == null ? null : } {(this.state.querytree[0].neighbor == null || this.state.querytree[1].neighbor == null) ? null : }

Manually entering a query is not recommended and only here for testing purposes, since the function will not be checked againg and therefor can crash the SSP.
) } } class BuildComponent extends React.Component { getExtracts = () => { const {extracts} = this.props; let options = []; extracts.forEach((element, index) => { options.push() }); return options; } getExtract = () => { const {leaf, extracts} = this.props; if (leaf.tupleextract == null) return {name: null, type: null}; return extracts[leaf.tupleextract]; } getComparator = () => { const type = this.getExtract().type; if (type == "string" || type == "bool") { return

=

; } if (type == "int" || type == "real") return ; return null; } getValuebox = () => { const type = this.getExtract().type; let isChecked = (this.props.leaf.comparevalue == "TRUE") ? true : false; if (type == "string") return ; if (type == "int") return ; if (type == "real") return ; if (type == "bool") return ; return null; } changeExtract = (event) => { let val; if (event.target.value == -1) { val=null; } else { val=event.target.value; } this.props.handleBCSelectExtractChange(this.props.num, val); const type = this.getExtract().type; if (type == "string" || type == "bool") { this.changeComparator(null); } } changeComparator = (event) => { if (event == null) { this.props.handleBCSelectComparatorChange(this.props.num, "eq"); return; } let val; if (event.target.value == -1) { val=null; } else { val=event.target.value; } this.props.handleBCSelectComparatorChange(this.props.num, val); } changeValue = (event) => { let val = event.target.value; if (event.target.type == "checkbox") { val = event.target.checked ? "TRUE" : "FALSE"; } this.props.handleBCCompareValueChange(this.props.num, val); } handleAddEvent = (event) => { let action = event.target.innerHTML; if (action.length > 1) action = event.target.value; this.props.handleAddAction(this.props.num, action); } getAddButtons = () => { const {leaf, num} = this.props; let btns = []; if (leaf.neighbor == null && num<2) btns.push(); if (leaf.neighbor == null && num>0) btns.push(); if (leaf.neighbor != null) btns.push(and); // if (leaf.neighbor != null) btns.push(); return
{btns}
; } render() { return (
{this.getComparator()} {this.getValuebox()}
{this.getAddButtons()}
) } }