Content added Content deleted
m (fix nil issue) |
m (remove row chunking) |
||
Line 46: | Line 46: | ||
end |
end |
||
end |
end |
||
⚫ | |||
local res = {} |
|||
local chunkSize = 5 |
|||
for a=0,math.floor(#icon_tbl/chunkSize),1 do |
|||
local section = {} |
|||
for b=0,chunkSize-1,1 do |
|||
table.insert(section, icon_tbl[a * chunkSize + b + 1]) |
|||
end |
|||
table.insert(res, table.concat(section, ' ')) |
|||
end |
|||
⚫ | |||
end |
end |
||
Revision as of 00:25, 21 December 2021
Documentation for this module may be created at Module:Event datatable/doc
local getArgs = require('Module:Arguments').getArgs
local DatatableBuilder = require('Module:DatatableBuilder')
local QueryBuilder = require('Module:QueryBuilder')
local icons = require('Module:Icons')._main
local p = {}
local function formatLogo(logo)
return string.format('[[File:%s|192px]]', logo)
end
local function formatName(pageName, eventName)
return string.format('[[%s|%s]]', pageName, eventName)
end
local function formatUnit(unit)
if unit and unit ~= 'Mixed' then
return string.format(
'%s %s',
icons({ unit, size = '25px' }),
unit
)
end
return unit
end
local function formatDuration(start_dt, end_dt)
if start_dt and end_dt then
return string.format(
'Start: %s <br> End: %s',
start_dt,
end_dt
)
end
end
local function formatCharacters(characters)
local characters = mw.text.split(characters, ',')
local icon_tbl = {}
for _,x in ipairs(characters) do
local _icon = icons({ mw.text.trim(x), size = '45px' })
if _icon then
table.insert(icon_tbl, _icon)
end
end
return table.concat(icon_tbl, '<br>')
end
local function formatAttribute(attribute)
if attribute then
return string.format(
'%s %s',
icons({ attribute, size = '25px' }),
attribute
)
end
end
function p.main(frame)
local args = getArgs(frame)
local qb = QueryBuilder.new()
qb
:setTables('Events')
:setFields([[
event_id,
_pageName,
image,
event_name,
DATE_FORMAT(DATE_ADD(start, INTERVAL 9 HOUR), "%Y/%m/%d, %H:%i JST") = start,
DATE_FORMAT(DATE_ADD(end, INTERVAL 9 HOUR), "%Y/%m/%d, %H:%i JST") = end,
unit_focus,
type,
characters,
attribute
]])
:addWhere('event_id', '>', 0)
:setOrderBy('event_id ASC')
:setGroupBy('_pageName')
:setLimit(200)
qb
:addWhere('type', '=', args['type'])
:addWhere('start', '<', args['start before'])
:addWhere('start', '>', args['start after'])
:addWhere('end', '<', args['end before'])
:addWhere('end', '>', args['end after'])
local datatable = DatatableBuilder.new()
datatable
:setColumns{
{ name = 'id', header = 'ID', data_fields = { 'event_id' } },
{ name = 'logo', header = 'Logo', data_fields = { 'image' }, func = formatLogo },
{ name = 'name', header = 'Event', data_fields = { '_pageName', 'event_name' }, func = formatName },
{ name = 'unit', header = 'Unit focus', data_fields = { 'unit_focus' }, func = formatUnit },
{ name = 'duration', header = 'Event period', data_fields = { 'start', 'end' }, func = formatDuration },
{ name = 'characters', header = 'Bonus characters', data_fields = { 'characters' }, func = formatCharacters },
{ name = 'attribute', header = 'Bonus attribute', data_fields = { 'attribute' }, func = formatAttribute },
{ name = 'type', header = 'Type', data_fields = { 'type' } },
}
:setHeaders{
'id',
'logo',
'name',
'unit',
'duration',
'characters',
'attribute',
'type'
}
:setData(qb:query())
return datatable:tostring()
end
return p