<commit_before>(function() {
    // Get application context
    var app = Sammy.apps['#main'];
    var store = app.store;

    /**
     * Apps
     *
     */

    // List installed apps
    app.get('#/apps', function (c) {
        c.api('/apps?installed', function(data) { // http://api.yunohost.org/#!/app/app_list_get_8
            var apps = data['apps'];
            c.arraySortById(apps);
            c.view('app/app_list', {apps: apps});
        });
    });

    function levelToColor(level) {
        if (level >= 8) {
            return 'success';
        }
        else if (level > 4) {
            return 'hmokay';
        }
        else if (level >= 1) {
            return 'warning';
        }
        else if (isNaN(level)) {
            return 'default';
        } else {
            return 'danger'
        }
    }

    function stateToColor(state) {
        if (state === "high-quality") {
            return 'success';
        }
        else if (state === "working") {
            return 'hmokay';
        }
        else {
            return 'danger';
        }
    }

    function maintainedStateToColor(state) {
        if ( state === "request_help" ) {
            return 'info';
        }
        else if ( state === "request_adoption" ) {
            return 'warning';
        }
        else if ( state === "orphaned" ) {
            return 'danger';
        }
        else {
            return 'success';
        }
    }

    function combineColors(stateColor, levelColor, installable) {
        if (stateColor === "danger" || levelColor === "danger") {
            return 'danger';
        }
        else if (stateColor === "warning" || levelColor === "warning" || levelColor === "default") {
            return 'warning';
        }
        else if (stateColor === "hmokay" || levelColor === "hmokay") {
            return 'hmokay';
        }
        else
        {
            return 'success';
        }
    }

    // List available apps
    app.get('#/apps/install', function (c) {
        c.api('/apps', function (data) { // http://api.yunohost.org/#!/app/app_list_get_8
            c.api('/apps?raw', function (dataraw) { // http://api.yunohost.org/#!/app/app_list_get_8
                var apps = []
                $.each(data['apps'], function(k, v) {
                    if (dataraw[v['id']]['high_quality'] && parseInt(dataraw[v['id']]['level']) > 7)
                    {
                        dataraw[v['id']]['state'] = "high-quality";
                    }
                    if ( dataraw[v['id']]['maintained'] === false )
                    {
                        dataraw[v['id']]['maintained'] = "orphaned";
                    }
                    else if ( dataraw[v['id']]['maintained'] === true )
                    {
                        dataraw[v['id']]['maintained'] = "maintained";
                    }

                    var state = dataraw[v['id']]['state'];
                    var levelFormatted = parseInt(dataraw[v['id']]['level']);
                    var isWorking = (state === 'working' || state === "high-quality") && levelFormatted > 0;

                    // Keep only the first instance of each app and remove not working apps
                    if (!v['id'].match(/__[0-9]{1,5}$/) && (state !== 'notworking')) {

                        dataraw[v['id']]['installable'] = (!v['installed'] || dataraw[v['id']].manifest.multi_instance)
                        dataraw[v['id']]['levelFormatted'] = isNaN(levelFormatted) ? '?' : levelFormatted;
                        dataraw[v['id']]['levelColor'] = levelToColor(levelFormatted);
                        dataraw[v['id']]['stateColor'] = stateToColor(state);
                        dataraw[v['id']]['maintainedColor'] = maintainedStateToColor(dataraw[v['id']]['maintained']);
                        dataraw[v['id']]['installColor'] = combineColors(dataraw[v['id']]['stateColor'], dataraw[v['id']]['levelColor']);
                        dataraw[v['id']]['displayLicense'] = (dataraw[v['id']]['manifest']['license'] !== undefined
                                                              && dataraw[v['id']]['manifest']['license'] !== 'free');
                        dataraw[v['id']]['updateDate'] = dataraw[v['id']]['lastUpdate'] * 1000 || 0;
                        dataraw[v['id']]['isSafe'] = (dataraw[v['id']]['installColor'] !== 'danger');
                        dataraw[v['id']]['decentQuality'] = (dataraw[v['id']]['levelColor'] === "hmokay"
                                                          || dataraw[v['id']]['levelColor'] === "success")?"decentQuality":"badQuality";
                        dataraw[v['id']]['isWorking'] = isWorking ? "isworking" : "notFullyWorking";
                        dataraw[v['id']]['isHighQuality'] = (state === "high-quality") ? "isHighQuality" : "";

                        jQuery.extend(dataraw[v['id']], v);
                        apps.push(dataraw[v['id']]);
                    }
                });

                // Sort app list
                c.arraySortById(apps);

                // setup filtering of apps once the view is loaded
                function  setupFilterEvents () {
                    // Uses plugin isotope to filter apps (we could had ordering to)
                    var cardGrid = jQuery('.grid').isotope({
                      itemSelector: '.app-card',
                      layoutMode: 'fitRows',
                      transitionDuration: 200
                    });

                    filterByClassAndName = function () {
                      var input = jQuery("#filter-app-cards").val().toLowerCase();
                      var inputMatch = (jQuery(this).find('.app-title').text().toLowerCase().indexOf(input) > -1);

                      var filterClass = jQuery("#dropdownFilter").attr("data-filter");
                      var classMatch = (filterClass === '*') ? true : jQuery(this).hasClass(filterClass);
                      return inputMatch && classMatch;
                    },

                    // Default filter is 'decent quality apps'
                    cardGrid.isotope({ filter: '.decentQuality' });

                    jQuery('.dropdownFilter').on('click', function() {
                        // change dropdown label
                        jQuery('#app-cards-list-filter-text').text(jQuery(this).find('.menu-item').text());
                         // change filter attribute
                        jQuery('#dropdownFilter').attr("data-filter", jQuery(this).attr("data-filter"));
                        // filter !
                        cardGrid.isotope({ filter: filterByClassAndName });
                    });

                    jQuery("#filter-app-cards").on("keyup", function() {
                        cardGrid.isotope({ filter: filterByClassAndName });
                    });
                }; 

                // render
                c.view('app/app_list_install', {apps: apps}, setupFilterEvents);

            });
        });
    });

    // List available apps lists
    app.get('#/apps/lists', function (c) {
        c.api('/appslists', function(data) {
            list = [];
            var has_community_list = false;
            $.each(data, function(listname, listinfo) {
                list.push({
                    'name': listname,
                    'url': listinfo['url'],
                    'lastUpdate': listinfo['lastUpdate']
                });

                // Check for community list
                if (listname == 'community' || listinfo['url'] == 'https://app.yunohost.org/community.json') {
                    has_community_list = true;
                }
            });

            c.view('app/app_appslists_list', {
                appslists: list,
                has_community_list: has_community_list
            });
        }, 'GET');<commit_msg>Clean / simplify code ...<commit_after>(function() {
    // Get application context
    var app = Sammy.apps['#main'];
    var store = app.store;

    /**
     * Apps
     *
     */

    // List installed apps
    app.get('#/apps', function (c) {
        c.api('/apps?installed', function(data) { // http://api.yunohost.org/#!/app/app_list_get_8
            var apps = data['apps'];
            c.arraySortById(apps);
            c.view('app/app_list', {apps: apps});
        });
    });

    function levelToColor(level) {
        if (level >= 8) {
            return 'success';
        }
        else if (level > 4) {
            return 'hmokay';
        }
        else if (level >= 1) {
            return 'warning';
        }
        else if (isNaN(level)) {
            return 'default';
        } else {
            return 'danger'
        }
    }

    function stateToColor(state) {
        if (state === "high-quality") {
            return 'success';
        }
        else if (state === "working") {
            return 'hmokay';
        }
        else {
            return 'danger';
        }
    }

    function maintainedStateToColor(state) {
        if ( state === "request_help" ) {
            return 'info';
        }
        else if ( state === "request_adoption" ) {
            return 'warning';
        }
        else if ( state === "orphaned" ) {
            return 'danger';
        }
        else {
            return 'success';
        }
    }

    function combineColors(stateColor, levelColor, installable) {
        if (stateColor === "danger" || levelColor === "danger") {
            return 'danger';
        }
        else if (stateColor === "warning" || levelColor === "warning" || levelColor === "default") {
            return 'warning';
        }
        else if (stateColor === "hmokay" || levelColor === "hmokay") {
            return 'hmokay';
        }
        else
        {
            return 'success';
        }
    }

    // List available apps
    app.get('#/apps/install', function (c) {
        c.api('/apps', function (data) { // http://api.yunohost.org/#!/app/app_list_get_8
            c.api('/apps?raw', function (dataraw) { // http://api.yunohost.org/#!/app/app_list_get_8
                var apps = []
                $.each(data['apps'], function(k, v) {
                    app = dataraw[v['id']];
                    app.level = parseInt(app.level);

                    if (app.high_quality && app.level > 7)
                    {
                        app.state = "high-quality";
                    }
                    if ( app.maintained === false )
                    {
                        app.maintained = "orphaned";
                    }
                    else if ( app.maintained === true )
                    {
                        app.maintained = "maintained";
                    }

                    var isWorking = (app.state === 'working' || app.state === "high-quality") && app.level > 0;

                    // Keep only the first instance of each app and remove not working apps
                    if (!v['id'].match(/__[0-9]{1,5}$/) && (app.state !== 'notworking')) {

                        app.installable = (!v.installed || app.manifest.multi_instance)
                        app.levelFormatted = isNaN(app.level) ? '?' : app.level;

                        app.levelColor = levelToColor(app.level);
                        app.stateColor = stateToColor(app.state);
                        app.maintainedColor = maintainedStateToColor(app.maintained);
                        app.installColor = combineColors(app.stateColor, app.levelColor);

                        app.displayLicense = (app['manifest']['license'] !== undefined
                                           && app['manifest']['license'] !== 'free');
                        app.updateDate = app.lastUpdate * 1000 || 0;
                        app.isSafe = (app.installColor !== 'danger');
                        app.isWorking = isWorking ? "isworking" : "notFullyWorking";
                        app.isHighQuality = (app.state === "high-quality") ? "isHighQuality" : "";
                        app.decentQuality = (app.levelColor === "hmokay"
                                          || app.levelColor === "success")?"decentQuality":"badQuality";

                        jQuery.extend(app, v);
                        apps.push(app);
                    }
                });

                // Sort app list
                c.arraySortById(apps);

                // setup filtering of apps once the view is loaded
                function  setupFilterEvents () {
                    // Uses plugin isotope to filter apps (we could had ordering to)
                    var cardGrid = jQuery('.grid').isotope({
                      itemSelector: '.app-card',
                      layoutMode: 'fitRows',
                      transitionDuration: 200
                    });

                    filterByClassAndName = function () {
                      var input = jQuery("#filter-app-cards").val().toLowerCase();
                      var inputMatch = (jQuery(this).find('.app-title').text().toLowerCase().indexOf(input) > -1);

                      var filterClass = jQuery("#dropdownFilter").attr("data-filter");
                      var classMatch = (filterClass === '*') ? true : jQuery(this).hasClass(filterClass);
                      return inputMatch && classMatch;
                    },

                    // Default filter is 'decent quality apps'
                    cardGrid.isotope({ filter: '.decentQuality' });

                    jQuery('.dropdownFilter').on('click', function() {
                        // change dropdown label
                        jQuery('#app-cards-list-filter-text').text(jQuery(this).find('.menu-item').text());
                         // change filter attribute
                        jQuery('#dropdownFilter').attr("data-filter", jQuery(this).attr("data-filter"));
                        // filter !
                        cardGrid.isotope({ filter: filterByClassAndName });
                    });

                    jQuery("#filter-app-cards").on("keyup", function() {
                        cardGrid.isotope({ filter: filterByClassAndName });
                    });
                };

                // render
                c.view('app/app_list_install', {apps: apps}, setupFilterEvents);

            });
        });
    });

    // List available apps lists
    app.get('#/apps/lists', function (c) {
        c.api('/appslists', function(data) {
            list = [];
            var has_community_list = false;
            $.each(data, function(listname, listinfo) {
                list.push({
                    'name': listname,
                    'url': listinfo['url'],
                    'lastUpdate': listinfo['lastUpdate']
                });

                // Check for community list
                if (listname == 'community' || listinfo['url'] == 'https://app.yunohost.org/community.json') {
                    has_community_list = true;
                }
            });

            c.view('app/app_appslists_list', {
                appslists: list,
                has_community_list: has_community_list
            });
        }, 'GET');
{'fraction_non_alphanumeric': 0.14955489614243322, 'fraction_numerical': 0.0027695351137487635, 'mean_word_length': 1.360099595393713, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 15, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5756018', 'n_tokens_mistral': 4104, 'n_tokens_neox': 3787, 'n_words': 726}