Module:User:Kai/sandbox: Difference between revisionsGive feedback
No edit summary |
Tag: Undo |
||
| Line 17: | Line 17: | ||
end | end | ||
-- Renders the individual feedback card | -- Renders the individual feedback visual card | ||
local function renderCard(user, feedback, resolved, pageName) | local function renderCard(user, feedback, resolved, pageName) | ||
local root = mw.html.create('div') | local root = mw.html.create('div') | ||
| Line 62: | Line 62: | ||
-- ========================================================================= | -- ========================================================================= | ||
-- 1. | -- 1. ARTICLE INGESTION & DISPLAY: {{#invoke:Feedback|main|...}} | ||
-- ========================================================================= | -- ========================================================================= | ||
function p.main(frame) | function p.main(frame) | ||
| Line 77: | Line 77: | ||
local currentPage = mw.title.getCurrentTitle().fullText | local currentPage = mw.title.getCurrentTitle().fullText | ||
-- Ingest to Bucket | -- Ingest to Bucket | ||
if mw.ext and mw.ext.bucket then | if mw.ext and mw.ext.bucket and mw.ext.bucket.put then | ||
mw.ext.bucket('feedback' | mw.ext.bucket.put('feedback', { | ||
page = currentPage, | page = currentPage, | ||
user = user, | user = user, | ||
| Line 85: | Line 85: | ||
feedback = feedback | feedback = feedback | ||
}) | }) | ||
elseif mw.ext and mw.ext.bucket then | |||
pcall(function() | |||
mw.ext.bucket('feedback').put({ | |||
page = currentPage, | |||
user = user, | |||
status = statusStr, | |||
feedback = feedback | |||
}) | |||
end) | |||
end | end | ||
| Line 96: | Line 105: | ||
-- ========================================================================= | -- ========================================================================= | ||
function p.dashboard(frame) | function p.dashboard(frame) | ||
local rows = | local rows = nil | ||
if mw.ext and mw.ext.bucket then | -- Method 1: mw.ext.bucket:select() syntax (common Scribunto Bucket API) | ||
rows = mw.ext.bucket('feedback') | if not rows and mw.ext and mw.ext.bucket and type(mw.ext.bucket) == 'function' then | ||
pcall(function() | |||
rows = mw.ext.bucket('feedback'):select('page', 'user', 'status', 'feedback'):run() | |||
end) | |||
end | end | ||
-- Method 2: mw.ext.bucket.query() or mw.ext.bucket.select() direct table syntax | |||
if not rows and mw.ext and mw.ext.bucket then | |||
if type(mw.ext.bucket.query) == 'function' then | |||
pcall(function() | |||
rows = mw.ext.bucket.query('feedback', { | |||
fields = { 'page', 'user', 'status', 'feedback' } | |||
}) | |||
end) | |||
elseif type(mw.ext.bucket.select) == 'function' then | |||
pcall(function() | |||
rows = mw.ext.bucket.select('feedback', { 'page', 'user', 'status', 'feedback' }) | |||
end) | |||
end | |||
end | |||
-- Method 3: Global mw.bucket syntax | |||
if not rows and mw.bucket then | |||
pcall(function() | |||
if type(mw.bucket) == 'function' then | |||
rows = mw.bucket('feedback'):select('page', 'user', 'status', 'feedback'):run() | |||
elseif type(mw.bucket.query) == 'function' then | |||
rows = mw.bucket.query('feedback', { | |||
fields = { 'page', 'user', 'status', 'feedback' } | |||
}) | |||
end | |||
end) | |||
end | |||
rows = rows or {} | |||
local allCards = {} | local allCards = {} | ||
| Line 109: | Line 149: | ||
for _, row in ipairs(rows) do | for _, row in ipairs(rows) do | ||
local pageName = row.page or '' | -- Support both string keys and positional keys | ||
local user = row.user or 'Anonymous' | local pageName = row.page or row[1] or '' | ||
local | local user = row.user or row[2] or 'Anonymous' | ||
local feedbackText = row.feedback or '' | local status = tostring(row.status or row[3] or 'unresolved'):lower() | ||
local isResolved = | local feedbackText = row.feedback or row[4] or '' | ||
local isResolved = status == 'resolved' or status == 'true' or status == '1' | |||
local card = renderCard(user, feedbackText, isResolved, pageName) | local card = renderCard(user, feedbackText, isResolved, pageName) | ||
| Line 132: | Line 173: | ||
end | end | ||
-- Construct the raw wikitext for the <tabber> extension | |||
local tabberWikitext = string.format( | local tabberWikitext = string.format( | ||
'<tabber>\n' .. | '<tabber>\n' .. | ||