From 10579a3c95364cab5d00f64c67bc0d3470281f97 Mon Sep 17 00:00:00 2001 From: Alexandr Date: Fri, 12 Dec 2014 15:38:51 +0300 Subject: [PATCH 1/3] Create bigwig_working_with_html.erl --- src/bigwig_working_with_html.erl | 76 ++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100644 src/bigwig_working_with_html.erl diff --git a/src/bigwig_working_with_html.erl b/src/bigwig_working_with_html.erl new file mode 100644 index 0000000..8fd6d54 --- /dev/null +++ b/src/bigwig_working_with_html.erl @@ -0,0 +1,76 @@ +-module(bigwig_working_with_html). +-compile(export_all). +%==================================================================================================================================================================================== +-define(Header, lists:append([""])). +-define(Footer, ""). +%==================================================================================================================================================================================== +-spec list_to_html(_) -> binary() | [#exchange_rec{good_id::0,new_good_id::0,brand_id::0,new_brand_id::0,undef_int::0,good_name::<<>>,new_good_name::<<>>,brand_name::<<>>,new_brand_name::<<>>,error::binary(),undef_bin::<<>>},...]. +list_to_html(List) when is_pid(List) -> list2binary_ex([?Header, pid_to_list(List),?Footer]); +list_to_html(List) when is_list(List) -> + case is_simple_list(List) of + true -> list2binary_ex([?Header, List,?Footer]); + false -> list2binary_ex([?Header,list_to_html_table(List),?Footer]) + end; +list_to_html(List) when is_tuple(List) -> list_to_html(tuple_to_list(List)); +list_to_html(List) when is_atom(List) -> list2binary_ex([?Header,atom_to_list(List),?Footer]); +list_to_html(_List) -> list2binary_ex([?Header, "error!!!",?Footer]); +%***************************************************************************************************************************************************************************************** +-spec list_to_html_table(maybe_improper_list()) -> binary(). +list_to_html_table(List) -> + case is_string(List) of + true -> list2binary_ex(["
",List,"
"]); + false -> list_to_html_table(List, []) + end. +%***************************************************************************************************************************************************************************************** +-spec list_to_html_table([any()],[any()]) -> binary(). +list_to_html_table([], ANS) -> list2binary_ex(["", lists:reverse(ANS), "
"]); +list_to_html_table([Head | Tail], ANS) ->list_to_html_table(Tail, [get_row(Head)| ANS]). +%***************************************************************************************************************************************************************************************** +-spec get_row(_) -> binary(). +get_row(Row) when is_tuple(Row)->get_row(tuple_to_list(Row)); +get_row(Row) when is_pid(Row)->list2binary_ex(["",pid_to_list(Row),""]); +get_row(Row) -> + case is_list(Row) of + true->case is_string(Row) of + true->list2binary_ex(["",Row,""]); + false->get_row(Row,[]) + end; + false->list2binary_ex(["",Row,""]) + end. +-spec get_row([any()],[any()]) -> binary(). +get_row([],ANS)->list2binary_ex(["", lists:reverse(ANS), ""]); +get_row([H|T],ANS)when is_list(H)-> + case is_string(H) of + true -> get_row(T,[list2binary_ex(["", H, ""])|ANS]); + false -> get_row(T,[list2binary_ex(["",list_to_html_table(H), ""])|ANS]) + end; +get_row([H|T],ANS)when is_tuple(H)->get_row([tuple_to_list(H)|T],ANS); +get_row([H|T],ANS)->get_row(T,[list2binary_ex(["", H , ""])|ANS]). +%==================================================================================================================================================================================== +-spec get_random_color() -> [any()]. +get_random_color()-> + lists:append(["#",integer_to_list(random:uniform(245)+10, 16),integer_to_list(random:uniform(245)+10, 16),integer_to_list(random:uniform(245)+10, 16)]). +%==================================================================================================================================================================================== +list2binary_ex(ListOfTerms) -> list_to_binary([list2binary_convert(E) || E <- ListOfTerms]). +list2binary_convert(X) when is_atom(X) -> atom_to_list(X); +list2binary_convert(X) when is_integer(X) -> integer_to_list(X); +list2binary_convert(X) when is_float(X) -> float_to_list(X); +list2binary_convert(X) when is_pid(X) -> pid_to_list(X); +list2binary_convert(X) -> X. +%==================================================================================================================================================================================== +is_string([]) -> true; +is_string([H | T]) when is_integer(H)-> + case H < 256 of + true -> is_string(T); + false-> false + end; +is_string([_H | _T]) -> false. +%============================================================================================================================================================================================= +is_simple_list([]) -> true; +is_simple_list([_H | _T]) when is_list(_H) -> false; +is_simple_list([_H | _T]) when is_tuple(_H) -> false; +is_simple_list([H | T]) -> + case array:is_array(H) of + true -> false; + _ -> is_simple_list(T) + end. From 8eea42db3f4c6d2113428692475ee17340dc49dc Mon Sep 17 00:00:00 2001 From: Alexandr Date: Fri, 12 Dec 2014 15:49:58 +0300 Subject: [PATCH 2/3] Create bigwig_http_etsinfo.erl --- src/bigwig_http_etsinfo.erl | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 src/bigwig_http_etsinfo.erl diff --git a/src/bigwig_http_etsinfo.erl b/src/bigwig_http_etsinfo.erl new file mode 100644 index 0000000..2a9fe6e --- /dev/null +++ b/src/bigwig_http_etsinfo.erl @@ -0,0 +1,20 @@ +-module(bigwig_http_etsinfo). +-behaviour(cowboy_http_handler). +-export([init/3, handle/2, terminate/2]). + +-compile(export_all). + +init({tcp, http}, Req, _Opts) -> + {ok, Req, undefined_state}. + +handle(Req, State) -> + Body = bigwig_working_with_html:list_to_html(etsinfo()), + Headers = [{<<"Content-Type">>, <<"application/json">>}], + {ok, Req2} = cowboy_http_req:reply(200, Headers, Body, Req), + {ok, Req2, State}. + +terminate(_Req, _State) -> + ok. + + +etsinfo() -> [{Tab,ets:info(Tab)}||Tab<-ets:all()]. From c7460469968ff28f69339242359870dc73585e22 Mon Sep 17 00:00:00 2001 From: Alexandr Date: Fri, 12 Dec 2014 15:51:04 +0300 Subject: [PATCH 3/3] Update bigwig_http.erl --- src/bigwig_http.erl | 1 + 1 file changed, 1 insertion(+) diff --git a/src/bigwig_http.erl b/src/bigwig_http.erl index f0b1bdc..9aec938 100644 --- a/src/bigwig_http.erl +++ b/src/bigwig_http.erl @@ -33,6 +33,7 @@ dispatch_rules() -> , {[<<"top">>, '...'], bigwig_http_etop2, []} , {[<<"appmon">>, '...'], bigwig_http_appmon, []} , {[<<"stats-stream">>], bigwig_http_stats_stream, []} + , {[<<"etsinfo">>], bigwig_http_etsinfo, []} , {'_', bigwig_http_catchall, []} ]}].