Module:User:Kai/sandbox: Difference between revisions

No edit summary
No edit summary
Line 105: Line 105:
-- =========================================================================
-- =========================================================================
function p.dashboard(frame)
function p.dashboard(frame)
     local rows = {}
     local rows = nil
     if mw.ext and mw.ext.bucket and mw.ext.bucket.query then
 
         rows = mw.ext.bucket.query('feedback', {
    -- Method 1: mw.ext.bucket:select() syntax (common Scribunto Bucket API)
            fields = { 'page', 'user', 'status', 'feedback' }
     if not rows and mw.ext and mw.ext.bucket and type(mw.ext.bucket) == 'function' then
         }) or {}
        pcall(function()
            rows = mw.ext.bucket('feedback'):select('page', 'user', 'status', 'feedback'):run()
        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
     end
    rows = rows or {}


     local allCards = {}
     local allCards = {}
Line 117: Line 149:


     for _, row in ipairs(rows) do
     for _, row in ipairs(rows) do
         local isResolved = (row.status or ''):lower() == 'resolved'
        -- Support both string keys and positional keys
         local card = renderCard(row.user or 'Anonymous', row.feedback or '', isResolved, row.page)
        local pageName = row.page or row[1] or ''
         local user = row.user or row[2] or 'Anonymous'
        local status = tostring(row.status or row[3] or 'unresolved'):lower()
        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)


         table.insert(allCards, card)
         table.insert(allCards, card)
Line 149: Line 187:
     )
     )


    -- Preprocess the wikitext so the tabber tags evaluate correctly
     return frame:preprocess(tabberWikitext)
     return frame:preprocess(tabberWikitext)
end
end


return p
return p