<commit_before>define([
    'app/AGSStore',
    'app/config',
    'app/Download',
    'app/_ResultsQueryMixin',

    'dgrid/extensions/ColumnResizer',
    'dgrid/extensions/DijitRegistry',
    'dgrid/OnDemandGrid',

    'dijit/_TemplatedMixin',
    'dijit/_WidgetBase',
    'dijit/_WidgetsInTemplateMixin',

    'dojo/date/locale',
    'dojo/dom-class',
    'dojo/store/Memory',
    'dojo/text!app/templates/Grid.html',
    'dojo/topic',
    'dojo/_base/declare',
    'dojo/_base/lang',

    'bootstrap'
], function (
    AGSStore,
    config,
    Download,
    _ResultsQueryMixin,

    ColumnResizer,
    DijitRegistry,
    Grid,

    _TemplatedMixin,
    _WidgetBase,
    _WidgetsInTemplateMixin,

    locale,
    domClass,
    Memory,
    template,
    topic,
    declare,
    lang
) {
    var fn = config.fieldNames;

    return declare([_WidgetBase, _TemplatedMixin, _WidgetsInTemplateMixin, _ResultsQueryMixin], {
        // description:
        //      A container to hold grids and download link.

        templateString: template,
        baseClass: 'grid',
        widgetsInTemplate: true,

        // stationsGrid: Grid
        stationsGrid: null,

        // resultsGrid: Grid
        resultsGrid: null,


        // Properties to be sent into constructor

        // mapServiceUrl: String
        //      updated to secured after successful sign in in app/App
        mapServiceUrl: config.urls.mapService,

        postCreate: function () {
            // summary:
            //      set up listeners
            console.log('app.Grid::postCreate', arguments);

            var that = this;
            this.download = new Download({}, this.downloadDiv);
            this.own(
                topic.subscribe(config.topics.queryIdsComplete, lang.hitch(this, 'populateGrid')),
                $('a[data-toggle="tab"]').on('shown.bs.tab', function () {
                    that.populateGrid(that.lastDefQuery);
                }),
                this.download
            );

            this.inherited(arguments);
        },
        onError: function () {
            // summary:
            //      show an error message
            console.log('app/Grid:onError', arguments);

            topic.publish(config.topics.toast, {
                message: 'There was an error populating the grid!',
                type: 'danger'
            });
        },
        switchToSecure: function () {
            // summary:
            //      switch url to secured url and refresh grid
            console.log('app/Grid:switchToSecure', arguments);

            this.mapServiceUrl = config.urls.secureMapService;

            // clear out collections to prevent caching in populateGrid
            if (this.stationsGrid && this.stationsGrid.collection) {
                this.stationsGrid.collection = null;
            }
            if (this.resultsGrid && this.resultsGrid.collection) {
                this.resultsGrid.collection = null;
            }

            this.download.switchToSecure();

            this.clearSelection();
        },
        populateGrid: function (defQuery) {
            // summary:
            //      Populate the grid with a newly created store based upon defQuery
            // defQuery: String
            console.log('app/Grid:populateGrid', arguments);

            var store;

            domClass.toggle(
                this.clearSelectionBtnContainer,
                'hidden',
                defQuery.indexOf(config.fieldNames.Id + ' = ') === -1
            );
            if (domClass.contains(this.stationsTab, 'active')) {
                if (!this.stationsGrid) {
                    this.initStationsGrid();
                }
                this.stationsGrid.resize();
                if (!this.stationsGrid.collection ||
                    (this.stationsGrid.collection && this.stationsGrid.collection.where !== defQuery)) {
                    store = new AGSStore({
                        target: this.mapServiceUrl + '/' + config.layerIndices.main,
                        idProperty: 'Id',
                        outFields: [
                            fn.Id,
                            fn.DataSource,
                            fn.StationId,
                            fn.StationName,
                            fn.StationType,
                            fn.Depth,
                            fn.WIN
                        ],
                        where: defQuery
                    });
                    this.stationsGrid.set('collection', store);
                }
            } else {
                if (!this.resultsGrid) {
                    this.initResultsGrid();
                }
                this.resultsGrid.resize();
                defQuery = this.convertToResultsQuery(defQuery);
                if (!this.resultsGrid.collection ||
                    (this.resultsGrid.collection && this.resultsGrid.collection.where !== defQuery)) {
                    store = new AGSStore({
                        target: this.mapServiceUrl + '/' + config.layerIndices.results,
                        idProperty: 'Id',
                        outFields: [
                            fn.Id,
                            fn.Param,
                            fn.ResultValue,
                            fn.Unit,
                            fn.SampleDate,
                            fn.StationId,
                            fn.DetectCond
                        ],
                        where: defQuery
                    });
                    this.resultsGrid.set('collection', store);
                }
            }
            this.lastDefQuery = defQuery;

            return defQuery; // for testing only
        },
        clearSelection: function () {<commit_msg>fix bug creating nested queries<commit_after>define([
    'app/AGSStore',
    'app/config',
    'app/Download',
    'app/_ResultsQueryMixin',

    'dgrid/extensions/ColumnResizer',
    'dgrid/extensions/DijitRegistry',
    'dgrid/OnDemandGrid',

    'dijit/_TemplatedMixin',
    'dijit/_WidgetBase',
    'dijit/_WidgetsInTemplateMixin',

    'dojo/date/locale',
    'dojo/dom-class',
    'dojo/store/Memory',
    'dojo/text!app/templates/Grid.html',
    'dojo/topic',
    'dojo/_base/declare',
    'dojo/_base/lang',

    'bootstrap'
], function (
    AGSStore,
    config,
    Download,
    _ResultsQueryMixin,

    ColumnResizer,
    DijitRegistry,
    Grid,

    _TemplatedMixin,
    _WidgetBase,
    _WidgetsInTemplateMixin,

    locale,
    domClass,
    Memory,
    template,
    topic,
    declare,
    lang
) {
    var fn = config.fieldNames;

    return declare([_WidgetBase, _TemplatedMixin, _WidgetsInTemplateMixin, _ResultsQueryMixin], {
        // description:
        //      A container to hold grids and download link.

        templateString: template,
        baseClass: 'grid',
        widgetsInTemplate: true,

        // stationsGrid: Grid
        stationsGrid: null,

        // resultsGrid: Grid
        resultsGrid: null,


        // Properties to be sent into constructor

        // mapServiceUrl: String
        //      updated to secured after successful sign in in app/App
        mapServiceUrl: config.urls.mapService,

        postCreate: function () {
            // summary:
            //      set up listeners
            console.log('app.Grid::postCreate', arguments);

            var that = this;
            this.download = new Download({}, this.downloadDiv);
            this.own(
                topic.subscribe(config.topics.queryIdsComplete, lang.hitch(this, 'populateGrid')),
                $('a[data-toggle="tab"]').on('shown.bs.tab', function () {
                    that.populateGrid(that.lastDefQuery);
                }),
                this.download
            );

            this.inherited(arguments);
        },
        onError: function () {
            // summary:
            //      show an error message
            console.log('app/Grid:onError', arguments);

            topic.publish(config.topics.toast, {
                message: 'There was an error populating the grid!',
                type: 'danger'
            });
        },
        switchToSecure: function () {
            // summary:
            //      switch url to secured url and refresh grid
            console.log('app/Grid:switchToSecure', arguments);

            this.mapServiceUrl = config.urls.secureMapService;

            // clear out collections to prevent caching in populateGrid
            if (this.stationsGrid && this.stationsGrid.collection) {
                this.stationsGrid.collection = null;
            }
            if (this.resultsGrid && this.resultsGrid.collection) {
                this.resultsGrid.collection = null;
            }

            this.download.switchToSecure();

            this.clearSelection();
        },
        populateGrid: function (defQuery) {
            // summary:
            //      Populate the grid with a newly created store based upon defQuery
            // defQuery: String
            console.log('app/Grid:populateGrid', arguments);

            var store;

            domClass.toggle(
                this.clearSelectionBtnContainer,
                'hidden',
                defQuery.indexOf(config.fieldNames.Id + ' = ') === -1
            );
            if (domClass.contains(this.stationsTab, 'active')) {
                if (!this.stationsGrid) {
                    this.initStationsGrid();
                }
                this.stationsGrid.resize();
                if (!this.stationsGrid.collection ||
                    (this.stationsGrid.collection && this.stationsGrid.collection.where !== defQuery)) {
                    store = new AGSStore({
                        target: this.mapServiceUrl + '/' + config.layerIndices.main,
                        idProperty: 'Id',
                        outFields: [
                            fn.Id,
                            fn.DataSource,
                            fn.StationId,
                            fn.StationName,
                            fn.StationType,
                            fn.Depth,
                            fn.WIN
                        ],
                        where: defQuery
                    });
                    this.stationsGrid.set('collection', store);
                }
            } else {
                if (!this.resultsGrid) {
                    this.initResultsGrid();
                }
                this.resultsGrid.resize();
                var resultsQuery = this.convertToResultsQuery(defQuery);
                if (!this.resultsGrid.collection ||
                    (this.resultsGrid.collection && this.resultsGrid.collection.where !== resultsQuery)) {
                    store = new AGSStore({
                        target: this.mapServiceUrl + '/' + config.layerIndices.results,
                        idProperty: 'Id',
                        outFields: [
                            fn.Id,
                            fn.Param,
                            fn.ResultValue,
                            fn.Unit,
                            fn.SampleDate,
                            fn.StationId,
                            fn.DetectCond
                        ],
                        where: resultsQuery
                    });
                    this.resultsGrid.set('collection', store);
                }
            }
            this.lastDefQuery = defQuery;

            return defQuery; // for testing only
        },
        clearSelection: function () {
{'fraction_non_alphanumeric': 0.09929078014184398, 'fraction_numerical': 0.0001729804532087874, 'mean_word_length': 1.2726022012578617, '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': 16, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6368256', 'n_tokens_mistral': 2954, 'n_tokens_neox': 2799, 'n_words': 535}