Module:Listings

From Eli's Software Encyclopedia

The datatable SearchPanes view built in the SemanticResultFormats is extremely buggy. So, we created this view from scratch using the original datatables. Other resources involved:


local utils = require('Module:Utils')

local p = {}

local function formatField(value)
	local val = ''
    if type(value) == 'table' then
    	val = table.concat(value, ';')
    else
    	val = value
    end
    return val
end

function p.titles(frame)
    local args      = frame.args
    local title     = mw.title.getCurrentTitle()
    local publisher = args[1] or title.text

    local titles = mw.smw.ask {
    	'[[Publisher name::' .. publisher .. ']]' ..
        '[[Modification date::+]] ' ..
        'OR ' .. 
        '[[Developer::' .. publisher .. ']]' ..
        '[[Modification date::+]]',
        'mainlabel=-',
        '?#-=Title',
        '?Has Title#-=Short',
        '?Release#-=Release',
        '?Copyright Date=Date',
        '?Publisher name=Publisher',
		'?Publisher name#-=PublisherFilter',
        '?Developer=Developer',
        '?Developer#-=DeveloperFilter',
        '?Digital Media#-=Media',
        '?Platform#-=Platform',
        '?Genre#-=Genre',
        '?Software Packaging#-=Packaging',
        'limit=5000'
    } or {}
    
	local html = mw.html.create()

	if #titles > 0 then
		--html:tag('h2')
		--	:wikitext('Titles by ' .. publisher ..  ' on Elisoftware')
			
		local datatable = html:tag('table')
			:addClass('publisherTitles smwtable-clean compact display')
    	local row = ''
    	
		for _, item in ipairs(titles) do
			local page = tostring(item['Title'])
			local displaytitle = formatField(item['Short']) or page or 'Title'
			row = datatable:tag('tr')
    		row:tag('td'):wikitext(string.format('[[%s|%s]]', page, tostring(displaytitle)))
    		row:tag('td'):wikitext(item['Release'])
    		row:tag('td'):wikitext(item['Date'])
    		row:tag('td'):wikitext(formatField(item['Publisher']))
    		row:tag('td'):wikitext(formatField(item['PublisherFilter']))
    		row:tag('td'):wikitext(formatField(item['Developer']))
    		row:tag('td'):wikitext(formatField(item['DeveloperFilter']))
    		row:tag('td'):wikitext(formatField(item['Media']))
    		row:tag('td'):wikitext(formatField(item['Platform']))
    		row:tag('td'):wikitext(formatField(item['Genre']))
    		row:tag('td'):wikitext(formatField(item['Packaging']))
		end
	end
	
    return html
end

return p