Module:SOM.Page.Real Property

From SunshinePPS Wiki

Documentation for this module may be created at Module:SOM.Page.Real Property/doc

require("Module:No globals")

local DBA = require("Module:SOM.meta.DateBoundedAttribute")
local Page = require("Module:SOM.meta.Page")
local StringBuffer = require("Module:SOM.util.StringBuffer")
local util = require("Module:SOM.util")

local HasCoordinates = require("Module:SOM.Simple.HasCoordinates")
local HasName = require("Module:SOM.DateBounded.HasName")
local StreetAddress = require("Module:SOM.DateBounded.StreetAddress")
local Owner = require("Module:SOM.DateBounded.Role.ThingOrg.Owner")
local FreeWikitext = require("Module:SOM.Simple.FreeWikitext")

local SchoolCampus = require("Module:SOM.DateBounded.Role.OrgPlace.SchoolCampus")

local ENTITY_ROOT_CATEGORY = require("Module:SOM.const.ENTITY_ROOT_CATEGORY")


local function render_associated_organizations(_, buffer, frame)
	-- TODO(maddog) Obviously this needs to be generalized with a category
	--              hierarchy to capture all OrgPlace relations.
	local roles = SchoolCampus.ask(
		mw.title.getCurrentTitle().fullText, "place", nil)
	buffer:add(SchoolCampus.render_table_and_references(
		roles, frame, {
			sort = DBA.sort_current_first,
			columns = {
				{ label = "Role", key = "role" },
				{ label = "Organization", key = "school" },
				DBA.COLUMN_FROM,
				DBA.COLUMN_UNTIL,
				DBA.COLUMN_REFERENCES,
			}
		}))
	--
	--
	--
end


return Page.generate_page{
	class_name = "Real Property",
	parent_categories = { ENTITY_ROOT_CATEGORY },
	category_description = [==[
A ''Real Property'' is a XXXXXXXYYYY.
]==],
	naming_advice = [[
New pages should be named using a functional/descriptive name of the property (e.g., "Clara Sweet School Building").]],
	attributes = {
		location = {
			arg = "location",
			class = HasCoordinates,
			label = "Location",
		},
		names = {
			arg = "names",
			class = HasName,
			label = "Name"
		},
		addresses = {
			arg = "addresses",
			class = StreetAddress,
			label = "Address"
		},
		owners = {
			arg = "owners",
			class = Owner,
			label = "Owner",
			link_to_key = "thing"
		},
		text = {
			arg = "text",
			class = FreeWikitext,
			label = "Article Text"
		},
	},
	form_layout = {
		{ section2 = "Basic Facts" },
		{ table = {
			{ attribute = "location" },
			}
		},
		{ section4 = "Names" },
		{ attribute = "names" },
		{ section4 = "Addresses" },
		{ attribute = "addresses" },
		{ section4 = "Owners" },
		{ attribute = "owners" },
		{ section2 = "Article Text" },
		{ attribute = "text" },
	},
	page_layout = {
		{ infobox = {
			{ attribute = "names", render = "render_current" },
			{ attribute = "addresses", render = "render_current",
				render_args = { render_with = StreetAddress.render_address } },
			{ attribute = "owners", render = "render_current",
				render_args = { key = "owner"} },
			{ attribute = "location" },
			}
		},
		{ attribute = "location",
			render = function (value, frame)
				if (value == nil) or (#value == 0) then
					return ""
				end
				-- {{#display_map:{{{coordinates|}}} }}
				return frame:extensionTag{
					name = "display_map",
					content = value}
			end
		},
		{ attribute = "text" },
		{ references = {} },
		{ section2 = "Roles" },
		{ renderer = render_associated_organizations },
		{ section2 = "Fact History" },
		{ attribute = "names", render = "render_table_and_references",
			render_args = HasName.basic_current_first_table_args() },
		{ attribute = "addresses", render = "render_table_and_references",
			render_args = {
				sort = DBA.sort_current_first,
				columns = {
					{ label = "Address", 
						render = StreetAddress.render_address },
					DBA.COLUMN_FROM,
					DBA.COLUMN_UNTIL,
					DBA.COLUMN_REFERENCES,
				}
			}
		},
		{ attribute = "owners", render = "render_table_and_references",
			render_args = {
				sort = DBA.sort_current_first,
				columns = {
					{ label = "Owner", key = "owner" },
--					{ label = "Role", key = "role" },
--					{ label = "Attributes", -- key = "role_attributes",
--						render = function (instance)
--							return table.concat(
--								instance.role_attributes, ", ")
--						end,
--					 },
					-- { label = "Property", key = "thing" },
					DBA.COLUMN_FROM,
					DBA.COLUMN_UNTIL,
					DBA.COLUMN_REFERENCES,
				}
			}
		},
	}
}