Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- handleAdvCheckboxChange = (event) => {
- var checkname = event.target.name;
- var checked = event.target.checked;
- this.setState({[checkname]: checked}, () =>{
- if(checkname == 'advancedcheck'){ //first advanced checkbox, not second one "AND"
- if(checked){ //the checkbox has just been checked
- this.setState({'advQueryTypes':this.advQueryTypes, 'advancedquery':this.advQueryTypes[0]}, () => {
- console.log("advancedquery: " + this.state.advancedquery);
- this.updateSpecificQuery(this.state.advancedquery, 'specificQueryTypes', 'specificquery', '', ''); //update specific query 1
- });
- }
- else{
- this.setState({advancedcheck2: false, advQueryTypes:[], specificQueryTypes: [], advQueryTypes2:[], specificQueryTypes2:[]});
- }
- }
- else{
- if(checked){ //second advanced check box just checked
- this.updateAdvQuery2();
- }
- else{
- this.setState({advQueryTypes2:[], specificQueryTypes2:[]});
- }
- }
- });
- }
- advQueryChange = (event) => {
- var eventname = event.target.name;
- this.setState({[eventname]: event.target.value}, () =>{
- if(eventname == 'advancedquery'){
- this.updateSpecificQuery(this.state.advancedquery, 'specificQueryTypes', 'specificquery');
- console.log("updating adv2");
- this.updateAdvQuery2();
- }
- else{
- this.updateSpecificQuery(this.state.advancedquery2, 'specificQueryTypes2', 'specificquery2', this.state.advancedquery, this.state.specificquery);
- }
- });
- }
- specificQueryChange = (event) => {
- this.setState({[event.target.name]: event.target.value}, () =>{
- if(this.state.advancedcheck2){
- this.updateSpecificQuery(this.state.advancedquery2, 'specificQueryTypes2', 'specificquery2', this.state.advancedquery, this.state.specificquery);
- }
- });
- }
- //This function handles updating specific query 1 and 2
- // col: the advanced query selector to be pulled from
- // whichspecific: the corresponding selector array to change and populate
- // querytoset: the actual selector element to change to the initial value
- updateSpecificQuery(col, whichspecific, querytoset, oldcol, otherquery){
- fetch('/getadvanced',{
- method: 'POST',
- headers: {
- 'Accept': 'application/json',
- 'Content-Type': 'application/json',
- },
- body: JSON.stringify({
- origquery: this.state.querytype,
- col: col, //advanced query
- rehash: this.state.rehash,
- fromdate: this.state.fromdate,
- todate: this.state.todate,
- oldcol: oldcol,
- otherquery: otherquery
- })
- })
- .then((res) => res.json())
- .then((result) => {
- console.log("result: " + JSON.stringify(result));
- this.setState({[whichspecific]:result.data, [querytoset]:result.data[0]});
- })
- .catch((error) => {
- console.error(error);
- })
- }
- //When either the advanced check or advanced query 1 are changed, this should update
- updateAdvQuery2(){
- //remove whichever advanced query is selected in the first advanced section from the array of options
- var adjustedQueryTypes = this.advQueryTypes.filter((value, index, arr) =>{
- return value != this.state.advancedquery;
- });
- this.setState({'advQueryTypes2':adjustedQueryTypes, 'advancedquery2':adjustedQueryTypes[0]}, () => {
- console.log("advancedquery2: " + this.state.advancedquery2);
- this.updateSpecificQuery(this.state.advancedquery2, 'specificQueryTypes2', 'specificquery2', this.state.advancedquery, this.state.specificquery);
- });
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement