Mercurial Hosting > chat
view 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 |
line wrap: on
line source
local Luan = require "luan:Luan.luan" local error = Luan.error local ipairs = Luan.ipairs or error() local Time = require "luan:Time.luan" local time_now = Time.now or error() local Table = require "luan:Table.luan" local sort = Table.sort or error() local Io = require "luan:Io.luan" local Http = require "luan:http/Http.luan" local Shared = require "site:/lib/Shared.luan" local head = Shared.head or error() local header = Shared.private_header or error() local User = require "site:/lib/User.luan" local Online = require "site:/lib/Online.luan" local get_online = Online.get_user or error() local Logging = require "luan:logging/Logging.luan" local logger = Logging.logger "tools/users.html" local function sorter(u1,u2) local o1 = u1.online local o2 = u2.online if o1 == nil then return false elseif o2 == nil then return true else return o1 > o2 end end return function() local users = User.search("type:user") for _, user in ipairs(users) do user.online = get_online(user) end sort(users,sorter) local now = time_now() Io.stdout = Http.response.text_writer() %> <!doctype html> <html> <head> <% head() %> <style> table { border-collapse: collapse; } th, td { border: 1px solid; padding: 4px; } </style> </head> <body> <% header() %> <div content> <h1>users</h1> <table> <tr> <th>ID</th> <th>name</th> <th>last seen</th> </tr> <% for _, user in ipairs(users) do local online = user.online local ago if online == nil then ago = "" else ago = `%><script>document.write(ago(<%= now - online %>))</script><%` end %> <tr> <td><%= user.id %></td> <td><a href="<%=user.login_url()%>"><%= user.name_html() %></a></td> <td><%= ago %></td> </tr> <% end %> </table> </div> </body> </html> <% end