15.082
Bearbeitungen
(besserer von/bis-Text) |
(Überarbeitung, + Sortierung Geburtshaus/ort und Letzter Wohnort) |
||
| Zeile 18: | Zeile 18: | ||
-- =p.adressenTab_({fullpagename="Rathaus"}) | -- =p.adressenTab_({fullpagename="Rathaus"}) | ||
-- =p.adressenTab_({fullpagename="E-Tankstelle Hochstraße"}) | -- =p.adressenTab_({fullpagename="E-Tankstelle Hochstraße"}) | ||
-- =p.adressenTab_({fullpagename="Jakob Wassermann"}) | -- =p.adressenTab_({fullpagename="Jakob Wassermann"}) | ||
-- =p.adressenTab_({fullpagename="Hedwig Gellinger"}) | |||
local t = "" | local t = "" | ||
| Zeile 41: | Zeile 41: | ||
if addresses ~= nil then | if addresses ~= nil then | ||
-- defaults fehlender Attribute | -- defaults setzen fehlender Attribute | ||
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 | ||
end | end | ||
-- | -- Chronologische Sortierung | ||
if #addresses > 1 then | |||
-- Sortier-Indizes setzen | |||
for | for i, _ in pairs(addresses) do | ||
addresses[i].von_sort_index, addresses[i].bis_sort_index = p.sortIndex(addresses[i]) | |||
end | end | ||
-- Tabelle sortieren | |||
table.sort(addresses, function(a1, a2) return a1.bis_sort_index < a2.von_sort_index end) | |||
end | end | ||
| Zeile 112: | Zeile 105: | ||
end | end | ||
function smwDate2SortIndex(date) | function p.sortIndex(address) | ||
local von_sort_index = p.smwDate2SortIndex(address["AdresseVon"]) | |||
local bis_sort_index = p.smwDate2SortIndex(address["AdresseBis"]) | |||
-- Ggf. Index von Geburtshaus/-ort setzen | |||
-- ganz nach vorne => höchste Prio = -99999999 | |||
if string.find(address["Adressart"], "Geburt") == 1 then -- beginnt mit "Geburt" | |||
von_sort_index = -99999999 | |||
end | |||
-- Ggf. Index von "Letzter Wohnort" (nicht unbedingt Fürth!) setzen | |||
-- ganz nach hinten => niedrigste Prio = 99999999 | |||
if address["Adressart"] == "Letzter Wohnort" then -- exakte Übereinstimmung | |||
von_sort_index = 99999999 | |||
bis_sort_index = 99999999 | |||
-- Ggf. Index von fehlenden von/bis setzen | |||
-- wenn fehlt, ganz nach hinten (aber vor "Letzter Wohnort") => drittniedrigste Prio = 77777777 | |||
-- "Letzter Wohnort" => zweitniedrigste Prio = 88888888 | |||
elseif von_sort_index == 0 and bis_sort_index == 0 then | |||
if string.find(address["Adressart"], "Letzter Wohnort") == 1 then -- beginnt mit "Letzter Wohnort" | |||
von_sort_index = 88888888 | |||
bis_sort_index = 88888888 | |||
else | |||
von_sort_index = 77777777 | |||
bis_sort_index = 77777777 | |||
end | |||
end | |||
-- Übernahme fehlender Index von => bis oder umgekehrt | |||
if von_sort_index == 0 and bis_sort_index ~= 0 then | |||
von_sort_index = bis_sort_index | |||
end | |||
if bis_sort_index == 0 and von_sort_index ~= 0 then | |||
bis_sort_index = von_sort_index | |||
end | |||
return von_sort_index, bis_sort_index | |||
end | |||
function p.smwDate2SortIndex(date) | |||
-- mw.log("smwDate2SortIndex(" .. date .. ")") | -- mw.log("smwDate2SortIndex(" .. date .. ")") | ||
-- Datum in Index wandeln | |||
-- Bsp.: 23 Apr. 1989 => 19890423 | |||
-- Konsolenzeile zum Debuggen: | -- Konsolenzeile zum Debuggen: | ||
-- =p.smwDate2SortIndex("2000") | -- =p.smwDate2SortIndex("2000") | ||
| Zeile 120: | Zeile 150: | ||
local sort_index = "" | local sort_index = "" | ||
local date=str.split2(date, " ") | local date=str.split2(date, " ") | ||
if #date == 1 then -- nur Jahr vorhanden | |||
if #date == 1 then -- nur Jahr | sort_index = tostring(date[1]) .. "0101" -- mit 1. Januar ergänzen | ||
sort_index = tostring(date[1]) .. | elseif #date == 2 then -- nur Monat + Jahr vorhanden | ||
sort_index = tostring(date[2]) .. string.format("%02d", com.getMonthnr(date[1])) .. "01" -- mit 1. Tag im Monat ergänzen | |||
elseif #date == 2 then -- nur Monat + Jahr | elseif #date == 3 then -- komplettes Datum vorhanden | ||
sort_index = tostring(date[2]) .. | sort_index = tostring(date[3]) .. string.format("%02d",com.getMonthnr(date[2])) .. string.format("%02d", tonumber(string.match(date[1], "%d*"))) | ||
elseif #date == 3 then -- komplettes Datum | |||
sort_index = tostring(date[3]) .. | |||
end | end | ||
sort_index = tonumber(sort_index) or 0 | sort_index = tonumber(sort_index) or 0 | ||
-- mw.log("sort_index = " .. tostring(sort_index)) | -- mw.log("sort_index = " .. tostring(sort_index)) | ||
return sort_index | return sort_index | ||
end | end | ||
return p | return p | ||