Module:Liste2 : Différence entre versions

 
(24 révisions intermédiaires par le même utilisateur non affichées)
Ligne 25 : Ligne 25 :
 
end
 
end
  
local tbl,tbl2,tbl3,tbl4,tbl5,tbl6 = {},{},{},{},{},{},{},{}
+
local tbl = {}
 
for _, row in ipairs(result) do
 
for _, row in ipairs(result) do
 
row['annee'] = tonumber(row['annee'])
 
row['annee'] = tonumber(row['annee'])
Ligne 33 : Ligne 33 :
 
end
 
end
 
 
local debut, fin = 1900, 1980
+
local debut = 1904
local periode, nperiode = 10, 0
+
local periode,nb = 7,0
local d,f = debut-100,debut+periode
+
local d,f = debut,debut+periode
local texte_periode = '\n Texte période'
+
local texte_periode = '\n <div class="collapsible"> '..  d+1 ..'-'..f .. '</div><div class="content"> '
local retour, msg = '', 1
+
local retour, tbl = '',{''}
  
 
for _,row in ipairs(result) do
 
for _,row in ipairs(result) do
if row['annee'] > d and row['annee'] < f then
+
if not tbl[2] then
if msg then
+
retour = retour .. '\n <div class="collapsible"> '.. d+1 .. '-' .. f .. '</div><div class="content"><br> '
retour = retour .. table.concat(tbl,args.delimiter or '') .. texte_periode .. an1 .. row['annee'] .. '\n\n'
+
end
msg = nil
+
if row['annee'] >= f + 1 then
else
+
while row['annee'] > f + periode do
tbl[#tbl+1] = frame:expandTemplate{ title = args.template, args = row }
+
d,f = f,f+periode
 
end
 
end
elseif f < fin then
+
retour = retour .. table.concat(tbl,args.delimiter or '') .. '</div><br>'
 +
tbl = {}
 
d,f = f,f+periode
 
d,f = f,f+periode
else
 
d,f=f,f+100
 
 
end
 
end
 +
tbl[#tbl+1] = frame:expandTemplate{ title = args.template, args = row }
 
end
 
end
 +
retour = retour .. table.concat(tbl,args.delimiter or '') .. '</div><br>'
 +
 
local intro = frame:preprocess(args.intro or '')
 
local intro = frame:preprocess(args.intro or '')
 
local outro = frame:preprocess(args.outro or '')
 
local outro = frame:preprocess(args.outro or '')

Version actuelle datée du 12 décembre 2018 à 18:40

La documentation pour ce module peut être créée à Module:Liste2/doc

local p = {}
function p.main(frame)
	if frame == mw.getCurrentFrame() then
		args = require('Module:ProcessArgs').merge(true)
	else
		frame = mw.getCurrentFrame()
	end
	
	local query = {}
	for k, v in pairs(args) do
		if string.sub(k, 0, 2) == 'q?' then
			query[string.sub(k, 3)] = v
		end
	end

	supports={}	
	local result = mw.ext.cargo.query('Supports','idSupport,video',{groupBy = 'idSupport',limit=3000})
	for d, row in ipairs(result) do
		supports[row['idSupport']] = row['video']
	end
	
	result = mw.ext.cargo.query(query.tables, query.fields, query)
	if not next(result) then
		return frame:preprocess(args.default or '')
	end

	local tbl = {}
	for _, row in ipairs(result) do
		row['annee'] = tonumber(row['annee'])
		if row['video'] == '' then
			if supports[row['idSupport']] then row['video']=supports[row['idSupport']] end
		end
	end
	
	local debut = 1904
	local periode,nb = 7,0
	local d,f = debut,debut+periode
	local texte_periode = '\n <div class="collapsible"> '..  d+1 ..'-'..f .. '</div><div class="content"> '
	local retour, tbl = '',{''}

	for _,row in ipairs(result) do
		if not tbl[2] then
			retour = retour .. '\n <div class="collapsible"> '.. d+1 .. '-' .. f .. '</div><div class="content"><br> '
		end
		if row['annee'] >= f + 1 then
			while row['annee'] > f + periode do
				d,f = f,f+periode
			end
			retour = retour .. table.concat(tbl,args.delimiter or '') .. '</div><br>'
			tbl = {}
			d,f = f,f+periode
		end
		tbl[#tbl+1] = frame:expandTemplate{ title = args.template, args = row }
	end	
	retour = retour .. table.concat(tbl,args.delimiter or '') .. '</div><br>'
	
	local intro = frame:preprocess(args.intro or '')
	local outro = frame:preprocess(args.outro or '')

	return  intro .. retour .. outro

end 
return p