Mercurial Hosting > chat
comparison 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 |
comparison
equal
deleted
inserted
replaced
| 87:246a792adedf | 88:7b339b1ccd11 |
|---|---|
| 1 local Luan = require "luan:Luan.luan" | |
| 2 local error = Luan.error | |
| 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() | |
| 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() | |
| 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" | |
| 18 | |
| 19 | |
| 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 | |
| 32 return function() | |
| 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() | |
| 39 Io.stdout = Http.response.text_writer() | |
| 40 %> | |
| 41 <!doctype html> | |
| 42 <html> | |
| 43 <head> | |
| 44 <% head() %> | |
| 45 <style> | |
| 46 table { | |
| 47 border-collapse: collapse; | |
| 48 } | |
| 49 th, td { | |
| 50 border: 1px solid; | |
| 51 padding: 4px; | |
| 52 } | |
| 53 </style> | |
| 54 </head> | |
| 55 <body> | |
| 56 <% header() %> | |
| 57 <div content> | |
| 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> | |
| 77 <td><a href="<%=user.login_url()%>"><%= user.name_html() %></a></td> | |
| 78 <td><%= ago %></td> | |
| 79 </tr> | |
| 80 <% | |
| 81 end | |
| 82 %> | |
| 83 </table> | |
| 84 </div> | |
| 85 </body> | |
| 86 </html> | |
| 87 <% | |
| 88 end |
