<commit_before>import { Component, OnInit, OnDestroy } from '@angular/core';
import { MdDialogRef } from '@angular/material';

import { ParameterService } from '../../services/parameter.service';
import { FilterService } from '../../services/filter.service';
import { ThemesService } from '../../services/themes.service';
import * as neon from 'neon-framework';

@Component({
    selector: 'app-filter-tray',
    templateUrl: './filter-tray.component.html',
    styleUrls: ['./filter-tray.component.css']
})
export class FilterTrayComponent implements OnInit, OnDestroy {

    private messenger: neon.eventing.Messenger;
    private filters: {
        raw: any[],
        formatted: any[]
    };

    constructor(private filterService: FilterService, private themesService: ThemesService,
        public dialogRef: MdDialogRef<FilterTrayComponent>) {
        this.messenger = new neon.eventing.Messenger();
        this.themesService = themesService;
        this.filters = {
            raw: [],
            formatted: []
        };
    }

    ngOnInit() {
        this.filters = {
            raw: [],
            formatted: []
        };

        this.messenger.events({
            activeDatasetChanged: this.onEventChanged,
            filtersChanged: this.onEventChanged
        });

        this.messenger.subscribe(ParameterService.STATE_CHANGED_CHANNEL, this.onEventChanged);
    }

    removeFilter(filterIds: string[]) {
        this.filterService.removeFiltersForKeys(filterIds);
    };

    onEventChanged() {
        this.updateFilterTray(this.filterService.getAllFilters());
    };

    updateFilterTray(rawState: any[]) {
        this.filters.raw = rawState;
        let filters = this.formatFilters(rawState);
        this.filters.formatted = filters;
    };

    formatFilters(filters: any[]): any[] {
        if (filters.length > 0) {
            // We only want unique filter names to eliminate display of multiple filters created by filter service

            // remove filters with empty string names
            let filterList = _.filter(filters, function(filter) {
                return (filter.filter.filterName && filter.filter.filterName !== '');
            });

            let result = {};
            _.each(filterList, function(filter) {
                if (result[filter.filter.filterName]) {
                    // add id to array
                    result[filter.filter.filterName].ids.push(filter.id);
                } else {<commit_msg>fixed functionality of filter tray.  still needs styling<commit_after>import { Component, OnInit, OnDestroy } from '@angular/core';
import { MdDialogRef } from '@angular/material';

import { ParameterService } from '../../services/parameter.service';
import { FilterService } from '../../services/filter.service';
import { ThemesService } from '../../services/themes.service';
import * as neon from 'neon-framework';

@Component({
    selector: 'app-filter-tray',
    templateUrl: './filter-tray.component.html',
    styleUrls: ['./filter-tray.component.css']
})
export class FilterTrayComponent implements OnInit, OnDestroy {

    private messenger: neon.eventing.Messenger;
    private filters: {
        raw: any[],
        formatted: any[]
    };

    constructor(private filterService: FilterService, private themesService: ThemesService,
        public dialogRef: MdDialogRef<FilterTrayComponent>) {
        this.messenger = new neon.eventing.Messenger();
        this.themesService = themesService;
        this.filters = {
            raw: [],
            formatted: []
        };
    }

    ngOnInit() {
        this.filters = {
            raw: [],
            formatted: []
        };

        this.messenger.events({
            activeDatasetChanged: this.onEventChanged,
            filtersChanged: this.onEventChanged
        });

        this.messenger.subscribe(ParameterService.STATE_CHANGED_CHANNEL, this.onEventChanged);
        this.onEventChanged();
    }

    removeFilter(filterIds: string[]) {
        let onSuccess = () => {
            this.onEventChanged();
        }
        this.filterService.removeFiltersForKeys(filterIds, onSuccess.bind(this));
    };

    onEventChanged() {
        this.updateFilterTray(this.filterService.getAllFilters());
    };

    updateFilterTray(rawState: any[]) {
        this.filters.raw = rawState;
        let filters = this.formatFilters(rawState);
        this.filters.formatted = filters;
    };

    formatFilters(filters: any[]): any[] {
        if (filters.length > 0) {
            // We only want unique filter names to eliminate display of multiple filters created by filter service

            // remove filters with empty string names
            let filterList = _.filter(filters, function(filter) {
                return (filter.filter.filterName && filter.filter.filterName !== '');
            });

            let result = {};
            _.each(filterList, function(filter) {
                if (result[filter.filter.filterName]) {
                    // add id to array
                    result[filter.filter.filterName].ids.push(filter.id);
                } else {
{'fraction_non_alphanumeric': 0.12053832650672908, 'fraction_numerical': 0.0003900916715428126, 'mean_word_length': 2.3407166123778502, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 8, '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': '4245519', 'n_tokens_mistral': 1370, 'n_tokens_neox': 1328, 'n_words': 288}