Module:Feedback: Difference between revisions
From The Petit Planet Wiki
More actions
ReisuDesign (talk | contribs) No edit summary |
ReisuDesign (talk | contribs) No edit summary |
||
| (10 intermediate revisions by the same user not shown) | |||
| Line 1: | Line 1: | ||
local p = {} | local p = {} | ||
------------------------------------------------------------ | ------------------------------------------------------------ | ||
-- | -- HELPERS | ||
------------------------------------------------------------ | ------------------------------------------------------------ | ||
local function isTruthy(value) | local function isTruthy(value) | ||
if value == nil then | if value == nil then | ||
return false | return false | ||
end | end | ||
value = | value = mw.text.trim(tostring(value)):lower() | ||
return value | return value == 'true' | ||
or value == 'yes' | |||
or value == '1' | |||
or value == 'resolved' | |||
end | end | ||
local function trim(value) | local function trim(value) | ||
if value == nil then | |||
return '' | |||
end | |||
return mw.text.trim( | return mw.text.trim(tostring(value)) | ||
end | end | ||
local function formatUser(user) | local function formatUser(user) | ||
user = trim(user) | |||
if user == '' then | |||
if user == '' | |||
return 'Anonymous' | return 'Anonymous' | ||
end | end | ||
| Line 50: | Line 40: | ||
user | user | ||
) | ) | ||
end | end | ||
local function currentSubjectPage() | local function currentSubjectPage() | ||
local title = mw.title.getCurrentTitle() | |||
if title.subjectPageTitle then | |||
return title.subjectPageTitle.fullText | |||
end | |||
return title.fullText | |||
end | end | ||
local function getBucket() | local function getBucket() | ||
if not (mw.ext and mw.ext.bucket) then | if not (mw.ext and mw.ext.bucket) then | ||
return nil | return nil | ||
end | end | ||
return mw.ext.bucket('feedback') | |||
end | end | ||
local function sortNewestFirst( | local function sortNewestFirst(entries) | ||
table.sort( | table.sort( | ||
entries, | |||
function(a, b) | function(a, b) | ||
local aDate = trim(a.createddate) | |||
local bDate = trim(b.createddate) | |||
return aDate > bDate | |||
end | end | ||
) | ) | ||
return entries | |||
return | |||
end | end | ||
local function queryFeedback( | local function queryFeedback(page) | ||
local bucket = getBucket() | |||
) | |||
local bucket | |||
if not bucket then | if not bucket then | ||
return | return {} | ||
end | end | ||
local query = bucket | |||
query.select( | |||
'page', | |||
'user', | |||
'status', | |||
'feedback', | |||
'id', | |||
'createddate', | |||
'link', | |||
'image', | |||
'resolvedby', | |||
'resolveddate' | |||
) | |||
query.where( | |||
'page', | |||
page | |||
) | ) | ||
end | local success, results = pcall(function() | ||
return query.run() | |||
end) | |||
if not success or not results then | |||
return {} | |||
if not | |||
return | |||
end | end | ||
return sortNewestFirst(results) | |||
end | end | ||
------------------------------------------------------------ | ------------------------------------------------------------ | ||
-- | -- ATTACHMENTS | ||
------------------------------------------------------------ | ------------------------------------------------------------ | ||
local function | local function renderAttachments(entry) | ||
local wrapper = | |||
mw.html.create('div') | |||
) | :addClass('feedback-attachments') | ||
local | |||
:addClass( | |||
local link = trim(entry.link) | |||
if link ~= '' then | if link ~= '' then | ||
local linkWrapper = | |||
wrapper:tag('span') | |||
:addClass( | :addClass('feedback-attachment-link') | ||
linkWrapper:tag('span') | |||
:addClass('feedback-attachment-icon') | |||
linkWrapper:wikitext( | |||
'[' .. link .. ' ' .. mw.text.nowiki(link) .. ']' | |||
) | |||
end | end | ||
local image = trim(entry.image) | |||
if image ~= '' then | if image ~= '' then | ||
image = mw.ustring.gsub( | |||
image, | |||
'^File:', | |||
'' | |||
) | |||
local | local title = | ||
mw.title.new('File:' .. image) | |||
if title then | |||
local imageWrapper = | |||
: | wrapper:tag('span') | ||
'feedback- | :addClass('feedback-attachment-image') | ||
imageWrapper:tag('span') | |||
:addClass('feedback-attachment-icon') | |||
imageWrapper:wikitext( | |||
'[' .. | |||
title:fullUrl() .. | |||
' ' .. | |||
mw.text.nowiki(image) .. | |||
']' | |||
) | ) | ||
end | |||
end | end | ||
return wrapper | |||
end | end | ||
------------------------------------------------------------ | ------------------------------------------------------------ | ||
-- | -- RESOLUTION | ||
------------------------------------------------------------ | ------------------------------------------------------------ | ||
local function renderResolution( | local function renderResolution(parent, entry) | ||
local resolvedBy = trim(entry.resolvedby) | |||
local resolvedDate = trim(entry.resolveddate) | |||
) | |||
local resolvedBy = | |||
if resolvedBy == '' and resolvedDate == '' then | |||
if resolvedBy == '' | |||
return | return | ||
end | end | ||
local resolution = | local resolution = | ||
parent:tag('div') | |||
:addClass( | :addClass('feedback-resolution') | ||
resolution:wikitext('Resolved by ') | |||
if resolvedBy ~= '' then | if resolvedBy ~= '' then | ||
resolution:wikitext( | resolution:wikitext( | ||
formatUser( | formatUser(resolvedBy) | ||
) | ) | ||
else | else | ||
resolution:wikitext('Unknown') | |||
resolution:wikitext( | |||
end | end | ||
if resolvedDate ~= '' then | if resolvedDate ~= '' then | ||
resolution:wikitext( | resolution:wikitext( | ||
' on ' .. | ' on ' .. mw.text.nowiki(resolvedDate) | ||
) | ) | ||
end | end | ||
end | end | ||
------------------------------------------------------------ | ------------------------------------------------------------ | ||
-- | -- RESOLVE CONTROL | ||
------------------------------------------------------------ | ------------------------------------------------------------ | ||
| Line 480: | Line 219: | ||
compact | compact | ||
) | ) | ||
if trim(id) == '' then | |||
if | |||
return | return | ||
end | end | ||
local wrapper = | |||
parent:tag('div') | |||
:addClass('feedback-resolve') | |||
local control = | local control = | ||
wrapper:tag('span') | |||
:addClass( | :addClass('feedback-resolve-button') | ||
:attr( | |||
'data-feedback-id', | |||
id | |||
) | ) | ||
:attr( | |||
'data-feedback-page', | |||
page or '' | |||
) | ) | ||
:attr( | :attr( | ||
| Line 531: | Line 249: | ||
'aria-label', | 'aria-label', | ||
'Resolve feedback' | 'Resolve feedback' | ||
) | ) | ||
if compact then | |||
control | control | ||
: | :addClass( | ||
' | 'feedback-resolve-button--compact' | ||
) | ) | ||
:attr( | :attr( | ||
' | 'title', | ||
'Resolve feedback' | 'Resolve feedback' | ||
) | ) | ||
:wikitext( | :wikitext('✓') | ||
else | |||
control:wikitext('Resolve') | |||
end | end | ||
end | end | ||
------------------------------------------------------------ | ------------------------------------------------------------ | ||
-- | -- FULL FEEDBACK CARD | ||
------------------------------------------------------------ | ------------------------------------------------------------ | ||
local function renderFullCard( | local function renderFullCard(entry) | ||
) | |||
local resolved = | local resolved = | ||
entry.status == 'resolved' | trim(entry.status):lower() == 'resolved' | ||
local id = trim(entry.id) | |||
local page = trim(entry.page) | |||
local feedback = trim(entry.feedback) | |||
local user = trim(entry.user) | |||
local createddate = trim(entry.createddate) | |||
local root = | local root = | ||
mw.html.create('div') | mw.html.create('div') | ||
:addClass( | :addClass('feedback-box') | ||
:addClass( | :addClass( | ||
resolved | resolved | ||
| Line 594: | Line 289: | ||
or 'feedback-box--unresolved' | or 'feedback-box--unresolved' | ||
) | ) | ||
if id ~= '' then | if id ~= '' then | ||
root:attr( | root:attr( | ||
'data-feedback-id', | 'data-feedback-id', | ||
id | id | ||
) | ) | ||
end | end | ||
-------------------------------------------------------- | |||
-- Main content column | |||
-------------------------------------------------------- | |||
local content = | |||
root:tag('div') | |||
:addClass('feedback-content') | |||
-------------------------------------------------------- | -------------------------------------------------------- | ||
| Line 611: | Line 310: | ||
local main = | local main = | ||
content:tag('div') | |||
:addClass( | :addClass('feedback-main-line') | ||
-------------------------------------------------------- | |||
-- Status | |||
-------------------------------------------------------- | |||
main:tag('span') | main:tag('span') | ||
:addClass( | :addClass('feedback-status') | ||
:addClass( | :addClass( | ||
resolved | resolved | ||
| Line 628: | Line 326: | ||
:wikitext( | :wikitext( | ||
resolved | resolved | ||
and ' | and 'Resolved' | ||
or ' | or 'Unresolved' | ||
) | ) | ||
-------------------------------------------------------- | |||
-- Feedback text | |||
-------------------------------------------------------- | |||
main:tag('span') | main:tag('span') | ||
:addClass( | :addClass('feedback-text') | ||
:wikitext( | :wikitext( | ||
feedback ~= '' | |||
and feedback | |||
or 'No feedback provided' | or 'No feedback provided' | ||
) | ) | ||
-------------------------------------------------------- | -------------------------------------------------------- | ||
-- | -- Metadata | ||
-------------------------------------------------------- | -------------------------------------------------------- | ||
local | local meta = | ||
main:tag('span') | main:tag('span') | ||
:addClass( | :addClass('feedback-inline-meta') | ||
if user ~= '' then | |||
if | meta:wikitext( | ||
' · ' .. formatUser(user) | |||
' · ' .. | |||
) | ) | ||
end | end | ||
if createddate ~= '' then | |||
if | meta:wikitext( | ||
' · ' .. mw.text.nowiki(createddate) | |||
' ' .. | |||
) | ) | ||
end | end | ||
-------------------------------------------------------- | -------------------------------------------------------- | ||
-- | -- Attachments | ||
-------------------------------------------------------- | -------------------------------------------------------- | ||
content:node( | |||
renderAttachments(entry) | |||
) | |||
-------------------------------------------------------- | -------------------------------------------------------- | ||
-- | -- Resolution information | ||
-------------------------------------------------------- | -------------------------------------------------------- | ||
renderResolution( | |||
content, | |||
entry | entry | ||
) | ) | ||
-------------------------------------------------------- | -------------------------------------------------------- | ||
-- | -- Missing ID warning | ||
-------------------------------------------------------- | -------------------------------------------------------- | ||
if | if id == '' then | ||
content:tag('div') | |||
:addClass('feedback-missing-id') | |||
:wikitext( | |||
entry | 'This feedback entry is missing an ID.' | ||
) | |||
end | end | ||
-------------------------------------------------------- | -------------------------------------------------------- | ||
-- | -- Resolve button | ||
-- | |||
-- IMPORTANT: | |||
-- This is outside .feedback-content so it | |||
-- remains on the right. | |||
-------------------------------------------------------- | -------------------------------------------------------- | ||
if not resolved | if not resolved then | ||
renderResolveControl( | |||
root, | |||
id, | |||
page, | |||
false | |||
) | |||
end | end | ||
return tostring(root) | return tostring(root) | ||
end | end | ||
------------------------------------------------------------ | ------------------------------------------------------------ | ||
-- | -- COMPACT CARD | ||
------------------------------------------------------------ | ------------------------------------------------------------ | ||
local function renderCompactCard( | local function renderCompactCard(entry) | ||
entry | return renderFullCard(entry) | ||
end | |||
------------------------------------------------------------ | |||
-- SAVE FEEDBACK | |||
------------------------------------------------------------ | |||
local | local function saveFeedback(data) | ||
local bucket = getBucket() | |||
if not bucket then | |||
return false, 'Bucket extension is not available' | |||
end | |||
local | local success, err = pcall(function() | ||
bucket.put({ | |||
page = data.page, | |||
user = data.user, | |||
status = data.status, | |||
feedback = data.feedback, | |||
id = data.id, | |||
createddate = data.createddate, | |||
link = data.link, | |||
image = data.image, | |||
resolvedby = data.resolvedby, | |||
resolveddate = data.resolveddate | |||
}) | |||
end) | |||
) | |||
if not success then | |||
return false, tostring(err) | |||
end | end | ||
return true | |||
end | |||
------------------------------------------------------------ | |||
-- MAIN | |||
-- | |||
-- Used by Template:Feedback | |||
------------------------------------------------------------ | |||
local | function p.main(frame) | ||
local parent = frame:getParent() | |||
local args = | |||
parent and parent.args | |||
or frame.args | |||
local pageTitle = nil | |||
if parent and parent.getTitle then | |||
local title = parent:getTitle() | |||
if title | |||
and title ~= '' | |||
and not title:find('^Template:') | |||
then | |||
pageTitle = title | |||
end | |||
end | |||
return p._main( | |||
args, | |||
pageTitle | |||
) | |||
end | |||
local | function p._main(args, pageTitle) | ||
local feedback = | |||
trim(args.feedback) | |||
if feedback == '' then | |||
feedback = 'No feedback provided' | |||
end | |||
local user = | |||
trim(args.user) | |||
if user == '' then | |||
user = 'Anonymous' | |||
end | end | ||
local resolved = | |||
isTruthy(args.resolved) | |||
local status = | |||
and | resolved | ||
and 'resolved' | |||
or 'unresolved' | |||
local currentPage = | |||
trim(pageTitle) | |||
if currentPage == '' then | |||
currentPage = | |||
mw.title.getCurrentTitle().fullText | |||
end | end | ||
local id = | |||
trim(args.id) | |||
local createddate = | |||
trim(args.createddate) | |||
local link = | |||
trim(args.link) | |||
local image = | |||
trim(args.image) | |||
local resolvedby = | |||
trim(args.resolvedby) | |||
local resolveddate = | |||
trim(args.resolveddate) | |||
-------------------------------------------------------- | |||
-- Save to Bucket | |||
-------------------------------------------------------- | |||
local saved, saveError = | |||
saveFeedback({ | |||
page = currentPage, | |||
user = user, | |||
status = status, | |||
feedback = feedback, | |||
id = id, | |||
createddate = createddate, | |||
link = link, | |||
image = image, | |||
resolvedby = resolvedby, | |||
resolveddate = resolveddate | |||
}) | |||
if not saved then | |||
return | |||
'<strong style="color:red;">Feedback bucket error: ' | |||
.. mw.text.nowiki( | |||
saveError or 'Unknown error' | |||
' | |||
) | ) | ||
.. '</strong>' | |||
end | |||
-------------------------------------------------------- | |||
-- Render | |||
-------------------------------------------------------- | |||
local card = | |||
renderFullCard({ | |||
page = currentPage, | |||
user = user, | |||
status = status, | |||
feedback = feedback, | |||
id = id, | |||
createddate = createddate, | |||
link = link, | |||
image = image, | |||
resolvedby = resolvedby, | |||
resolveddate = resolveddate | |||
}) | |||
-------------------------------------------------------- | |||
-- Categories | |||
-------------------------------------------------------- | |||
local category | |||
if resolved then | |||
category = | |||
'[[Category:Resolved Feedback]]' | |||
else | |||
category = | |||
'[[Category:Unresolved Feedback]]' | |||
end | |||
end | if id == '' then | ||
category = | |||
category .. | |||
'[[Category:Feedbacks Missing ID]]' | |||
end | |||
return card .. category | |||
end | |||
------------------------------------------------------------ | |||
-- RENDER FEEDBACK LIST | |||
------------------------------------------------------------ | |||
local function renderFeedbackList(results) | |||
if not results or #results == 0 then | |||
return '<em>No feedback entries found.</em>' | |||
end | |||
local list = {} | |||
for _, row in ipairs(results) do | |||
table.insert( | |||
list, | |||
renderFullCard(row) | |||
) | |||
end | end | ||
return table.concat( | |||
list, | |||
'\n' | |||
) | ) | ||
end | end | ||
------------------------------------------------------------ | ------------------------------------------------------------ | ||
-- | -- PAGE FEEDBACK | ||
------------------------------------------------------------ | ------------------------------------------------------------ | ||
function p.page(frame) | function p.page(frame) | ||
local page = | local page = | ||
currentSubjectPage() | currentSubjectPage() | ||
local entries = | |||
local | queryFeedback(page) | ||
queryFeedback( | |||
local unresolved = {} | local unresolved = {} | ||
local resolved = {} | local resolved = {} | ||
for _, entry in ipairs(entries) do | |||
for _, | if trim(entry.status):lower() | ||
== 'resolved' | |||
if | then | ||
table.insert( | table.insert( | ||
resolved, | resolved, | ||
entry | |||
) | ) | ||
else | else | ||
table.insert( | table.insert( | ||
unresolved, | unresolved, | ||
entry | |||
) | ) | ||
end | end | ||
end | end | ||
local root = | local root = | ||
mw.html.create('section') | mw.html.create('section') | ||
:attr( | :attr( | ||
'id', | 'id', | ||
'feedback-section' | 'feedback-section' | ||
) | ) | ||
: | :addClass('feedback-page') | ||
-------------------------------------------------------- | -------------------------------------------------------- | ||
| Line 1,034: | Line 674: | ||
root:tag('h2') | root:tag('h2') | ||
:addClass( | :addClass('feedback-page-title') | ||
:wikitext('Feedbacks') | |||
:wikitext( | |||
-------------------------------------------------------- | -------------------------------------------------------- | ||
| Line 1,048: | Line 683: | ||
local filters = | local filters = | ||
root:tag('div') | root:tag('div') | ||
:addClass( | :addClass('feedback-filters') | ||
local function addFilter( | |||
local | label, | ||
value, | |||
active | |||
) | |||
return filters:tag('button') | |||
:attr( | :attr( | ||
' | 'type', | ||
'button' | 'button' | ||
) | ) | ||
:attr( | :attr( | ||
' | 'data-feedback-filter', | ||
value | |||
) | ) | ||
: | :addClass('feedback-filter') | ||
:addClass( | |||
' | active | ||
and 'feedback-filter--active' | |||
or nil | |||
) | ) | ||
:wikitext(label) | |||
end | |||
addFilter( | |||
'Unresolved', | |||
'unresolved', | |||
true | |||
) | |||
addFilter( | |||
' | 'Resolved', | ||
'resolved', | |||
false | |||
) | ) | ||
addFilter( | |||
'All', | |||
'all', | |||
false | |||
) | |||
-------------------------------------------------------- | |||
-- Unresolved | |||
-------------------------------------------------------- | |||
local unresolvedList = | |||
root:tag('div') | |||
:addClass( | |||
'feedback-page-list' | |||
) | |||
:addClass( | |||
'feedback-page-list--unresolved' | |||
) | ) | ||
:addClass( | :addClass( | ||
'feedback-page- | 'feedback-page-list--visible' | ||
) | ) | ||
if #unresolved == 0 then | |||
unresolvedList:tag('div') | |||
:addClass('feedback-empty') | |||
:wikitext( | :wikitext( | ||
'No unresolved feedback.' | |||
) | ) | ||
else | |||
for _, entry in ipairs(unresolved) do | |||
unresolvedList:wikitext( | |||
renderCompactCard(entry) | |||
) | |||
end | |||
end | end | ||
-------------------------------------------------------- | -------------------------------------------------------- | ||
-- | -- Resolved | ||
-------------------------------------------------------- | -------------------------------------------------------- | ||
local | local resolvedList = | ||
root:tag('div') | root:tag('div') | ||
:addClass( | :addClass( | ||
| Line 1,140: | Line 766: | ||
) | ) | ||
:addClass( | :addClass( | ||
'feedback-page-list-- | 'feedback-page-list--resolved' | ||
) | ) | ||
if #resolved == 0 then | |||
if # | resolvedList:tag('div') | ||
:addClass('feedback-empty') | |||
:wikitext( | |||
'No resolved feedback.' | |||
) | ) | ||
else | else | ||
for _, entry in ipairs(resolved) do | |||
resolvedList:wikitext( | |||
: | renderCompactCard(entry) | ||
) | ) | ||
end | |||
end | end | ||
-------------------------------------------------------- | -------------------------------------------------------- | ||
-- | -- All | ||
-------------------------------------------------------- | -------------------------------------------------------- | ||
local allList = | |||
root:tag('div') | |||
:addClass( | |||
'feedback-page-list' | |||
) | |||
:addClass( | |||
'feedback-page-list--all' | |||
) | |||
if #entries == 0 then | |||
allList:tag('div') | |||
:addClass('feedback-empty') | |||
:wikitext( | |||
'No feedback.' | |||
) | |||
else | |||
for _, entry in ipairs(entries) do | |||
allList:wikitext( | |||
renderCompactCard(entry) | |||
for _, | |||
renderCompactCard( | |||
) | ) | ||
end | end | ||
end | end | ||
return tostring(root) | return tostring(root) | ||
end | end | ||
------------------------------------------------------------ | ------------------------------------------------------------ | ||
-- | -- COUNTS | ||
------------------------------------------------------------ | ------------------------------------------------------------ | ||
function p.counts(frame) | function p.counts(frame) | ||
local entries = | local entries = | ||
queryFeedback( | queryFeedback( | ||
currentSubjectPage() | |||
) | ) | ||
local unresolved = 0 | local unresolved = 0 | ||
local resolved = 0 | local resolved = 0 | ||
for _, entry in ipairs(entries) do | |||
for _, | if trim(entry.status):lower() | ||
== 'resolved' | |||
if | then | ||
resolved = resolved + 1 | resolved = resolved + 1 | ||
else | else | ||
unresolved = unresolved + 1 | unresolved = unresolved + 1 | ||
end | end | ||
end | end | ||
return tostring( | return tostring( | ||
mw.html.create('span') | mw.html.create('span') | ||
:addClass( | :addClass('feedback-count-data') | ||
:attr( | :attr( | ||
'data-unresolved', | 'data-unresolved', | ||
| Line 1,253: | Line 848: | ||
resolved | resolved | ||
) | ) | ||
) | ) | ||
end | end | ||
------------------------------------------------------------ | ------------------------------------------------------------ | ||
-- | -- TABLE / DASHBOARD | ||
------------------------------------------------------------ | ------------------------------------------------------------ | ||
function | local function renderTable(entries) | ||
if not entries or #entries == 0 then | |||
return '<em>No feedback entries found.</em>' | |||
return | |||
end | end | ||
local table = | |||
local | |||
mw.html.create('table') | mw.html.create('table') | ||
:addClass( | :addClass('feedback-table') | ||
local head = | |||
table:tag('thead') | |||
:tag('tr') | |||
head:tag('th') | |||
:wikitext('Status') | |||
head:tag('th') | |||
:wikitext('Page') | |||
head:tag('th') | |||
:wikitext('Feedback') | |||
head:tag('th') | |||
:wikitext('User') | |||
head:tag('th') | |||
:wikitext('Date') | |||
local body = | |||
table:tag('tbody') | |||
for _, entry in ipairs(entries) do | |||
local row = | local row = | ||
body:tag('tr') | |||
local resolved = | |||
trim(entry.status):lower() | |||
== 'resolved' | |||
row:tag('td') | row:tag('td') | ||
:addClass( | :addClass( | ||
'feedback-table- | resolved | ||
and 'feedback-table-status--resolved' | |||
or 'feedback-table-status--unresolved' | |||
) | ) | ||
:wikitext( | :wikitext( | ||
' | resolved | ||
and 'Resolved' | |||
or 'Unresolved' | |||
) | ) | ||
row:tag('td') | row:tag('td') | ||
:addClass( | :addClass('feedback-table-page') | ||
:wikitext( | :wikitext( | ||
entry.page or '' | |||
entry.page | |||
) | ) | ||
row:tag('td') | row:tag('td') | ||
:addClass( | :addClass('feedback-table-text') | ||
:wikitext( | :wikitext( | ||
entry.feedback or '' | |||
) | ) | ||
row:tag('td') | row:tag('td') | ||
:wikitext( | :wikitext( | ||
formatUser(entry.user) | |||
) | ) | ||
row:tag('td') | row:tag('td') | ||
:wikitext( | :wikitext( | ||
entry. | entry.createddate or '' | ||
) | ) | ||
end | end | ||
return tostring(table) | |||
return tostring( | |||
end | end | ||
function p.view(frame) | function p.view(frame) | ||
local parent = | local parent = | ||
frame:getParent() | frame:getParent() | ||
local args | |||
if frame | |||
and frame.args | |||
and frame.args.status | |||
then | |||
args = frame.args | |||
elseif parent | |||
and parent.args | |||
and parent.args.status | |||
then | |||
args = parent.args | |||
elseif frame | |||
and frame.args | |||
then | |||
args = frame.args | |||
elseif parent | |||
and parent.args | |||
then | then | ||
args = parent.args | |||
else | |||
args = {} | |||
end | |||
return p._view( | |||
args, | |||
frame | |||
) | |||
end | |||
function p._view(args, frame) | |||
local bucket = | |||
getBucket() | |||
return | if not bucket then | ||
return | |||
'<em>Bucket extension is not available.</em>' | |||
end | |||
local rawStatus = | |||
args.status | |||
or args[1] | |||
local filterStatus = | |||
rawStatus | |||
and trim(rawStatus):lower() | |||
or nil | |||
-------------------------------------------------------- | -------------------------------------------------------- | ||
-- | -- Query | ||
-------------------------------------------------------- | -------------------------------------------------------- | ||
local | local query = | ||
bucket | |||
query.select( | |||
'page', | |||
'user', | |||
'status', | |||
'feedback', | |||
'id', | |||
'createddate', | |||
'link', | |||
'image', | |||
'resolvedby', | |||
'resolveddate' | |||
) | |||
if filterStatus == 'resolved' | |||
or filterStatus == 'unresolved' | |||
then | |||
query.where( | |||
'status', | |||
filterStatus | |||
) | ) | ||
end | end | ||
local success, entries = | |||
pcall(function() | |||
return query.run() | |||
end) | |||
if not | if not success or not entries then | ||
return | |||
'<em>Could not load feedback.</em>' | |||
end | end | ||
entries = | |||
sortNewestFirst(entries) | |||
-------------------------------------------------------- | |||
-- Specific status | |||
-------------------------------------------------------- | |||
if filterStatus == 'resolved' | |||
or filterStatus == 'unresolved' | |||
then | |||
return renderFeedbackList( | |||
entries | |||
) | ) | ||
end | |||
-------------------------------------------------------- | |||
-- All | |||
-------------------------------------------------------- | |||
return renderTable(entries) | |||
end | end | ||
p.table = p.view | p.table = p.view | ||
return p | return p | ||