comparison src/admin/index.html.luan @ 0:dfc36e7ed22c

init
author Vadim Filimonov <fffilimonov@yandex.ru>
date Thu, 12 May 2022 13:51:59 +0400
parents
children 028e74c8889d
comparison
equal deleted inserted replaced
-1:000000000000 0:dfc36e7ed22c
1 local Luan = require "luan:Luan.luan"
2 local error = Luan.error
3 local pairs = Luan.pairs or error()
4 local ipairs = Luan.ipairs or error()
5 local Io = require "luan:Io.luan"
6 local Http = require "luan:http/Http.luan"
7 local Shared = require "site:/lib/Shared.luan"
8 local head = Shared.head or error()
9 local header = Shared.admin_header or error()
10 local get_user = Shared.get_user or error()
11 local config = Shared.config or error()
12
13
14 local user_repos = {}
15 for _, repo in pairs(config.repos) do
16 for user in pairs(repo.users) do
17 local repos = user_repos[user]
18 if repos == nil then
19 repos = {}
20 user_repos[user] = repos
21 end
22 repos[#repos+1] = repo
23 end
24 end
25
26 return function()
27 local user = get_user()
28 Io.stdout = Http.response.text_writer()
29 %>
30 <!doctype html>
31 <html>
32 <head>
33 <% head() %>
34 <title>Your Mercurial Repositories</title>
35 <script>
36 function deleteRepo(name) {
37 if( confirm('Are you sure that you want to delete repo "'+name+'"?') )
38 location = "delete.html?repo="+name;
39 }
40 </script>
41 </head>
42 <body>
43 <% header() %>
44 <div content>
45 <h1>Repositories of <%=user%></h1>
46 <% for _, repo in ipairs(user_repos[user] or {}) do
47 local name = repo.name
48 %>
49 <p>
50 <a href="/repo/<%=name%>/"><%=name%></a>
51 <% if repo.admins[user] then %>
52 - <a href="edit.html?repo=<%=name%>">edit</a>
53 - <a href="javascript:deleteRepo('<%=name%>')">delete</a>
54 <% end %>
55 </p>
56 <% end %>
57 <hr>
58 <h2>Add Repository</h2>
59 <form action="add.html">
60 <p>
61 <label prompt>Repo name</label>
62 <input type=text name=repo required>
63 </p>
64 <p>
65 <input type=submit value="Add Repo">
66 </p>
67 </form>
68 <% if config.private==nil or config.private[user] then %>
69 <hr>
70 <p><a href="/private/">/private/</a></p>
71 <% end %>
72 </div>
73 </body>
74 </html>
75 <%
76 end