Модуль:Дорожная карта 2016
Материал из Справочника наблюдателя
Описание модуля[]
Документация отсутствует!
Вы можете создать документацию ( создать ).
Задавайте категории на странице документации, а не здесь! Показать подстраницы
Задавайте категории на странице документации, а не здесь! Показать подстраницы
local p = {}
local global = mw.ext.luaglobal
local family = 'Дорожная карта 2016'
local tab = mw.loadData( 'Модуль:' .. family .. '/Параметры')
local billModule = require ('Модуль:Ссылки на закон')
global.strict( true )
local function defValue( val, def )
if ( val or '' ) == '' then
return def
end
return val
end
--local Err = {}
--local function outputErr( s )
-- Err[#Err+1] = '<p class="error">' .. s .. '</p>'
--end
local function err( s )
return '<p class="error">' .. s .. '</p>'
end
function p.Start( frame )
local args = frame:getParent().args
local param = {}
param.method = mw.ustring.lower( defValue( args['подсчет'], 'ручной' ))
if not tab.methods [param.method] then
return err( 'Ошибка: недопустимое значение параметра «подсчет»' )
elseif type( tab.methods[param.method] ) == 'string' then
param.method = tab.methods[param.method]
end
param.code = defValue( args['код'], 'все' )
param.elections = tonumber (args ['кампаний'] or 1) or 1
if param.elections < 1 then
param.elections = '1'
end
param.constituencies = args ['округов'] or ''
if param.constituencies == 'нет' or param.constituencies == '1' then
param.constituencies = ''
end
param.twitter = defValue (args ['твиттер'], 'выборы')
param.twitter = mw.ustring.gsub (param.twitter, '#', '')
param.appearance = mw.ustring.lower( defValue( args['вид'], 'экран' ) )
if not tab.formats[param.appearance] then
return err( 'Ошибка: недопустимое значение параметра «вид»' )
end
param.flags = args['условия'] or ''
param.candidates = args['кандидатов'] or ''
param.sms = args['смс'] or ''
local pageName = mw.title.getCurrentTitle().baseText
local pageCity, pageReg, pageDate = mw.ustring.match( pageName, '^(.+) %((.+)%)%, (%d%d%.%d%d%.%d%d%d%d)' )
if not pageCity then
pageCity, pageDate = mw.ustring.match( pageName, '^(.+)%, (%d%d%.%d%d%.%d%d%d%d)' )
pageReg = ''
end
param.city = defValue( args ['место'], pageCity or '' )
param.reg = defValue( args ['регион'], pageReg or '' )
param.date = defValue( args['дата'], pageDate or '' )
local d,m,y = mw.ustring.match( param.date, '^(%d%d)%.(%d%d)%.(%d%d%d%d)$' )
if d then
local months = { 'января', 'февраля', 'марта', 'апреля', 'мая', 'июня', 'июля', 'августа', 'сентября', 'октября', 'ноября', 'декабря' }
d = tonumber (d)
m = months [tonumber(m)]
y = tonumber (y)
param.date = d .. ' ' .. m .. ' ' .. y .. ' года'
end
global.set( 'RMparam', param )
if tab.formats[param.appearance] == 'Просмотр' then
return tostring( mw.uri.fullUrl( family,
{ code = param.code,
method = param.method,
flags = param.flags,
} ) )
end
return frame:expandTemplate{
title = family .. '/' .. tab.formats[param.appearance].format, args = param }
end
p['Шапка обычной формы'] = function ( frame )
local param = global.get( 'RMparam' )
local res = [[
<table class="nwrm-hdr">
<tr>
<td class="nwrm-hdr-title">ДОРОЖНАЯ КАРТА</td>
<td class="nwrm-hdr-space"> </td>
<td class="nwrm-hdr-date">]] .. param.date .. [[</td>
<td class="nwrm-hdr-space"> </td>
<td class="nwrm-hdr-city">]] .. param.city .. '<span class="nwrm-hdr-reg"><br>' .. param.reg .. '</span></td>'
if param.constituencies ~= '' then
res = res .. [[
<td class="nwrm-hdr-space"> </td>
<td class="nwrm-hdr-constituency">№ округа</td>]]
end
res = res .. [[
<td class="nwrm-hdr-space"> </td>
<td class="nwrm-hdr-district">№ УИК</td>
</tr>
</table>
<table class="rm-2col">
<tr>
<td><p class="nwrm-hdr-c">∇ <i>nablawiki.ru, 2016. Концепция К−З−К, 2012</i></p></td>
<td><p class="nwrm-hdr-type">]] .. param.method ..[[</p></td>
</tr>
</table>
]]
return res
end
p['Заголовок основной таблицы'] = function ( frame )
local param = global.get( 'RMparam' )
local appearance = param.appearance
local format = tab.formats[appearance].format
local rowspan = ' rowspan=2'
if appearance == 'новая' then
rowspan = ''
end
local res = [[
<table class="rm">
<tr>
<th]] .. rowspan .. [[><p class="rmp-th">Контролируемое событие</p></th>
]]
if format.format ~= 'Просмотр' then
res = res .. [[
<th]] .. rowspan .. [[><p class="rmp-th">кол-во/<br>время</p></th>
]]
end
if appearance == 'компактная' then -- прежняя обычная
res = res .. [[
<th]] .. rowspan .. [[><p class="rmp-th">да</p></th>
<th]] .. rowspan .. [[><p class="rmp-th">нет</p></th>
]]
end
if appearance ~= 'новая' then
res = res .. [[
<th colspan=2 style="border-bottom:0; "><p class="rmp-th" style="text-align:right; ">Куда писать жалобу</p></th>
]]
else
res = res .. [[
<th ><p class="rmp-th">Каким законом установлено</p></th>
]]
end
res = res .. [[
<th]] .. rowspan .. [[><p class="rmp-th">Норма об отв-сти</p></th>
]]
if format == 'Просмотр' then
res = res .. [[
<th]] .. rowspan .. [[><p class="rmp-th">Полезные ссылки</p></th>
]]
end
if appearance ~= 'новая' then
res = res .. [[
</tr>
<tr>
<th ><p class="rmp-th">Каким законом установлено</p></th>
<th style="border-top:0"><p class="rmp-th"> </p></th>
]]
end
return res .. [[
</tr>
]]
end
p['Печать раздела'] = function ( frame )
-- Теперь это печать раздела целиком, а не только заголовка!!!
local ownArgs = frame.args
local gArgs = frame:getParent().args
local code, method, view, flags, chapter = gArgs.code, gArgs.method, gArgs.view, gArgs.flags, gArgs.chapter
if not tab.methods [method].incC then
return ''
end
if view ~= 'Блокнот' then
return ' <tr>\n <td class="rm-section" colspan=' .. tab.formats[view].cols .. '><p class="rmp-section">' .. ownArgs [1] .. '</p></td>\n </tr>\n'
else
return [[
<tr style="page-break-inside: avoid; ">
<td class="rm-section" colspan=]] .. tab.formats[view].cols .. '><p style="page-break-after:avoid; "><span class="rm-section-t"> ' .. mw.text.trim (ownArgs [1]) .. [[. </span></p></td>
</tr>
<tr style="page-break-inside: avoid; ">
<th rowspan=2 ><p style="page-break-after:avoid; ">№</p></th>
<th rowspan=2 ><p style="page-break-after:avoid; ">Действие или событие</p></th>
<th rowspan=2 ><p style="page-break-after:avoid; ">Да?</p></th>
<th colspan=2 style="text-align:right; border-bottom:0; "><p style="page-break-after:avoid; ">Комиссия, куда жаловаться</p></th>
<th rowspan=2 ><p style="page-break-after:avoid; ">Ответственность</p></th>
</tr>
<tr>
<th ><p style="page-break-after:avoid; ">Норма</p></th>
<th style="border-top:0"><p style="page-break-after:avoid; "> </p></th>
</tr>
]]
end
end
local outRes = { '' } -- 1 строка для сообщений об ошибках
function p.Chapter( frame )
local chapters = global.get( 'RMchapters' ) or {}
local lines = global.get( 'RMlines' ) or {}
local chap = mw.title.getCurrentTitle().subpageText
chapters[chap] = #lines + 1
global.set( 'RMchapters', chapters )
return '<b>' .. chap .. '</b><br>'
end
function p.Branch( frame )
local args = frame:getParent().args
local lines = global.get( 'RMlines' ) or {}
local branch = mw.ustring.lower( args[1] or '' )
if branch == 'ручной' or branch == 'коиб' then
lines[#lines+1] = { branch = branch, name = args[2] }
return '<i>' .. branch .. ': ' .. args[2] .. '</i></br>'
end
global.set( 'RMlines', lines )
return err( 'Ветка для непредусмотренного способа подсчета: ' .. branch )
end
function p.Line( frame )
local args = frame:getParent().args
local lines = global.get( 'RMlines' ) or {}
local function bool( z )
local x = args[z]
if x == 'да' or x == 'есть' then
return true
end
if x == 'нет' or (x or '') == '' then
return false
end
outRes[#outRes+1] = err( 'Недопустимое значение параметра «' .. z .. ' = ' .. x ..'»' )
end
local regNo = ( args['кроме'] or '') ~= ''
if ( args['для'] or '') ~= '' and regNo then
outRes[#outRes+1] = err( 'Одновременно заданы параметры «для» и «кроме»' )
end
local record = {
event = args['событие'],
action = args['совет'],
field = bool( args['показатель'] ),
forKOIB = bool( args['дляКОИБ'] ),
situation = args['ТС'],
complaint = args['жалоба'],
KoAP = args['КоАП'],
UK = args['УК'],
regions = ( args['для'] or '' ) .. ( args['кроме'] or '' ),
regExcept = regNo,
condition = args['если'],
}
args['событие'], args['совет'], args['показатель'], args['дляКОИБ'],
args['ТС'], args['жалоба'], args['КоАП'], args['УК'], args['для'],
args['кроме'], args['если'] = nil
for key,value in pairs( args ) do
record[key] = value
end
lines[#lines+1] = record
global.set( 'RMlines', lines )
outRes[#outRes+1] = record.event .. '<br>'
return table.concat( outRes )
end
return p