<commit_before>/* globals jQuery */

(function ($) {
    // XXX this is the test server
    var base = "https://api-test.w3.org/";
    
    function defaultErrorHandler (xhr) {
        console.error("ERROR:", xhr.statusText);
    }
    
    // gets JSON in a way that works
    function getJSON (path, success, error) {
        path = path.indexOf("http") === 0 ? path : base + path;
        $.ajax(path, {
            type: "GET"
        ,   xhrFields: {
                withCredentials:    true
            }
        ,   success:    success
        ,   error:      error || defaultErrorHandler
        });
    }
    
    function renderCharter ($el, href) {
        getJSON(
            href
        ,   function (data) {
                console.log(data);
                $el.find("div.meta a").first().attr("href", data.uri);
            }
        );
    }
    
    function renderDomain ($el, href) {
        getJSON(
            href
        ,   function (data) {
                console.log(data);
                $el.find("div.meta a")
                    .last()
                    .attr("href", data._links.homepage.href)
                    .text(data.name + " Domain")
                ;
            }
        );
    }

    function renderPeople ($parent, href, field, name, plural) {
        if (!plural) plural = name;
        getJSON(
            href
        ,   function (data) {
                var list = data._embedded[field];
                name = list.length > 1 ? plural : name;
                console.log(name, data);
                var $card = $("<div></div>").addClass("person-card");
                $("<h3></h3>").text(name).appendTo($card);
                var $ul = $("<ul></ul>").appendTo($card);
                for (var i = 0, n = list.length; i < n; i++) {
                    var item = list[i]
                    ,   fullName = item.name.replace("[tm]", "™")
                    ,   $li = $("<li></li>").text(fullName).appendTo($ul)
                    ;
                    $("<img>")
                        .attr({
                            src:    item._links.photos ?
                                        item._links.photos.filter(function (it) { return it.name === "tiny"; })[0].href :
                                        "img/faceless.svg"
                        ,   alt:    fullName
                        ,   width:  36
                        ,   height: 48
                        })
                        .prependTo($li);
                }
                $card.appendTo($parent);
            }
        );
    }
    
    function renderReports ($ul, href) {
        getJSON(
            href
        ,   function (data) {
                // XXX we need to sort these reports
                $.each(data._embedded.reports, function (_, report) {
                    $("<li><a></a> </li>")
                        .find("a")
                            .attr("href", report.shortlink)
                            .text(report.title)
                        .end()
                        .append($("<span class='status'></span>").text("(" + report._links.latest.title + ")"))
                        .prepend(
                            $("<img width='25' height='25' src='icons/icons/ei-chevron-right.svg' alt=''>")
                        )
                        .appendTo($ul)
                    ;
                });
            }
        );
    }

    var icons = {
        tracker:    "exclamation"
    ,   wiki:       "pencil"
    ,   lists:      "envelope"
    ,   repository: "sc-github"
    ,   unknown:    "question"
    };
    function renderServices ($ul, href) {
        getJSON(
            href
        ,   function (data) {
                $.each(data._embedded.services, function (_, service) {
                    $("<li><a></a></li>")
                        .find("a")
                            .attr("href", service.link)
                            .text(service.longdesc || service.shortdesc || service.type)
                        .end()
                        .prepend(
                            $("<img width='25' height='25'>")
                                .attr({
                                    alt:    service.type
                                ,   src:    "icons/icons/ei-" + (icons[service.type] || icons.unknown) + ".svg"
                                })
                        )<commit_msg>Added sorting of services (resources)<commit_after>/* globals jQuery */

(function ($) {
    // XXX this is the test server
    var base = "https://api-test.w3.org/";
    
    function defaultErrorHandler (xhr) {
        console.error("ERROR:", xhr.statusText);
    }
    
    // gets JSON in a way that works
    function getJSON (path, success, error) {
        path = path.indexOf("http") === 0 ? path : base + path;
        $.ajax(path, {
            type: "GET"
        ,   xhrFields: {
                withCredentials:    true
            }
        ,   success:    success
        ,   error:      error || defaultErrorHandler
        });
    }
    
    function renderCharter ($el, href) {
        getJSON(
            href
        ,   function (data) {
                console.log(data);
                $el.find("div.meta a").first().attr("href", data.uri);
            }
        );
    }
    
    function renderDomain ($el, href) {
        getJSON(
            href
        ,   function (data) {
                console.log(data);
                $el.find("div.meta a")
                    .last()
                    .attr("href", data._links.homepage.href)
                    .text(data.name + " Domain")
                ;
            }
        );
    }

    function renderPeople ($parent, href, field, name, plural) {
        if (!plural) plural = name;
        getJSON(
            href
        ,   function (data) {
                var list = data._embedded[field];
                name = list.length > 1 ? plural : name;
                console.log(name, data);
                var $card = $("<div></div>").addClass("person-card");
                $("<h3></h3>").text(name).appendTo($card);
                var $ul = $("<ul></ul>").appendTo($card);
                for (var i = 0, n = list.length; i < n; i++) {
                    var item = list[i]
                    ,   fullName = item.name.replace("[tm]", "™")
                    ,   $li = $("<li></li>").text(fullName).appendTo($ul)
                    ;
                    $("<img>")
                        .attr({
                            src:    item._links.photos ?
                                        item._links.photos.filter(function (it) { return it.name === "tiny"; })[0].href :
                                        "img/faceless.svg"
                        ,   alt:    fullName
                        ,   width:  36
                        ,   height: 48
                        })
                        .prependTo($li);
                }
                $card.appendTo($parent);
            }
        );
    }
    
    function renderReports ($ul, href) {
        getJSON(
            href
        ,   function (data) {
                // XXX we need to sort these reports
                $.each(data._embedded.reports, function (_, report) {
                    $("<li><a></a> </li>")
                        .find("a")
                            .attr("href", report.shortlink)
                            .text(report.title)
                        .end()
                        .append($("<span class='status'></span>").text("(" + report._links.latest.title + ")"))
                        .prepend(
                            $("<img width='25' height='25' src='icons/icons/ei-chevron-right.svg' alt=''>")
                        )
                        .appendTo($ul)
                    ;
                });
            }
        );
    }

    var icons = {
        tracker:    "exclamation"
    ,   wiki:       "pencil"
    ,   lists:      "envelope"
    ,   repository: "sc-github"
    ,   unknown:    "question"
    };
    function renderServices ($ul, href) {
        getJSON(
            href
        ,   function (data) {
                // Sort the services array by type
                function sortByType(a, b) {
                    return ((a.type < b.type) ? -1 : ((a.type > b.type) ? 1 : 0));
                }
                var services = data._embedded.services;
                services.sort(sortByType);

                $.each(services, function (_, service) {
                    $("<li><a></a></li>")
                        .find("a")
                            .attr("href", service.link)
                            .text(service.longdesc || service.shortdesc || service.type)
                        .end()
                        .prepend(
                            $("<img width='25' height='25'>")
                                .attr({
                                    alt:    service.type
                                ,   src:    "icons/icons/ei-" + (icons[service.type] || icons.unknown) + ".svg"
                                })
                        )
{'fraction_non_alphanumeric': 0.1384109589041096, 'fraction_numerical': 0.004493150684931507, 'mean_word_length': 0.9554317548746518, 'pattern_counts': {'":': 0, '<': 48, '<?xml version=': 0, '>': 48, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 12, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5404919', 'n_tokens_mistral': 2468, 'n_tokens_neox': 2317, 'n_words': 467}