Permalink
Browse files

modified so that users can click links in the result

  • Loading branch information...
mille-printemps committed Nov 12, 2011
1 parent 231982a commit 9360270e55916bc7122373fbb6bbea84d4d4b3bd
View
@@ -25,7 +25,7 @@ def #{m}(*args)
puts $!
end
end
- METHOD
+METHOD
end
require 'irb'
@@ -29,17 +29,17 @@ def shellforce_current_path
post "#{shellforce_api}" do
# parse parameters
+ path = params[:path]
method = params[:method]
url = params[:url]
body = params[:body]
# depending on the parameters, call
+ set_current_path(path)
response = case method
when 'GET'
- # TODO : if url starts with '/id', then change the current path
@@client.get(url)
when 'POST'
- # TODO : make sure if the current path is correct
@@client.post(url, body)
when 'PATCH'
@@client.patch(url, body)
@@ -50,24 +50,38 @@ def shellforce_current_path
when 'SEARCH'
@@client.search(url)
else
- '{"error" : "Illegal method : #{method}"}'
+ "{\"error\" : \"Illegal method : #{method}\"}"
end
if response.is_a?(Array) && response.length == 2
- # TODO : make a json string with the body and the elapsed time
- response[0]
+ "{\"raw\" : #{response[0]}, \"clickable\" : #{make_link_clickable(response[0])}, \"time\" : \"#{response[1]}\"}"
else
- '{"error" : "Illegal response : #{response}"}'
+ "{\"error\" : \"Illegal response : #{response}\"}"
end
end
# Utility functions
def make_link_clickable(body)
- clickableBody = body.gsub(/(\/services\/data\/v\d+\.\d+)(\/sobjects\/[^\"]*)/){ |match|
- match = '<a href=' + sprintf("\'javascript:getSObjectRecord(\"%s%s\")\'", $1, $2) + '>' + match + '</a>'
+ body = body.gsub(/(\/services\/data\/v\d+\.\d+\/[^\"]*)/){ |match|
+ match = '<a href=\'javascript:void(0);\' onclick=' + sprintf("\'getSObjectRecord(\\\"%s\\\");\'", $1) + '>' + match + '</a>'
}
- clickableBody.gsub!(/(https:\/\/login.salesforce.com)(\/id\/[^\"]*)/){ |match|
- match = '<a href=' + sprintf("\'javascript:getSObjectRecord(\"%s\")\'", $2) + '>' + $2 + '</a>'
+ body = body.gsub(/(https:\/\/login.salesforce.com)(\/id\/[^\"]*)/){ |match|
+ match = '<a href=\'javascript:void(0);\' onclick=' + sprintf("\'getSObjectRecord(\\\"%s\\\");\'", $2) + '>' + $2 + '</a>'
}
+
+ body
+end
+
+
+def set_current_path(path)
+ if /\/services\/data\/v\d+\.\d+/ =~ path
+ @@client.to(:data)
+ elsif /\/services\/apexrest/ =~ path
+ @@client.to(:apex)
+ elsif path == ''
+ @@client.to(:root)
+ else
+ @@client.to(:root)
+ end
end
View
@@ -63,11 +63,6 @@ def id
@agent.id
end
-
- def current_path=(path)
- @current_path = path if /\/services\/data\/v\d+\.\d+/ =~ path || /\/services\/apexrest/ =~ path || path == '/'
- end
-
def reload(config)
ShellForce.config.use(config)
@@ -77,19 +72,19 @@ def reload(config)
def to(type)
case type
when :apex
- if @current_path == '/'
+ if @current_path == ''
@current_path = @@apex_path
else
@current_path.gsub!(/\/services\/data\/v\d+\.\d+/, @@apex_path)
end
when :data
- if @current_path == '/'
+ if @current_path == ''
@current_path = @data_path
else
@current_path.gsub!(/\/services\/apexrest/, @data_path)
end
when :root
- @current_path = '/'
+ @current_path = ''
else
"#{type} is not supported"
end
View
@@ -10,10 +10,6 @@
module ShellForce
module Command
- def xsl
- @xsl ||= Nokogiri::XSLT(XSLT)
- end
-
def pp(headers, body)
format = headers["content-type"][0]
if format.match("json")
@@ -26,6 +22,12 @@ def pp(headers, body)
return headers, body
end
+
+ def xsl
+ @xsl ||= Nokogiri::XSLT(XSLT)
+ end
+
+
XSLT = <<-XSLT
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" encoding="UTF-8"/>
@@ -1,37 +0,0 @@
-// Copied from REST Explorer
-/* ================================================================
-This copyright notice must be kept untouched in the stylesheet at
-all times.
-
-The original version of this script and the associated (x)html
-is available at http://www.stunicholls.com/menu/pro_drop_1.html
-Copyright (c) 2005-2007 Stu Nicholls. All rights reserved.
-This script and the associated (x)html may be modified in any
-way to fit your requirements.
-=================================================================== */
-stuHover = function() {
- var cssRule;
- var newSelector;
- for ( var i = 0; i < document.styleSheets.length; i++)
- for ( var x = 0; x < document.styleSheets[i].rules.length; x++) {
- cssRule = document.styleSheets[i].rules[x];
- if (cssRule.selectorText.indexOf("LI:hover") != -1) {
- newSelector = cssRule.selectorText.replace(/LI:hover/gi,
- "LI.iehover");
- document.styleSheets[i].addRule(newSelector,
- cssRule.style.cssText);
- }
- }
- var getElm = document.getElementById("nav").getElementsByTagName("LI");
- for ( var i = 0; i < getElm.length; i++) {
- getElm[i].onmouseover = function() {
- this.className += " iehover";
- }
- getElm[i].onmouseout = function() {
- this.className = this.className.replace(new RegExp(" iehover\\b"),
- "");
- }
- }
-}
-if (window.attachEvent)
- window.attachEvent("onload", stuHover);
@@ -1,7 +1,7 @@
// Functions that handle requests to shellforce
$(function() {
- var shellforce_path = [shellforce_current_path, '/services/apexrest', '/'];
+ var shellforce_path = [shellforce_current_path, '/services/apexrest', '(root)'];
var index = 0;
$("span[name='path']").empty().append(shellforce_current_path);
$("span[name='path']").click(function() {
@@ -11,19 +11,19 @@ $(function() {
});
$(function() {
- $("input[id='execBtn']").click(function() {
+ $("input[id='executeButton']").click(function() {
executeShellForce(
- $("span[name='path']").val(),
- $('input[name="requestMethod"]:checked').val(),
- $('input[name="urlInput"]').val(),
- $('input[name="requestBody"]').val()
+ (function(path) {return (path.match(/\(root\)/) ? '' : path);})($("span[name='path']").text()),
+ $("input[name='requestMethod']:checked").val(),
+ $("input[name='urlInput']").val(),
+ $("input[name='requestBody']").val()
);
});
});
var getSObjectRecord = function(url) {
- executeShellForce('/', 'GET', url, '');
+ executeShellForce('', 'GET', url, '');
};
@@ -34,7 +34,7 @@ var executeShellForce = function(path, method, url, body) {
$.ajax({
type : 'POST',
url : shellforce_api,
- dataType : 'text',
+ dataType : 'json',
data : {'path' : path, 'method' : method, 'url' : url, 'body' : body},
success : function(response) {
var expand = "javascript:ddtreemenu.flatten('responseList', 'expand');";
@@ -45,8 +45,19 @@ var executeShellForce = function(path, method, url, body) {
var showRawResponse = $("<a id='codeViewPortToggler' href='javascript:toggleCodeViewPort();'>Show Raw Response</a>");
var responseListContainer = $("<div id='responseListContainer' class='results'><div/>");
- var responseBody = $("<script type='text/javascript'>convert(" + response + ");</script>");
- var rawResponseBody = $("<strong>Raw Response</strong><p id='codeViewPort'><br/>"+ response + "</p>");
+ var responseBody = $("<script type='text/javascript'>convert(" + JSON.stringify(response.clickable, null, " ") + ");</script>");
+ var rawResponseBody = $("<strong>Raw Response</strong><p id='codeViewPort'><br/>"+ JSON.stringify(response.raw, null, " ") + "</p>");
+ var time = $("<br/>Requested in " + response.time + " sec<br/>");
+
+ $("span[name='path']").empty().append(path == '' ? '(root)' : path);
+
+ $("input[name='requestMethod']").attr('checked', false);
+ $("input[value='" + method + "']").attr('checked', true);
+
+ $("input[name='urlInput']").val('');
+ $("input[name='urlInput']").val(path + url);
+
+ $("input[name='requestBody']").empty().append(body);
$("div[id='results']").empty().append(expandAll).append(" | ").
append(collapseAll).append(" | ").
@@ -56,6 +67,8 @@ var executeShellForce = function(path, method, url, body) {
$("div[id='codeViewPortContainer']").empty().append(rawResponseBody);
+ $("div[id='disclaimer']").empty().append(time);
+
$("span[id='waitingNotice']").hide();
}
});
Oops, something went wrong.

0 comments on commit 9360270

Please sign in to comment.