Модуль:ArbCom Elections Calendar

Материал из Википедии — свободной энциклопедии
Перейти к навигации Перейти к поиску
Документация

Реализация шаблона {{Календарь выборов АК}}.

local p = {}
local frame = mw.getCurrentFrame()
local args = frame.args
-- основная функция
p.start = function()
local dt2 = {} -- параметр из шаблона (дата начала выборов)
dt2.y, dt2.m, dt2.d = string.match(args[1],"(%d%d%d%d)(%d%d)(%d%d)")
-- date of first monday
local monday
-- date of start
local startdate = os.time{year = dt2.y, month = dt2.m, day = dt2.d}
-- now
local nowdate = os.time()
local calend = {}
local com_order = {1,2,2,2,2,3,4,4,4,4,4,5,5,5,5,5,5,5,6,6,7,7,8,8,8,8,8,8,8,8,8} -- порядок выборов
local com_array = {}
--определим первый понедельник календаря
for i = 0,6 do
	if (os.date("*t", startdate - (24*60*60*(i))).wday == 2) then
	monday = startdate - (24*60*60*(i))
	end
end
-- разница в днях от понедельника до начала выборов
local diff = (startdate-monday)/(24*60*60)
-- составим массив всех дней календаря
local j=1;
for i=0,27 do
  calend[i] = os.date("%d", monday + (24*60*60*(i)))
  if i>=diff then -- что-то вроде аналога двумерного массива, чтобы порядок выборов прилепить к календарю
	com_array[i] = com_order[j]
	j=j+1
	else com_array[i] = 0
	end
end
local text = ''
for i=0,27 do
	local today = calend[i]
	local month = 14
	local monthNames = {'янв ', 'фев ', 'мар ', 'апр ', 'мая ', 'июн ', 'июл ', 'авг ', 'сен ', 'окт ', 'ноя ', 'дек ', 'янв ', ''}
	-- добавление подписи месяца к первому понедельнику и первому числу нового месяца
	if i==0 then month = os.date("*t", monday).month 
		elseif calend[i] == '01' then month = (os.date("*t", monday).month+1)
	end
	-- выделение сегодняшнего дня
	if (nowdate-monday)/(24*60*60) <= 28 and (nowdate-monday)/(24*60*60) >= -7 and nowdate>=monday then
		if os.date("%d", nowdate) == calend[i] then
			local templatelink = frame:expandTemplate{ title = 'Очищать кэш' }
			today = [[<span style="padding: 1px 3px; border: 2px solid #E30; background: rgba(238, 51, 0, 0.15)">]]..templatelink..calend[i]..[[</span>]]
		end
	end
	-- разукрашивание по порядку выборов
	if com_array[i] == 0 then -- дни до выборов
		text = text..[[|style="font-size:160%;background:inherit"|<div style="float:right;padding-right:0.3em;color:#AAA">''']]..monthNames[month]..today..[['''</div>
		]]
	elseif com_array[i] == 1 then -- уведомления
		text = text..[[|style="font-size:160%;background:#E0F0FF"|<div style="float:right;padding-right:0.3em;color:#333">''']]..monthNames[month]..today..[['''</div>
		]]
	elseif com_array[i] == 2 then -- выдвижение
		text = text..[[|style="font-size:160%;background:#FFFACD"|<div style="float:right;padding-right:0.3em;color:#333">''']]..monthNames[month]..today..[['''</div>
		]]
	elseif com_array[i] == 3 then -- самовыдвижение
		text = text..[[|style="font-size:160%;background:#FFFCE7"|<div style="float:right;padding-right:0.3em;color:#333">''']]..monthNames[month]..today..[['''</div>
		]]
	elseif com_array[i] == 4 then -- Обсуждение
		text = text..[[|style="font-size:160%;background:#AFA"|<div style="float:right;padding-right:0.3em;color:#333">''']]..monthNames[month]..today..[['''</div>
		]]
	elseif com_array[i] == 5 then -- голосование
		text = text..[[|style="font-size:160%;background:#87CEFA"|<div style="float:right;padding-right:0.3em;color:#333">''']]..monthNames[month]..today..[['''</div>
		]]
	elseif com_array[i] == 6 then -- Итоги
		text = text..[[|style="font-size:160%;background:#D8BFD8"|<div style="float:right;padding-right:0.3em;color:#333">''']]..monthNames[month]..today..[['''</div>
		]]
	elseif com_array[i] == 7 then -- Передача дел
		text = text..[[|style="font-size:160%;background:#FFE4E1"|<div style="float:right;padding-right:0.3em;color:#333">''']]..monthNames[month]..today..[['''</div>
		]]
	elseif com_array[i] == 8 then -- Следующий тур
		text = text..[[|style="font-size:160%;background:inherit"|<div style="float:right;padding-right:0.3em;color:#AAA">''']]..monthNames[month]..today..[['''</div>
		]]	
	end
	-- добавление подписей под числами
	if i == 6 then
	text = text..[[
	|-
	]].. p.comment(1,diff) ..[[
 	|-
	]]
	elseif i == 13 then
	text = text..[[
	|-
	]].. p.comment(2,diff) ..[[
 	|-
	]]
	elseif i == 20 then
	text = text..[[
	|-
	]].. p.comment(3,diff) ..[[
 	|-
	]]
	elseif i == 27 then
	text = text..[[
	|-
	]].. p.comment(4,diff) ..[[
 	|-
	]]
	end
end

return text
end

-- отдельная как бы функция наподобие switch для подписей под числами
p.comment = function(i,diff)
local tr = {'','','',''}
-- для удобства редактирования подписей
local notice = frame:expandTemplate{ title = 'comment', args = { 'Уведомление', 'Размещение на форуме и в шаблоне &#123;&#123;Актуально&#125;&#125; уведомления о выборах' } }
local nomination = frame:expandTemplate{ title = 'comment', args = { 'Выдвижение', 'Выдвижение, самовыдвижение, сбор согласий кандидатов' } }
local selfnomination = frame:expandTemplate{ title = 'comment', args = { 'Самовыдвиж.', 'Возможно только самовыдвижение кандидатов, ранее выдвинутые кандидаты могут подтвердить участие или отказаться' } }
local talk = frame:expandTemplate{ title = 'comment', args = { 'Обсуждение', 'Обсуждение кандидатур сообществом (начало в 01:30 UTC)' } }
local vote = 'Голосование'
local results = frame:expandTemplate{ title = 'comment', args = { 'Итоги', 'Бюрократы подводят окончательные итоги выборов и знакомят с ними сообщество' } }
local newAK = frame:expandTemplate{ title = 'comment', args = { 'Передача дел', 'Старый состав АК передаёт дела новому' } }
local next = frame:expandTemplate{ title = 'comment', args = { 'Возможен следующий тур', 'Если избрано недостаточно арбитров, будет назначен следующий тур' } }
if diff == 0 then
tr[1] = [[|style="background:#E0F0FF"|]]..notice..[[ 
|colspan="4" style="background:#FFFACD"|]]..nomination..[[ 
|style="background:#FFFCE7"|]]..selfnomination..[[ 
|style="background:#AFA"|]]..talk..[[ 
]]
tr[2] = [[|colspan="4" style="background:#AFA"|]]..talk..[[ 
|colspan="3" style="background:#87CEFA"|Голосование
]]
tr[3] = [[|colspan="4" style="background:#87CEFA"|Голосование
|colspan="2" style="background:#D8BFD8"|]]..results..[[ 
|style="background:#FFE4E1"|]]..newAK..[[ 
]]
tr[4] = [[|style="background:#FFE4E1"|]]..newAK..[[ 
|colspan="6" style="color:#AAA"|]]..next..[[ 
]]
end
if diff == 1 then
tr[1] = [[|style="background:4=#AAA|
|style="background:#E0F0FF"|]]..notice..[[ 
|colspan="4" style="background:#FFFACD"|]]..nomination..[[ 
|style="background:#FFFCE7"|]]..selfnomination..[[ 
]]
tr[2] = [[|colspan="5" style="background:#AFA"|]]..talk..[[ 
|colspan="2" style="background:#87CEFA"|Голосование
]]
tr[3] = [[|colspan="5" style="background:#87CEFA"|Голосование
|colspan="2" style="background:#D8BFD8"|]]..results..[[ 
]]
tr[4] = [[|colspan="2" style="background:#FFE4E1"|]]..newAK..[[ 
|colspan="5" style="color:#AAA"|]]..next..[[ 
]]
end
if diff == 2 then
tr[1] = [[|colspan="2" style="background:4=#AAA|
|style="background:#E0F0FF"|]]..notice..[[ 
|colspan="4" style="background:#FFFACD"|]]..nomination..[[ 
]]
tr[2] = [[|style="background:#FFFCE7"|]]..selfnomination..[[ 
|colspan="5" style="background:#AFA"|]]..talk..[[ 
|style="background:#87CEFA"|Голосование
]]
tr[3] = [[|colspan="6" style="background:#87CEFA"|Голосование
|style="background:#D8BFD8"|]]..results..[[ 
]]
tr[4] = [[|style="background:#D8BFD8"|]]..results..[[ 
|colspan="2" style="background:#FFE4E1"|]]..newAK..[[ 
|colspan="4" style="color:#AAA"|]]..next..[[ 
]]
end
if diff == 3 then
tr[1] = [[|colspan="3" style="background:4=#AAA|
|style="background:#E0F0FF"|]]..notice..[[ 
|colspan="3" style="background:#FFFACD"|]]..nomination..[[ 
]]
tr[2] = [[|style="background:#FFFACD"|]]..nomination..[[ 
|style="background:#FFFCE7"|]]..selfnomination..[[ 
|colspan="5" style="background:#AFA"|]]..talk..[[ 
]]
tr[3] = [[|colspan="7" style="background:#87CEFA"|Голосование
]]
tr[4] = [[|colspan="2" style="background:#D8BFD8"|]]..results..[[ 
|colspan="2" style="background:#FFE4E1"|]]..newAK..[[ 
|colspan="3" style="color:#AAA"|]]..next..[[ 
]]
end
if diff == 4 then
tr[1] = [[|colspan="4" style="background:4=#AAA|
|style="background:#E0F0FF"|]]..notice..[[ 
|colspan="2" style="background:#FFFACD"|]]..nomination..[[ 
]]
tr[2] = [[|colspan="2" style="background:#FFFACD"|]]..nomination..[[ 
|style="background:#FFFCE7"|]]..selfnomination..[[ 
|colspan="4" style="background:#AFA"|]]..talk..[[ 
]]
tr[3] = [[|style="background:#AFA"|]]..talk..[[ 
|colspan="6" style="background:#87CEFA"|Голосование
]]
tr[4] = [[|style="background:#87CEFA"|Голосование
|colspan="2" style="background:#D8BFD8"|]]..results..[[ 
|colspan="2" style="background:#FFE4E1"|]]..newAK..[[ 
|colspan="2" style="color:#AAA"|]]..next..[[ 
]]
end
if diff == 5 then
tr[1] = [[|colspan="5" style="background:4=#AAA|
|style="background:#E0F0FF"|]]..notice..[[ 
|style="background:#FFFACD"|]]..nomination..[[ 
]]
tr[2] = [[|colspan="3" style="background:#FFFACD"|]]..nomination..[[ 
|style="background:#FFFCE7"|]]..selfnomination..[[ 
|colspan="3" style="background:#AFA"|]]..talk..[[ 
]]
tr[3] = [[|colspan="2" style="background:#AFA"|]]..talk..[[ 
|colspan="5" style="background:#87CEFA"|Голосование
]]
tr[4] = [[|colspan="2" style="background:#87CEFA"|Голосование
|colspan="2" style="background:#D8BFD8"|]]..results..[[ 
|colspan="2" style="background:#FFE4E1"|]]..newAK..[[ 
|style="color:#AAA"|]]..next..[[ 
]]
end
if diff == 6 then
tr[1] = [[|colspan="6" style="background:4=#AAA|
|style="background:#E0F0FF"|]]..notice..[[ 
]]
tr[2] = [[|colspan="4" style="background:#FFFACD"|]]..nomination..[[ 
|style="background:#FFFCE7"|]]..selfnomination..[[ 
|colspan="2" style="background:#AFA"|]]..talk..[[ 
]]
tr[3] = [[|colspan="3" style="background:#AFA"|]]..talk..[[ 
|colspan="4" style="background:#87CEFA"|Голосование
]]
tr[4] = [[|colspan="3" style="background:#87CEFA"|Голосование
|colspan="2" style="background:#D8BFD8"|]]..results..[[ 
|colspan="2" style="background:#FFE4E1"|]]..newAK..[[ 
]]
end
return tr[i]
end

return p