Comparison

mod_client_management/mod_client_management.lua @ 5309:09656e2b4927

mod_client_management: Improve table output Requires 1f89a2a9f532 and 1023c3faffac from Prosody.
author Matthew Wild <mwild1@gmail.com>
date Thu, 06 Apr 2023 15:22:10 +0100
parent 5308:f370ccb15f05
child 5310:5806e05346b8
comparison
equal deleted inserted replaced
5308:f370ccb15f05 5309:09656e2b4927
387 if not clients or #clients == 0 then 387 if not clients or #clients == 0 then
388 return true, "No clients associated with this account"; 388 return true, "No clients associated with this account";
389 end 389 end
390 390
391 local colspec = { 391 local colspec = {
392 { title = "Software", key = "software" }; 392 { title = "Software", key = "software", width = "1p" };
393 { title = "Last seen", key = "last_seen" }; 393 { title = "Last seen", key = "last_seen", width = 10 };
394 { title = "Authentication", key = "auth_methods" }; 394 { title = "Authentication", key = "auth_methods", width = "2p" };
395 }; 395 };
396 396
397 local row = require "util.human.io".table(colspec, self.session.width); 397 local row = require "util.human.io".table(colspec, self.session.width);
398 398
399 local print = self.session.print; 399 local print = self.session.print;
400 print(row()); 400 print(row());
401 print(string.rep("-", self.session.width));
401 for _, client in ipairs(clients) do 402 for _, client in ipairs(clients) do
402 print(row({ 403 print(row({
403 software = client.user_agent.software; 404 id = client.id;
405 software = client.user_agent and client.user_agent.software;
404 last_seen = os.date("%Y-%m-%d", client.last_seen); 406 last_seen = os.date("%Y-%m-%d", client.last_seen);
405 auth_methods = array.collect(it.keys(client.active)):sort(); 407 auth_methods = array.collect(it.keys(client.active)):sort();
406 })); 408 }));
407 end 409 end
408 print(("%d clients"):format(#clients)); 410 print(string.rep("-", self.session.width));
411 return true, ("%d clients"):format(#clients);
409 end 412 end
410 end); 413 end);