~smagoun/whoopsie/whoopsie-lp1017637

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
function most_common_problems_table() {
YUI().use('node', 'io-queue', 'datatable', 'datatable-sort', 'datasource-get',
          'datasource-jsonschema', 'datatable-datasource', 'datatable-message',
          'datatype', 'event-key',
function(Y) {

    var scale = d3.scale.log()
        .range(["10", "50"]);

    var chartFormatter = function(o) {
        return "<div class=\"chart\" style=\"width: " + scale(o.value) + "px;\">" + o.value + "</div>";
    }
    var bugFormatter = function(o) {
        return "<a href=\"http://pad.lv/" + o.value + "\">" + o.value + "</a>";
    }
    var cols = [
        {key: "count", label: "Frequency", sortable:true, formatter:chartFormatter, allowHTML: true},
        {key: "package", label: "Package", sortable:true},
        {key: "seen", label: "First seen"},
        {key: "function", label: "Function", allowHTML: true,
         cellTemplate: '<td class="{className}">' +
                       '<div class="outer"><div class="inner">' +
                       '<a href="bucket/?id={content}">{content}</a>' +
                       '</div></div></td>'},
        {key: "report", label: "Bug report", sortable:true, formatter:bugFormatter, allowHTML: true},
    ];

    var datasource = new Y.DataSource.Get({
        source: "/anonymous-api/most-common-problems",
        /* FIXME Clearing the current pending request before starting a new one
         * does not work:
         * http://yuilibrary.com/projects/yui3/ticket/2529999 */
        asyncMode: "cancelStaleRequests",
    });
    datasource.plug(Y.Plugin.DataSourceJSONSchema, {
        schema: {
            resultFields: [{key: 'count'}, {key: 'seen'}, {key: 'function'}, {key: 'package'}, {key: 'report'}]
        }
    });
    table = new Y.DataTable({
        columnset: cols,
          sortBy: { count: -1 },
    });

    table.plug(Y.Plugin.DataTableDataSource, {
        datasource: datasource,
    })

    function loadRequest (period) {
        table.datasource.load({
            // TODO we can override this query= nonsense by setting the
            // generateRequestCallback attribute. See datasource-get.js:114.
            request: '/' + period + '?query=fake',
            callback: {
                /* Provide a better message on failure */
                success: function (e) {
                    table.datasource.onDataReturnInitializeTable(e);
                },
                failure: function (e) {
                    table.showMessage("An error occurred while trying to load the most common problems.");
                },
            },
        });
    }

    function interval_changed () {
        var values = [];
        Y.one('#release_interval').get("options").each(function () {
            if (this.get('selected') && this.get('value') != 'all releases') {
                values.push(this.get('value'));
            }
        });
        var specific_package = Y.one('#package').get('value');
        if (specific_package != '') {
            values.push(specific_package);
        }
        Y.one('#problem_interval').get("options").each(function () {
            if (this.get('selected')) {
                values.push(this.get('value'));
            }
        });
        // FIXME need to clear the table first, otherwise we see the loading
        // message in a row above the data.
        //datasource.sendRequest(null,
        //      {success: table.onDataReturnInitializeTable},
        //        table);
        var value = values.join('/');
        table.showMessage("loadingMessage");
        table.datasource.load({request: null });
        loadRequest(value);
    }

    Y.one('#release_interval').on('change', interval_changed );
    Y.one('#problem_interval').on('change', interval_changed );
    Y.one('#package').on('key', interval_changed, 'enter');
    table.render("#problems").showMessage("loadingMessage");
    loadRequest('today');

});
}