|
|
| (4 dazwischenliegende Versionen desselben Benutzers werden nicht angezeigt) |
| Zeile 5: |
Zeile 5: |
| local wik = require("Modul:Wiki") | | local wik = require("Modul:Wiki") |
| local que = require("Modul:Queries") | | local que = require("Modul:Queries") |
| local lfd = require("Modul:LinkFormDatum")
| |
|
| |
|
| 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 60: |
Zeile 57: |
| -- Tab draus machen | | -- Tab draus machen |
| t = p.tab_(t, "Bild") | | t = p.tab_(t, "Bild") |
| -- mw.log("t = " .. t)
| |
| return t
| |
| end
| |
|
| |
| function p.kartenTab_(fbdata)
| |
| -- mw.log("kartenTab_(fbdata)")
| |
| -- mw.logObject(fbdata)
| |
| -- Konsolenzeile zum Debuggen:
| |
| -- fab=require("Modul:Faktenbox/Work"); fab_common = require("Modul:Faktenbox/Common"); fbdata=fab_common.fbdata_{pargs={["location"]="Erlanger Straße 11, Fürth, Bayern, Deutschland",Debug="ja"}}; print(p.kartenTab_(fbdata))
| |
| -- fab=require("Modul:Faktenbox/Work"); fab_common = require("Modul:Faktenbox/Common"); fbdata=fab_common.fbdata_{pargs={["Gebäude"]="Erlanger Straße 11;Erlanger Straße 12",Debug="ja"}}; print(p.kartenTab_(fbdata))
| |
| t = ""
| |
| if string.find(fbdata.pagename, ";") ~= nil then
| |
| t = "Semikolon im Artikel-/Seitennamen für korrekte Kartendarstellung nicht erlaubt!"
| |
| else
| |
| local args = {
| |
| lat = fbdata.pargs["lat"] or "", location = fbdata.pargs["location"] or "",
| |
| lon = fbdata.pargs["lon"] or "", locationlist = fbdata.pargs["locationlist"] or "",
| |
| geojson = fbdata.pargs["geojson"] or "", zoom = fbdata.pargs["zoom"] or "18", -- 18 ist default-zoom
| |
| Debug = fbdata.pargs["Debug"] or "",
| |
| width = "", height = "", -- passt sich beides automatisch an die Box an
| |
| box = "nein", form = "ja" -- keine eigene Box; Seite hat Formular
| |
| }
| |
| -- Wenn kein geojson-Formular-Wert vorgegeben, prüfen,
| |
| -- ob sich hinter der Artikelseite eine gleichnamige GeoJson-Karte versteckt oder
| |
| -- über Formular-Wert GeoJsonKarte eine Karte aktiviert ist
| |
| if args.geojson == "" then
| |
| if wik.pageExists("GeoJson:" .. fbdata.pagename) or com.isTrue(fbdata.pargs["GeoJsonKarte"]) then
| |
| args.geojson = fbdata.pagename
| |
| end
| |
| end
| |
| -- Verwende Geolokation des Gebäudes, sofern vorhanden und wenn keine location oder locationlist übergeben
| |
| if args.location == "" and args.locationlist == "" then
| |
| local gebaeude = str.splitAndStrip(fbdata.pargs["Gebäude"] or "", ";")
| |
| if #gebaeude > 0 then -- Gebäude angegeben?
| |
| args.locationlist = ""
| |
| local first = true
| |
| for _, g in ipairs(gebaeude) do -- alle Gebäude durchiterieren
| |
| local seite = que.getValues(g, "Seite", true)
| |
| if seite[1] ~= fbdata.pagename then -- Weiterleitung auf sich selbst rausfiltern
| |
| local geolokation = que.getValues(g, "Geolokation", true)
| |
| for _, l in ipairs(geolokation) do -- alle Geolokationen eines Gebäudes durchiterieren
| |
| if first then
| |
| first = false
| |
| else
| |
| args.locationlist = args.locationlist .. ";"
| |
| end
| |
| args.locationlist = args.locationlist .. l
| |
| end
| |
| end
| |
| end
| |
| end
| |
| end
| |
| -- Karte-Vorlage einbinden
| |
| -- mw.logObject(args)
| |
| if (args.lat ~= "" and args.lon ~= "") or args.location ~= "" or args.locationlist ~= "" or args.geojson ~= "" then
| |
| t = fbdata.frame:expandTemplate{title = "Karte", args = args}
| |
| end
| |
| end
| |
| -- Tab draus machen
| |
| t = p.tab_(t, "Karte")
| |
| -- mw.log("t = " .. t) | | -- mw.log("t = " .. t) |
| return t | | return t |
| Zeile 171: |
Zeile 108: |
| -- Tab draus machen | | -- Tab draus machen |
| t = p.tab_(t, "Benennungen") | | t = p.tab_(t, "Benennungen") |
| -- mw.log("t = " .. t)
| |
| return t
| |
| end
| |
|
| |
| function p.adressenTab_(fbdata)
| |
| -- mw.log("adressenTab_()")
| |
| -- mw.logObject(fbdata)
| |
| -- Konsolenzeile zum Debuggen:
| |
| -- =p.adressenTab_({fullpagename="Jakob Bock"})
| |
| -- =p.adressenTab_({fullpagename="Ludwig Erhard"})
| |
| -- =p.adressenTab_({fullpagename="Druck & Kopie Hartmann KG"})
| |
| -- =p.adressenTab_({fullpagename="Rathaus"})
| |
| -- =p.adressenTab_({fullpagename="E-Tankstelle Hochstraße"})
| |
| -- =p.adressenTab_({fullpagename="TestPerson2"})
| |
| local t = ""
| |
|
| |
| -- Attribute-Liste
| |
| local attr = {
| |
| ["Adressart"] = { querypostfix = "", default = ""},
| |
| ["Straße"] = { querypostfix = "#-", default = ""},
| |
| ["Hausnummer"] = { querypostfix = "", default = 0},
| |
| ["StraßeHnr"] = { querypostfix = "#-", default = ""},
| |
| ["VonObjekt"] = { querypostfix = "#-", default = ""},
| |
| ["AdresseVon"] = { querypostfix = "", default = ""},
| |
| ["AdresseBis"] = { querypostfix = "", default = ""}}
| |
|
| |
| -- DB-Abfrage
| |
| local query = "[[-Has subobject::".. fbdata.fullpagename .. "]][[SubObjektTyp::Adresse]]|?#-|limit=100"
| |
| for i, a in pairs(attr) do
| |
| query = query .. "|?" .. i .. a.querypostfix
| |
| end
| |
| local addresses = mw.smw.ask(query)
| |
|
| |
| if addresses ~= nil then
| |
|
| |
| -- defaults fehlender Attribute und Sortier-Index setzen
| |
| for i, _ in pairs(addresses) do
| |
| for j, a in pairs(attr) do
| |
| addresses[i][j] = addresses[i][j] or a.default
| |
| end
| |
| addresses[i].von_sort_index = smwDate2SortIndex(addresses[i]["AdresseVon"])
| |
| addresses[i].bis_sort_index = smwDate2SortIndex(addresses[i]["AdresseBis"])
| |
| end
| |
|
| |
| -- Tabelle sortieren
| |
| sort_iteration_limit_countdown = 1000
| |
| table.sort(addresses, vonBisSortCompare)
| |
|
| |
| -- Liste erstellen
| |
| t = t .. "<nowiki></nowiki>\n" -- nötig, warum auch immer, damit erster Listeeintrag richtig gerendert wird
| |
| for _, e in ipairs(addresses) do
| |
| t = t .. "* '''" -- Zeilenanfang Liste
| |
| -- Straße/Hausnummer ausgeben
| |
| if wik.pageExists(e["StraßeHnr"]) then -- Link zu Einzel-Gebäude-Seite
| |
| t = t .. "[[" .. e["StraßeHnr"] .. "]]"
| |
| elseif wik.pageExists(e["VonObjekt"]) then -- alternativ Link zu Gebäude-Komplex-Seite
| |
| t = t .. "[[" .. e["VonObjekt"] .. "|" .. e["StraßeHnr"] .. "]]"
| |
| elseif wik.pageExists(e["Straße"]) then -- alternativ Link zu Straße-Seite
| |
| t = t .. "[[" .. e["Straße"] .. "]] " .. tostring(e["Hausnummer"])
| |
| else
| |
| t = t .. "" .. e["StraßeHnr"] .. "" -- alternativ nur fetter Text
| |
| end
| |
| t = t .. "'''"
| |
|
| |
| -- Zusatzinfos in Klammern anfügen
| |
| local bracket = {}
| |
| if e["Adressart"] ~= "" then
| |
| table.insert(bracket, e["Adressart"])
| |
| end
| |
| if e["AdresseVon"] ~= "" then
| |
| table.insert(bracket, "von " .. lfd.formatDate(e["AdresseVon"]))
| |
| end
| |
| if e["AdresseBis"] ~= "" then
| |
| table.insert(bracket, "bis " .. lfd.formatDate(e["AdresseBis"]))
| |
| end
| |
| if #bracket > 0 then
| |
| t = t .. " (" .. table.concat(bracket, " ") ..")"
| |
| end
| |
| t = t .. "\n"
| |
| end
| |
| end
| |
|
| |
| -- Tab draus machen
| |
| t = p.tab_(t, "Adressen")
| |
| -- mw.log("t = " .. t) | | -- mw.log("t = " .. t) |
| return t | | return t |
| Zeile 268: |
Zeile 121: |
| -- 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 |