Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

implement module dialog with reload method

  • Loading branch information...
commit 46ebdc54f12af3455b382783f4d3d2532b29c134 1 parent 42c0b7f
@RJ authored
Showing with 45 additions and 3 deletions.
  1. +30 −1 priv/js/renderer.js
  2. +15 −2 src/bigwig_http_module.erl
View
31 priv/js/renderer.js
@@ -48,7 +48,36 @@ var RENDERER = (function() {
}
var show_mfa_dialog = function(m, f, a) {
- alert('MFA DIALOG HERE: ' + m + ':' + f + '/' + a);
+ var url = '/module/' + m;
+ $.ajax({
+ url: url,
+ dataType: 'json',
+ success: function(json){
+ $('<div class="mfa_dialog"></div>')
+ .append( gen_pid_html(json) )
+ .dialog({
+ title: m + ':module_info() &nbsp; ' +
+ '<small>(<a href="'+url+'">json</a>)</small>',
+ width: 460,
+ buttons: {
+ "Close": function() { $(this).dialog("close"); },
+ "Reload Module": function() {
+ if(confirm("Sure you want to reload this module?"))
+ {
+ var thisdiag = $(this);
+ $.ajax({
+ url:url,
+ type:'POST',
+ data: {reload: "yes"},
+ success: function(resp){
+ alert('Module reloaded');
+ }
+ })
+ }
+ }
+ }
+ })
+ }});
}
View
17 src/bigwig_http_module.erl
@@ -13,6 +13,16 @@ handle(Req0, State) ->
{Method, Req1} = cowboy_http_req:method(Req),
handle_path(Method, Path, Req1, State).
+handle_path('POST', [<<"module">>, Module], Req, State) ->
+ {Props, Req2} = cowboy_http_req:body_qs(Req),
+ case proplists:get_value(<<"reload">>, Props) of
+ undefined ->
+ not_found(Req2, State);
+ <<"yes">> ->
+ c:l(list_to_existing_atom(binary_to_list(Module))),
+ {ok, Req3} = cowboy_http_req:reply(200, [], <<"ok">>, Req2),
+ {ok, Req3, State}
+ end;
handle_path('GET', [<<"module">>, Module], Req, State) ->
case to_module_info(Module) of
[_|_] = Info -> json_response(Info, Req, State);
@@ -30,10 +40,13 @@ terminate(_Req, _State) ->
-spec to_module_info(binary()) -> list().
to_module_info(Bin) ->
- case catch(list_to_existing_atom(binary_to_list(Bin))) of
+ ModInfo = case catch(list_to_existing_atom(binary_to_list(Bin))) of
Mod when is_atom(Mod) -> catch(Mod:module_info());
_ -> []
- end.
+ 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) ].
json_response(Info, Req, State) ->
Body = jsx:term_to_json(Info),
Please sign in to comment.
Something went wrong with that request. Please try again.