Content added Content deleted
(using character icon module) |
mNo edit summary |
||
Line 117: | Line 117: | ||
dataFields = { 'unit_focus' }, |
dataFields = { 'unit_focus' }, |
||
func = formatUnit, |
func = formatUnit, |
||
css = { ['white-space'] = 'nowrap' } |
|||
}, |
|||
{ |
|||
name = 'start', |
|||
header = 'Start date', |
|||
dataFields = { 'start' }, |
|||
css = { ['white-space'] = 'nowrap' } |
css = { ['white-space'] = 'nowrap' } |
||
}, |
}, |
Revision as of 07:49, 15 March 2022
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 cicon = require('Module:Character icon')._main
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 = cicon({ mw.text.trim(x), size = '45px' })
if _icon then
table.insert(icon_tbl, _icon)
end
end
return table.concat(icon_tbl, ' ')
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',
dataFields = { 'event_id' }
},
{
name = 'logo',
header = 'Logo',
dataFields = { 'image' },
func = formatLogo,
sortable = false
},
{
name = 'name',
header = 'Event',
dataFields = { '_pageName', 'event_name' },
func = formatName
},
{
name = 'unit',
header = 'Unit focus',
dataFields = { 'unit_focus' },
func = formatUnit,
css = { ['white-space'] = 'nowrap' }
},
{
name = 'start',
header = 'Start date',
dataFields = { 'start' },
css = { ['white-space'] = 'nowrap' }
},
{
name = 'duration',
header = 'Event period',
dataFields = { 'start', 'end' },
func = formatDuration,
css = { ['white-space'] = 'nowrap' }
},
{
name = 'characters',
header = 'Bonus characters',
dataFields = { 'characters' },
func = formatCharacters
},
{
name = 'attribute',
header = 'Bonus attribute',
dataFields = { 'attribute' },
func = formatAttribute,
css = { ['white-space'] = 'nowrap' }
},
{
name = 'type',
header = 'Type',
dataFields = { 'type' }
},
}
:setData(qb:query())
return datatable:tostring()
end
return p