/**
* Rating Results Table
*
* @param str $type - report type being run
* @param uri $uri - base uri (default: page.uri)
* @param map $params - query params to preserve
* @param str $query - query to execute
* @param str $constraint - query constraints (default: nil)
* @param num $total - total report size
* @param str $default - default sort (default: nil)
* @param num $perPage - results per page (default: 30)
*/
var reportType = $type;
var uri = $uri ?? page.uri;
var params = $params;
var searchQuery = $query;
var searchConstraint = $constraint;
var queryTotal = $total;
var defaultSort = $default;
var resultsPerPage = $perPage ?? 30;
// compute the page
var currentPage = __request.args.page ?? 1;
if (currentPage < 1) {
let currentPage = 1;
}
var currentSort = __request.args.sortBy ?? defaultSort;
// fetch the results
var queryResults = wiki.getsearch{
query: searchQuery,
offset: (currentPage - 1) * resultsPerPage,
max: resultsPerPage,
sortBy: currentSort,
constraint: searchConstraint
};
var queryCount = #queryResults;
// Paging
Template("MindTouch/Reports/Controls/SearchPaging", {
uri: uri,
params: params,
total: queryTotal,
perPage: resultsPerPage,
showingKey: "MindTouch.ContentAnalytics." .. reportType .. ".results"
});
// computed page statistics
var aggregateScore = 0;
var aggregateTrendscore = 0;
<table class=("table mt-report-results" .. (queryTotal == 0 ? " ui-no-results": ""))>
Template('MindTouch/Controls/TableSortHeading', {
uri: uri,
params: params,
columns: [
{width: "", label: wiki.localize("MindTouch.Reports.data.title"), field: "title"},
{width: "10", label: wiki.localize("MindTouch.Reports.data.rating"), field: "rating.score"},
{width: "10", label: wiki.localize("MindTouch.Reports.data.votes"), field: "rating.count"},
{width: "50", label: wiki.localize("MindTouch.Reports.data.date"), field: "date"},
{
width: "30",
sortclass: "views",
label: wiki.localize("MindTouch.Reports.data.views")
},
{
width: "30",
sortclass: "edits",
label: wiki.localize("MindTouch.Reports.data.edits")
},
{
width: "30",
sortclass: "comments",
label: wiki.localize("MindTouch.Reports.data.comments")
}
],
default: defaultSort,
enabled: (queryCount > 0)
});
if (queryCount < 1) {
<tr>
<td colspan="7">
wiki.localize("MindTouch.Reports.data.empty")
</td>
</tr>
}
foreach (var queryResult in queryResults) {
// skip empty results
if (!#queryResult) {
continue;
}
// compute page statistics
let aggregateScore += num.cast(queryResult.rating.score ?? 0);
let aggregateTrendscore += num.cast(queryResult.rating.trendscore ?? 0);
<tr class=("row-" .. (__count % 2))>
Template("MindTouch/Reports/Controls/TableCellPage", {
page: queryResult,
class: "col-0"
});
<td class="col-1 data-type-numeric">
if ((queryResult.rating.count > 0) && (queryResult.rating.score is not nil)) {
<span class=("trending trending-" .. (queryResult.rating.trendscore < .5 ? "down" : "up"))>
num.round(queryResult.rating.score * 100) .. "%";
</span>
} else {
"--";
}
</td>
<td class="col-2 data-type-numeric">
queryResult.rating.count;
</td>
<td class="col-3 data-type-numeric">
Template("MindTouch/Controls/DateTime", [queryResult.date]);
</td>
<td class="col-4 data-type-numeric">queryResult.viewcount</td>
<td class="col-5 data-type-numeric">queryResult.revision</td>
<td class="col-6 data-type-numeric">
<a href=(queryResult.uri .. "#comments")>#queryResult.comments</a>
</td>
</tr>
}
// computed information if results are found
if (queryCount > 0) {
<tr class="summary">
<td class="col-0"> </td>
<td class="col-1">
<dl>
<dt>"Score:"</dt>
<dd>num.round(aggregateScore / queryCount * 100); "%";</dd>
<dt>"Trend:"</dt>
<dd>num.round(aggregateTrendscore / queryCount * 100); "%"</dd>
</dl>
</td>
<td class="col-2"> </td>
<td class="col-3"> </td>
<td class="col-4"> </td>
<td class="col-5"> </td>
<td class="col-6"> </td>
</tr>
}
</table>
// Paging
Template("MindTouch/Reports/Controls/SearchPaging", {
uri: uri,
params: params,
total: queryTotal,
perPage: resultsPerPage,
showingKey: "MindTouch.ContentAnalytics." .. reportType .. ".results"
});