Skip to content
Browse files

improve renderer, handle bags and times, module_info dialog

  • Loading branch information...
1 parent a26f38e commit 8b0d5e83b853c51fa66892e24e645634769d2c22 @RJ committed
Showing with 92 additions and 26 deletions.
  1. +73 −25 priv/js/renderer.js
  2. +19 −1 src/bigwig_http_module.erl
View
98 priv/js/renderer.js
@@ -95,11 +95,11 @@ var RENDERER = (function() {
}
- var render_list = function( list, stag, etag ) {
- var d = $('<span>'+stag+'</span>');
+ var render_list = function( list) {
+ var d = $('<span>[</span>');
if(list.length == 0)
{
- return d.append(' ' + etag);
+ return d.append(' ]');
}
else
{
@@ -112,37 +112,84 @@ var RENDERER = (function() {
d.append( render_json_val(list[i]) );
first = false;
}
- d.append(etag);
+ d.append(']');
return d;
}
}
+ var pad = function pad(number, length) {
+ var str = '' + number;
+ while (str.length < length) str = '0' + str;
+ return str;
+ }
+
+ var render_object = function( obj ) {
+ switch (obj._type)
+ {
+ // Node we use delegate to bind onclick for all a.pid, a.mfa
+ case 'tuple':
+ if(obj.data.length == 3 && (typeof obj.data[2] == 'number'))
+ {
+ return $('<a class="mfa" href="#">' + obj.data[0] + ':' + obj.data[1] + '/' + obj.data[2] + '</a>');
+ }
+ return render_list(obj.data, '{', '}');
+ case 'pid':
+ var Pid = obj.data.replace(/[<>]/g, '');
+ return $('<a class="_pid" href="#">&lt;'+Pid+'&gt;</a>');
+ case 'port':
+ return $(obj.data)
+ case 'date':
+ var o = obj.data;
+ var str = o[0] + '-' + pad(o[1],2) + '-' + pad(o[2],2) +
+ ' ' + pad(o[3],2) + ':' + pad(o[4],2) + ':' + pad(o[5],2);
+ return $('<span>' + str + '</span>');
+ case 'bag':
+ var d = $('<span>{</span>');
+ var first = true;
+ for(var k=0;k<obj.data.length;++k)
+ {
+ if(!first) {
+ d.append(', ');
+ }
+ d.append( render_json_val(obj.data[k]) );
+ first = false;
+ }
+ d.append('}');
+ return d;
+
+ default:
+ var d = $('<span>{</span>');
+ if(obj.length == 0)
+ {
+ return d.append(' }');
+ }
+ else
+ {
+ var first = true;
+ for(var i in obj)
+ {
+ if(!first) {
+ d.append(', ');
+ }
+ d.append( render_json_val(i) );
+ d.append(' : ');
+ d.append( render_json_val(obj[i]) );
+ first = false;
+ }
+ d.append('}');
+ return d;
+ }
+ }
+ }
+
var render_json_val = function( obj ) {
if( obj === true ) return $('<span>true</span>');
if( obj === false ) return $('<span>false</span>');
if( typeof obj == 'number' ) return $('<span>' + obj + '</span>');
if( typeof obj == 'string' ) return $('<span>' + obj + '</span>');
- if( $.isArray(obj) ) return render_list(obj, '[', ']');
- if( typeof obj == 'object' )
- {
- switch (obj._type)
- {
- // Node we use delegate to bind onclick for all a.pid, a.mfa
- case 'tuple':
- if(obj.data.length == 3 && (typeof obj.data[2] == 'number'))
- {
- return $('<a class="mfa" href="#">' + obj.data[0] + ':' + obj.data[1] + '/' + obj.data[2] + '</a>');
- }
- return render_list(obj.data, '{', '}');
- case 'pid':
- var Pid = obj.data.replace(/[<>]/g, '');
- return $('<a class="_pid" href="#">&lt;'+Pid+'&gt;</a>');
- case 'port':
- return $(obj.data)
- default:
- return render_list(obj, '{', '}');
- }
- }
+ if( $.isArray(obj) ) return render_list(obj);
+ if( typeof obj == 'object' ) return render_object(obj);
+ console.log("ERRRR what type is this");
}
var stringify = function(json) {
return (JSON.stringify(json, null, 4)).replace(/\<(\d+)\.(\d+)\.(\d+)\>/, '<a class="_pid" href="#">&lt;$1.$2.$3&gt;</a>');
@@ -154,6 +201,7 @@ var RENDERER = (function() {
show_mfa_dialog: show_mfa_dialog,
gen_pid_html: gen_pid_html,
render_list: render_list,
+ render_object: render_object,
render_json_val: render_json_val,
json: render_json_val,
stringify: stringify
View
20 src/bigwig_http_module.erl
@@ -38,6 +38,7 @@ not_found(Req, State) ->
terminate(_Req, _State) ->
ok.
+%% Reads and modifies module_info a bit to be more json friendly
-spec to_module_info(binary()) -> list().
to_module_info(Bin) ->
ModInfo = case catch(list_to_existing_atom(binary_to_list(Bin))) of
@@ -46,7 +47,24 @@ to_module_info(Bin) ->
end,
Exports = proplists:get_value(exports, ModInfo),
NewExports = [ list_to_binary(lists:flatten(io_lib:format("~w/~w",[F,A]))) || {F,A} <- Exports ],
- [ {exports, NewExports} | proplists:delete(exports, ModInfo) ].
+ ModInfo2 = [ {exports, NewExports} | proplists:delete(exports, ModInfo) ],
+ ModInfo3 =
+ case proplists:get_value(compile, ModInfo2) of
+ L when is_list(L) ->
+ case proplists:get_value(time, L) of
+ T when is_tuple(T) ->
+ proplists:delete(compile, L) ++
+ [ {compile, [ {time, [{'_type',<<"date">>},{data,tuple_to_list(T)}]}]}
+ | proplists:delete(time, L) ];
+ _ ->
+ ModInfo2
+ end;
+ _ ->
+ ModInfo2
+ end,
+ ModInfo3.
+
+
json_response(Info, Req, State) ->
Body = jsx:term_to_json(Info),

0 comments on commit 8b0d5e8

Please sign in to comment.
Something went wrong with that request. Please try again.