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

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

// CSS
require('css/quick-project-search-plugin.css');

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

var quickSearchProject = {
    controller: function() {
        var self = this;
        self.nodes = m.prop([]); // Pending nodes waiting to be displayed
        self.displayedNodes = m.prop([]); // Nodes that are rendered
        self.nonMatchingNodes = m.prop([]); //Nodes that don't match search query
        //self.lastLogin = '';
        // NEED TO FIGURE OUT WHAT TO DO ABOUT LASTLOGIN.
        self.lastLogin = '2016-01-01T15:20:11.531000';
        self.commentsCount = {};
        self.logsCount = {};
        self.sortState = m.prop();
        self.countState = m.prop();
        self.next = m.prop();
        self.allLoaded = m.prop(false);

        // Load first ten nodes
        var url = $osf.apiV2Url('users/me/nodes/', { query : { 'embed': 'contributors'}});
        var promise = m.request({method: 'GET', url : url, config : xhrconfig});
        promise.then(function(result) {
            result.data.forEach(function (node) {
                self.nodes().push(node);
            });
            self.next(result.links.next);
            self.countState(10);
            self.displayedNodes(self.nodes().splice(0, 10));
        });
        promise.then(
            function(){
                self.recursiveNodes(self.next())
            }
        );

        // Recursively calls remaining user's nodes
        self.recursiveNodes = function (url) {
             var nextPromise = m.request({method: 'GET', url : url, config : xhrconfig, background : true});
                nextPromise.then(function(result){
                    result.data.forEach(function(node){
                        self.nodes().push(node)
                    });
                    self.next(result.links.next);
                    console.log(self.next());<commit_msg>Default sort state of nodes is dateDesc.<commit_after>/**
 * UI and function to quick search projects
 */

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

// CSS
require('css/quick-project-search-plugin.css');

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

var quickSearchProject = {
    controller: function() {
        var self = this;
        self.nodes = m.prop([]); // Pending nodes waiting to be displayed
        self.displayedNodes = m.prop([]); // Nodes that are rendered
        self.nonMatchingNodes = m.prop([]); //Nodes that don't match search query
        //self.lastLogin = '';
        // NEED TO FIGURE OUT WHAT TO DO ABOUT LASTLOGIN.
        self.lastLogin = '2016-01-01T15:20:11.531000';
        self.commentsCount = {};
        self.logsCount = {};
        self.sortState = m.prop('dateDesc');
        self.countState = m.prop();
        self.next = m.prop();
        self.allLoaded = m.prop(false);

        // Load first ten nodes
        var url = $osf.apiV2Url('users/me/nodes/', { query : { 'embed': 'contributors'}});
        var promise = m.request({method: 'GET', url : url, config : xhrconfig});
        promise.then(function(result) {
            result.data.forEach(function (node) {
                self.nodes().push(node);
            });
            self.next(result.links.next);
            self.countState(10);
            self.displayedNodes(self.nodes().splice(0, 10));
        });
        promise.then(
            function(){
                self.recursiveNodes(self.next())
            }
        );

        // Recursively calls remaining user's nodes
        self.recursiveNodes = function (url) {
             var nextPromise = m.request({method: 'GET', url : url, config : xhrconfig, background : true});
                nextPromise.then(function(result){
                    result.data.forEach(function(node){
                        self.nodes().push(node)
                    });
                    self.next(result.links.next);
                    console.log(self.next());
{'fraction_non_alphanumeric': 0.14285714285714285, 'fraction_numerical': 0.012319355602937692, 'mean_word_length': 1.969057665260197, 'pattern_counts': {'":': 0, '<': 3, '<?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': '7382837', 'n_tokens_mistral': 1247, 'n_tokens_neox': 1184, 'n_words': 267}