% this file is written in sections so you can take parts you like % and leave the rest % % display page heading, node name, and ISO date and time out(A) -> {ok,Hostname} = inet:gethostname(), NowYMDHMS = erlang:localtime(), {{YYYY, MM, DD}, {H,M,S}} = NowYMDHMS, IsoDateTime = io_lib:format( "~4.10.0b-~2.10.0b-~2.10.0b ~2.10.0b:~2.10.0b:~2.10.0b", [YYYY, MM, DD, H, M, S]), {ehtml,[{h1,[],["mnesia_tables"]}, {pre,[],f(" node: ~s now: ~s", [atom_to_list(node()),IsoDateTime])}]}. % list local tables, making each line a link to the table view out(A) -> Q = yaws_api:parse_query(A), ServerPath=A#arg.server_path, QryLink=fun(Tab)-> String=atom_to_list(Tab), Link=ServerPath++"?t="++String, [{a,[{href,Link}],String},f("\t(~p)\n",[mnesia:table_info(Tab,size)])] end, % local tables, excluding schema LT=lists:sort(lists:delete(schema,mnesia:system_info(local_tables))), {ehtml,[{h2,[],f("~p local tables",[length(LT)])}, {pre,[],lists:map(QryLink,LT)} ]}. % display links to other files in this directory out(A) -> Dir=filename:dirname(A#arg.fullpath), {ok,FL}=file:list_dir(Dir), Link=fun(String)->{a,[{href,String}],[String,"\n"]} end, {ehtml,[{h2,[],"links"}, {pre,[],[lists:map(Link,lists:sort(FL))]} ]}. % if there is a query, ?t=tablename, display table contents % sort rows by key order % if table has > 500 rows, display slot 0 of the table out(A) -> Q = yaws_api:parse_query(A), case Q of [{_,Table}] -> TableA=list_to_atom(Table), Size=mnesia:table_info(TableA,size), if Size =< 500 -> Rows=ets:tab2list(TableA), View="full table view"; true -> Rows=mnesia:dirty_slot(TableA,0), View="partial table view" end, {ehtml,[{h2,[],f("~s - ~p rows - ~s",[Table,Size,View])}, {pre,[],f("~p",[lists:sort(Rows)])} ]}; _ -> ok end.