Modul:Faktenbox/Tabs: Unterschied zwischen den Versionen

Änderung 758655 von HeikoBot (Diskussion) rückgängig gemacht.
(adressenTab_(fbdata) eigener Sortieralgorithmus)
Markierung: Zurückgesetzt
(Änderung 758655 von HeikoBot (Diskussion) rückgängig gemacht.)
Markierung: Rückgängigmachung
Zeile 9: Zeile 9:
local fab_zeilen = require("Modul:Faktenbox/Zeilen")
local fab_zeilen = require("Modul:Faktenbox/Zeilen")
local fab_common = require("Modul:Faktenbox/Common")
local fab_common = require("Modul:Faktenbox/Common")
local sort_iteration_limit_countdown


function p.universalDatenTab_(fbdata)
function p.universalDatenTab_(fbdata)
Zeile 195: Zeile 193:
["VonObjekt"] = { querypostfix = "#-", default = ""},
["VonObjekt"] = { querypostfix = "#-", default = ""},
["AdresseVon"] = { querypostfix = "", default = ""},
["AdresseVon"] = { querypostfix = "", default = ""},
["AdresseBis"] = { querypostfix = "", default = ""}}
["AdresseBis"] = { querypostfix = "", default = ""},
["Index"] = { querypostfix = "", default = 0} }


-- DB-Abfrage
-- DB-Abfrage
Zeile 206: Zeile 205:
if addresses ~= nil then
if addresses ~= nil then


-- defaults fehlender Attribute und Sortier-Index setzen
-- defaults fehlender Attribute setzen
for i, _ in pairs(addresses) do
for i, _ in pairs(addresses) do
for j, a in pairs(attr) do
for j, a in pairs(attr) do
addresses[i][j] = addresses[i][j] or a.default
addresses[i][j] = addresses[i][j] or a.default
end
end
addresses[i].von_sort_index = smwDate2SortIndex(addresses[i]["AdresseVon"])
addresses[i].bis_sort_index = smwDate2SortIndex(addresses[i]["AdresseBis"])
end
end


-- Tabelle sortieren
-- Tabelle sortieren
sort_iteration_limit_countdown = 1000
table.sort(addresses, function (k1, k2) return k1["Index"] < k2["Index"] end)
table.sort(addresses, vonBisSortCompare)


-- Liste erstellen
-- Liste erstellen
Zeile 268: Zeile 264:
-- mw.log("t = " .. t)
-- mw.log("t = " .. t)
return t
return t
end
function smwDate2SortIndex(date)
-- mw.log("smwDate2SortIndex(" .. date .. ")")
-- Konsolenzeile zum Debuggen:
-- =p.smwDate2SortIndex("2000")
-- =p.smwDate2SortIndex("Februar 2000")
-- =p.smwDate2SortIndex("3. Februar 2000")
local sort_index = ""
local date=str.split2(date, " ")
if #date == 1 then -- nur Jahr
sort_index = tostring(date[1]) ..
"0101" -- 1. Januar
elseif #date == 2 then -- nur Monat + Jahr
sort_index = tostring(date[2]) ..
string.format("%02d", com.getMonthnr(date[1])) ..
"01" -- 1. Tag
elseif #date == 3 then -- komplettes Datum
sort_index = tostring(date[3]) ..
string.format("%02d",com.getMonthnr(date[2])) ..
string.format("%02d", tonumber(string.match(date[1], "%d*")))
end
sort_index = tonumber(sort_index) or 0
-- mw.log("sort_index = " .. tostring(sort_index))
return sort_index
end
function vonBisSortCompare(k1, k2)
-- mw.log("vonBisSortCompare(k1, k2)")
-- mw.logObject(k1)
-- mw.logObject(k2)
local swap = false
if sort_iteration_limit_countdown > 0 then
if k2.von_sort_index ~= 0 then
if k1.bis_sort_index ~= 0 then
swap = ( k1.bis_sort_index > k2.von_sort_index )
elseif k1.von_sort_index ~= 0 then
swap = ( k1.von_sort_index > k2.von_sort_index )
else
swap = true
end
elseif k2.bis_sort_index ~= 0 then
if k1.bis_sort_index ~= 0 then
swap = ( k1.bis_sort_index > k2.bis_sort_index )
elseif k1.von_sort_index ~= 0 then
swap = ( k1.von_sort_index > k2.bis_sort_index )
else
swap = true
end
end
sort_iteration_limit_countdown = sort_iteration_limit_countdown - 1
end
-- mw.log("swap = " .. tostring(swap))
return not swap
end
end


return p
return p