<commit_before>/*******************************************************************************************************
 * File: advancedOpts.js
 * Project: hootenanny-ui
 * @author <NAME> - <EMAIL> on 4/23/18
 *******************************************************************************************************/

import _cloneDeep from 'lodash-es/cloneDeep';
import _map       from 'lodash-es/map';

import FieldsetData     from './fieldsetData';
import FieldsetControls from './fieldsetControls';
import { d3combobox }   from '../../../../lib/hoot/d3.combobox';


export default class AdvancedOpts {
    constructor() {
        this.sidebar         = d3.select( '#hoot-sidebar' );
        this.optTypes        = [ 'custom', 'horizontal', 'average', 'reference', 'diffConflator', 'diffTags'];
        this.advancedOptions = null;
    }

    get isOpen() {
        return this.form.classed( 'visible' );
    }

    async init() {
        // this.optTypes = [ 'custom', 'horizontal', 'average', 'reference', 'diff', 'diffTags'];
        let allOpts   = await Promise.all( _map( this.optTypes, type => Hoot.api.getAdvancedOptions( type ) ) );

        // console.log( allOpts );

        this.advancedOptions = {
            base: allOpts[ 0 ],
            horizontal: allOpts[ 1 ],
            average: allOpts[ 2 ],
            reference: allOpts[ 3 ],
            diffConflator: allOpts[ 4 ],
            diffTags: allOpts[ 5 ]
        };

        this.data    = new FieldsetData( this, _cloneDeep( this.advancedOptions ) );
        this.control = new FieldsetControls( this );

        this.render();
    }

    render() {
        this.fieldsMeta = this.data.getDefaultMeta();

        this.createContainer();
        this.createHeader();
        this.createContentDiv();
        this.createGroups();
        this.createButtons();

        this.control.saveFields();

        this.control.defaultFields = this.control.lastSetFields;
    }

    reRender() {

        this.fieldsMeta = this.data.getDefaultMeta();

        this.createHeader();
        this.createContentDiv();
        this.createGroups();
        this.createButtons();

        this.control.saveFields();

        this.control.defaultFields = this.control.lastSetFields;

    }

    clear() {
        d3.selectAll('.advanced-opts-content').remove();
        this.reRender();
    }

    toggle() {
        let formState = this.form.classed( 'visible' );

        this.form.classed( 'visible', !formState );
        this.overlay.classed( 'visible', !formState );
        d3.select( '#sidebar-resizer' ).classed( 'light', !formState );
    }

    createContainer() {
        this.form = this.sidebar.append( 'div' )
            .attr( 'id', 'advanced-opts-panel' )<commit_msg>update reRender method<commit_after>/*******************************************************************************************************
 * File: advancedOpts.js
 * Project: hootenanny-ui
 * @author <NAME> - <EMAIL> on 4/23/18
 *******************************************************************************************************/

import _cloneDeep from 'lodash-es/cloneDeep';
import _map       from 'lodash-es/map';

import FieldsetData     from './fieldsetData';
import FieldsetControls from './fieldsetControls';
import { d3combobox }   from '../../../../lib/hoot/d3.combobox';


export default class AdvancedOpts {
    constructor() {
        this.sidebar         = d3.select( '#hoot-sidebar' );
        this.optTypes        = [ 'custom', 'horizontal', 'average', 'reference', 'diffConflator', 'diffTags'];
        this.advancedOptions = null;
    }

    get isOpen() {
        return this.form.classed( 'visible' );
    }

    async init() {
        // this.optTypes = [ 'custom', 'horizontal', 'average', 'reference', 'diff', 'diffTags'];
        let allOpts   = await Promise.all( _map( this.optTypes, type => Hoot.api.getAdvancedOptions( type ) ) );

        // console.log( allOpts );

        this.advancedOptions = {
            base: allOpts[ 0 ],
            horizontal: allOpts[ 1 ],
            average: allOpts[ 2 ],
            reference: allOpts[ 3 ],
            diffConflator: allOpts[ 4 ],
            diffTags: allOpts[ 5 ]
        };

        this.data    = new FieldsetData( this, _cloneDeep( this.advancedOptions ) );
        this.control = new FieldsetControls( this );

        this.render();
    }

    render() {
        this.fieldsMeta = this.data.getDefaultMeta();

        this.createContainer();
        this.createHeader();
        this.createContentDiv();
        this.createGroups();
        this.createButtons();

        this.control.saveFields();

        this.control.defaultFields = this.control.lastSetFields;
    }

    reRender() {

        this.fieldsMeta = this.data.getDefaultMeta();

        this.createContentDiv();
        this.createGroups();

        this.control.saveFields();

        this.control.defaultFields = this.control.lastSetFields;

    }

    clear() {
        d3.selectAll('.advanced-opts-content').remove();
        this.reRender();
    }

    toggle() {
        let formState = this.form.classed( 'visible' );

        this.form.classed( 'visible', !formState );
        this.overlay.classed( 'visible', !formState );
        d3.select( '#sidebar-resizer' ).classed( 'light', !formState );
    }

    createContainer() {
        this.form = this.sidebar.append( 'div' )
            .attr( 'id', 'advanced-opts-panel' )
{'fraction_non_alphanumeric': 0.21118469462840322, 'fraction_numerical': 0.005886681383370125, 'mean_word_length': 2.4830237027546445, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 9, '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': '3133845', 'n_tokens_mistral': 1562, 'n_tokens_neox': 1490, 'n_words': 298}