Module:User:Kai/sandbox: Difference between revisionsGive feedback
Jump to navigation
Jump to search
No edit summary |
No edit summary |
||
| Line 17: | Line 17: | ||
end | end | ||
-- Renders the individual feedback | -- Renders the individual feedback 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. SAVE TO BUCKET & 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 using :put() | ||
if mw.ext and mw.ext.bucket | if mw.ext and mw.ext.bucket then | ||
mw.ext.bucket | mw.ext.bucket('feedback'):put({ | ||
page = currentPage, | page = currentPage, | ||
user = user, | user = user, | ||
| Line 85: | Line 85: | ||
feedback = feedback | feedback = feedback | ||
}) | }) | ||
end | end | ||
| Line 105: | Line 96: | ||
-- ========================================================================= | -- ========================================================================= | ||
function p.dashboard(frame) | function p.dashboard(frame) | ||
local rows = | local rows = {} | ||
if mw.ext and mw.ext.bucket then | |||
if | rows = mw.ext.bucket('feedback') | ||
:select('page', 'user', 'status', 'feedback') | |||
:run() or {} | |||
end | end | ||
local allCards = {} | local allCards = {} | ||
| Line 149: | Line 109: | ||
for _, row in ipairs(rows) do | for _, row in ipairs(rows) do | ||
local pageName = row.page or '' | |||
local pageName = row.page | local user = row.user or 'Anonymous' | ||
local user = row.user | local statusVal = tostring(row.status or 'unresolved'):lower() | ||
local | local feedbackText = row.feedback or '' | ||
local feedbackText = row.feedback | local isResolved = statusVal == 'resolved' or statusVal == 'true' or statusVal == '1' | ||
local isResolved = | |||
local card = renderCard(user, feedbackText, isResolved, pageName) | local card = renderCard(user, feedbackText, isResolved, pageName) | ||
| Line 173: | Line 132: | ||
end | end | ||
local tabberWikitext = string.format( | local tabberWikitext = string.format( | ||
'<tabber>\n' .. | '<tabber>\n' .. | ||
Revision as of 21:05, 27 August 2026
Documentation for this module may be created at Module:User:Kai/sandbox/doc
local p = {}
local function isTruthy(v)
if v == nil then
return false
end
v = mw.text.trim(tostring(v)):lower()
return v ~= '' and v ~= '0' and v ~= 'false' and v ~= 'no' and v ~= 'off'
end
local function formatUser(user)
user = mw.text.trim(tostring(user or ''))
if user == '' or user:lower() == 'anonymous' then
return 'Anonymous'
end
return string.format('[[User:%s|%s]]', user, user)
end
-- Renders the individual feedback card
local function renderCard(user, feedback, resolved, pageName)
local root = mw.html.create('div')
:addClass('feedback-box')
:addClass(resolved and 'feedback-box--resolved' or 'feedback-box--unresolved')
local meta = root:tag('div')
:addClass('feedback-meta')
if pageName and pageName ~= '' then
meta:tag('span')
:addClass('feedback-page')
:wikitext(string.format("'''[[%s]]'''", pageName))
meta:tag('span')
:addClass('feedback-separator')
:wikitext(' • ')
end
meta:tag('span')
:addClass('feedback-user')
:wikitext(formatUser(user))
meta:tag('span')
:addClass('feedback-separator')
:wikitext(' • ')
meta:tag('span')
:addClass('feedback-status')
:addClass(resolved and 'feedback-status--resolved' or 'feedback-status--unresolved')
:wikitext(resolved and 'Resolved' or 'Unresolved')
root:tag('div')
:addClass('feedback-body')
:wikitext(feedback)
if not resolved and (not pageName or pageName == '') then
root:tag('div')
:addClass('feedback-instruction')
:wikitext('If this feedback has been resolved, edit this page and set <code>|resolved=true</code>.')
end
return tostring(root)
end
-- =========================================================================
-- 1. SAVE TO BUCKET & DISPLAY: {{#invoke:Feedback|main|...}}
-- =========================================================================
function p.main(frame)
local parent = frame:getParent()
local args = parent and parent.args or frame.args
return p._main(args)
end
function p._main(args)
local feedback = args.feedback or "No feedback provided"
local user = args.user or "Anonymous"
local resolved = isTruthy(args.resolved)
local statusStr = resolved and 'resolved' or 'unresolved'
local currentPage = mw.title.getCurrentTitle().fullText
-- Ingest to Bucket using :put()
if mw.ext and mw.ext.bucket then
mw.ext.bucket('feedback'):put({
page = currentPage,
user = user,
status = statusStr,
feedback = feedback
})
end
local card = renderCard(user, feedback, resolved, nil)
local category = resolved and '[[Category:Resolved Feedback]]' or '[[Category:Unresolved Feedback]]'
return card .. category
end
-- =========================================================================
-- 2. DASHBOARD QUERY WITH TABBER: {{#invoke:Feedback|dashboard}}
-- =========================================================================
function p.dashboard(frame)
local rows = {}
if mw.ext and mw.ext.bucket then
rows = mw.ext.bucket('feedback')
:select('page', 'user', 'status', 'feedback')
:run() or {}
end
local allCards = {}
local unresolvedCards = {}
local resolvedCards = {}
for _, row in ipairs(rows) do
local pageName = row.page or ''
local user = row.user or 'Anonymous'
local statusVal = tostring(row.status or 'unresolved'):lower()
local feedbackText = row.feedback or ''
local isResolved = statusVal == 'resolved' or statusVal == 'true' or statusVal == '1'
local card = renderCard(user, feedbackText, isResolved, pageName)
table.insert(allCards, card)
if isResolved then
table.insert(resolvedCards, card)
else
table.insert(unresolvedCards, card)
end
end
local function getListHtml(cards, emptyMsg)
if #cards == 0 then
return string.format('<div class="feedback-empty" style="padding: 12px; color: #72777d; font-style: italic;">%s</div>', emptyMsg)
end
return table.concat(cards, '\n\n')
end
local tabberWikitext = string.format(
'<tabber>\n' ..
'Unresolved (%d)=\n%s\n' ..
'|-|\n' ..
'Resolved (%d)=\n%s\n' ..
'|-|\n' ..
'All (%d)=\n%s\n' ..
'</tabber>',
#unresolvedCards, getListHtml(unresolvedCards, 'No unresolved feedback found.'),
#resolvedCards, getListHtml(resolvedCards, 'No resolved feedback found.'),
#allCards, getListHtml(allCards, 'No feedback records found.')
)
return frame:preprocess(tabberWikitext)
end
return p