Модуль:Таблица ЦИК

Материал из Справочника наблюдателя
Перейти к:навигация, поиск

(i)      Описание модуля[]

Документация отсутствует!


local p = {}

p[''] = function ( frame )
	local doctypeClass = { '', 'style="background-color:#ffffd0"', 'style="background-color:#ffffd0"', 'style="background-color:#ffffd0"' }  -- e0e0ff
	local specialStyle = {
		['отм'] = { '<s>', '</s>' },
		['2011'] = { '<span class="badge badge-pill badge-secondary">2011</span>&nbsp; <span style="color:grey">', '</span>' },
		['2012'] = { '<span class="badge badge-pill badge-secondary">2012</span>&nbsp; <span style="color:grey">', '</span>' },
		['Ö']    = { '<span class="badge badge-pill badge-secondary">&nbsp;Ö&nbsp;</span>&nbsp; ', '' },
		['2016'] = { '<span class="badge badge-pill badge-secondary">2016</span>&nbsp; ', '' },
		['2018'] = { '<span class="badge badge-pill badge-success">2018</span>&nbsp; ', '' },
		['2019'] = { '<span class="badge badge-pill badge-secondary">2019</span>&nbsp; ', '' },
		['2020'] = { '<span class="badge badge-pill badge-secondary">2020</span>&nbsp; ', '' },
		['2021'] = { '<span class="badge badge-pill badge-danger">2021</span>&nbsp; ', '' },
-- warning желтый primary синий
		['|'] = { ' &nbsp;<span class="badge badge-pill badge-primary" style="float:right">', '</span>' },
	}	
--	local delete
	local special = {}
	local args = frame:getParent().args
	
	local link, title, add = mw.text.trim( args[1] or '' ), mw.text.trim( args[2] or '' ), args['доп']
	if  link == '' then
		return '<tr class="active>'
			.. '<td style="margin-top:0;margin-bottom:0;padding:0;line-height:90%; text-align:right;" '
			.. 'class="text-muted"><small><i>' .. title ..  '&nbsp;</i></small></td></tr>'
	end
	for k, v in ipairs( args ) do
		if mw.ustring.len( v ) < 15 then
			special[mw.text.trim( v )] = k
		end
	end
	if mw.ustring.len( title or '' ) < 15 then
		title = nil
	end
--[===[
	local deBUG = ' <small> (' .. (args[2] or '—') .. ')</small>'
	for k, v in pairs( special ) do
		args[v] = nil
		if v == 2 then
			deBUG = deBUG .. '---2---'
		end
		
	end
	if args[2] == 'отм' then
		deBUG = deBUG .. mw.dumpObject( special )
	end
--]===]	
--	if title == 'отм' then
--		title = nil
--		delete = true
--	else 
--		delete = args[3] == 'отм'
--	end
	
	local titlelink, titleattr = mw.ustring.match( link, '^(.+) %(([^)]+)%)$' )
	local doctype = 1
	if not titlelink then
		titlelink, titleattr = mw.ustring.match( link, '^(НПА:Письмо ЦИК)( от %d%d%.%d%d%.%d%d%d%d № ?[%d-−/]+)$' )
		if titlelink then
			doctype = 3
		else
			titlelink, titleattr = mw.ustring.match( link, '^(НПА:Постановление ЦИК России)( от %d%d%.%d%d%.%d%d%d%d № ?[%d-−/I]+)$' )
			if titlelink then
				doctype = 1
			else
				titlelink, titleattr = mw.ustring.match( link, '^(НПА:Выписка из протокола заседания ЦИК России)( от %d%d%.%d%d%.%d%d%d%d № ?[%d-−/I]+)$' )
				if titlelink then
					doctype = 2
				else
					titlelink, titleattr = mw.ustring.match( link, '^(НПА:Распоряжение председателя ЦИК России)( от %d%d%.%d%d%.%d%d%d%d № ?[%d-−]+р)$' )
					if titlelink then
						doctype = 4
					else
						return error( 'parsing «' .. link .. '»' )
					end
				end
			end
		end
	end
	if mw.ustring.sub( titlelink, 1, 4 ) == 'НПА:' then
		titlelink = mw.ustring.sub( titlelink, 5, -1 )
	end
	local titledate, titlenum = mw.ustring.match( titleattr, ' от (%d%d%.%d%d%.%d%d%d%d) № ?([%d-−/Iр]+)$' )
	if not titledate then
		return error( 'parse 2 «' .. titleattr .. '»<br>' )
	end
	local x1, x2, x3 = mw.ustring.match( titlenum, '^(%d+)/(%d+)[-−]([%dI]+)$' )
	local sortnum
	--[=[
	if not x1 then
		x1, x2, x3 = mw.ustring.match( titlenum, '^(%d+)[-−](%d+)[-−]([%dI]+)$' )
		doctype = 2
		if not x1 then
			x1, x2, x3 = mw.ustring.match( titlenum, '^(%d+)[-−](%d+)/([%dI]+)$' )
			doctype = 3
			if not x1 then
				return error( 'parse 3 «' .. titlenum .. '»<br>' )
			end
			sortnum = '9' .. mw.ustring.sub( '0000' .. x1, -4, -1 ) .. '9' .. mw.ustring.sub( '0000' .. x2, -4, -1 )
			titlenum = titlenum .. '**'
		else
			sortnum = '0' .. mw.ustring.sub( '0000' .. x1, -4, -1 ) .. '9' .. mw.ustring.sub( '0000' .. x2, -4, -1 )
			titlenum = titlenum .. '*'
		end
	else
		sortnum = '0' .. mw.ustring.sub( '0000' .. x1, -4, -1 ) .. '0' .. mw.ustring.sub( '0000' .. x2, -4, -1 )
	end
	if not tonumber( x3 ) then
		x3 = mw.ustring.len( x3 )
	end
	--]=]
	sortnum = 'x' .. mw.ustring.sub( titledate, 7, 10 ) .. mw.ustring.sub( titledate, 4, 5 ) .. mw.ustring.sub( titledate, 1, 2 )
--		.. mw.ustring.sub( '00' .. x3, -2, -1 ) .. sortnum
	title = title or titlelink
	for k, v in pairs( special ) do
		if specialStyle[k] then
			title = specialStyle[k][1] .. title .. specialStyle[k][2]
		else
			title = title .. specialStyle['|'][1] .. k .. specialStyle['|'][2]
		end
	end
--	if delete then
--		title = '<s>' .. title .. '</s>'
--	end
	if add then
		add = ' &nbsp; <small>' .. add .. '</small>'
	end
	return  '<tr ' .. doctypeClass [doctype] .. '><td data-sort-value="' .. sortnum .. '">' 
		.. '<span class="d-md-none d-inline-block" style="width: 85px; vertical-align: top; font-weight: bold">' .. titledate .. '</span>'
		.. '<span class="d-md-none d-inline-block" style="width: 130px; vertical-align: top; font-weight: bold">' .. titlenum .. '</span>'
		.. '<div class="d-none d-md-table-cell" style="display:table-cell; width:80px; vertical-align:top; ">' .. titledate .. '</div>'
		.. '<div class="d-none d-md-table-cell" style="display:table-cell; width:110px; vertical-align:top; ">' .. titlenum .. '</div>'
		.. '<div style="display:table-cell">[[' .. link .. '|' .. title .. ']]' .. ( add or '' ) .. '</div></td></tr>'
end

return p