annotate src/admin/index.html.luan @ 1:92a0646e38b6

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