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