Skip to content

Commit

Permalink
add snippets for query body
Browse files Browse the repository at this point in the history
  • Loading branch information
xjsender committed Mar 31, 2015
1 parent 465a1a4 commit 11bbe07
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 54 deletions.
3 changes: 2 additions & 1 deletion config.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,6 @@ var heroku_oauth2 = {
exports.test = test_oauth2;
exports.heroku = heroku_oauth2;
exports.fields = {
"Account": ["Name", "Phone", "Website"]
"Account": ["Name", "Phone", "Website"],
"Opportunity": ["Name", "StageName", "CloseDate"]
}
9 changes: 9 additions & 0 deletions controller/query.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
var jsforce = require("jsforce")
, session = require("express-session")
, _ = require("underscore");

exports.query = function(req, res, next) {
res.render("query");
Expand All @@ -8,6 +9,14 @@ exports.query = function(req, res, next) {
exports.doQuery = function(req, res, next) {
var soql = req.body.soql;

// Keep the soql history
if (req.session.soqls && !_.contains(req.session.soqls, soql)) {
req.session.soqls.push(soql);
}
else {
req.session.soqls = [soql];
}

var conn = new jsforce.Connection({
accessToken: req.session.accessToken,
instanceUrl: req.session.instanceUrl
Expand Down
1 change: 1 addition & 0 deletions routes/web_router.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ module.exports = function(app) {
app.use(function(req, res, next) {
res.locals.session = req.session;
res.locals.fields = config.fields;
res.locals.soqls = req.session.soqls || [];
next();
});

Expand Down
87 changes: 53 additions & 34 deletions views/query.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,31 @@ <h3 class="panel-title">Place your SOQL here: </h3>
</div>

<div class="panel-body">
<div class="row" id="query_div">
<div class="col-sm-8" style="margin-top: 5px;">
<textarea class="form-control" rows="5" id="soql" name="soql"
<div class="row">
<div class="col-sm-6" id="query_div" style="margin-top: 5px;">
<textarea class="form-control" rows="10" id="soql" name="soql"
required="true" placeholder="SELECT Id FROM Account LIMIT 50"></textarea>

<button type="button" id="executeQuery" style="margin-top: 5px;" class="btn btn-primary">
<span class="glyphicon glyphicon-search"></span> Query
</button>
</div>

<div class="col-sm-4">
<div class="btn-group" style="margin-top: 5px;">
<button type="button" id="executeQuery" class="btn btn-primary connect">
<span class="glyphicon glyphicon-search"></span> Query
</button>
</div>
<div class="col-sm-6">
<select multiple size="12" class="form-control" id="snippets"
title="Double click the row to paste it into query body"
data-toggle="tooltip" data-placement="top">
<optgroup label="Standard">
<option>SELECT Id, Name FROM Account LIMIT 10</option>
<option>SELECT Id, Name, StageName, CloseDate FROM Opportunity LIMIT 10</option>
</optgroup>

<optgroup label="Custom">
<%soqls.forEach(function(soql) {%>
<option><%- soql%></option>
<%});%>
</optgroup>
</select>
</div>
</div>
</div>
Expand Down Expand Up @@ -56,36 +69,42 @@ <h3 class="panel-title">Execution Result:</h3>
var records = [];
var object_type = "";

$("#executeQuery").on("click", function() {
soql = $("#soql").val();
if (!soql) {
$("#query_div").addClass("has-error");
return false;
}
else {
$("#query_div").removeClass("has-error");
}

body = {soql: soql};
$(function() {
$("#snippets").on("dblclick", function() {
$("#soql").val($(this).val());
});

$.post('/query', body, function(resp) {
// Error Response
if (type.isString(resp)) {
$('#query_result').html(error_div.format(resp));
return;
$("#executeQuery").on("click", function() {
soql = $("#soql").val();
if (!soql) {
$("#query_div").addClass("has-error");
return false;
}

if (resp.totalSize == 0) {
$('#query_result').html("No matched records");
return;
else {
$("#query_div").removeClass("has-error");
}

body = {soql: soql};

// Keep this variable
records = resp.records;
object_type = records[0].attributes.type;
$.post('/query', body, function(resp) {
// Error Response
if (type.isString(resp)) {
$('#query_result').html(error_div.format(resp));
return;
}

if (resp.totalSize == 0) {
$('#query_result').html("No matched records");
return;
}

// Initiate table
initiateTable(records);
// Keep this variable
records = resp.records;
object_type = records[0].attributes.type;

// Initiate table
initiateTable(records);
});
});
});

Expand Down
19 changes: 2 additions & 17 deletions views/template/footer.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,23 +18,6 @@
<script src="/jstree/js/jstree.min.js"></script>
<script src="/highlight/highlight.js"></script>
<script src="/common/js/util.js"></script>
<script src="/spin/spin.js"></script>
<script src="/spin/jquery.spin.js"></script>
<script>
/*
var spinner;
$(document).on({
ajaxStart: function() {
var target = document.getElementById('executeQuery');
spinner = new Spinner().spin(target);
},
ajaxStop: function() {
spinner.stop();
}
})
*/
</script>

<script>
$(function() {
Expand All @@ -45,6 +28,8 @@
$('pre code').each(function(i, element) {
hljs.highlightBlock(element);
});

$('[data-toggle="tooltip"]').tooltip()
});
</script>
</body>
Expand Down
9 changes: 7 additions & 2 deletions views/template/header.html
Original file line number Diff line number Diff line change
Expand Up @@ -88,12 +88,17 @@
<%} else {%>
<li>
<a href="#" id="logout">
<span class="glyphicon glyphicon-log-in"></span>
<span class="glyphicon glyphicon glyphicon-user"></span>
Logout as <%- session.userInfo.Username %>
</a>
</li>
<%}%>
<li><a target="_blank" href="https://github.com/xjsender/Haoku">Github</a></li>
<li>
<a target="_blank" href="https://github.com/xjsender/Haoku">
<span class="glyphicon glyphicon-heart"></span>
Github
</a>
</li>
</ul>
</div>

Expand Down

0 comments on commit 11bbe07

Please sign in to comment.