<commit_before>/**
 * Initialization code for the home page.
 */

'use strict';

var $ = require('jquery');
var m = require('mithril');

var QuickSearchProject = require('js/home-page/quickProjectSearchPlugin');
var NewAndNoteworthy = require('js/home-page/newAndNoteworthyPlugin');
var MeetingsAndConferences = require('js/home-page/meetingsAndConferencesPlugin');
var AddProject = require('js/addProjectPlugin');
var $osf = require('js/osfHelpers');
var Raven = require('raven-js');

var xhrconfig = function (xhr) {
    xhr.withCredentials = true;
    xhr.setRequestHeader('Content-Type', 'application/vnd.api+json;');
    xhr.setRequestHeader('Accept', 'application/vnd.api+json; ext=bulk');
};
var columnSizeClass = '.col-md-10 col-md-offset-1 col-lg-8 col-lg-offset-2';

$(document).ready(function(){
    var osfHome = {
        controller : function(){
            var self = this;
            self.categoryList = [];
            self.loadCategories = function _loadCategories () {
                var promise = m.request({method : 'OPTIONS', url : $osf.apiV2Url('nodes/', { query : {}}), config : xhrconfig});
                promise.then(function _success(results){
                    if(results.actions.POST.category){
                        self.categoryList = results.actions.POST.category.choices;
                        self.categoryList.sort(function(a, b){ // Quick alphabetical sorting
                            if(a.value < b.value) return -1;
                            if(a.value > b.value) return 1;
                            return 0;
                        });
                    }
                }, function _error(results){
                    var message = 'Error loading project category names for the home page.';
                    Raven.captureMessage(message, {requestReturn: results});
                });
                return promise;
            };
            self.loadCategories();

        },
        view : function(ctrl, args) {
            return [
                m('.quickSearch', m('.container.p-t-lg',
                    [
                        m('.row', [
                            m(columnSizeClass, m('.pull-right',
                                m.component(AddProject, {
                                    buttonTemplate : m('button.btn.btn-success.m-t-md[data-toggle="modal"][data-target="#addProjectFromHome"]', {onclick: function(){
                                        $osf.trackClick('quickSearch', 'add-project', 'open-add-project-modal');
                                    }}, 'Create New Project'),
                                    modalID : 'addProjectFromHome',
                                    categoryList : ctrl.categoryList,
                                    stayCallback : function _stayCallback_inPanel() {
                                        document.location.reload(true);
                                    },
                                    trackingCategory: 'quickSearch',
                                    trackingAction: 'add-project'
                                })
                            ))
                        ]),
                        m('.row.m-t-lg', [
                            m(columnSizeClass, m.component(QuickSearchProject, {}))
                        ])
                    ]<commit_msg>Add title to "My Dashboard"<commit_after>/**
 * Initialization code for the home page.
 */

'use strict';

var $ = require('jquery');
var m = require('mithril');

var QuickSearchProject = require('js/home-page/quickProjectSearchPlugin');
var NewAndNoteworthy = require('js/home-page/newAndNoteworthyPlugin');
var MeetingsAndConferences = require('js/home-page/meetingsAndConferencesPlugin');
var AddProject = require('js/addProjectPlugin');
var $osf = require('js/osfHelpers');
var Raven = require('raven-js');

var xhrconfig = function (xhr) {
    xhr.withCredentials = true;
    xhr.setRequestHeader('Content-Type', 'application/vnd.api+json;');
    xhr.setRequestHeader('Accept', 'application/vnd.api+json; ext=bulk');
};
var columnSizeClass = '.col-md-10 col-md-offset-1 col-lg-8 col-lg-offset-2';

$(document).ready(function(){
    var osfHome = {
        controller : function(){
            var self = this;
            self.categoryList = [];
            self.loadCategories = function _loadCategories () {
                var promise = m.request({method : 'OPTIONS', url : $osf.apiV2Url('nodes/', { query : {}}), config : xhrconfig});
                promise.then(function _success(results){
                    if(results.actions.POST.category){
                        self.categoryList = results.actions.POST.category.choices;
                        self.categoryList.sort(function(a, b){ // Quick alphabetical sorting
                            if(a.value < b.value) return -1;
                            if(a.value > b.value) return 1;
                            return 0;
                        });
                    }
                }, function _error(results){
                    var message = 'Error loading project category names for the home page.';
                    Raven.captureMessage(message, {requestReturn: results});
                });
                return promise;
            };
            self.loadCategories();

        },
        view : function(ctrl, args) {
            return [
                m('.quickSearch', m('.container.p-t-lg',
                    [
                        m('.row', [
                            m(columnSizeClass, m('h2.col-sm-9', 'My Dashboard'), m('.pull-right.col-sm-3',
                                m.component(AddProject, {
                                    buttonTemplate : m('button.btn.btn-success.m-t-md[data-toggle="modal"][data-target="#addProjectFromHome"]', {onclick: function(){
                                        $osf.trackClick('quickSearch', 'add-project', 'open-add-project-modal');
                                    }}, 'Create New Project'),
                                    modalID : 'addProjectFromHome',
                                    categoryList : ctrl.categoryList,
                                    stayCallback : function _stayCallback_inPanel() {
                                        document.location.reload(true);
                                    },
                                    trackingCategory: 'quickSearch',
                                    trackingAction: 'add-project'
                                })
                            ))
                        ]),
                        m('.row.m-t-lg', [
                            m(columnSizeClass, m.component(QuickSearchProject, {}))
                        ])
                    ]
{'fraction_non_alphanumeric': 0.1213743864346274, 'fraction_numerical': 0.0031236055332440876, 'mean_word_length': 1.3860894251242015, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 20, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5774856', 'n_tokens_mistral': 1694, 'n_tokens_neox': 1598, 'n_words': 295}