Jump to content

Module:AutoHeader: Difference between revisions

From The Telecommunications Inventory Wiki
No edit summary
No edit summary
 
(51 intermediate revisions by the same user not shown)
Line 1: Line 1:
local p = {}
local p = {}
p.getQuery = function(frame)
return mw.title.getCurrentTitle()
end
p.getData = function(frame)
-- local ret = mw.visualdata.query( schema ("inventory_item"), query (string), printouts (list or table), params (table)  )
local inventoryItemResult = mw.visualdata.query( 'Inventory_item', tostring(mw.title.getCurrentTitle()), {''}, {} )
if(inventoryItemResult.title ~= nil) then
inventoryItemResult.classification = 'inventory item'
return inventoryItemResult
end
local phoneResult = mw.visualdata.query( 'Phone', tostring(mw.title.getCurrentTitle()), {'manufacturer'}, {} )
if(phoneResult.title ~= nil) then
phoneResult.classification = 'phone'
return phoneResult
end
-- local result = mw.visualdata.query( 'Phone', "Model 500", {'manufacturer'}, {} )
-- return result
end


p.getJson = function(frame)
p.getJson = function(frame)
-- local ret = mw.visualdata.query( schema ("inventory_item"), query (string), printouts (list or table), params (table)  )
-- local newObj = {}
local ret = mw.visualdata.query( 'Phone', '[[manufacturer::+]]', {'manufacturer'}, {} )
-- for k in pairs(frame) do newObj[k] = "value" end
return mw.text.jsonEncode(ret)
-- return mw.text.jsonEncode(newObj)
local data = p.getData(frame)
return mw.text.jsonEncode(data)
end
end


p.getIntroParagraph = function(frame)
p.getIntroParagraph = function(frame)
local data = p.getJson(frame)
local obj = p.getData(frame)
local title = data[0].title
if(obj == nil) then return end
local title = data[0].data.manufacturer
local title = obj.title
return string.format("The %q was manufactured by %q", title)
local classification = obj.classification
local manufacturer = obj.data.manufacturer
if(classification == "phone") then
return string.format('The %s is a %s that was manufactured by %s.', title, classification, manufacturer)
end
return ""
end
end


return p
return p

Latest revision as of 21:17, 6 January 2025

Documentation for this module may be created at Module:AutoHeader/doc

local p = {}

p.getQuery = function(frame)
	return mw.title.getCurrentTitle()
end

p.getData = function(frame)
	-- local ret = mw.visualdata.query( schema ("inventory_item"), query (string), printouts (list or table), params (table)  )
	local inventoryItemResult = mw.visualdata.query( 'Inventory_item', tostring(mw.title.getCurrentTitle()), {''}, {} )
	if(inventoryItemResult.title ~= nil) then
		inventoryItemResult.classification = 'inventory item'
		return inventoryItemResult
	end
	local phoneResult = mw.visualdata.query( 'Phone', tostring(mw.title.getCurrentTitle()), {'manufacturer'}, {} )
	if(phoneResult.title ~= nil) then
		phoneResult.classification = 'phone'
		return phoneResult
	end
	-- local result = mw.visualdata.query( 'Phone', "Model 500", {'manufacturer'}, {} )
	-- return result
end

p.getJson = function(frame)
	-- local newObj = {}
	-- for k in pairs(frame) do newObj[k] = "value" end
	-- return mw.text.jsonEncode(newObj)
	local data = p.getData(frame)
	return mw.text.jsonEncode(data)
end

p.getIntroParagraph = function(frame)
	local obj = p.getData(frame)
	if(obj == nil) then return end
	local title = obj.title
	local classification = obj.classification
	local manufacturer = obj.data.manufacturer
	if(classification == "phone") then
		return string.format('The %s is a %s that was manufactured by %s.', title, classification, manufacturer)
	end
	return ""
end

return p