<commit_before>"use strict";

var filterView = {

    components: [
        //TODO this hard coded array of objects is just a temporary method.
        //This should be served from the API, probably from meta.json
        //"source" is the column name from the filter table, which should match the table in the original database table.
        //  For this approach to work, it will be cleanest if we never have duplicate column names in our sql tables unless the data has
        //  the same meaning in both places (e.g. 'ward' and 'ward' can appear in two tables but should have same name/format)

        {   source: 'proj_units_tot',
            display_name: 'Total units in project',
            display_text: 'Total count of units in the project, including both subsidized and market rate units.',
            component_type: 'continuous',
            data_type:'integer',
            min: 0,
            max: 717,
            num_decimals_displayed: 0 //0 if integer, 1 otherwise. Could also store data type instead. 
        },
        
        {   source: 'proj_units_assist_max',
            display_name: "Subsidized units (max)",
            display_text: "The number of subsidized units in the project. When a project participates in multiple subsidy programs, this number is the number of units subsidized by the project with the most units. Partially overlapping subsidies could result in more units than are reflected here.",
            component_type: 'continuous',
            data_type:'integer',
            min:0,
            max:800,
            num_decimals_displayed:0
        },
        {   source: 'hud_own_type',
            display_name:'Ownership Type (per HUD)',
            display_text:"This field is only available for buildings participating in HUD programs; others are listed as 'Unknown'",
            component_type: 'categorical',
            data_type:'text'
        },

        {   source:'ward',
            display_name: 'Ward',
            display_text: "The largest geograpical division of the city.",
            component_type: 'categorical',
            data_type: 'text'
        },
        {   source:'neighborhood_cluster_desc',
            display_name: 'Neighborhood Cluster',
            display_text: "39 clusters each combining a set of smaller neighborhoods.",
            component_type: 'categorical',
            data_type: 'text'
        },
        {   source:'anc',
            display_name: 'ANC',
            display_text: 'Advisory Neighborhood Council',
            component_type: 'categorical',
            data_type: 'text'
        },
        {   source:'census_tract',
            display_name: 'Census Tract',
            display_text: 'A small division used in collection of the US Census.',
            component_type: 'categorical',
            data_type: 'text',
        },
        {   source:'zip',
            display_name: 'Zipcode',
            display_text: '',
            component_type: 'categorical',
            data_type: 'text',
        },

        {   source: 'acs_median_rent',
            display_name: 'Neighborhood Rent (ACS median)',
            display_text: 'Filters to buildings that are in a census tract that has a median rent between the indicated levels, per the American Community Survey. ACS rent combines both subsidized and market rate rent.',
            component_type: 'continuous',
            data_type:'decimal',
            min: 0,
            max: 2500,
            num_decimals_displayed: 0 //0 if integer, 1 otherwise. Could also store data type instead.
        },

        {   source: 'portfolio',
            display_name: 'Subsidy Program',
            display_text: 'Filters to buildings that participate in at least one of the selected programs. Note some larger programs are divided into multiple parts in this list',
            component_type:'categorical',
            data_type: 'text'
        },
        {   source:'poa_start',
            display_name:'Subsidy Start Date',
            display_text: 'Filters to buildings with at least one subsidy whose start date falls between the selected dates.',
            component_type: 'date',
            data_type: 'timestamp',
            min: '1950-01-01', //just example, TODO change to date format
            max: 'now'         //dummy example
        },
        {   source:'poa_end',
            display_name:'Subsidy End Date',
            display_text: 'Filters to buildings with at least one subsidy whose end date falls between the selected dates.',
            component_type: 'date',
            data_type: 'timestamp',
            min: '1950-01-01', //just example, TODO change to date format
            max: 'now'         //dummy example
        },



       
    ],

    init: function(msg, data) {
        //msg and data are from the pubsub module that this init is subscribed to. 
        //when called from dataLoaded.metaData, 'data' is boolean of whether data load was successful
        
        if ( data === true ) {
            //Make sure other functionality is hooked up
            setSubs([
                ['filterViewLoaded', filterUtil.init],
                ['sidebar', filterView.toggleSidebar],
                ['subNav', filterView.toggleSubNavButtons],
                ['filterValues', filterView.indicateActivatedFilters]
            ]);

            setState('subNav.left','layers');
            setState('subNav.right','buildings');

            document.querySelectorAll('.sidebar-tab').forEach(function(tab){
                tab.onclick = function(e){
                    var sideBarMsg = e.currentTarget.parentElement.id.replace('-','.');
                    filterView.toggleSidebarState(sideBarMsg);
                }
            });

            document.querySelectorAll('.sub-nav-button').forEach(function(button){
                button.onclick = function(e){
                    var leftRight = e.currentTarget.parentElement.id.replace('-options','');
                    var subNavType = e.currentTarget.id.replace('button-','');
                    if ( getState()['sidebar.' + leftRight] && getState()['sidebar.' + leftRight][0] ) { // if the associated sidebar is open
                        if (getState()['subNav.' + leftRight][0] === subNavType) { // if the clicked subNav button is already active
                            setState('sidebar.' + leftRight, false); // close the sidebar
                        }
                    } else {
                        setState('sidebar.' + leftRight, true); // open the sidebar
                    }
                    setState('subNav.' + leftRight, subNavType);
                   /* console.log('click');
                    var leftRight = e.currentTarget.parentElement.id.replace('-options','');
                    console.log(leftRight);
                    var sideBarMsg = 'sidebar.' + leftRight;
                    var subButton = e.currentTarget.id.replace('button-','');
                    console.log(subButton);
                    if (getState()[sideBarMsg] && getState()[sideBarMsg][0])  { // if the associated sidebar is open
                        if (getState()['subNav.' + leftRight] && getState()['subNav.' + leftRight][0] === e.currentTarget.id){
                            filterView.toggleSidebarState(sideBarMsg);
                            setState('subNav.' + leftRight, e.currentTarget.id);
                        } else {
                            setState('subNav.' + leftRight, 'none');
                        }

                    }*/
                }
            });

            //Get the data and use it to dynamically apply configuration such as the list of categorical options
            controller.getData({
                        name: 'filterData',
                        url: model.URLS.filterData, 
                        callback: filterView.buildFilterComponents
                    }) 
        } else {
            console.log("ERROR data loaded === false")
        };

    }, //end init


    buildFilterComponents: function(){

        //First we need to read the actual data to get our categories, mins, maxes, etc. 
        var workingData = model.dataCollection['filterData'].items; <commit_msg>Remove some code that had been commented out in filter-view.js<commit_after>"use strict";

var filterView = {

    components: [
        //TODO this hard coded array of objects is just a temporary method.
        //This should be served from the API, probably from meta.json
        //"source" is the column name from the filter table, which should match the table in the original database table.
        //  For this approach to work, it will be cleanest if we never have duplicate column names in our sql tables unless the data has
        //  the same meaning in both places (e.g. 'ward' and 'ward' can appear in two tables but should have same name/format)

        {   source: 'proj_units_tot',
            display_name: 'Total units in project',
            display_text: 'Total count of units in the project, including both subsidized and market rate units.',
            component_type: 'continuous',
            data_type:'integer',
            min: 0,
            max: 717,
            num_decimals_displayed: 0 //0 if integer, 1 otherwise. Could also store data type instead. 
        },
        
        {   source: 'proj_units_assist_max',
            display_name: "Subsidized units (max)",
            display_text: "The number of subsidized units in the project. When a project participates in multiple subsidy programs, this number is the number of units subsidized by the project with the most units. Partially overlapping subsidies could result in more units than are reflected here.",
            component_type: 'continuous',
            data_type:'integer',
            min:0,
            max:800,
            num_decimals_displayed:0
        },
        {   source: 'hud_own_type',
            display_name:'Ownership Type (per HUD)',
            display_text:"This field is only available for buildings participating in HUD programs; others are listed as 'Unknown'",
            component_type: 'categorical',
            data_type:'text'
        },

        {   source:'ward',
            display_name: 'Ward',
            display_text: "The largest geograpical division of the city.",
            component_type: 'categorical',
            data_type: 'text'
        },
        {   source:'neighborhood_cluster_desc',
            display_name: 'Neighborhood Cluster',
            display_text: "39 clusters each combining a set of smaller neighborhoods.",
            component_type: 'categorical',
            data_type: 'text'
        },
        {   source:'anc',
            display_name: 'ANC',
            display_text: 'Advisory Neighborhood Council',
            component_type: 'categorical',
            data_type: 'text'
        },
        {   source:'census_tract',
            display_name: 'Census Tract',
            display_text: 'A small division used in collection of the US Census.',
            component_type: 'categorical',
            data_type: 'text',
        },
        {   source:'zip',
            display_name: 'Zipcode',
            display_text: '',
            component_type: 'categorical',
            data_type: 'text',
        },

        {   source: 'acs_median_rent',
            display_name: 'Neighborhood Rent (ACS median)',
            display_text: 'Filters to buildings that are in a census tract that has a median rent between the indicated levels, per the American Community Survey. ACS rent combines both subsidized and market rate rent.',
            component_type: 'continuous',
            data_type:'decimal',
            min: 0,
            max: 2500,
            num_decimals_displayed: 0 //0 if integer, 1 otherwise. Could also store data type instead.
        },

        {   source: 'portfolio',
            display_name: 'Subsidy Program',
            display_text: 'Filters to buildings that participate in at least one of the selected programs. Note some larger programs are divided into multiple parts in this list',
            component_type:'categorical',
            data_type: 'text'
        },
        {   source:'poa_start',
            display_name:'Subsidy Start Date',
            display_text: 'Filters to buildings with at least one subsidy whose start date falls between the selected dates.',
            component_type: 'date',
            data_type: 'timestamp',
            min: '1950-01-01', //just example, TODO change to date format
            max: 'now'         //dummy example
        },
        {   source:'poa_end',
            display_name:'Subsidy End Date',
            display_text: 'Filters to buildings with at least one subsidy whose end date falls between the selected dates.',
            component_type: 'date',
            data_type: 'timestamp',
            min: '1950-01-01', //just example, TODO change to date format
            max: 'now'         //dummy example
        },



       
    ],

    init: function(msg, data) {
        //msg and data are from the pubsub module that this init is subscribed to. 
        //when called from dataLoaded.metaData, 'data' is boolean of whether data load was successful
        
        if ( data === true ) {
            //Make sure other functionality is hooked up
            setSubs([
                ['filterViewLoaded', filterUtil.init],
                ['sidebar', filterView.toggleSidebar],
                ['subNav', filterView.toggleSubNavButtons],
                ['filterValues', filterView.indicateActivatedFilters]
            ]);

            setState('subNav.left','layers');
            setState('subNav.right','buildings');

            document.querySelectorAll('.sidebar-tab').forEach(function(tab){
                tab.onclick = function(e){
                    var sideBarMsg = e.currentTarget.parentElement.id.replace('-','.');
                    filterView.toggleSidebarState(sideBarMsg);
                }
            });

            document.querySelectorAll('.sub-nav-button').forEach(function(button){
                button.onclick = function(e){
                    var leftRight = e.currentTarget.parentElement.id.replace('-options','');
                    var subNavType = e.currentTarget.id.replace('button-','');
                    if ( getState()['sidebar.' + leftRight] && getState()['sidebar.' + leftRight][0] ) { // if the associated sidebar is open
                        if (getState()['subNav.' + leftRight][0] === subNavType) { // if the clicked subNav button is already active
                            setState('sidebar.' + leftRight, false); // close the sidebar
                        }
                    } else {
                        setState('sidebar.' + leftRight, true); // open the sidebar
                    }
                    setState('subNav.' + leftRight, subNavType);
                }
            });

            //Get the data and use it to dynamically apply configuration such as the list of categorical options
            controller.getData({
                        name: 'filterData',
                        url: model.URLS.filterData, 
                        callback: filterView.buildFilterComponents
                    }) 
        } else {
            console.log("ERROR data loaded === false")
        };

    }, //end init


    buildFilterComponents: function(){

        //First we need to read the actual data to get our categories, mins, maxes, etc. 
        var workingData = model.dataCollection['filterData'].items; 
{'fraction_non_alphanumeric': 0.09437828147009861, 'fraction_numerical': 0.00525035215776668, 'mean_word_length': 1.8290164825212825, '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': '4207444', 'n_tokens_mistral': 3928, 'n_tokens_neox': 3720, 'n_words': 1267}