Skip to content

Commit

Permalink
Fix opening prebuilt queries if space in path
Browse files Browse the repository at this point in the history
  • Loading branch information
rvazarkar committed Jan 19, 2018
1 parent 31ecc26 commit 7771af2
Showing 1 changed file with 52 additions and 50 deletions.
102 changes: 52 additions & 50 deletions src/components/SearchContainer/Tabs/PrebuiltQueriesDisplay.jsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import React, { Component } from 'react';
import PrebuiltQueryNode from './PrebuiltQueryNode'
import PrebuiltQueryNode from './PrebuiltQueryNode';
import { If, Then, Else } from 'react-if';
const { app } = require('electron').remote
var fs = require('fs')
var path = require('path')
var process = require('process')
const { app } = require('electron').remote;
var fs = require('fs');
var path = require('path');
var process = require('process');
var exec = require('child_process').exec;

export default class PrebuiltQueriesDisplay extends Component {
Expand All @@ -14,70 +14,72 @@ export default class PrebuiltQueriesDisplay extends Component {
this.state = {
queries: [],
custom: []
}
};
}

componentWillMount() {
$.ajax({
url: path.join(app.getPath('userData'), '/customqueries.json'),
type: 'GET',
success: function (response) {
var x = JSON.parse(response);
var y = [];

$.each(x.queries, function (index, el) {
y.push(el);
});

this.setState({ custom: y });
}.bind(this)
});

$.ajax({
url: 'src/components/SearchContainer/Tabs/PrebuiltQueries.json',
type: 'GET',
success: function (response) {
var x = JSON.parse(response);
var y = [];

$.each(x.queries, function (index, el) {
y.push(el);
});

this.setState({ queries: y });
}.bind(this)
});
}

getCommandLine() {
switch (process.platform) {
case 'darwin' : return 'open';
case 'win32' : return 'start';
case 'win64' : return 'start';
case 'win32' : return '';
case 'win64' : return '';
default : return 'xdg-open';
}
}

editCustom(){
exec(this.getCommandLine() + ' ' + path.join(app.getPath('userData'),'/customqueries.json'));
exec(this.getCommandLine() + ' "' + path.join(app.getPath('userData'),'/customqueries.json') + '"');
}

refreshCustom(){
$.ajax({
url: path.join(app.getPath('userData'),'/customqueries.json'),
type: 'GET',
success: function(response){
var x = JSON.parse(response)
var y = []
var x = JSON.parse(response);
var y = [];

$.each(x.queries, function(index, el) {
y.push(el)
y.push(el);
});

this.setState({custom: y})
this.setState({custom: y});
}.bind(this)
})
});
}

componentWillMount() {
$.ajax({
url: path.join(app.getPath('userData'),'/customqueries.json'),
type: 'GET',
success: function(response){
var x = JSON.parse(response)
var y = []

$.each(x.queries, function(index, el) {
y.push(el)
});

this.setState({custom: y})
}.bind(this)
})

$.ajax({
url: 'src/components/SearchContainer/Tabs/PrebuiltQueries.json',
type: 'GET',
success: function(response){
var x = JSON.parse(response)
var y = []

$.each(x.queries, function(index, el) {
y.push(el)
});

this.setState({queries: y})
}.bind(this)
})
}


render() {
return (
Expand All @@ -87,21 +89,21 @@ export default class PrebuiltQueriesDisplay extends Component {
</h3>
<div className="query-box">
{this.state.queries.map(function(a){
return <PrebuiltQueryNode key={a.name} info={a} />
return <PrebuiltQueryNode key={a.name} info={a} />;
})}
</div>
<h3>
Custom Queries
<i className="glyphicon glyphicon-pencil customQueryGlyph" data-toggle="tooltip" title="Edit Queries" onClick={this.editCustom.bind(this)}></i>
<i className="glyphicon glyphicon-refresh customQueryGlyph" onClick={this.refreshCustom.bind(this)} style={{"paddingLeft": "5px"}} data-toggle="tooltip" title="Refresh Queries"></i>
<i className="glyphicon glyphicon-pencil customQueryGlyph" data-toggle="tooltip" title="Edit Queries" onClick={this.editCustom.bind(this)} />
<i className="glyphicon glyphicon-refresh customQueryGlyph" onClick={this.refreshCustom.bind(this)} style={{"paddingLeft": "5px"}} data-toggle="tooltip" title="Refresh Queries" />
</h3>
<div className="query-box">
<If condition={ this.state.custom.length == 0}>
<If condition={this.state.custom.length === 0}>
<Then><div>No user defined queries.</div></Then>
<Else>{() =>
<div>
{this.state.custom.map(function(a){
return <PrebuiltQueryNode key={a.name} info={a} />
return <PrebuiltQueryNode key={a.name} info={a} />;
})}
</div>
}
Expand Down

0 comments on commit 7771af2

Please sign in to comment.