<commit_before>'use strict';

(function () {

    var ulTanaman = document.querySelector('#ulTanaman');
    var apiUrl = appUrl + '/api/:id/tanaman';
    var apiUrlUser = appUrl + '/api/:id';
    var dbResult;

    function updateTanaman (data) {
        dbResult = JSON.parse(data);
        console.log(dbResult);
        sortAscending();
        isiListTanaman();
    }

    function isiListTanaman () {
        while (ulTanaman.firstChild) {
            ulTanaman.removeChild(ulTanaman.firstChild);
        }

        for (var i=0; i<dbResult.length; i++) {
            var li = document.createElement('li');
            li.setAttribute('id', dbResult[i]._id);

            var aTanaman = document.createElement('a');
            aTanaman.setAttribute('class', 'btn btn-default btn-lg');
            aTanaman.setAttribute('href', '#');

            var node = document.createTextNode(dbResult[i].nama + ' (' + dbResult[i].upvotes + ' poin)');
            aTanaman.appendChild(node);
            li.appendChild(aTanaman);
            ulTanaman.appendChild(li);
        }
    }

    function sortAscending () {
        dbResult.sort( function (a, b) {
            var nameA = a.nama.toUpperCase();
            var nameB = b.nama.toUpperCase();
            if (nameA < nameB) {
                return -1;
            }
            if (nameA > nameB) {
                return 1;
            }
            return 0;
        });
    }
    function sortDescending () {
        dbResult.sort( function (a, b) {
            var nameA = a.nama.toUpperCase();
            var nameB = b.nama.toUpperCase();
            if (nameA > nameB) {
                return -1;
            }
            if (nameA < nameB) {
                return 1;
            }
            return 0;
        });
    }
    function sortUpvotes () {
        dbResult.sort( function (a, b) {
            if (a.upvotes > b.upvotes) {
                return -1;
            }
            if (a.upvotes < b.upvotes) {
                return 1;
            }
            return 0;
        });
    }

    ajaxFunctions.ready(ajaxFunctions.ajaxRequest('GET', apiUrl, updateTanaman));


    //event-event
    var btnSortAsc = document.getElementById('btnSortAsc');
    btnSortAsc.addEventListener('click', function () {
        sortAscending();
        isiListTanaman();
    });

    var btnSortDsc = document.getElementById('btnSortDsc');
    btnSortDsc.addEventListener('click', function () {
        sortDescending();
        isiListTanaman();
    });

    var btnSortUpv = document.getElementById('btnSortUpv');
    btnSortUpv.addEventListener('click', function () {
        sortUpvotes();
        isiListTanaman();
    });

})();<commit_msg>Tampilkan nama user di page tanaman<commit_after>'use strict';

(function () {

    var ulTanaman = document.querySelector('#ulTanaman');
    var apiUrl = appUrl + '/api/:id/tanaman';
    var apiUrlUser = appUrl + '/api/:id';
    var dbResult;

    function updateTanaman (data) {
        dbResult = JSON.parse(data);
        console.log(dbResult);
        sortAscending();
        isiListTanaman();
    }

    function isiListTanaman () {
        while (ulTanaman.firstChild) {
            ulTanaman.removeChild(ulTanaman.firstChild);
        }

        for (var i=0; i<dbResult.length; i++) {
            var li = document.createElement('li');
            li.setAttribute('id', dbResult[i]._id);

            var aTanaman = document.createElement('a');
            aTanaman.setAttribute('class', 'btn btn-default btn-lg');
            aTanaman.setAttribute('href', '#');

            var node = document.createTextNode(dbResult[i].nama + ' (' + dbResult[i].upvotes + ' poin)');
            aTanaman.appendChild(node);
            li.appendChild(aTanaman);
            ulTanaman.appendChild(li);
        }
    }

    function sortAscending () {
        dbResult.sort( function (a, b) {
            var nameA = a.nama.toUpperCase();
            var nameB = b.nama.toUpperCase();
            if (nameA < nameB) {
                return -1;
            }
            if (nameA > nameB) {
                return 1;
            }
            return 0;
        });
    }
    function sortDescending () {
        dbResult.sort( function (a, b) {
            var nameA = a.nama.toUpperCase();
            var nameB = b.nama.toUpperCase();
            if (nameA > nameB) {
                return -1;
            }
            if (nameA < nameB) {
                return 1;
            }
            return 0;
        });
    }
    function sortUpvotes () {
        dbResult.sort( function (a, b) {
            if (a.upvotes > b.upvotes) {
                return -1;
            }
            if (a.upvotes < b.upvotes) {
                return 1;
            }
            return 0;
        });
    }

    ajaxFunctions.ready(ajaxFunctions.ajaxRequest('GET', apiUrl, updateTanaman));


    //event-event
    document.addEventListener('DOMContentLoaded', function() {
        ajaxFunctions.ready(ajaxFunctions.ajaxRequest('GET', apiUrlUser, function(data) {
            var userObject = JSON.parse(data);
            var username = document.getElementById('display-name');
            username.innerHTML = userObject['displayName'];
        }));
    });

    var btnSortAsc = document.getElementById('btnSortAsc');
    btnSortAsc.addEventListener('click', function () {
        sortAscending();
        isiListTanaman();
    });

    var btnSortDsc = document.getElementById('btnSortDsc');
    btnSortDsc.addEventListener('click', function () {
        sortDescending();
        isiListTanaman();
    });

    var btnSortUpv = document.getElementById('btnSortUpv');
    btnSortUpv.addEventListener('click', function () {
        sortUpvotes();
        isiListTanaman();
    });

})();
{'fraction_non_alphanumeric': 0.13153340256143994, 'fraction_numerical': 0.003461405330564209, 'mean_word_length': 1.7730326295585412, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2390719', 'n_tokens_mistral': 1757, 'n_tokens_neox': 1661, 'n_words': 310}