Content added Content deleted
m (add no-wrap) |
No edit summary |
||
Line 93: | Line 93: | ||
datatable |
datatable |
||
:setColumns{ |
:setColumns{ |
||
⚫ | |||
{ name = 'id', header = 'ID', data_fields = { 'event_id' } }, |
|||
name = 'id', |
|||
{ name = 'logo', header = 'Logo', data_fields = { 'image' }, func = formatLogo }, |
|||
header = 'ID', |
|||
{ name = 'name', header = 'Event', data_fields = { '_pageName', 'event_name' }, func = formatName }, |
|||
dataFields = { 'event_id' } |
|||
{ name = 'unit', header = 'Unit focus', data_fields = { 'unit_focus' }, func = formatUnit, css = { ['white-space'] = 'nowrap' } }, |
|||
}, |
|||
{ name = 'duration', header = 'Event period', data_fields = { 'start', 'end' }, func = formatDuration, css = { ['white-space'] = 'nowrap' } }, |
|||
{ |
|||
{ name = 'characters', header = 'Bonus characters', data_fields = { 'characters' }, func = formatCharacters }, |
|||
name = 'logo', |
|||
{ name = 'attribute', header = 'Bonus attribute', data_fields = { 'attribute' }, func = formatAttribute, css = { ['white-space'] = 'nowrap' } }, |
|||
header = 'Logo', |
|||
dataFields = { 'image' }, |
|||
⚫ | |||
func = formatLogo |
|||
:setHeaders{ |
|||
}, |
|||
{ |
|||
'name', |
name = 'name', |
||
' |
header = 'Event', |
||
dataFields = { '_pageName', 'event_name' }, |
|||
⚫ | |||
func = formatName |
|||
⚫ | |||
}, |
|||
{ |
|||
name = 'unit', |
|||
header = 'Unit focus', |
|||
dataFields = { 'unit_focus' }, |
|||
func = formatUnit, |
|||
css = { ['white-space'] = 'nowrap' } |
|||
}, |
|||
{ |
|||
⚫ | |||
header = 'Event period', |
|||
dataFields = { 'start', 'end' }, |
|||
func = formatDuration, |
|||
css = { ['white-space'] = 'nowrap' } |
|||
}, |
|||
{ |
|||
⚫ | |||
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()) |
:setData(qb:query()) |
Revision as of 03:09, 4 February 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 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, ' ')
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
},
{
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 = '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