<commit_before>var app = {};
var facets = ["keywords"];
var solr_url = settings_solr_url;
var gp_url = settings_gp_url;

function viewModel() {
    var self = this;


    //HOME PAGE
    self.totalRecordsCount = ko.observable(0);
    self.currentRecords = ko.observable({});
    self.search = ko.observable("");
    self.title = ko.observable("");
    self.keywords = ko.observable({});
    self.keywordsDisplay = ko.observable("");
    self.resultsDisplay = ko.observable("");
    self.numFound = ko.observable("");
    self.q_query = ko.observable("");
    self.fq_query = ko.observable("");
    self.bbLat = ko.observable("");
    self.bbLon = ko.observable("");
    self.useBb = ko.observable(false);
    self.displayRows = ko.observable(5);
    self.startIndex = ko.observable(0);
    self.recordPaginator = ko.observable("");
    self.pageCount = ko.observable(0);
    self.displayPages = ko.observable(5);
    self.pageIndex = ko.observable(0);

    self.queryFilter = ko.observableArray();

    self.useBb.subscribe(function(val){
        app.runQuery(app.defaultQueryCallback);
    });

    //RECORD PAGE
    self.record_id = ko.observable("");
    self.record_title = ko.observable("");
    self.record_abstract = ko.observable("");
    self.record_originator = ko.observable("");
    self.record_updated = ko.observable("");
    self.record_source = ko.observable("");



}

app.viewModel = new viewModel();
ko.applyBindings(app.viewModel);
window.location.hash.replace('#', '');

function load() {

    init();      //Init the map

    if (getURLParameter('search')) {
        app.viewModel.search(getURLParameter('search'));
    }
    
    if (getURLParameter('keywords')) {
        for (var i = 0; i < JSON.parse(getURLParameter('keywords')).length; i++){
            app.viewModel.keywords()[JSON.parse(getURLParameter('keywords'))[i].toLowerCase()] = 1;
        }
    }
    
    if (getURLParameter('useBb').toLowerCase() == "true" && getURLParameter('lat') && getURLParameter('lon')) {
        app.viewModel.useBb(true);
        app.viewModel.bbLat(getURLParameter('lat'));
        app.viewModel.bbLon(getURLParameter('lon'));
        updateMap({
            'latlng':{
                'lat': app.viewModel.bbLat(),
                'lng': app.viewModel.bbLon()
            }
        });
    }

    if (app.viewModel.search() == "" && !app.viewModel.useBb() && isEmpty(app.viewModel.keywords())) {
        app.runQuery(function(data) { /* process e.g. data.response.docs... */ 
                var items = [];
                app.viewModel.totalRecordsCount(data.response.numFound.toString());
                console.log(data);
                app.viewModel.currentRecords(data);
                app.updateKeywords();
                app.viewModel.recordPaginator(app.buildPaginator());
            }
        );
    } else {
        app.runQuery(app.defaultQueryCallback);
    }

}

function load_record() {
    init();

    if (getURLParameter('id')) {
        app.viewModel.record_id(getURLParameter('id'));
        getRecord(app.viewModel.record_id());
    }
}

app.updateKeywords = function() {
    html = "<div class=\"row-fluid\"><div class=\"span12\" id =\"keyword-html\">";

    $.each(app.viewModel.keywords(), function(key, val){
        html = html + "<div class=\"row-fluid selected-keyword\"><div class=\"span10 selected-keyword\">" + key + "</div>" +
        "<div class=\"span2 selected-keyword\"><img src='static/img/cross.png' onclick='app.removeKeyword(\"" + key + "\")'/></div></div>";
    });

    var facet_keywords = app.viewModel.currentRecords().facet_counts.facet_fields.keywords;

    for (var i=0, j = 0; j < 10 && i < facet_keywords.length; i = i+2) {
        var kw = facet_keywords[i];
        if (!app.viewModel.keywords()[kw]) {
            var count = facet_keywords[i+1];
            html = html + "<div class=\"row-fluid\"><div class=\"span12\"><a onclick='kwSearch(\"" + kw + "\", " + count + ")''>" + kw + " (" + count + ")</a></div></div>";
            j++;
        }
    }
    app.viewModel.keywordsDisplay(html);
};

function kwSearch(keyword, count){
    app.viewModel.pageIndex(0);
    app.viewModel.startIndex(0);
    app.viewModel.keywords()[keyword] = count;
    app.runQuery(app.defaultQueryCallback);
}

app.removeKeyword = function(keyword){
    delete app.viewModel.keywords()[keyword];
    app.viewModel.startIndex(0);
    app.viewModel.pageIndex(0);
    app.updateKeywords();
    app.runQuery(app.defaultQueryCallback);

}

function unwrap(lst){
    var fullList = [];
    var maxDesc = 300;
    if (lst.id) {
        fullList.push('<div id = "' + lst.id + '" class="record" onclick="window.location=\'record.html?id=' + lst.id + '\'">');
    } else {
        fullList.push('<div class="record">');
    }
    if (lst.title) {
        fullList.push('<h3 class="record-title">' + lst.title[0] + '</h3>');
    } else {
        fullList.push('<h3 class="record-title">' + 'No Title Provided' + '</h3>');
    }
    if (lst.description) {
        fullList.push('<p class="record-abstract">' + lst.description.slice(0, maxDesc));
        if (lst.description.length > maxDesc){
            fullList.push('...');
        }
        fullList.push('</p>');
    } else {
        fullList.push('<p class="record-abstract">' + 'No description provided.' + '</p>');
    }

    if (lst["sys.src.item.lastmodified_tdt"]) {
        var date = new Date(lst["sys.src.item.lastmodified_tdt"]);
        var date_string = (date.getMonth() + 1).toString() + '/' + date.getDate().toString() + '/' + date.getFullYear().toString();
        fullList.push('<p class="record-date">Last updated: ' + date_string + '</p>');
    }

    fullList.push('</div>');

    return fullList.join('');
};

function querySolr(q, fq, fl, wt, callback) {
    var mincount = 1;
    //Cannot figure out how to search multiple facets with jquery ajax syntax. Using for loop instead.
    var url = solr_url;
    for (var i = 0; i<facets.length; i++) {
        url = url + 'facet.field=' + facets[i] + '&facet.mincount=' + mincount + '&';
    }

    $.ajax({
        url: url,
        data: {
            'start': app.viewModel.startIndex(),
            'rows': app.viewModel.displayRows(),
            'wt':wt, 
            'q':q, 
            'fq': fq,
            'fl':fl,
            'facet':true
        },
        dataType: 'jsonp',
        jsonp: 'json.wrf',
        success: callback
    });
}

function getRecord(id){
    var rec_id = id.slice(0,8) + '-' + id.slice(8,12) + '-' + id.slice(12,16) + '-' + id.slice(16,20) + '-' + id.slice(20);
    var url = gp_url + '/csw?service=CSW&request=GetRecordById&id=' + rec_id;
    $.ajax({
        url: url,
        data: {
            'f':'jsonp'
        },
        dataType: 'jsonp',  
        jsonp: 'json.wrf',
        success: function(val){
            alert(val);
        }
    });
}

app.submit = function () {
    app.viewModel.pageIndex(0);
    app.viewModel.startIndex(0);
    app.runQuery(app.defaultQueryCallback);
}

$(document).ready(function(){

    var formatDate = function(date_obj, limit){
        if (date_obj != '*') {
            var year = date_obj.getFullYear().toString();
            var month = date_obj.getMonth() + 1;
            if (month < 10) {
                month = "0" + month.toString();
            } else {
                month = month.toString();
            }
            var day = date_obj.getDate();
            if (day < 10) {
                day = "0" + day.toString();
            } else {
                day = day.toString();<commit_msg>going to try this live and see what we get.<commit_after>var app = {};
var facets = ["keywords"];
var solr_url = settings_solr_url;
var gp_url = settings_gp_url;

function viewModel() {
    var self = this;


    //HOME PAGE
    self.totalRecordsCount = ko.observable(0);
    self.currentRecords = ko.observable({});
    self.search = ko.observable("");
    self.title = ko.observable("");
    self.keywords = ko.observable({});
    self.keywordsDisplay = ko.observable("");
    self.resultsDisplay = ko.observable("");
    self.numFound = ko.observable("");
    self.q_query = ko.observable("");
    self.fq_query = ko.observable("");
    self.bbLat = ko.observable("");
    self.bbLon = ko.observable("");
    self.useBb = ko.observable(false);
    self.displayRows = ko.observable(5);
    self.startIndex = ko.observable(0);
    self.recordPaginator = ko.observable("");
    self.pageCount = ko.observable(0);
    self.displayPages = ko.observable(5);
    self.pageIndex = ko.observable(0);

    self.queryFilter = ko.observableArray();

    self.useBb.subscribe(function(val){
        app.runQuery(app.defaultQueryCallback);
    });

    //RECORD PAGE
    self.record_id = ko.observable("");
    self.record_title = ko.observable("");
    self.record_abstract = ko.observable("");
    self.record_originator = ko.observable("");
    self.record_updated = ko.observable("");
    self.record_source = ko.observable("");



}

app.viewModel = new viewModel();
ko.applyBindings(app.viewModel);
window.location.hash.replace('#', '');

function load() {

    init();      //Init the map

    if (getURLParameter('search')) {
        app.viewModel.search(getURLParameter('search'));
    }
    
    if (getURLParameter('keywords')) {
        for (var i = 0; i < JSON.parse(getURLParameter('keywords')).length; i++){
            app.viewModel.keywords()[JSON.parse(getURLParameter('keywords'))[i].toLowerCase()] = 1;
        }
    }
    
    if (getURLParameter('useBb').toLowerCase() == "true" && getURLParameter('lat') && getURLParameter('lon')) {
        app.viewModel.useBb(true);
        app.viewModel.bbLat(getURLParameter('lat'));
        app.viewModel.bbLon(getURLParameter('lon'));
        updateMap({
            'latlng':{
                'lat': app.viewModel.bbLat(),
                'lng': app.viewModel.bbLon()
            }
        });
    }

    if (app.viewModel.search() == "" && !app.viewModel.useBb() && isEmpty(app.viewModel.keywords())) {
        app.runQuery(function(data) { /* process e.g. data.response.docs... */ 
                var items = [];
                app.viewModel.totalRecordsCount(data.response.numFound.toString());
                console.log(data);
                app.viewModel.currentRecords(data);
                app.updateKeywords();
                app.viewModel.recordPaginator(app.buildPaginator());
            }
        );
    } else {
        app.runQuery(app.defaultQueryCallback);
    }

}

function load_record() {
    init();

    if (getURLParameter('id')) {
        app.viewModel.record_id(getURLParameter('id'));
        getRecord(app.viewModel.record_id());
    }
}

app.updateKeywords = function() {
    html = "<div class=\"row-fluid\"><div class=\"span12\" id =\"keyword-html\">";

    $.each(app.viewModel.keywords(), function(key, val){
        html = html + "<div class=\"row-fluid selected-keyword\"><div class=\"span10 selected-keyword\">" + key + "</div>" +
        "<div class=\"span2 selected-keyword\"><img src='static/img/cross.png' onclick='app.removeKeyword(\"" + key + "\")'/></div></div>";
    });

    var facet_keywords = app.viewModel.currentRecords().facet_counts.facet_fields.keywords;

    for (var i=0, j = 0; j < 10 && i < facet_keywords.length; i = i+2) {
        var kw = facet_keywords[i];
        if (!app.viewModel.keywords()[kw]) {
            var count = facet_keywords[i+1];
            html = html + "<div class=\"row-fluid\"><div class=\"span12\"><a onclick='kwSearch(\"" + kw + "\", " + count + ")''>" + kw + " (" + count + ")</a></div></div>";
            j++;
        }
    }
    app.viewModel.keywordsDisplay(html);
};

function kwSearch(keyword, count){
    app.viewModel.pageIndex(0);
    app.viewModel.startIndex(0);
    app.viewModel.keywords()[keyword] = count;
    app.runQuery(app.defaultQueryCallback);
}

app.removeKeyword = function(keyword){
    delete app.viewModel.keywords()[keyword];
    app.viewModel.startIndex(0);
    app.viewModel.pageIndex(0);
    app.updateKeywords();
    app.runQuery(app.defaultQueryCallback);

}

function unwrap(lst){
    var fullList = [];
    var maxDesc = 300;
    if (lst.id) {
        fullList.push('<div id = "' + lst.id + '" class="record" onclick="window.location=\'record.html?id=' + lst.id + '\'">');
    } else {
        fullList.push('<div class="record">');
    }
    if (lst.title) {
        fullList.push('<h3 class="record-title">' + lst.title[0] + '</h3>');
    } else {
        fullList.push('<h3 class="record-title">' + 'No Title Provided' + '</h3>');
    }
    if (lst.description) {
        fullList.push('<p class="record-abstract">' + lst.description.slice(0, maxDesc));
        if (lst.description.length > maxDesc){
            fullList.push('...');
        }
        fullList.push('</p>');
    } else {
        fullList.push('<p class="record-abstract">' + 'No description provided.' + '</p>');
    }

    if (lst["sys.src.item.lastmodified_tdt"]) {
        var date = new Date(lst["sys.src.item.lastmodified_tdt"]);
        var date_string = (date.getMonth() + 1).toString() + '/' + date.getDate().toString() + '/' + date.getFullYear().toString();
        fullList.push('<p class="record-date">Last updated: ' + date_string + '</p>');
    }

    fullList.push('</div>');

    return fullList.join('');
};

function querySolr(q, fq, fl, wt, callback) {
    var mincount = 1;
    //Cannot figure out how to search multiple facets with jquery ajax syntax. Using for loop instead.
    var url = solr_url;
    for (var i = 0; i<facets.length; i++) {
        url = url + 'facet.field=' + facets[i] + '&facet.mincount=' + mincount + '&';
    }

    $.ajax({
        url: url,
        data: {
            'start': app.viewModel.startIndex(),
            'rows': app.viewModel.displayRows(),
            'wt':wt, 
            'q':q, 
            'fq': fq,
            'fl':fl,
            'facet':true
        },
        dataType: 'jsonp',
        jsonp: 'json.wrf',
        success: callback
    });
}

function getRecord(id){
    var rec_id = id.slice(0,8) + '-' + id.slice(8,12) + '-' + id.slice(12,16) + '-' + id.slice(16,20) + '-' + id.slice(20);
    var url = gp_url + '/rest/document';
    $.ajax({
        // type: 'Get',
        url: url,
        data: {
            'id': rec_id,
            // 'id': '%7B' + rec_id + '%7D',
            'f':'pjson'
        },
        dataType: 'text',  
        // jsonp: false,
        // crossDomain: true,
        // jsonpCallback: "callback",
        success: function(val){
            alert(val);
        }
    });
}

app.submit = function () {
    app.viewModel.pageIndex(0);
    app.viewModel.startIndex(0);
    app.runQuery(app.defaultQueryCallback);
}

$(document).ready(function(){

    var formatDate = function(date_obj, limit){
        if (date_obj != '*') {
            var year = date_obj.getFullYear().toString();
            var month = date_obj.getMonth() + 1;
            if (month < 10) {
                month = "0" + month.toString();
            } else {
                month = month.toString();
            }
            var day = date_obj.getDate();
            if (day < 10) {
                day = "0" + day.toString();
            } else {
                day = day.toString();
{'fraction_non_alphanumeric': 0.18345017362248575, 'fraction_numerical': 0.008124221974710083, 'mean_word_length': 2.407142857142857, 'pattern_counts': {'":': 0, '<': 71, '<?xml version=': 0, '>': 61, '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': '5426948', 'n_tokens_mistral': 5037, 'n_tokens_neox': 4904, 'n_words': 841}