diff --git a/app/controllers/apis_controller.rb b/app/controllers/apis_controller.rb index 796af52aa..803c3eb6d 100644 --- a/app/controllers/apis_controller.rb +++ b/app/controllers/apis_controller.rb @@ -38,7 +38,7 @@ class ApisController < ActionController::Metal ##people def people_index set_defaults - people = Person.search(params[:q]).paginate(:page => params[:page], :per_page => params[:per_page], :order => "#{params[:order]} DESC") + people = Person.search(params[:q], nil).paginate(:page => params[:page], :per_page => params[:per_page], :order => "#{params[:order]} DESC") render :json => people.as_json end diff --git a/app/views/admins/user_search.html.haml b/app/views/admins/user_search.html.haml index f57ba0f3c..5ec26af37 100644 --- a/app/views/admins/user_search.html.haml +++ b/app/views/admins/user_search.html.haml @@ -39,3 +39,14 @@ = "invite token: #{accept_invitation_url(user, :invitation_token => user.invitation_token)}" if user.invitation_token %br %br += javascript_include_tag 'apiconsole' +#query + %h3 api console + = text_field_tag :api + = submit_tag 'ping this api', :id => 'api_submit' + + response: + %br + %br + #resp + diff --git a/public/javascripts/apiconsole.js b/public/javascripts/apiconsole.js new file mode 100644 index 000000000..e9a4c7a48 --- /dev/null +++ b/public/javascripts/apiconsole.js @@ -0,0 +1,54 @@ +var ApiConsole = { + + prettyPrint: function(obj, indent) + { + var result = ""; + if (indent == null) indent = ""; + + for (var property in obj) + { + var value = obj[property]; + if (typeof value == 'string') + value = "'" + value + "'"; + else if (typeof value == 'object') + { + if (value instanceof Array) + { + // Just let JS convert the Array to a string! + value = "[ " + value + " ]"; + } + else + { + // Recursive dump + // (replace " " by "\t" or something else if you prefer) + var od = ApiConsole.prettyPrint(value, indent + " "); + // If you like { on the same line as the key + //value = "{\n" + od + "\n" + indent + "}"; + // If you prefer { and } to be aligned + value = "\n" + indent + "{\n" + od + "\n" + indent + "}"; + } + } + result += indent + "'" + property + "' : " + value + ",\n"; + } + return result.replace(/,\n$/, ""); + }, + init: function(field, query_box, button){ + this.field = $(field); + this.query = $(query_box); + this.button = $(button); + + + this.button.click(function(){ + $.getJSON(ApiConsole.query.val(), function(data){ + var json = ApiConsole.prettyPrint(data, ''); + console.dir(json); + ApiConsole.field.html(json); + }); + }); + } +} + +$(document).ready(function(){ + + ApiConsole.init('#resp', 'input[name=api]', '#api_submit:input'); +});