Module:ToolInventoryData: Difference between revisions
From Claremont MakerSpace
(Make asset tag a link) |
(Remove model number, switch to status_meta) |
||
Line 8: | Line 8: | ||
format='json', | format='json', | ||
'use jsonpath', | 'use jsonpath', | ||
data='status=$.status_label. | data='status=$.status_label.status_meta' | ||
} | } | ||
) | ) | ||
return { | return { | ||
status = mw.getCurrentFrame():callParserFunction('#external_value', {'status | status = mw.getCurrentFrame():callParserFunction('#external_value', {'status'}) | ||
} | } | ||
end | end | ||
Line 22: | Line 21: | ||
for idx, asset_tag in ipairs(mw.text.split(frame.args[1], ';')) | for idx, asset_tag in ipairs(mw.text.split(frame.args[1], ';')) | ||
do | do | ||
data = getToolInfo(asset_tag) | local data = getToolInfo(asset_tag) | ||
local link ='[https://inventory.claremontmakerspace.org/hardware/bytag?assetTag='..asset_tag..' '..asset_tag..']' | |||
out = out .. '|' .. link .. '||' .. data.status .. '\n|-\n' | |||
end | end | ||
Revision as of 21:14, 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.status_meta' } ) return { status = mw.getCurrentFrame():callParserFunction('#external_value', {'status'}) } end function p.ToolInstanceTable(frame) local out = '{| class="wikitable" style="margin: 0;"\n! Asset Tag || Model Number || Status \n|-\n' for idx, asset_tag in ipairs(mw.text.split(frame.args[1], ';')) do local data = getToolInfo(asset_tag) local link ='[https://inventory.claremontmakerspace.org/hardware/bytag?assetTag='..asset_tag..' '..asset_tag..']' out = out .. '|' .. link .. '||' .. data.status .. '\n|-\n' end return out .. '|}' end return p