annotate src/private/tools/users.html.luan @ 88:7b339b1ccd11

add tools/users.html
author Franklin Schmidt <fschmidt@gmail.com>
date Thu, 13 Mar 2025 16:18:39 -0600
parents src/private/tools/index.html.luan@e22a1ba4b2ed
children 3053a4fc10be
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1 local Luan = require "luan:Luan.luan"
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2 local error = Luan.error
88
7b339b1ccd11 add tools/users.html
Franklin Schmidt <fschmidt@gmail.com>
parents: 6
diff changeset
3 local ipairs = Luan.ipairs or error()
7b339b1ccd11 add tools/users.html
Franklin Schmidt <fschmidt@gmail.com>
parents: 6
diff changeset
4 local Time = require "luan:Time.luan"
7b339b1ccd11 add tools/users.html
Franklin Schmidt <fschmidt@gmail.com>
parents: 6
diff changeset
5 local time_now = Time.now or error()
7b339b1ccd11 add tools/users.html
Franklin Schmidt <fschmidt@gmail.com>
parents: 6
diff changeset
6 local Table = require "luan:Table.luan"
7b339b1ccd11 add tools/users.html
Franklin Schmidt <fschmidt@gmail.com>
parents: 6
diff changeset
7 local sort = Table.sort or error()
0
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
8 local Io = require "luan:Io.luan"
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
9 local Http = require "luan:http/Http.luan"
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
10 local Shared = require "site:/lib/Shared.luan"
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
11 local head = Shared.head or error()
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
12 local header = Shared.private_header or error()
88
7b339b1ccd11 add tools/users.html
Franklin Schmidt <fschmidt@gmail.com>
parents: 6
diff changeset
13 local User = require "site:/lib/User.luan"
7b339b1ccd11 add tools/users.html
Franklin Schmidt <fschmidt@gmail.com>
parents: 6
diff changeset
14 local Online = require "site:/lib/Online.luan"
7b339b1ccd11 add tools/users.html
Franklin Schmidt <fschmidt@gmail.com>
parents: 6
diff changeset
15 local get_online = Online.get_user or error()
7b339b1ccd11 add tools/users.html
Franklin Schmidt <fschmidt@gmail.com>
parents: 6
diff changeset
16 local Logging = require "luan:logging/Logging.luan"
7b339b1ccd11 add tools/users.html
Franklin Schmidt <fschmidt@gmail.com>
parents: 6
diff changeset
17 local logger = Logging.logger "tools/users.html"
0
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
18
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
19
88
7b339b1ccd11 add tools/users.html
Franklin Schmidt <fschmidt@gmail.com>
parents: 6
diff changeset
20 local function sorter(u1,u2)
7b339b1ccd11 add tools/users.html
Franklin Schmidt <fschmidt@gmail.com>
parents: 6
diff changeset
21 local o1 = u1.online
7b339b1ccd11 add tools/users.html
Franklin Schmidt <fschmidt@gmail.com>
parents: 6
diff changeset
22 local o2 = u2.online
7b339b1ccd11 add tools/users.html
Franklin Schmidt <fschmidt@gmail.com>
parents: 6
diff changeset
23 if o1 == nil then
7b339b1ccd11 add tools/users.html
Franklin Schmidt <fschmidt@gmail.com>
parents: 6
diff changeset
24 return false
7b339b1ccd11 add tools/users.html
Franklin Schmidt <fschmidt@gmail.com>
parents: 6
diff changeset
25 elseif o2 == nil then
7b339b1ccd11 add tools/users.html
Franklin Schmidt <fschmidt@gmail.com>
parents: 6
diff changeset
26 return true
7b339b1ccd11 add tools/users.html
Franklin Schmidt <fschmidt@gmail.com>
parents: 6
diff changeset
27 else
7b339b1ccd11 add tools/users.html
Franklin Schmidt <fschmidt@gmail.com>
parents: 6
diff changeset
28 return o1 > o2
7b339b1ccd11 add tools/users.html
Franklin Schmidt <fschmidt@gmail.com>
parents: 6
diff changeset
29 end
7b339b1ccd11 add tools/users.html
Franklin Schmidt <fschmidt@gmail.com>
parents: 6
diff changeset
30 end
7b339b1ccd11 add tools/users.html
Franklin Schmidt <fschmidt@gmail.com>
parents: 6
diff changeset
31
0
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
32 return function()
88
7b339b1ccd11 add tools/users.html
Franklin Schmidt <fschmidt@gmail.com>
parents: 6
diff changeset
33 local users = User.search("type:user")
7b339b1ccd11 add tools/users.html
Franklin Schmidt <fschmidt@gmail.com>
parents: 6
diff changeset
34 for _, user in ipairs(users) do
7b339b1ccd11 add tools/users.html
Franklin Schmidt <fschmidt@gmail.com>
parents: 6
diff changeset
35 user.online = get_online(user)
7b339b1ccd11 add tools/users.html
Franklin Schmidt <fschmidt@gmail.com>
parents: 6
diff changeset
36 end
7b339b1ccd11 add tools/users.html
Franklin Schmidt <fschmidt@gmail.com>
parents: 6
diff changeset
37 sort(users,sorter)
7b339b1ccd11 add tools/users.html
Franklin Schmidt <fschmidt@gmail.com>
parents: 6
diff changeset
38 local now = time_now()
0
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
39 Io.stdout = Http.response.text_writer()
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
40 %>
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
41 <!doctype html>
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
42 <html>
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
43 <head>
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
44 <% head() %>
88
7b339b1ccd11 add tools/users.html
Franklin Schmidt <fschmidt@gmail.com>
parents: 6
diff changeset
45 <style>
7b339b1ccd11 add tools/users.html
Franklin Schmidt <fschmidt@gmail.com>
parents: 6
diff changeset
46 table {
7b339b1ccd11 add tools/users.html
Franklin Schmidt <fschmidt@gmail.com>
parents: 6
diff changeset
47 border-collapse: collapse;
7b339b1ccd11 add tools/users.html
Franklin Schmidt <fschmidt@gmail.com>
parents: 6
diff changeset
48 }
7b339b1ccd11 add tools/users.html
Franklin Schmidt <fschmidt@gmail.com>
parents: 6
diff changeset
49 th, td {
7b339b1ccd11 add tools/users.html
Franklin Schmidt <fschmidt@gmail.com>
parents: 6
diff changeset
50 border: 1px solid;
7b339b1ccd11 add tools/users.html
Franklin Schmidt <fschmidt@gmail.com>
parents: 6
diff changeset
51 padding: 4px;
7b339b1ccd11 add tools/users.html
Franklin Schmidt <fschmidt@gmail.com>
parents: 6
diff changeset
52 }
7b339b1ccd11 add tools/users.html
Franklin Schmidt <fschmidt@gmail.com>
parents: 6
diff changeset
53 </style>
0
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
54 </head>
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
55 <body>
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
56 <% header() %>
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
57 <div content>
88
7b339b1ccd11 add tools/users.html
Franklin Schmidt <fschmidt@gmail.com>
parents: 6
diff changeset
58 <h1>users</h1>
7b339b1ccd11 add tools/users.html
Franklin Schmidt <fschmidt@gmail.com>
parents: 6
diff changeset
59 <table>
7b339b1ccd11 add tools/users.html
Franklin Schmidt <fschmidt@gmail.com>
parents: 6
diff changeset
60 <tr>
7b339b1ccd11 add tools/users.html
Franklin Schmidt <fschmidt@gmail.com>
parents: 6
diff changeset
61 <th>ID</th>
7b339b1ccd11 add tools/users.html
Franklin Schmidt <fschmidt@gmail.com>
parents: 6
diff changeset
62 <th>name</th>
7b339b1ccd11 add tools/users.html
Franklin Schmidt <fschmidt@gmail.com>
parents: 6
diff changeset
63 <th>last seen</th>
7b339b1ccd11 add tools/users.html
Franklin Schmidt <fschmidt@gmail.com>
parents: 6
diff changeset
64 </tr>
7b339b1ccd11 add tools/users.html
Franklin Schmidt <fschmidt@gmail.com>
parents: 6
diff changeset
65 <%
7b339b1ccd11 add tools/users.html
Franklin Schmidt <fschmidt@gmail.com>
parents: 6
diff changeset
66 for _, user in ipairs(users) do
7b339b1ccd11 add tools/users.html
Franklin Schmidt <fschmidt@gmail.com>
parents: 6
diff changeset
67 local online = user.online
7b339b1ccd11 add tools/users.html
Franklin Schmidt <fschmidt@gmail.com>
parents: 6
diff changeset
68 local ago
7b339b1ccd11 add tools/users.html
Franklin Schmidt <fschmidt@gmail.com>
parents: 6
diff changeset
69 if online == nil then
7b339b1ccd11 add tools/users.html
Franklin Schmidt <fschmidt@gmail.com>
parents: 6
diff changeset
70 ago = ""
7b339b1ccd11 add tools/users.html
Franklin Schmidt <fschmidt@gmail.com>
parents: 6
diff changeset
71 else
7b339b1ccd11 add tools/users.html
Franklin Schmidt <fschmidt@gmail.com>
parents: 6
diff changeset
72 ago = `%><script>document.write(ago(<%= now - online %>))</script><%`
7b339b1ccd11 add tools/users.html
Franklin Schmidt <fschmidt@gmail.com>
parents: 6
diff changeset
73 end
7b339b1ccd11 add tools/users.html
Franklin Schmidt <fschmidt@gmail.com>
parents: 6
diff changeset
74 %>
7b339b1ccd11 add tools/users.html
Franklin Schmidt <fschmidt@gmail.com>
parents: 6
diff changeset
75 <tr>
7b339b1ccd11 add tools/users.html
Franklin Schmidt <fschmidt@gmail.com>
parents: 6
diff changeset
76 <td><%= user.id %></td>
7b339b1ccd11 add tools/users.html
Franklin Schmidt <fschmidt@gmail.com>
parents: 6
diff changeset
77 <td><a href="<%=user.login_url()%>"><%= user.name_html() %></a></td>
7b339b1ccd11 add tools/users.html
Franklin Schmidt <fschmidt@gmail.com>
parents: 6
diff changeset
78 <td><%= ago %></td>
7b339b1ccd11 add tools/users.html
Franklin Schmidt <fschmidt@gmail.com>
parents: 6
diff changeset
79 </tr>
7b339b1ccd11 add tools/users.html
Franklin Schmidt <fschmidt@gmail.com>
parents: 6
diff changeset
80 <%
7b339b1ccd11 add tools/users.html
Franklin Schmidt <fschmidt@gmail.com>
parents: 6
diff changeset
81 end
7b339b1ccd11 add tools/users.html
Franklin Schmidt <fschmidt@gmail.com>
parents: 6
diff changeset
82 %>
7b339b1ccd11 add tools/users.html
Franklin Schmidt <fschmidt@gmail.com>
parents: 6
diff changeset
83 </table>
0
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
84 </div>
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
85 </body>
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
86 </html>
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
87 <%
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
88 end