Модуль:Бланки

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

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

Модуль предназначен для реализации шаблона {{Бланки}} 


local p={}

function p.Cases( frame )
	local cases = mw.loadData( 'Модуль:Бланки/Данные' )
	local outres, toc = {}, {}
	outres[1] = '' -- for toc
	outres[2] = '<table class="table table-hover" width=100%><tr style="background-color:#8d6cbf;font-weight:bold;text-align:center"><td>№</td><td>Ситуация</td><td>Пояснение</td></tr>'
	for i, chap in ipairs( cases ) do
		outres[#outres+1] = '<tr  style="background-color:#cfacf7"><td style="font-weight:bold">' .. chap.id .. '</td><td style="font-weight:bold"><span id="chap'
			.. string.sub ('0' .. i, -2, -1) .. '"></span>' .. chap.title .. '</td><td style="font-size:83%; line-height:105%;">' .. (chap.comment or '') .. '</td></tr>'
		toc[#toc+1] = '* [[#chap'.. string.sub ('0' .. i, -2, -1) .. '|' .. chap.title .. ']] — ' .. (chap.comment or '') .. '\n'

		for _, case in ipairs( chap.cases ) do
			outres[#outres+1] = '<tr><td>' .. chap.id .. case.id .. '</td><td>' .. case.title
			for _, tpt in ipairs( case.templates ) do
				if tpt.poses then
					-- если есть варианты жалоб для отдельных статусов, то badge содержит текст-заголовок
					if tpt.badge then
						outres[#outres+1] = '&nbsp; &nbsp;<span style="font-weight:bold; font-style:italic">' .. tpt.badge .. ':&nbsp;</span>'
					end
					for _, tptv in pairs( tpt.poses ) do
						outres[#outres+1] = ' [[' .. tptv.title .. '|<span class="badge badge-primary">' .. tptv.badge .. '</span>]]'
					end
				else
					outres[#outres+1] = ' [[' .. tpt.title .. '|<span class="badge badge-primary">' .. tpt.badge .. '</span>]]'
				end
				if tpt.regions then
					outres[#outres+1] = '&nbsp; <span class="fas fa-share-alt" title="есть региональные варианты"></span>'
				end
			end
			outres[#outres+1] = '</td><td style="font-size:83%; line-height:105%;">' .. (case.comment or '') .. '</td></tr>'
		end
	end
	outres[1] = table.concat( toc )
	outres[#outres+1] = '</table>'
	return table.concat( outres )
end

function p.Templates( frame )
	local function printCell( tpt, withPage )
		if not tpt then
			return ''
		end
		local name = tpt.title
		local res = {}
		if withPage then
			res[#res+1] = ' [[Файл:Fam-page.png|link=' .. name .. ']]'
		end
		local fiti = mw.title.new (name .. '.pdf', 'File')
		if fiti.id ~= 0 then
			res[#res+1] = ' [[Файл:Icons-mini-file acrobat.png|Распечатать бланк для рукописного заполнения|link=' .. frame:callParserFunction('filepath', name .. '.pdf') .. ']]'
		end
		fiti = mw.title.new (name .. '!.doc', 'File')
		if fiti.id ~= 0 then
			res[#res+1] = ' [[Файл:Page word.png|Загрузить шаблон для редактирования|link=' .. frame:callParserFunction('filepath', name .. '!.doc') .. ']]'
		end
		return table.concat( res )
	end

	local columns = { 'prg',  'nabl',  'smi',  'other' }
	local coltext = { 'ПРГ,', 'набл,', 'СМИ,', 'любой,' }

	local cases = mw.loadData( 'Модуль:Бланки/Данные' )
	local outres, toc = {}, {}
	outres[1] = '' -- for toc
	outres[2] = '<table class="standard sortable" width=100%><tr><th>№</th><th>Документ</th><th>файл</th><th>ПРГ</th><th>набл</th><th>СМИ</th><th>иное</th><th>Пояснение</th></tr>'
	for i, chap in ipairs( cases ) do
		outres[#outres+1] = '<tr style="background-color:#efd7fa"><td style="font-weight:bold">'
			.. chap.id .. '</td><td  style="font-weight:bold"><span id="chap'
			.. string.sub ('0' .. i, -2, -1) .. '"></span>' .. chap.title
			.. '</td><td></td><td></td><td></td><td></td><td></td><td style="font-size:83%; line-height:105%;">'
			.. (chap.comment or '') .. '</td></tr>'
		toc[#toc+1] = '* [[#chap'.. string.sub ('0' .. i, -2, -1) .. '|' .. chap.title .. ']] — ' .. (chap.comment or '') .. '\n'

		for _, case in ipairs( chap.cases ) do
--			outres[#outres+1] = '<tr><td>' .. chap.id .. case.id .. '</td><td>' .. case.title
--			.. '</td><td></td><td></td><td></td><td></td><td></td><td style="font-size:83%; line-height:105%;">'
--			.. (case.comment or '') .. '</td></tr>'

			for _, tpt in ipairs( case.templates ) do
				local ourposes = ''
				outres[#outres+1] = '<tr><td>' .. chap.id .. case.id
				if tpt.id then
					outres[#outres+1] = '.' .. tpt.id
				end
				outres[#outres+1] = '</td><td>'
				if not tpt.poses then
					outres[#outres+1] = '[[' .. tpt.title .. ']]'
					ourposes = frame:callParserFunction('#show', {tpt.title, '?Пользователь документа' }) .. ', '
				elseif tpt.poses.all then
					outres[#outres+1] = '[[' .. tpt.poses.all.title .. ']]' -- вообще-то они должны совпадать
				else
					outres[#outres+1] = tpt.title
				end
				outres[#outres+1] = '</td><td align=center>'
				local uni
				if tpt.poses then
					uni = tpt.poses.all
				else
					uni = tpt
				end
				outres[#outres+1] = printCell( uni )
				if tpt.regions then
					outres[#outres+1] = ' <span class="fas fa-share-alt" title="есть региональные варианты"></span>'
				end

				for k, who in ipairs( columns ) do
					if tpt.poses then
						outres[#outres+1] = '</td><td align=center>' .. printCell( tpt.poses[who], true )
					elseif mw.ustring.find (ourposes, coltext[k], 1, true) then
						outres[#outres+1] = '</td><td align=center>[[Файл:Galochka-check 32x32.png|16px|text-bottom|link=]]'
					else
						outres[#outres+1] = '</td><td align=center>'
					end
				end

				outres[#outres+1] = '</td><td style="font-size:83%; line-height:105%;">' .. ( tpt.comment or case.comment or '' ) .. '</td></tr>'
			end
		end
	end
	outres[1] = table.concat( toc )
	outres[#outres+1] = '</table>'
	return table.concat( outres )
end

function p.getNumber( name )
	local function idtpt( id )
		if id then
			return '.' .. id
		end
		return ''
	end
	local codes = {
		prg = 'прг',
		nabl = 'набл',
		smi = 'сми',
		other = 'др',
	}
	local function code( who, pose )
		local code = pose.code or codes[who]
		if code then
			return '(' .. code .. ')'
		end
		return ''
	end

	local cases = mw.loadData( 'Модуль:Бланки/Данные' )
	for _, chap in ipairs( cases ) do
		for _, case in ipairs( chap.cases ) do
			for _, tpt in ipairs( case.templates ) do
				if tpt.title == name and not tpt.poses then
					return chap.id .. case.id .. idtpt( tpt.id ), 0, nil, tpt
				end
				if tpt.poses then
					for who, pose in pairs( tpt.poses ) do
						if pose.title == name then
							return chap.id .. case.id .. idtpt( tpt.id ) .. code( who, pose ), 1, tpt, pose
						end
					end
				end
				if tpt.regions then
					for _, reg in pairs( tpt.regions ) do
						if reg.title == name then
							return chap.id .. case.id .. idtpt( tpt.id ) .. '/' .. reg.id, 2, tpt, reg
						end
					end
				end
			end
		end
	end
	return '<span class=error>Нет номера</span>'
end

return p