Module:ToolInventoryData: Difference between revisions
From Claremont MakerSpace
(Add ToolInstanceTable) |
(ToolInstanceTable: Take argument for asset tags list) |
||
Line 20: | Line 20: | ||
function p.ToolInstanceTable(frame) | function p.ToolInstanceTable(frame) | ||
local out = '{| class="wikitable"\n! Asset Tag || Model Number || Status \n|-\n' | local out = '{| class="wikitable"\n! Asset Tag || Model Number || Status \n|-\n' | ||
for idx, asset_tag in ipairs(mw.text.split( | for idx, asset_tag in ipairs(mw.text.split(frame.args[1], ';')) | ||
do | do | ||
data = getToolInfo(asset_tag) | data = getToolInfo(asset_tag) |
Revision as of 20:54, 7 July 2020
Documentation for this module may be created at Module:ToolInventoryData/doc
local p = {} local function getToolInfo(asset_tag) mw.getCurrentFrame():callParserFunction( '#get_web_data', { url = 'SNIPEIT_URL/api/v1/hardware/bytag/' .. asset_tag, format='json', 'use jsonpath', data='status=$.status_label.name, modelno=$.model_number' } ) return { status = mw.getCurrentFrame():callParserFunction('#external_value', {'status'}), modelno = mw.getCurrentFrame():callParserFunction('#external_value', {'modelno'}) } end function p.ToolInstanceTable(frame) local out = '{| class="wikitable"\n! Asset Tag || Model Number || Status \n|-\n' for idx, asset_tag in ipairs(mw.text.split(frame.args[1], ';')) do data = getToolInfo(asset_tag) out = out .. '|' .. table.concat({asset_tag, data.modelno, data.status}, '||') .. '\n|-\n' end return out .. '|}' end return p