<commit_before>"use strict";
/*
 * ooiui/static/js/views/common/TOCView.js
 * View definitions to build the table of contents
 *
 * Dependencies
 * Libs
 * - ooiui/static/lib/underscore/underscore.js
 * - ooiui/static/lib/backbone/backbone.js
 * - ooiui/static/js/ooi.js
 */


var TOCView = Backbone.View.extend({
    id: 'assetBrowser',
    events: {
        'keyup #search-filter' : 'filterToc'
    },
    initialize: function(options){
        _.bindAll(this, "render", "derender", "renderArrays", "renderAssets", "renderStreams");
        this.arrayCollection = options.arrayCollection;
        this.assetCollection = options.assetCollection;
        this.streamCollection = options.streamCollection;
        this.listenTo(vent, 'toc:derenderItems', function() {
            this.derender();
        });
    },
    template: JST['ooiui/static/js/partials/TOC.html'],
    renderArrays: function(){
        var arrayContainerView = this.arrayCollection.map(function(model) {
            return (new ArrayContainerView({ model:model })).render().el;
        });
        this.$el.find('ul.nav-list').append(arrayContainerView);
    },
    renderAssets: function(){
        // create a model for each item in the collection, and based on it's class,
        // render it in the browser as a platform or instrument.
        var filteredPlatforms = this.assetCollection.byClass('.AssetRecord');
        var filteredInstruments = this.assetCollection.byClass('.InstrumentAssetRecord');

        filteredPlatforms.map(function(model) {
            try {
                // get the array code from the reference designator
                var arrayCode = model.get('ref_des').substr(0,2);
                // set the target to where this item will be inserted.
                var arrayTarget = String('#array_'+ arrayCode);
                if ( document.getElementById( model.get('ref_des').substring(0,8)) == null ) {
                    var assetItemView = new AssetItemView({ model:model });
                    $( arrayTarget ).append( assetItemView.render().el );
                }
            } catch(e) {
            //    console.log(e);
            }
        });

        filteredInstruments.map(function(model) {
            try {
                var platformCode = model.get('ref_des').substr(0,8);
                // set the target to where this item will be inserted.
                var platformTarget = String('ul#'+platformCode);
                if ( document.getElementById( model.get('ref_des')) == null ) {
                    var assetItemView = new AssetItemView({ model:model });
                    $( platformTarget ).append( assetItemView.render().el );
                }
            }catch (e) {
             //   console.log(e);
            }
        });
    },
    renderStreams: function() {
        if ( this.streamCollection != undefined ) {
            this.streamCollection.map( function(model) {
                try {
                    var instrumentCode = model.get('reference_designator');
                    var instrumentTarget = String('ul#'+instrumentCode);
                    var streamItemView = new StreamItemView({ model:model });
                    $( instrumentTarget ).append( streamItemView.render().el );
                } catch (e) {
               //     console.log(e);
                }<commit_msg>keeping except logging for now.<commit_after>"use strict";
/*
 * ooiui/static/js/views/common/TOCView.js
 * View definitions to build the table of contents
 *
 * Dependencies
 * Libs
 * - ooiui/static/lib/underscore/underscore.js
 * - ooiui/static/lib/backbone/backbone.js
 * - ooiui/static/js/ooi.js
 */


var TOCView = Backbone.View.extend({
    id: 'assetBrowser',
    events: {
        'keyup #search-filter' : 'filterToc'
    },
    initialize: function(options){
        _.bindAll(this, "render", "derender", "renderArrays", "renderAssets", "renderStreams");
        this.arrayCollection = options.arrayCollection;
        this.assetCollection = options.assetCollection;
        this.streamCollection = options.streamCollection;
        this.listenTo(vent, 'toc:derenderItems', function() {
            this.derender();
        });
    },
    template: JST['ooiui/static/js/partials/TOC.html'],
    renderArrays: function(){
        var arrayContainerView = this.arrayCollection.map(function(model) {
            return (new ArrayContainerView({ model:model })).render().el;
        });
        this.$el.find('ul.nav-list').append(arrayContainerView);
    },
    renderAssets: function(){
        // create a model for each item in the collection, and based on it's class,
        // render it in the browser as a platform or instrument.
        var filteredPlatforms = this.assetCollection.byClass('.AssetRecord');
        var filteredInstruments = this.assetCollection.byClass('.InstrumentAssetRecord');

        filteredPlatforms.map(function(model) {
            try {
                // get the array code from the reference designator
                var arrayCode = model.get('ref_des').substr(0,2);
                // set the target to where this item will be inserted.
                var arrayTarget = String('#array_'+ arrayCode);
                if ( document.getElementById( model.get('ref_des').substring(0,8)) == null ) {
                    var assetItemView = new AssetItemView({ model:model });
                    $( arrayTarget ).append( assetItemView.render().el );
                }
            } catch(e) {
                console.log(e);
            }
        });

        filteredInstruments.map(function(model) {
            try {
                var platformCode = model.get('ref_des').substr(0,8);
                // set the target to where this item will be inserted.
                var platformTarget = String('ul#'+platformCode);
                if ( document.getElementById( model.get('ref_des')) == null ) {
                    var assetItemView = new AssetItemView({ model:model });
                    $( platformTarget ).append( assetItemView.render().el );
                }
            }catch (e) {
                console.log(e);
            }
        });
    },
    renderStreams: function() {
        if ( this.streamCollection != undefined ) {
            this.streamCollection.map( function(model) {
                try {
                    var instrumentCode = model.get('reference_designator');
                    var instrumentTarget = String('ul#'+instrumentCode);
                    var streamItemView = new StreamItemView({ model:model });
                    $( instrumentTarget ).append( streamItemView.render().el );
                } catch (e) {
                    console.log(e);
                }
{'fraction_non_alphanumeric': 0.12261620977353993, 'fraction_numerical': 0.0017878426698450535, 'mean_word_length': 1.9809058614564832, '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': '4027869', 'n_tokens_mistral': 1790, 'n_tokens_neox': 1721, 'n_words': 378}