<commit_before>'use strict';

require('c3/c3.css');
require('../../css/share-search.css');

var $ = require('jquery');
var m = require('mithril');
var $osf = require('js/osfHelpers');
var Stats = require('./stats');
var utils = require('./utils');
var SideBar = require('./sideBar');
var Results = require('./results');
var Footer = require('./footer');
var History = require('exports?History!history');
var SearchBar = require('./searchBar');

var ShareApp = {};

ShareApp.ViewModel = function() {
    var self = this;

    self.time = 0;
    self.page = 0;
    self.count = 0;
    self.results = null;
    self.query = m.prop($osf.urlParams().q || '');
    self.sort = m.prop($osf.urlParams().sort || 'Relevance');
    self.showStats = false;
    self.resultsLoading = m.prop(false);
    self.rawNormedLoaded = m.prop(false);
    self.showFooter = (self.query() === '');
    self.requiredFilters = $osf.urlParams().required ? $osf.urlParams().required.split('|') : [];
    self.optionalFilters = $osf.urlParams().optional ? $osf.urlParams().optional.split('|') : [];

    self.sortMap = {
        'Date': 'providerUpdatedDateTime',
        Relevance: null
    };

    /** Sort the SHARE provider list for display. **/
    self.sortProviders = function() {
        return $.map(Object.keys(self.ProviderMap), function(result, index){
            return self.ProviderMap[result];
        }).sort(function(a,b){
                return a.long_name.toUpperCase() > b.long_name.toUpperCase() ? 1: -1;
        });
    };
};


ShareApp.view = function(ctrl) {
    return m('', [
        m('.col-xs-12', [
            SearchBar.view(ctrl.searchBarController),
            Stats.view(ctrl.statsController),
            ctrl.vm.results !== null ? m.component(SortBox, {vm: ctrl.vm}): [],
            ctrl.vm.results !== null ? m('.row.search-content', [
               m('.col-md-2.col-lg-3', [
                    m.component(SideBar, {vm: ctrl.vm})
                ]),
                m('.col-md-10.col-lg-9', [
                    m.component(Results, {vm: ctrl.vm})
                ])
            ]) : [],
            Footer.view(ctrl.footerController),
        ])
    ]);
};

ShareApp.controller = function() {
    var self = this;

    self.vm = new ShareApp.ViewModel(self.vm);

    History.replaceState({
        query: self.vm.query(),
        sort: self.vm.sort(),
        optionalFilters: self.vm.optionalFilters,
        requiredFilters: self.vm.requiredFilters
    }, 'OSF | SHARE', '?' + utils.buildURLParams(self.vm));

    m.request({
        method: 'get',
        background: false,
        url: '/api/v1/share/providers/'
    }).then(function(data) {
        self.vm.ProviderMap = data.providerMap;

        self.statsController = new Stats.controller(self.vm);
        self.searchBarController = new SearchBar.controller(self.vm);
        self.footerController = new Footer.controller(self.vm);

    });

    m.request({<commit_msg>update index.js to use new footer component<commit_after>'use strict';

require('c3/c3.css');
require('../../css/share-search.css');

var $ = require('jquery');
var m = require('mithril');
var $osf = require('js/osfHelpers');
var Stats = require('./stats');
var utils = require('./utils');
var SideBar = require('./sideBar');
var Results = require('./results');
var Footer = require('./footer');
var History = require('exports?History!history');
var SearchBar = require('./searchBar');

var ShareApp = {};

ShareApp.ViewModel = function() {
    var self = this;

    self.time = 0;
    self.page = 0;
    self.count = 0;
    self.results = null;
    self.query = m.prop($osf.urlParams().q || '');
    self.sort = m.prop($osf.urlParams().sort || 'Relevance');
    self.showStats = false;
    self.resultsLoading = m.prop(false);
    self.rawNormedLoaded = m.prop(false);
    self.showFooter = (self.query() === '');
    self.requiredFilters = $osf.urlParams().required ? $osf.urlParams().required.split('|') : [];
    self.optionalFilters = $osf.urlParams().optional ? $osf.urlParams().optional.split('|') : [];

    self.sortMap = {
        'Date': 'providerUpdatedDateTime',
        Relevance: null
    };

    /** Sort the SHARE provider list for display. **/
    self.sortProviders = function() {
        return $.map(Object.keys(self.ProviderMap), function(result, index){
            return self.ProviderMap[result];
        }).sort(function(a,b){
                return a.long_name.toUpperCase() > b.long_name.toUpperCase() ? 1: -1;
        });
    };
};


ShareApp.view = function(ctrl) {
    return m('', [
        m('.col-xs-12', [
            SearchBar.view(ctrl.searchBarController),
            Stats.view(ctrl.statsController),
            ctrl.vm.results !== null ? m.component(SortBox, {vm: ctrl.vm}): [],
            ctrl.vm.results !== null ? m('.row.search-content', [
               m('.col-md-2.col-lg-3', [
                    m.component(SideBar, {vm: ctrl.vm})
                ]),
                m('.col-md-10.col-lg-9', [
                    m.component(Results, {vm: ctrl.vm})
                ])
            ]) : [],
            m.component(Footer, {vm: ctrl.vm})
        ])
    ]);
};

ShareApp.controller = function() {
    var self = this;

    self.vm = new ShareApp.ViewModel(self.vm);

    History.replaceState({
        query: self.vm.query(),
        sort: self.vm.sort(),
        optionalFilters: self.vm.optionalFilters,
        requiredFilters: self.vm.requiredFilters
    }, 'OSF | SHARE', '?' + utils.buildURLParams(self.vm));

    m.request({
        method: 'get',
        background: false,
        url: '/api/v1/share/providers/'
    }).then(function(data) {
        self.vm.ProviderMap = data.providerMap;

        self.statsController = new Stats.controller(self.vm);
        self.searchBarController = new SearchBar.controller(self.vm);

    });

    m.request({
{'fraction_non_alphanumeric': 0.1799692360280294, 'fraction_numerical': 0.00512732866176722, 'mean_word_length': 2.4242246928028086, 'pattern_counts': {'":': 0, '<': 3, '<?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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1343287', 'n_tokens_mistral': 1849, 'n_tokens_neox': 1803, 'n_words': 318}