Content added Content deleted
(Created page with "local getArgs = require('Module:Arguments').getArgs local DatatableBuilder = require('Module:DatatableBuilder') local QueryBuilder = require('Module:QueryBuilder') local p = {} local function formatLogo(logo) return string.format('192px', logo) end local function formatName(pageName, eventName) return string.format('%s', pageName, eventName) end local function formatDuration(start_dt, end_dt) if start_dt and end_dt then return str...") |
No edit summary |
||
(31 intermediate revisions by the same user not shown) | |||
Line 2: | Line 2: | ||
local DatatableBuilder = require('Module:DatatableBuilder') |
local DatatableBuilder = require('Module:DatatableBuilder') |
||
local QueryBuilder = require('Module:QueryBuilder') |
local QueryBuilder = require('Module:QueryBuilder') |
||
local DisplayFns = require('Module:DisplayFunctions') |
|||
local ProcessingFns = require('Module:ProcessingFunctions') |
|||
local p = {} |
local p = {} |
||
local function |
local function formatName(pageName, gachaName) |
||
return string.format('[[ |
return string.format('[[%s|%s]]', pageName, gachaName) |
||
end |
end |
||
local function |
local function formatRateUp(ids) |
||
if ids == nil then return nil end |
|||
return string.format('[[%s|%s]]', pageName, eventName) |
|||
end |
|||
local qb = QueryBuilder.new() |
|||
qb |
|||
local function formatDuration(start_dt, end_dt) |
|||
:setTables('cards') |
|||
if start_dt and end_dt then |
|||
:setFields([[ |
|||
return string.format( |
|||
_pageName, |
|||
'Start: %s <br> End: %s', |
|||
thumbnail |
|||
]]) |
|||
:addWhereList('card_id', '=', ids, ',', 'OR') |
|||
) |
|||
:setOrderBy('card_id ASC') |
|||
local results = qb:query() |
|||
if results and #results > 0 then |
|||
local content = '' |
|||
for _, card in ipairs(results) do |
|||
content = content .. string.format( |
|||
'[[File:%s|80px|link=%s]] ', |
|||
card.thumbnail, |
|||
card._pageName |
|||
) |
|||
end |
|||
local wrapper = mw.html.create('div') |
|||
wrapper |
|||
:css({ |
|||
['display'] = 'flex', |
|||
['flex-wrap'] = 'wrap', |
|||
['gap'] = '5px' |
|||
}) |
|||
:wikitext(content) |
|||
return tostring(wrapper) |
|||
end |
end |
||
end |
end |
||
Line 26: | Line 54: | ||
function p.main(frame) |
function p.main(frame) |
||
local args = getArgs(frame) |
local args = getArgs(frame) |
||
local columns = args['columns'] |
|||
local qb = QueryBuilder.new() |
local qb = QueryBuilder.new() |
||
qb |
qb |
||
:setTables(' |
:setTables('gachas, gacha_rate_up') |
||
:setFields([[ |
:setFields([[ |
||
_pageName, |
gachas._pageName, |
||
gacha_name, |
gachas.gacha_name, |
||
gachas.logo, |
|||
DATE_FORMAT(DATE_ADD( |
DATE_FORMAT(DATE_ADD(gachas.start_date, INTERVAL 9 HOUR), "%Y/%m/%d, %H:%i JST") = start_date, |
||
DATE_FORMAT(DATE_ADD( |
DATE_FORMAT(DATE_ADD(gachas.end_date, INTERVAL 9 HOUR), "%Y/%m/%d, %H:%i JST") = end_date, |
||
gachas.seal, |
|||
gacha_rate_up.ids |
|||
]]) |
]]) |
||
:setJoinOn('gachas._pageID = gacha_rate_up._pageID') |
|||
:addWhere('gacha_id', '>', 0) |
|||
: |
:addWhere('gachas.gacha_id', '>', 0) |
||
:setOrderBy('gachas.start_date ASC, gachas.gacha_id ASC') |
|||
:setGroupBy('_pageName') |
|||
:setGroupBy('gachas._pageName') |
|||
:setLimit(200) |
|||
:setLimit(200) |
|||
qb |
|||
:addWhere('start_date', '<', args['start before']) |
|||
:addWhere('start_date', '>', args['start after']) |
|||
:addWhere('end_date', '<', args['end before']) |
|||
:addWhere('end_date', '>', args['end after']) |
|||
:addWhereList( |
|||
'gacha_type', |
|||
'=', |
|||
args['type'], |
|||
',', |
|||
'OR' |
|||
) |
|||
:addWhereList( |
|||
'seal', |
|||
'=', |
|||
args['seal'], |
|||
',', |
|||
'OR' |
|||
) |
|||
local datatable = DatatableBuilder.new() |
local datatable = DatatableBuilder.new() |
||
datatable |
datatable |
||
:setColumns{ |
:setColumns{ |
||
{ |
|||
{ name = 'logo', header = 'Logo', data_fields = { 'image' }, func = formatLogo }, |
|||
name = 'logo', |
|||
{ name = 'name', header = 'Gacha', data_fields = { '_pageName', 'gacha_name' }, func = formatName }, |
|||
header = 'Logo', |
|||
{ name = 'duration', header = 'Gacha period', data_fields = { 'start', 'end' }, func = formatDuration, css = { ['white-space'] = 'nowrap' } }, |
|||
dataFields = { 'gachas.logo' }, |
|||
} |
|||
fn = DisplayFns.image('192px'), |
|||
:setHeaders{ |
|||
css = { ['width'] = '192px' }, |
|||
'logo', |
|||
sortable = false |
|||
'name', |
|||
}, |
|||
{ |
|||
name = 'name', |
|||
header = 'Gacha', |
|||
dataFields = { 'gachas._pageName', 'gachas.gacha_name' }, |
|||
fn = formatName, |
|||
css = { ['min-width'] = '150px' }, |
|||
}, |
|||
{ |
|||
name = 'start', |
|||
header = 'Start date', |
|||
dataFields = { 'start_date' }, |
|||
css = { ['white-space'] = 'nowrap' }, |
|||
visible = false |
|||
}, |
|||
{ |
|||
name = 'end', |
|||
header = 'End date', |
|||
dataFields = { 'end_date' }, |
|||
css = { ['white-space'] = 'nowrap' }, |
|||
visible = false |
|||
}, |
|||
{ |
|||
name = 'seal', |
|||
header = 'Seal type', |
|||
dataFields = { 'gachas.seal' }, |
|||
visible = false |
|||
}, |
|||
{ |
|||
name = 'rate up', |
|||
header = 'Rate up cards', |
|||
dataFields = { 'gacha_rate_up.ids' }, |
|||
fn = formatRateUp, |
|||
default = '', |
|||
css = { ['min-width'] = '275px' }, |
|||
visible = false |
|||
} |
|||
} |
} |
||
:setData(qb:query()) |
:setData(qb:query()) |
||
columns = ProcessingFns.stringToArray(',')(columns) |
|||
if columns and #columns > 0 then |
|||
for _, column in ipairs(columns) do |
|||
datatable:setColumnVisibility(column, true) |
|||
end |
|||
end |
|||
return datatable:tostring() |
return datatable:tostring() |
||
end |
end |
||
Latest revision as of 15:14, 2 May 2023
This module depends on the following other modules: |
To generate {{Gacha datatable}}, invoke using the main function.
local getArgs = require('Module:Arguments').getArgs
local DatatableBuilder = require('Module:DatatableBuilder')
local QueryBuilder = require('Module:QueryBuilder')
local DisplayFns = require('Module:DisplayFunctions')
local ProcessingFns = require('Module:ProcessingFunctions')
local p = {}
local function formatName(pageName, gachaName)
return string.format('[[%s|%s]]', pageName, gachaName)
end
local function formatRateUp(ids)
if ids == nil then return nil end
local qb = QueryBuilder.new()
qb
:setTables('cards')
:setFields([[
_pageName,
thumbnail
]])
:addWhereList('card_id', '=', ids, ',', 'OR')
:setOrderBy('card_id ASC')
local results = qb:query()
if results and #results > 0 then
local content = ''
for _, card in ipairs(results) do
content = content .. string.format(
'[[File:%s|80px|link=%s]] ',
card.thumbnail,
card._pageName
)
end
local wrapper = mw.html.create('div')
wrapper
:css({
['display'] = 'flex',
['flex-wrap'] = 'wrap',
['gap'] = '5px'
})
:wikitext(content)
return tostring(wrapper)
end
end
function p.main(frame)
local args = getArgs(frame)
local columns = args['columns']
local qb = QueryBuilder.new()
qb
:setTables('gachas, gacha_rate_up')
:setFields([[
gachas._pageName,
gachas.gacha_name,
gachas.logo,
DATE_FORMAT(DATE_ADD(gachas.start_date, INTERVAL 9 HOUR), "%Y/%m/%d, %H:%i JST") = start_date,
DATE_FORMAT(DATE_ADD(gachas.end_date, INTERVAL 9 HOUR), "%Y/%m/%d, %H:%i JST") = end_date,
gachas.seal,
gacha_rate_up.ids
]])
:setJoinOn('gachas._pageID = gacha_rate_up._pageID')
:addWhere('gachas.gacha_id', '>', 0)
:setOrderBy('gachas.start_date ASC, gachas.gacha_id ASC')
:setGroupBy('gachas._pageName')
:setLimit(200)
qb
:addWhere('start_date', '<', args['start before'])
:addWhere('start_date', '>', args['start after'])
:addWhere('end_date', '<', args['end before'])
:addWhere('end_date', '>', args['end after'])
:addWhereList(
'gacha_type',
'=',
args['type'],
',',
'OR'
)
:addWhereList(
'seal',
'=',
args['seal'],
',',
'OR'
)
local datatable = DatatableBuilder.new()
datatable
:setColumns{
{
name = 'logo',
header = 'Logo',
dataFields = { 'gachas.logo' },
fn = DisplayFns.image('192px'),
css = { ['width'] = '192px' },
sortable = false
},
{
name = 'name',
header = 'Gacha',
dataFields = { 'gachas._pageName', 'gachas.gacha_name' },
fn = formatName,
css = { ['min-width'] = '150px' },
},
{
name = 'start',
header = 'Start date',
dataFields = { 'start_date' },
css = { ['white-space'] = 'nowrap' },
visible = false
},
{
name = 'end',
header = 'End date',
dataFields = { 'end_date' },
css = { ['white-space'] = 'nowrap' },
visible = false
},
{
name = 'seal',
header = 'Seal type',
dataFields = { 'gachas.seal' },
visible = false
},
{
name = 'rate up',
header = 'Rate up cards',
dataFields = { 'gacha_rate_up.ids' },
fn = formatRateUp,
default = '',
css = { ['min-width'] = '275px' },
visible = false
}
}
:setData(qb:query())
columns = ProcessingFns.stringToArray(',')(columns)
if columns and #columns > 0 then
for _, column in ipairs(columns) do
datatable:setColumnVisibility(column, true)
end
end
return datatable:tostring()
end
return p