<commit_before>/* global require */

require({
    config: {
        tpl: {
            variable: 'data'
        }
    },
    shim: {
        bootstrap: ['jquery'],
        marionette: {
            deps: ['backbone'],
            exports: 'Marionette'
        },
        highcharts: {
            deps: ['jquery'],
            exports: 'Highcharts'
        }
    }
}, [
    'cilantro',
    'project/ui',
    'project/csrf'
], function(c, ui, csrf) {
    var SAMPLE_CONCEPT_ID = 2,
        SAMPLE_FIELD_ID = 111;

    // Add namespaced variables for reference in other modules
    c.config.set('varify.sample.concept', SAMPLE_CONCEPT_ID);
    c.config.set('varify.sample.field', SAMPLE_FIELD_ID);

    // Session options
    var options = {
        url: c.config.get('url'),
        credentials: c.config.get('credentials')
    };

    var augmentFixedView = function() {
        var newView = {
            view: {
                columns: [SAMPLE_CONCEPT_ID]
            }
        };

        var json;
        if ((json = c.session.data.views.session.get('json')) != null) {
            newView['view']['ordering'] = json['ordering'];
        }

        return newView;
    };

    // Globally disable stats on all fields
    c.config.set('fields.defaults.form.stats', false);

    // Disable charts for all the types they are enabled for in the default
    // Cilantro config.
    c.config.set('fields.types.number.form.chart', false);
    c.config.set('fields.types.date.form.chart', false);
    c.config.set('fields.types.time.form.chart', false);
    c.config.set('fields.types.datetime.form.chart', false);

    // Convert the Chromosome, Effect, Effect Region, Effect Impact, and
    // Functional Class fields to be multi-selection drop down lists.
    c.config.set('fields.instances.27.form.controls', ['multiSelectionList']);
    c.config.set('fields.instances.28.form.controls', ['multiSelectionList']);
    c.config.set('fields.instances.29.form.controls', ['multiSelectionList']);
    c.config.set('fields.instances.61.form.controls', ['multiSelectionList']);
    c.config.set('fields.instances.64.form.controls', ['multiSelectionList']);

    // Force the Cohort field to use the built-in search control.
    c.config.set('fields.instances.75.form.controls', ['search']);

    // Convert the Genotype field to be a single selection drop down.
    c.config.set('fields.instances.68.form.controls', ['singleSelectionList']);

    // Set the custom control for the Sift and PolyPhen2 fields.
    c.controls.set('Sift', ui.SiftSelector);
    c.controls.set('PolyPhen', ui.PolyPhenSelector);
    c.config.set('fields.instances.58.form.controls', ['Sift']);
    c.config.set('fields.instances.56.form.controls', ['PolyPhen']);

    // Use a NullSelector control for the HGMD field with custom labels
    // defined for the options.
    c.config.set('fields.instances.110.form.controls', [{
        options: {
            'isNullLabel': 'Not In HGMD',
            'isNotNullLabel': 'In HGMD'
        },
        control: 'nullSelector'
    }]);

    // A simple handler for CONTEXT_REQUIRED and CONTEXT_INVALID events that
    // tells the user which concept is required(when possible) or prints a
    // generic message in the case the concept name could not be found.
    var notifyRequired = (function(_this) {
        return function(concepts) {
            if (c.data == null) return;

            var names = _.map(concepts || [], function(concept) {
                if ((currConcept = c.data.concepts.get(concept.concept)) != null) {
                    return currConcept.get('name');
                }
            });

            var message;
            if (names) {
                message = 'The following concepts are required: ' + names.join(', ');
            }
            else {
                message = 'There are 1 or more required concepts';
            }

            return c.notify({
                level: 'error',
                message: message
            });
        };
    })(this);

    // Mark the Sample concept as required and display a notification to the
    // user when it is not populated.
    c.config.set('filters.required', [{concept: SAMPLE_CONCEPT_ID}]);
    c.on(c.CONTEXT_INVALID, notifyRequired);
    c.on(c.CONTEXT_REQUIRED, notifyRequired);

    // Open the default session when Cilantro is ready
    c.ready(function() {

        // Open the default session defined in the pre-defined configuration.
        // Initialize routes once data is confirmed to be available
        c.sessions.open(options).then(function() {

            // Force calls to the preview endpoint to use a fixed view composed solely
            // of the sample concept. This will have the intended result of removing
            // "duplicate" rows in the results table that sometimes occured due to
            // the user's view.
            c.config.set('session.defaults.data.preview', augmentFixedView);

            // Panels are defined in their own namespace since they shared
            // across workflows
            c.panels = {
                concept: new c.ui.ConceptPanel({
                    collection: this.data.concepts.queryable
                }),

                context: new c.ui.ContextPanel({
                    model: this.data.contexts.session
                })
            };

            c.dialogs = {
                exporter: new ui.ExporterDialog({
                    // TODO rename data.exporter on session
                    exporters: this.data.exporter
                }),

                columns: new c.ui.ConceptColumnsDialog({
                    view: this.data.views.session,
                    concepts: this.data.concepts.viewable
                }),

                query: new c.ui.EditQueryDialog({
                    view: this.data.views.session,
                    context: this.data.contexts.session,
                    collection: this.data.queries
                }),

                deleteQuery: new c.ui.DeleteQueryDialog(),

                resultDetails: new ui.ResultDetails,

                phenotype: new ui.Phenotype({
                    context: this.data.contexts.session
                })<commit_msg>Integrate sample dialog in main module<commit_after>/* global require */

require({
    config: {
        tpl: {
            variable: 'data'
        }
    },
    shim: {
        bootstrap: ['jquery'],
        marionette: {
            deps: ['backbone'],
            exports: 'Marionette'
        },
        highcharts: {
            deps: ['jquery'],
            exports: 'Highcharts'
        }
    }
}, [
    'jquery',
    'underscore',
    'cilantro',
    'project/ui',
    'project/csrf'
], function($, _, c, ui) {

    var SAMPLE_CONCEPT_ID = 2,
        SAMPLE_FIELD_ID = 111;

    // Add namespaced variables for reference in other modules
    c.config.set('varify.sample.concept', SAMPLE_CONCEPT_ID);
    c.config.set('varify.sample.field', SAMPLE_FIELD_ID);

    // Session options
    var options = {
        url: c.config.get('url'),
        credentials: c.config.get('credentials')
    };

    var augmentFixedView = function() {
        var newView = {
            view: {
                columns: [SAMPLE_CONCEPT_ID]
            }
        };

        var json;
        if ((json = c.session.data.views.session.get('json')) != null) {
            newView['view']['ordering'] = json['ordering'];
        }

        return newView;
    };

    // Globally disable stats on all fields
    c.config.set('fields.defaults.form.stats', false);

    // Disable charts for all the types they are enabled for in the default
    // Cilantro config.
    c.config.set('fields.types.number.form.chart', false);
    c.config.set('fields.types.date.form.chart', false);
    c.config.set('fields.types.time.form.chart', false);
    c.config.set('fields.types.datetime.form.chart', false);

    // Convert the Chromosome, Effect, Effect Region, Effect Impact, and
    // Functional Class fields to be multi-selection drop down lists.
    c.config.set('fields.instances.27.form.controls', ['multiSelectionList']);
    c.config.set('fields.instances.28.form.controls', ['multiSelectionList']);
    c.config.set('fields.instances.29.form.controls', ['multiSelectionList']);
    c.config.set('fields.instances.61.form.controls', ['multiSelectionList']);
    c.config.set('fields.instances.64.form.controls', ['multiSelectionList']);

    // Force the Cohort field to use the built-in search control.
    c.config.set('fields.instances.75.form.controls', ['search']);

    // Convert the Genotype field to be a single selection drop down.
    c.config.set('fields.instances.68.form.controls', ['singleSelectionList']);

    // Set the custom control for the Sift and PolyPhen2 fields.
    c.controls.set('Sift', ui.SiftSelector);
    c.controls.set('PolyPhen', ui.PolyPhenSelector);
    c.config.set('fields.instances.58.form.controls', ['Sift']);
    c.config.set('fields.instances.56.form.controls', ['PolyPhen']);

    // Use a NullSelector control for the HGMD field with custom labels
    // defined for the options.
    c.config.set('fields.instances.110.form.controls', [{
        options: {
            'isNullLabel': 'Not In HGMD',
            'isNotNullLabel': 'In HGMD'
        },
        control: 'nullSelector'
    }]);

    // If no sample is selected, open the dialog to select one
    var showSampleDialog = function(required) {
        if (_.findWhere(required, {concept: SAMPLE_CONCEPT_ID})) {
            c.dialogs.sample.open();
        }
    };

    // Mark the Sample concept as required and display a notification to the
    // user when it is not populated.
    c.config.set('filters.required', [{concept: SAMPLE_CONCEPT_ID}]);
    c.on(c.CONTEXT_INVALID, showSampleDialog);
    c.on(c.CONTEXT_REQUIRED, showSampleDialog);

    // Open the default session when Cilantro is ready
    c.ready(function() {

        // Open the default session defined in the pre-defined configuration.
        // Initialize routes once data is confirmed to be available
        c.sessions.open(options).then(function() {

            // Force calls to the preview endpoint to use a fixed view composed solely
            // of the sample concept. This will have the intended result of removing
            // "duplicate" rows in the results table that sometimes occured due to
            // the user's view.
            c.config.set('session.defaults.data.preview', augmentFixedView);

            // Panels are defined in their own namespace since they shared
            // across workflows
            c.panels = {
                concept: new c.ui.ConceptPanel({
                    collection: this.data.concepts.queryable
                }),

                context: new c.ui.ContextPanel({
                    model: this.data.contexts.session
                })
            };

            c.dialogs = {
                exporter: new ui.ExporterDialog({
                    // TODO rename data.exporter on session
                    exporters: this.data.exporter
                }),

                columns: new c.ui.ConceptColumnsDialog({
                    view: this.data.views.session,
                    concepts: this.data.concepts.viewable
                }),

                query: new c.ui.EditQueryDialog({
                    view: this.data.views.session,
                    context: this.data.contexts.session,
                    collection: this.data.queries
                }),

                deleteQuery: new c.ui.DeleteQueryDialog(),

                resultDetails: new ui.ResultDetails(),

                phenotype: new ui.Phenotype({
                    context: this.data.contexts.session
                }),

                sample: new ui.SampleDialog({
                    context: this.data.contexts.session
                })
{'fraction_non_alphanumeric': 0.11986531986531987, 'fraction_numerical': 0.004461279461279461, 'mean_word_length': 1.940841584158416, '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': '334259', 'n_tokens_mistral': 3387, 'n_tokens_neox': 3185, 'n_words': 815}