comparison mod_client_management/mod_client_management.lua @ 5371:b2d51c6ae89a

mod_client_management: Move table cell formatting into column specification It's only more lines because of lua-format!
author Kim Alvefur <zash@zash.se>
date Wed, 26 Apr 2023 11:55:55 +0200
parents d9d52ad8c1ae
children 2d8076577e14
comparison
equal deleted inserted replaced
5370:d9d52ad8c1ae 5371:b2d51c6ae89a
417 if not clients or #clients == 0 then 417 if not clients or #clients == 0 then
418 return true, "No clients associated with this account"; 418 return true, "No clients associated with this account";
419 end 419 end
420 420
421 local colspec = { 421 local colspec = {
422 { title = "Software", key = "software", width = "1p" }; 422 {
423 { title = "Last seen", key = "last_seen", width = 10 }; 423 title = "Software";
424 { title = "Authentication", key = "auth_methods", width = "2p" }; 424 key = "software";
425 width = "1p";
426 mapper = function(user_agent)
427 return user_agent and user_agent.software;
428 end;
429 };
430 {
431 title = "Last seen";
432 key = "last_seen";
433 width = 10;
434 mapper = function(last_seen)
435 return os.date("%Y-%m-%d", last_seen);
436 end;
437 };
438 {
439 title = "Authentication";
440 key = "active";
441 width = "2p";
442 mapper = function(active)
443 return array.collect(it.keys(active)):sort():concat(", ");
444 end;
445 };
425 }; 446 };
426 447
427 local row = require "util.human.io".table(colspec, self.session.width); 448 local row = require "util.human.io".table(colspec, self.session.width);
428 449
429 local print = self.session.print; 450 local print = self.session.print;
430 print(row()); 451 print(row());
431 print(string.rep("-", self.session.width)); 452 print(string.rep("-", self.session.width));
432 for _, client in ipairs(clients) do 453 for _, client in ipairs(clients) do
433 print(row({ 454 print(row(client));
434 id = client.id;
435 software = client.user_agent and client.user_agent.software;
436 last_seen = os.date("%Y-%m-%d", client.last_seen);
437 auth_methods = array.collect(it.keys(client.active)):sort():concat(", ");
438 }));
439 end 455 end
440 print(string.rep("-", self.session.width)); 456 print(string.rep("-", self.session.width));
441 return true, ("%d clients"):format(#clients); 457 return true, ("%d clients"):format(#clients);
442 end 458 end
443 end); 459 end);