<commit_before>/**
 * Handles Project Organizer on dashboard page of OSF.
 * For Treebeard and _item API's check: https://github.com/caneruguz/treebeard/wiki
 */
'use strict';

var Treebeard = require('treebeard');

// CSS
require('css/typeahead.css');
require('css/fangorn.css');

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


var LinkObject;
var NodeFetcher;
var formatDataforPO;
var MOBILE_WIDTH = 767;

/**
 * Edits the template for the column titles.
 * @param {Object} item A Treebeard _item object for the row involved. Node information is inside item.data
 * @this Treebeard.controller Check Treebeard API for methods available
 * @private
 */
function _poTitleColumn(item) {
    var tb = this;
    var preventSelect = function(e){
        e.stopImmediatePropagation();
    };
    var node = item.data; // Where actual data of the node is
    var css = ''; // Keep for future expandability -- Remove: item.data.isSmartFolder ? 'project-smart-folder smart-folder' : '';
    if (item.data.archiving) { // TODO check if this variable will be available
        return  m('span', {'class': 'registration-archiving'}, node.attributes.title + ' [Archiving]');
    } else if(node.links.html){
        return [ m('a.fg-file-links', { 'class' : css, href : node.links.html, 'data-nodeID' : node.id, 'data-nodeTitle': node.attributes.title, onclick : function(event) {
            preventSelect.call(this, event);
            $osf.trackClick('myProjects', 'projectOrganizer', 'navigate-to-specific-project');
        }}, node.attributes.title) ];
    } else {
        return  m('span', { 'class' : css, 'data-nodeID' : node.id, 'data-nodeTitle': node.attributes.title }, node.attributes.title);
    }
}

/**
 * Contributors have first person's name and then number of contributors. This function returns the proper html
 * @param {Object} item A Treebeard _item object for the row involved. Node information is inside item.data
 * @returns {Object} A Mithril virtual DOM template object
 * @private
 */
function _poContributors(item) {
    var contributorList = item.data.embeds.contributors.data;
    if(!contributorList){
        return '';
    }
    if (contributorList.length === 0) {
        return '';
    }

    return contributorList.map(function (person, index, arr) {
        var name;
        var familyName;
        var givenName;
        var fullName;
        if (person.embeds.users.data) {
            familyName = person.embeds.users.data.attributes.family_name;
            givenName = person.embeds.users.data.attributes.given_name;
            fullName = person.embeds.users.data.attributes.full_name;

        }
        if (person.embeds.users.errors) {
            familyName = person.embeds.users.errors[0].meta.family_name;
            givenName = person.embeds.users.errors[0].meta.given_name;
            fullName = person.embeds.users.errors[0].meta.full_name;
        }
        if (familyName) {
            name = familyName;
        } else if(givenName){
            name = givenName;
        } else if(fullName){
            name = fullName;
        } else {
            name = 'A contributor';
        }
        var comma;
        if (index === 0) {
            comma = '';
        } else {
            comma = ', ';
        }
        if (index > 2) {
            return m('span');
        }
        if (index === 2) {
            return m('span', ' + ' + (arr.length - 2));
        }
        return m('span', comma + name);<commit_msg>fix total contributor number in project organizer<commit_after>/**
 * Handles Project Organizer on dashboard page of OSF.
 * For Treebeard and _item API's check: https://github.com/caneruguz/treebeard/wiki
 */
'use strict';

var Treebeard = require('treebeard');

// CSS
require('css/typeahead.css');
require('css/fangorn.css');

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


var LinkObject;
var NodeFetcher;
var formatDataforPO;
var MOBILE_WIDTH = 767;

/**
 * Edits the template for the column titles.
 * @param {Object} item A Treebeard _item object for the row involved. Node information is inside item.data
 * @this Treebeard.controller Check Treebeard API for methods available
 * @private
 */
function _poTitleColumn(item) {
    var tb = this;
    var preventSelect = function(e){
        e.stopImmediatePropagation();
    };
    var node = item.data; // Where actual data of the node is
    var css = ''; // Keep for future expandability -- Remove: item.data.isSmartFolder ? 'project-smart-folder smart-folder' : '';
    if (item.data.archiving) { // TODO check if this variable will be available
        return  m('span', {'class': 'registration-archiving'}, node.attributes.title + ' [Archiving]');
    } else if(node.links.html){
        return [ m('a.fg-file-links', { 'class' : css, href : node.links.html, 'data-nodeID' : node.id, 'data-nodeTitle': node.attributes.title, onclick : function(event) {
            preventSelect.call(this, event);
            $osf.trackClick('myProjects', 'projectOrganizer', 'navigate-to-specific-project');
        }}, node.attributes.title) ];
    } else {
        return  m('span', { 'class' : css, 'data-nodeID' : node.id, 'data-nodeTitle': node.attributes.title }, node.attributes.title);
    }
}

/**
 * Contributors have first person's name and then number of contributors. This function returns the proper html
 * @param {Object} item A Treebeard _item object for the row involved. Node information is inside item.data
 * @returns {Object} A Mithril virtual DOM template object
 * @private
 */
function _poContributors(item) {
    var contributorList = item.data.embeds.contributors.data;
    if(!contributorList){
        return '';
    }
    if (contributorList.length === 0) {
        return '';
    }
    var totalContributors = item.data.embeds.contributors.links.meta.total;

    return contributorList.map(function (person, index, arr) {
        var name;
        var familyName;
        var givenName;
        var fullName;
        if (person.embeds.users.data) {
            familyName = person.embeds.users.data.attributes.family_name;
            givenName = person.embeds.users.data.attributes.given_name;
            fullName = person.embeds.users.data.attributes.full_name;

        }
        if (person.embeds.users.errors) {
            familyName = person.embeds.users.errors[0].meta.family_name;
            givenName = person.embeds.users.errors[0].meta.given_name;
            fullName = person.embeds.users.errors[0].meta.full_name;
        }
        if (familyName) {
            name = familyName;
        } else if(givenName){
            name = givenName;
        } else if(fullName){
            name = fullName;
        } else {
            name = 'A contributor';
        }
        var comma;
        if (index === 0) {
            comma = '';
        } else {
            comma = ', ';
        }
        if (index > 2) {
            return m('span');
        }
        if (index === 2) {
            return m('span', ' + ' + (totalContributors -2)); // We already show names of the two
        }
        return m('span', comma + name);
{'fraction_non_alphanumeric': 0.13021264843965755, 'fraction_numerical': 0.0030378348522507597, 'mean_word_length': 2.55223148602256, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 2, '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': '6256547', 'n_tokens_mistral': 2175, 'n_tokens_neox': 2125, 'n_words': 559}