<commit_before>L.Dropchop = L.Dropchop || {};
/*
**
** AppController is the primary point of app initialization. It basically 'ties
** every together'
**
*/
L.Dropchop.AppController = L.Class.extend({

    statics: {},

    // default options
    options: {},

    // L.Class.extend automatically executes 'initialize'
    initialize : function( options ) {

        // override defaults with passed options
        L.setOptions(this, options);

        this.mapView = new L.Dropchop.MapView();
        this.dropzone = new L.Dropchop.DropZone( this.mapView._map, {} );
        this.layerlist = new L.Dropchop.LayerList( this.mapView._map, { layerContainerId: 'sidebar' } );
        this.notification = new L.Dropchop.Notifications();

        this.menubar = new L.Dropchop.MenuBar(
            { id: 'menu-bar' }
        ).addTo( document.body );
        this.bottom_menu = new L.Dropchop.MenuBar(
            { id: 'add-remove', classList: ["bottom", "menu"] }
        ).addTo( document.getElementById('sidebar') );

        // build out menus
        this.menus = {
            // GEO
            geo: new L.Dropchop.Menu('Geoprocessing', {     // New dropdown menu
                items: [
                    'along',
                    'bezier',
                    'buffer',
                    'center',
                    'centroid',
                    'destination',
                    'envelope',
                    'explode',
                    'midpoint',
                    'simplify',
                    'union',
                    'tin'
                ]
            }).addTo( this.menubar ),                       // Append to menubar

            // SAVE
            save: new L.Dropchop.Menu('Save', {
                items: ['save geojson', 'save shapefile']
            }).addTo( this.menubar ),

            // ADD LAYER
            addLayer: new L.Dropchop.Menu('Add', {
                items: ['upload', 'load from url', 'load from gist'],
                menuDirection: 'above',
                iconClassName: "fa fa-plus",
            }).addTo( this.bottom_menu ),           // Append to menubar

            // REMOVE LAYER
            removeLayer: new L.Dropchop.Menu('Remove', {
                iconClassName: "fa fa-minus",
            }).addTo( this.bottom_menu ),
        };

        this.geoOpsConfig = {
            operations: new L.Dropchop.Geo(),        // Configurations of GeoOperations
            executor: new L.Dropchop.TurfExecute( this.notification )   // Executor of GeoOperations
        };

        this.fileOpsConfig = {
            operations: new L.Dropchop.File(),        // Configurations of FileOperations
            executor: new L.Dropchop.FileExecute( this.notification ) // Executor of FileOperations
        };

        this.forms = new L.Dropchop.Forms();
        this._addEventHandlers();
        this._handleGetParams();
    },

    /*
    **
    ** Bind events to handlers
    **
    */
    _addEventHandlers: function(){
        this.dropzone.fileReader.on( 'fileparsed', this._handleParsedFile.bind( this ) );
        this.fileOpsConfig.executor.on( 'uploadedfiles', this.dropzone.fileReader._handleFiles.bind(this) );

        // Handle clicks on items within menus
        // NOTE: This is where an operation is tied to a menu item
        this.menus.geo.on( 'clickedOperation', this._handleOperationClick.bind( this, this.geoOpsConfig ) );
        this.menus.save.on( 'clickedOperation', this._handleOperationClick.bind( this, this.fileOpsConfig ) );
        this.menus.addLayer.on( 'clickedOperation', this._handleOperationClick.bind( this, this.fileOpsConfig ) );
        this.menus.removeLayer.on( 'clickedOperation', this._handleOperationClick.bind( this, this.fileOpsConfig ) );
    },

    /*
    **
    ** Lookup operation by name from operations configuration, validate selection,
    ** and render appropriate form
    **
    */
    _handleOperationClick: function( opsConfig, e ) {
        var config = opsConfig.operations[e.action];
        // Validate selection
        try {
            opsConfig.executor.validate( e.action, this.getLayerSelection(), config );
        }
        catch(err) {
            this.notification.add({
                text: err.message,
                type: 'alert',<commit_msg>Correctly set scope (fixes #158)<commit_after>L.Dropchop = L.Dropchop || {};
/*
**
** AppController is the primary point of app initialization. It basically 'ties
** every together'
**
*/
L.Dropchop.AppController = L.Class.extend({

    statics: {},

    // default options
    options: {},

    // L.Class.extend automatically executes 'initialize'
    initialize : function( options ) {

        // override defaults with passed options
        L.setOptions(this, options);

        this.mapView = new L.Dropchop.MapView();
        this.dropzone = new L.Dropchop.DropZone( this.mapView._map, {} );
        this.layerlist = new L.Dropchop.LayerList( this.mapView._map, { layerContainerId: 'sidebar' } );
        this.notification = new L.Dropchop.Notifications();

        this.menubar = new L.Dropchop.MenuBar(
            { id: 'menu-bar' }
        ).addTo( document.body );
        this.bottom_menu = new L.Dropchop.MenuBar(
            { id: 'add-remove', classList: ["bottom", "menu"] }
        ).addTo( document.getElementById('sidebar') );

        // build out menus
        this.menus = {
            // GEO
            geo: new L.Dropchop.Menu('Geoprocessing', {     // New dropdown menu
                items: [
                    'along',
                    'bezier',
                    'buffer',
                    'center',
                    'centroid',
                    'destination',
                    'envelope',
                    'explode',
                    'midpoint',
                    'simplify',
                    'union',
                    'tin'
                ]
            }).addTo( this.menubar ),                       // Append to menubar

            // SAVE
            save: new L.Dropchop.Menu('Save', {
                items: ['save geojson', 'save shapefile']
            }).addTo( this.menubar ),

            // ADD LAYER
            addLayer: new L.Dropchop.Menu('Add', {
                items: ['upload', 'load from url', 'load from gist'],
                menuDirection: 'above',
                iconClassName: "fa fa-plus",
            }).addTo( this.bottom_menu ),           // Append to menubar

            // REMOVE LAYER
            removeLayer: new L.Dropchop.Menu('Remove', {
                iconClassName: "fa fa-minus",
            }).addTo( this.bottom_menu ),
        };

        this.geoOpsConfig = {
            operations: new L.Dropchop.Geo(),        // Configurations of GeoOperations
            executor: new L.Dropchop.TurfExecute( this.notification )   // Executor of GeoOperations
        };

        this.fileOpsConfig = {
            operations: new L.Dropchop.File(),        // Configurations of FileOperations
            executor: new L.Dropchop.FileExecute( this.notification ) // Executor of FileOperations
        };

        this.forms = new L.Dropchop.Forms();
        this._addEventHandlers();
        this._handleGetParams();
    },

    /*
    **
    ** Bind events to handlers
    **
    */
    _addEventHandlers: function(){
        this.dropzone.fileReader.on( 'fileparsed', this._handleParsedFile.bind( this ) );
        this.fileOpsConfig.executor.on( 'uploadedfiles', this.dropzone.fileReader._handleFiles.bind( this.dropzone.fileReader ) );

        // Handle clicks on items within menus
        // NOTE: This is where an operation is tied to a menu item
        this.menus.geo.on( 'clickedOperation', this._handleOperationClick.bind( this, this.geoOpsConfig ) );
        this.menus.save.on( 'clickedOperation', this._handleOperationClick.bind( this, this.fileOpsConfig ) );
        this.menus.addLayer.on( 'clickedOperation', this._handleOperationClick.bind( this, this.fileOpsConfig ) );
        this.menus.removeLayer.on( 'clickedOperation', this._handleOperationClick.bind( this, this.fileOpsConfig ) );
    },

    /*
    **
    ** Lookup operation by name from operations configuration, validate selection,
    ** and render appropriate form
    **
    */
    _handleOperationClick: function( opsConfig, e ) {
        var config = opsConfig.operations[e.action];
        // Validate selection
        try {
            opsConfig.executor.validate( e.action, this.getLayerSelection(), config );
        }
        catch(err) {
            this.notification.add({
                text: err.message,
                type: 'alert',
{'fraction_non_alphanumeric': 0.12171395483497394, 'fraction_numerical': 0.0003474232773595831, 'mean_word_length': 1.765289785462696, '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': '4534975', 'n_tokens_mistral': 2435, 'n_tokens_neox': 2338, 'n_words': 520}