<commit_before>/**
 * UI and function to quick search projects
 */

var $ = require('jquery');
var m = require('mithril');
var $osf = require('js/osfHelpers');

// XHR config for apiserver connection
var xhrconfig = function(xhr) {
    xhr.withCredentials = true;
};


var quickSearchProject = {
    controller: function() {
        var self = this;
        self.nodes = [];
        self.displayedNodes = [];

        // Load node list
        var url = $osf.apiV2Url('users/me/nodes/', { query : { 'embed': 'contributors', 'page[size]': 100}});
        var promise = m.request({method: 'GET', url : url, config : xhrconfig});
        promise.then(function(result){
            result.data.forEach(function(node){
                self.nodes.push(node);
            })
        });

        self.getFamilyName = function(i, node) {
            return node.embeds.contributors.data[i].embeds.users.data.attributes.family_name
        };
        self.getContributors = function (node) {
            var numContributors = node.embeds.contributors.links.meta.total;
            if (numContributors === 1) {
                return self.getFamilyName(0, node)
            }
            else if (numContributors == 2) {
                return self.getFamilyName(0, node) + ' and ' +
                        self.getFamilyName(1, node)
            }
            else {
                return self.getFamilyName(0, node) + ', ' +
                        self.getFamilyName(1, node) + ', ' +
                        self.getFamilyName(2, node) + ' and ' +
                    (numContributors - 3) + ' others'
            }

        };
        self.loadUpToTen = function () {
            requested = self.nodes.splice(0, 10);
            for (i = 0; i < requested.length; i++) {
                self.displayedNodes.push(requested[i])
            }
            return self.displayedNodes
        };

        self.formatDate = function (node) {
            return new $osf.FormattableDate(node.attributes.date_modified).local
        }

    },
    view : function(ctrl) {
        function projectView(project) {
            return m('tr', [
                m('td', project.attributes.title),
                m('td', ctrl.getContributors(project)),
                m('td', ctrl.formatDate(project))
            ])
        }

        return m('div', [
            m('table', [
                m('tr', [
                    m('th', 'Name'),
                    m('th', 'Contributors'),
                    m('th', 'Modified')
                ]),
                ctrl.loadUpToTen().map(function(n){
                    return projectView(n)
                }),
                m('button', { onclick: function() {
                    ctrl.loadUpToTen() }
                }, 'Add more')
            ])
        ])
    }
};

module.exports = quickSearchProject;<commit_msg>Display first ten nodes automatically, and then add up to ten at a time when button clicked.<commit_after>/**
 * UI and function to quick search projects
 */

var $ = require('jquery');
var m = require('mithril');
var $osf = require('js/osfHelpers');

// XHR config for apiserver connection
var xhrconfig = function(xhr) {
    xhr.withCredentials = true;
};


var quickSearchProject = {
    controller: function() {
        var self = this;
        self.nodes = [];
        self.displayedNodes = [];

        // Load node list
        var url = $osf.apiV2Url('users/me/nodes/', { query : { 'embed': 'contributors', 'page[size]': 100}});
        var promise = m.request({method: 'GET', url : url, config : xhrconfig});
        promise.then(function(result){
            result.data.forEach(function(node){
                self.nodes.push(node);
            })
            self.displayedNodes = self.nodes.splice(0, 10)
        });

        self.getFamilyName = function(i, node) {
            return node.embeds.contributors.data[i].embeds.users.data.attributes.family_name
        };
        self.getContributors = function (node) {
            var numContributors = node.embeds.contributors.links.meta.total;
            if (numContributors === 1) {
                return self.getFamilyName(0, node)
            }
            else if (numContributors == 2) {
                return self.getFamilyName(0, node) + ' and ' +
                        self.getFamilyName(1, node)
            }
            else {
                return self.getFamilyName(0, node) + ', ' +
                        self.getFamilyName(1, node) + ', ' +
                        self.getFamilyName(2, node) + ' and ' +
                    (numContributors - 3) + ' others'
            }

        };
        self.loadUpToTen = function () {
            requested = self.nodes.splice(0, 10);
            for (i = 0; i < requested.length; i++) {
                self.displayedNodes.push(requested[i])
            }
            return self.displayedNodes
        };

        self.formatDate = function (node) {
            return new $osf.FormattableDate(node.attributes.date_modified).local
        }

    },
    view : function(ctrl) {
        function projectView(project) {
            return m('tr', [
                m('td', project.attributes.title),
                m('td', ctrl.getContributors(project)),
                m('td', ctrl.formatDate(project))
            ])
        }

        return m('div', [
            m('table', [
                m('tr', [
                    m('th', 'Name'),
                    m('th', 'Contributors'),
                    m('th', 'Modified')
                ]),

                ctrl.displayedNodes.map(function(n){
                    return projectView(n)
                }),
            ])
        ])
    }
};

module.exports = quickSearchProject;
{'fraction_non_alphanumeric': 0.13374125874125875, 'fraction_numerical': 0.006468531468531468, 'mean_word_length': 1.530296329057939, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, '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': '4033904', 'n_tokens_mistral': 1651, 'n_tokens_neox': 1555, 'n_words': 310}