view piecrust/resources/server/piecrust-debug-info.js @ 380:f33712c4cfab

routing: Fix bugs with matching URLs with correct route but missing metadata. When matching a route like `/foo/%slug%` against an URL like `/foo`, the route will (correctly) return a match, but it will be completely missing the `slug` metadata, resulting in problems elsewhere. This change makes it so that any missing route metadata will be filled in with an empty string. And because this means generated URLs may differ from the incoming URL when using trailing slashes (`/foo/` _vs._ `/foo`), we make the assert in the chef server handle those discrepancies.
author Ludovic Chabant <ludovic@chabant.com>
date Sun, 10 May 2015 00:34:21 -0700
parents d7a548ebcd58
children 9612cfc6455a
line wrap: on
line source

var eventSource = new EventSource("/__piecrust_debug/pipeline_status");

//window.onbeforeunload = function(e) {
//    console.log("Disconnecting SSE.", e);
//    eventSource.close();
//};

eventSource.onerror = function(e) {
    console.log("Error with SSE, closing.", e);
    eventSource.close();
};

eventSource.addEventListener('pipeline_success', function(e) {
    var placeholder = document.getElementById('piecrust-debug-info-pipeline-status');
    //if (placeholder.firstChild !== null)
    placeholder.removeChild(placeholder.firstChild);
});

eventSource.addEventListener('pipeline_error', function(e) {
    var obj = JSON.parse(e.data);

    var outer = document.createElement('div');
    outer.style = 'padding: 1em;';
    for (var i = 0; i < obj.assets.length; ++i) {
        var item = obj.assets[i];
        var markup = (
            '<p>Error processing: <span style="font-family: monospace;">' +
            item.path + '</span></p>\n' +
            '<ul>');
        for (var j = 0; j < item.errors.length; ++j) {
            markup += (
                '<li style="font-family: monospace;">' + 
                item.errors[j] +
                '</li>\n');
        }
        markup += '</ul>\n';
        var entry = document.createElement('div');
        entry.innerHTML = markup;
        outer.appendChild(entry);
    }

    var placeholder = document.getElementById('piecrust-debug-info-pipeline-status');
    placeholder.appendChild(outer);
});