aboutsummaryrefslogtreecommitdiff
path: root/apps/dreki_web/src/ui/dreki_web_ui_tasks.erl
blob: e9748b8ff71cab59b0a689d082f14ec12e1e9e28 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
-module(dreki_web_ui_tasks).
-behaviour(cowboy_handler).
-export([init/2]).

init(Req = #{method := <<"GET">>}, State) ->
  Local = maps:fold(fun
    (Ln, #{mod := Mod, path := Path}, Acc) ->
      [#{name => Ln, mod => Mod, path => Path, url => <<"/api/admin/tasks/", Path>>} | Acc]
     end, [], dreki_tasks:local_stores()),
  Html = dreki_web_ui:render(Req, tasks_dtl, [{"page_title", "Tasks"}, {"stores", Local}, {"tasks", []}]),
  {ok, dreki_web_ui:reply_html(Req, 200, Html), State};
init(Req, _) ->
  dreki_web_ui_error:init(Req, #{code => 400, status => "Bad request"}).