Subversion Repositories SmartDukaan

Rev

Rev 37337 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 37337 Rev 37526
Line 913... Line 913...
913
            }
913
            }
914
        }
914
        }
915
        return null;
915
        return null;
916
    }
916
    }
917
 
917
 
-
 
918
    /**
-
 
919
     * The ingest summary is a Java Map.toString():
-
 
920
     *   {rowsInPdf=334, offers=298, ...} products={AUTO_EXACT=332, ...} dropped={...} warnings=1157
-
 
921
     * One unbreakable line that ran off the card. Parsed into chips instead, with the
-
 
922
     * drop reasons - by far the longest part, and the part you only want when a number
-
 
923
     * looks wrong - behind a disclosure.
-
 
924
     */
-
 
925
    function parsePairs(text) {
-
 
926
        var out = [];
-
 
927
        (text || '').split(', ').forEach(function (part) {
-
 
928
            var at = part.lastIndexOf('=');
-
 
929
            if (at > 0) {
-
 
930
                out.push({ key: part.slice(0, at).trim(), value: part.slice(at + 1).trim() });
-
 
931
            }
-
 
932
        });
-
 
933
        return out;
-
 
934
    }
-
 
935
 
-
 
936
    var COUNT_LABEL = {
-
 
937
        rowsInPdf: 'rows in PDF', rowsLoaded: 'loaded', offers: 'offers',
-
 
938
        benefits: 'benefits', tenures: 'tenures', banks: 'bank links',
-
 
939
        products: 'products', channelScopes: 'channel scopes', conditions: 'conditions'
-
 
940
    };
-
 
941
 
-
 
942
    function chip(label, value, warn) {
-
 
943
        return '<span class="oc-sum-chip' + (warn ? ' oc-sum-chip-warn' : '') + '">'
-
 
944
            + '<b>' + esc(value) + '</b> ' + esc(label) + '</span>';
-
 
945
    }
-
 
946
 
-
 
947
    function summaryHtml(summary) {
-
 
948
        if (!summary) { return ''; }
-
 
949
        var counts = /^\{([^}]*)\}/.exec(summary);
-
 
950
        var products = /products=\{([^}]*)\}/.exec(summary);
-
 
951
        var dropped = /dropped=\{([^}]*)\}/.exec(summary);
-
 
952
        var warnings = /warnings=(\d+)/.exec(summary);
-
 
953
 
-
 
954
        // nothing recognised - show it, but let it wrap instead of overflowing
-
 
955
        if (!counts) {
-
 
956
            return '<span class="oc-num oc-sum-raw">' + esc(summary) + '</span>';
-
 
957
        }
-
 
958
 
-
 
959
        var html = '<span class="oc-sum">';
-
 
960
        parsePairs(counts[1]).forEach(function (p) {
-
 
961
            // benefits/tenures/banks at zero means the masters are unseeded - the ingest
-
 
962
            // reports what it TRIED to write, so a zero here is worth flagging, not hiding
-
 
963
            var zeroMoney = p.value === '0'
-
 
964
                && (p.key === 'benefits' || p.key === 'tenures' || p.key === 'banks');
-
 
965
            html += chip(COUNT_LABEL[p.key] || p.key, p.value, zeroMoney);
-
 
966
        });
-
 
967
        if (products) {
-
 
968
            parsePairs(products[1]).forEach(function (p) {
-
 
969
                var needsWork = p.key === 'REVIEW' || p.key === 'CATALOG_GAP';
-
 
970
                html += chip(p.key.toLowerCase().replace(/_/g, ' '), p.value, needsWork);
-
 
971
            });
-
 
972
        }
-
 
973
        if (warnings) { html += chip('warnings', warnings[1], false); }
-
 
974
 
-
 
975
        var drops = dropped ? parsePairs(dropped[1]) : [];
-
 
976
        if (drops.length) {
-
 
977
            html += '<button type="button" class="oc-sum-toggle" data-oc-sum-toggle>'
-
 
978
                 + drops.length + ' drop reasons</button>';
-
 
979
        }
-
 
980
        html += '</span>';
-
 
981
 
-
 
982
        if (drops.length) {
-
 
983
            html += '<div class="oc-sum-detail" data-oc-sum-detail>'
-
 
984
                 + drops.sort(function (a, b) { return Number(b.value) - Number(a.value); })
-
 
985
                        .map(function (d) {
-
 
986
                            return '<div><span>' + esc(d.key) + '</span>'
-
 
987
                                 + '<span>' + esc(d.value) + '</span></div>';
-
 
988
                        }).join('')
-
 
989
                 + '</div>';
-
 
990
        }
-
 
991
        return html;
-
 
992
    }
-
 
993
 
-
 
994
    $(document).on('click', '.oc-root [data-oc-sum-toggle]', function () {
-
 
995
        var detail = root().find('[data-oc-sum-detail]');
-
 
996
        var showing = detail.is(':visible');
-
 
997
        detail.toggle(!showing);
-
 
998
    });
-
 
999
 
918
    function renderIngestState() {
1000
    function renderIngestState() {
919
        var box = root().find('[data-oc-ingest-state]');
1001
        var box = root().find('[data-oc-ingest-state]');
920
        var doc = selectedDoc();
1002
        var doc = selectedDoc();
921
        if (!doc) { box.empty(); return; }
1003
        if (!doc) { box.empty(); return; }
922
 
1004
 
Line 924... Line 1006...
924
            box.html('<span class="oc-pill oc-pill-warn">' + esc(PENDING_STATES[doc.status])
1006
            box.html('<span class="oc-pill oc-pill-warn">' + esc(PENDING_STATES[doc.status])
925
                + '</span> <span class="oc-num">usually a few seconds; '
1007
                + '</span> <span class="oc-num">usually a few seconds; '
926
                + 'this refreshes itself</span>');
1008
                + 'this refreshes itself</span>');
927
        } else if (doc.status === 'FAILED') {
1009
        } else if (doc.status === 'FAILED') {
928
            box.html('<span class="oc-pill oc-pill-danger">ingest failed</span> '
1010
            box.html('<span class="oc-pill oc-pill-danger">ingest failed</span> '
929
                + '<span class="oc-num">' + esc(doc.ingestError || 'no reason recorded')
1011
                + '<span class="oc-num oc-sum-raw">'
930
                + '</span>');
1012
                + esc(doc.ingestError || 'no reason recorded') + '</span>');
931
        } else if (doc.status === 'PUBLISHED') {
1013
        } else if (doc.status === 'PUBLISHED') {
932
            box.html('<span class="oc-pill oc-pill-ok">parsed</span> '
1014
            box.html('<span class="oc-pill oc-pill-ok">parsed</span> '
933
                + '<span class="oc-num">' + esc(doc.ingestSummary || '') + '</span>');
1015
                + summaryHtml(doc.ingestSummary));
934
        } else {
1016
        } else {
935
            box.html('<span class="oc-pill oc-pill-muted">' + esc(doc.status) + '</span>');
1017
            box.html('<span class="oc-pill oc-pill-muted">' + esc(doc.status) + '</span>');
936
        }
1018
        }
937
    }
1019
    }
938
 
1020