Update mod_muc_admin web interface to work with ejabberd master

(Switch list strings to binary strings)
This commit is contained in:
Paul Donohue 2013-04-19 15:46:21 -04:00
parent a380488235
commit b87effe882
1 changed files with 45 additions and 46 deletions

View File

@ -54,8 +54,7 @@ stop(Host) ->
ejabberd_hooks:delete(webadmin_menu_main, ?MODULE, web_menu_main, 50), ejabberd_hooks:delete(webadmin_menu_main, ?MODULE, web_menu_main, 50),
ejabberd_hooks:delete(webadmin_menu_host, Host, ?MODULE, web_menu_host, 50), ejabberd_hooks:delete(webadmin_menu_host, Host, ?MODULE, web_menu_host, 50),
ejabberd_hooks:delete(webadmin_page_main, ?MODULE, web_page_main, 50), ejabberd_hooks:delete(webadmin_page_main, ?MODULE, web_page_main, 50),
ejabberd_hooks:delete(webadmin_page_host, Host, ?MODULE, web_page_host, 50), ejabberd_hooks:delete(webadmin_page_host, Host, ?MODULE, web_page_host, 50).
ejabberd_hooks:delete(webadmin_user, Host, ?MODULE, web_user, 50).
%%% %%%
%%% Register commands %%% Register commands
@ -207,34 +206,34 @@ muc_unregister_nick(Nick) ->
%% Web Admin Menu %% Web Admin Menu
web_menu_main(Acc, Lang) -> web_menu_main(Acc, Lang) ->
Acc ++ [{"muc", ?T("Multi-User Chat")}]. Acc ++ [{<<"muc">>, ?T(<<"Multi-User Chat">>)}].
web_menu_host(Acc, _Host, Lang) -> web_menu_host(Acc, _Host, Lang) ->
Acc ++ [{"muc", ?T("Multi-User Chat")}]. Acc ++ [{<<"muc">>, ?T(<<"Multi-User Chat">>)}].
%%--------------- %%---------------
%% Web Admin Page %% Web Admin Page
-define(TDTD(L, N), -define(TDTD(L, N),
?XE("tr", [?XCT("td", L), ?XE(<<"tr">>, [?XCT(<<"td">>, L),
?XC("td", integer_to_list(N)) ?XC(<<"td">>, jlib:integer_to_binary(N))
])). ])).
web_page_main(_, #request{path=["muc"], lang = Lang} = _Request) -> web_page_main(_, #request{path=[<<"muc">>], lang = Lang} = _Request) ->
Res = [?XC("h1", "Multi-User Chat"), Res = [?XC(<<"h1">>, <<"Multi-User Chat">>),
?XC("h3", "Statistics"), ?XC(<<"h3">>, <<"Statistics">>),
?XAE("table", [], ?XAE(<<"table">>, [],
[?XE("tbody", [?TDTD("Total rooms", ets:info(muc_online_room, size)), [?XE(<<"tbody">>, [?TDTD(<<"Total rooms">>, ets:info(muc_online_room, size)),
?TDTD("Permanent rooms", mnesia:table_info(muc_room, size)), ?TDTD(<<"Permanent rooms">>, mnesia:table_info(muc_room, size)),
?TDTD("Registered nicknames", mnesia:table_info(muc_registered, size)) ?TDTD(<<"Registered nicknames">>, mnesia:table_info(muc_registered, size))
]) ])
]), ]),
?XE("ul", [?LI([?ACT("rooms", "List of rooms")])]) ?XE(<<"ul">>, [?LI([?ACT(<<"rooms">>, <<"List of rooms">>)])])
], ],
{stop, Res}; {stop, Res};
web_page_main(_, #request{path=["muc", "rooms"], q = Q, lang = Lang} = _Request) -> web_page_main(_, #request{path=[<<"muc">>, <<"rooms">>], q = Q, lang = Lang} = _Request) ->
Sort_query = get_sort_query(Q), Sort_query = get_sort_query(Q),
Res = make_rooms_page(global, Lang, Sort_query), Res = make_rooms_page(global, Lang, Sort_query),
{stop, Res}; {stop, Res};
@ -242,7 +241,7 @@ web_page_main(_, #request{path=["muc", "rooms"], q = Q, lang = Lang} = _Request)
web_page_main(Acc, _) -> Acc. web_page_main(Acc, _) -> Acc.
web_page_host(_, Host, web_page_host(_, Host,
#request{path = ["muc"], #request{path = [<<"muc">>],
q = Q, q = Q,
lang = Lang} = _Request) -> lang = Lang} = _Request) ->
Sort_query = get_sort_query(Q), Sort_query = get_sort_query(Q),
@ -273,36 +272,36 @@ make_rooms_page(Host, Lang, {Sort_direction, Sort_column}) ->
Rooms_prepared = prepare_rooms_infos(Rooms_sorted), Rooms_prepared = prepare_rooms_infos(Rooms_sorted),
TList = lists:map( TList = lists:map(
fun(Room) -> fun(Room) ->
?XE("tr", [?XC("td", E) || E <- Room]) ?XE(<<"tr">>, [?XC(<<"td">>, E) || E <- Room])
end, Rooms_prepared), end, Rooms_prepared),
Titles = ["Jabber ID", Titles = [<<"Jabber ID">>,
"# participants", <<"# participants">>,
"Last message", <<"Last message">>,
"Public", <<"Public">>,
"Persistent", <<"Persistent">>,
"Logging", <<"Logging">>,
"Just created", <<"Just created">>,
"Title"], <<"Title">>],
{Titles_TR, _} = {Titles_TR, _} =
lists:mapfoldl( lists:mapfoldl(
fun(Title, Num_column) -> fun(Title, Num_column) ->
NCS = integer_to_list(Num_column), NCS = jlib:integer_to_binary(Num_column),
TD = ?XE("td", [?CT(Title), TD = ?XE(<<"td">>, [?CT(Title),
?C(" "), ?C(<<" ">>),
?ACT("?sort="++NCS, "<"), ?ACT(<<"?sort=", NCS/binary>>, <<"<">>),
?C(" "), ?C(<<" ">>),
?ACT("?sort=-"++NCS, ">")]), ?ACT(<<"?sort=-", NCS/binary>>, <<">">>)]),
{TD, Num_column+1} {TD, Num_column+1}
end, end,
1, 1,
Titles), Titles),
[?XC("h1", "Multi-User Chat"), [?XC(<<"h1">>, <<"Multi-User Chat">>),
?XC("h2", "Rooms"), ?XC(<<"h2">>, <<"Rooms">>),
?XE("table", ?XE(<<"table">>,
[?XE("thead", [?XE(<<"thead">>,
[?XE("tr", Titles_TR)] [?XE(<<"tr">>, Titles_TR)]
), ),
?XE("tbody", TList) ?XE(<<"tbody">>, TList)
] ]
) )
]. ].
@ -332,14 +331,14 @@ build_info_room({Name, Host, Pid}) ->
Ts_last_message = Ts_last_message =
case queue:is_empty(History) of case queue:is_empty(History) of
true -> true ->
"A long time ago"; <<"A long time ago">>;
false -> false ->
Last_message1 = queue:last(History), Last_message1 = queue:last(History),
{_, _, _, Ts_last, _} = Last_message1, {_, _, _, Ts_last, _} = Last_message1,
jlib:timestamp_to_iso(Ts_last) jlib:timestamp_to_iso(Ts_last)
end, end,
{Name++"@"++Host, {<<Name/binary, "@", Host/binary>>,
Num_participants, Num_participants,
Ts_last_message, Ts_last_message,
Public, Public,
@ -360,12 +359,12 @@ prepare_room_info(Room_info) ->
Just_created, Just_created,
Title} = Room_info, Title} = Room_info,
[NameHost, [NameHost,
integer_to_list(Num_participants), jlib:integer_to_binary(Num_participants),
Ts_last_message, Ts_last_message,
atom_to_list(Public), jlib:atom_to_binary(Public),
atom_to_list(Persistent), jlib:atom_to_binary(Persistent),
atom_to_list(Logging), jlib:atom_to_binary(Logging),
atom_to_list(Just_created), jlib:atom_to_binary(Just_created),
Title]. Title].