Modhul:Progress bar
Praèn
Dhokumèntasi modhul iki bisa digawé ing Modhul:Progress bar/doc
local p = {} --p stands for package
local getArgs = require('Module:Arguments').getArgs
local make_style_string = require('Module:Optional style').make_style_string
local yesno = require('Module:Yesno')
--[=[
Construct a progress bar
]=]
function p._progress_bar(args)
-- args
local total = tonumber(args.total) or 0
local notext = tonumber(args.notext) or 0
local not_proofread = tonumber(args.not_proofread) or tonumber(args['not proofread']) or 0
local problematic = tonumber(args.problematic) or 0
local proofread = tonumber(args.proofread) or 0
local validated = tonumber(args.validated) or 0
local missing = total - (validated + proofread + not_proofread + problematic + notext)
if yesno(args.existing_only or 'no') then
total = total - missing
missing = 0
end
-- status info
local status_info = {
{['n'] = validated, ['id'] = 'q4'},
{['n'] = proofread, ['id'] = 'q3'},
{['n'] = problematic, ['id'] = 'q2'},
{['n'] = not_proofread, ['id'] = 'q1'},
{['n'] = notext, ['id'] = 'q0'},
{['n'] = missing, ['id'] = 'missing'}
}
-- construct table params
local title = "title = '" .. validated .. " validated pages, " .. proofread .. " only proofread pages and " .. not_proofread .. " not proofread pages (" .. total .. " pages in index)'"
local data_table = {"data-total='" .. total .. "'"}
for k, v in pairs(status_info) do
table.insert(data_table, "data-" .. v['id'] .. "='" .. v['n'] .. "'")
end
local datas = table.concat(data_table, " ")
local style = make_style_string({['height'] = args.height, ['max-width'] = args.width})
-- construct table rows
local row_table
if total <= 0 then
row_table = { "<td class='wst-progress-bar-missing' style='width:100%;'></td>" }
else
row_table = {}
for k, v in pairs(status_info) do
if v['n'] > 0 then
table.insert(row_table, "<td class='wst-progress-bar-" .. v['id'] .. "' style='width:" .. 100 * v['n'] / total .. "%;'></td>")
end
end
end
local rows = table.concat(row_table)
return "<table class='wst-progress-bar' " .. title .. " " .. datas .. " " .. style .. ">" .. "<tr>" .. rows .. "</tr></table>"
end
--[=[
For calling from template
]=]
function p.progress_bar(frame)
return p._progress_bar(getArgs(frame))
end
return p