RatingResultsTable

From $1

    Table of contents
    No headers
    /**
     * 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">&nbsp;</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">&nbsp;</td>
                <td class="col-3">&nbsp;</td>
                <td class="col-4">&nbsp;</td>
                <td class="col-5">&nbsp;</td>
                <td class="col-6">&nbsp;</td>
            </tr>
        }
    </table>
    
    // Paging
    Template("MindTouch/Reports/Controls/SearchPaging", {
        uri: uri,
        params: params,
        total: queryTotal,
        perPage: resultsPerPage,
        showingKey: "MindTouch.ContentAnalytics." .. reportType .. ".results"
    });
    Tags: (Edit tags)
    • No tags
     
    Comments (0)
    You must login to post a comment.

     
    Powered by MindTouch Core

    Disclaimer: Vespa Labs contains information that is VERY likely to wreck your scooter and possibly yourself both intentionally (i.e. gaining more peformance while sacrificing reliability + safety) and unintentionally (i.e. misleading or incorrect information). Vespa Labs is only a wiki and intended as a dumping ground for information and not as a properly reviewed source. The same disclaimers that wikipedia.org use apply to Vespa Labs. The short version is use information at your own risk, both information on the main wiki and in the user areas are intended to be used only as "thought provoking" for someone that knows what they are doing. If you try to implement a "thought" Vespa Labs is not reponsible and if something goes wrong we hope that you live and update the offending information with corrections to warn others.

    Vespa Labs is an international site and therefore may contain information that is not road legal in some countries/states and may also invalidate insurance policies. Treat all information as experimental and for "race use only" (i.e. not for road use - even if it is implied or explicitly stated). Refer to and adhere to your local road and legal rules, as well as the manufacturers recommendations.