diff options
author | Jordan Bracco <href@random.sh> | 2022-04-17 03:25:09 +0000 |
---|---|---|
committer | Jordan Bracco <href@random.sh> | 2022-04-17 03:25:09 +0000 |
commit | 93d3514676cad95b94bbb3e483d02b7ea0076bba (patch) | |
tree | 0f7548c1cd274ec01873b5ebf39b6a39bea4e282 /apps/dreki_web/src/ui/dreki_web_ui_index.erl | |
parent | guess it was time for an initial commit (diff) |
Diffstat (limited to 'apps/dreki_web/src/ui/dreki_web_ui_index.erl')
-rw-r--r-- | apps/dreki_web/src/ui/dreki_web_ui_index.erl | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/apps/dreki_web/src/ui/dreki_web_ui_index.erl b/apps/dreki_web/src/ui/dreki_web_ui_index.erl new file mode 100644 index 0000000..9f4684e --- /dev/null +++ b/apps/dreki_web/src/ui/dreki_web_ui_index.erl @@ -0,0 +1,31 @@ +-module(dreki_web_ui_index). +-behaviour(cowboy_handler). +-export([init/2]). + +init(Req = #{method := <<"GET">>}, State) -> + PrettyWorld = jsone:encode(dreki_world:to_map(), [canonical_form, {space, 1}, {indent, 4}]), + LocalTasksStores = dreki_tasks:local_stores(), + {ok, Peers} = partisan_peer_service:members(), + NavTree = nav_tree(dreki_world_dns:as_map()), + Html = dreki_web_ui:render(Req, index_dtl, [ + {"page_title", "Admin UI"}, + {"dreki_world_pretty_json", PrettyWorld}, + {"dreki_local_tasks_stores", LocalTasksStores}, + {"dreki_peers", Peers}, + {"nav_tree", NavTree} + ]), + {ok, dreki_web_ui:reply_html(Req, 200, Html), State}; +init(Req, _) -> + dreki_web_ui_error:init(Req, #{code => 400, status => "Bad request"}). + +nav_tree(#{vertices := Vertices}) -> + nav_tree(Vertices, []). + +nav_tree([Region = #{type := region, name := Name, data := #{display_name := Display}} | Rest], Acc) -> + nav_tree(Rest, [Region#{href => <<"/admin/regions/", Name/binary>>, title => Display} | Acc]); +nav_tree([Node = #{type := node, name := Name, data := #{display_name := Display}} | Rest], Acc) -> + nav_tree(Rest, [Node#{href => <<"/admin/nodes/", Name/binary>>, title => Display} | Acc]); +nav_tree([#{type := Root} | Rest], Acc) -> + nav_tree(Rest, Acc); +nav_tree([], Acc) -> + Acc. |