<commit_before>/*
 * Copyright (c) 2018, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
 *
 * WSO2 Inc. licenses this file to you under the Apache License,
 * Version 2.0 (the "License"); you may not use this file except
 * in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied. See the License for the
 * specific language governing permissions and limitations
 * under the License.
 */

define(['require', 'log', 'lodash', 'jquery', 'partition', 'stream', 'query', 'formBuilder', 'aggregation',
    'jsonValidator', 'sourceOrSinkAnnotation', 'stream', 'table', 'window', 'trigger', 'functionDefinition',
        'constants'],
    function (require, log, _, $, Partition, Stream, Query, FormBuilder, Aggregation, JSONValidator,
        SourceOrSinkAnnotation, Stream, Table, Window, Trigger, FunctionDefinition,Constants) {

        /**
         * @class DesignView
         * @constructor
         * @class DesignView  Wraps the Ace editor for design view
         * @param {Object} options Rendering options for the view
         */

        const ENTER_KEY = 13;
        const DELETE_KEY = 46;
        const MAC_COMMAND_KEY = 91;
        const MAC_DELETE_KEY = 8;

        var DropElements = function (options) {
            var errorMessage = 'unable to find design view container';
            if (!_.has(options, 'container')) {
                log.error(errorMessage);
                throw errorMessage;
            }
            var container = $(_.get(options, 'container'));
            if (!container.length > 0) {
                log.error(errorMessage);
                throw errorMessage;
            }
            this.configurationData = options.configurationData;
            this.container = options.container;
            this.application = options.application;
            this.designGrid = options.designGrid;
            this.jsPlumbInstance = options.jsPlumbInstance;
            var currentTabId = this.application.tabController.activeTab.cid;
            this.designViewContainer = $('#design-container-' + currentTabId);
            this.toggleViewButton = $('#toggle-view-button-' + currentTabId);

            var formBuilderOptions = {};
            _.set(formBuilderOptions, 'application', this.application);
            _.set(formBuilderOptions, 'configurationData', this.configurationData);
            _.set(formBuilderOptions, 'jsPlumbInstance', this.jsPlumbInstance);
            _.set(formBuilderOptions, 'dropElementInstance', this);
            this.formBuilder = new FormBuilder(formBuilderOptions);
        };

        /**
         * @function drop the source element on the canvas
         * @param newAgent new element
         * @param i id of the element
         * @param top top position of the element
         * @param left left position of the element
         * @param isCodeToDesignMode whether code to design mode is enable or not
         * @param sourceName name of the source
         */
        DropElements.prototype.dropSource = function (newAgent, i, top, left, isCodeToDesignMode, sourceName) {

            var self = this;
            if (isCodeToDesignMode) {
                name = sourceName;
            } else {
                var sourceOptions = {};
                _.set(sourceOptions, 'id', i);
                _.set(sourceOptions, 'annotationType', 'SOURCE');
                _.set(sourceOptions, 'type', undefined);
                var source = new SourceOrSinkAnnotation(sourceOptions);
                self.configurationData.getSiddhiAppConfig().addSource(source);

                JSONValidator.prototype.validateSourceOrSinkAnnotation(source, 'Source', true)
            }
            var node = $('<div> ' + name + ' </div>');
            newAgent.append(node);
            node.attr('id', i + "-nodeInitial");
            node.attr('class', "sourceNameNode");

            var nodeId = $('#' + i)[0];
            nodeId.addEventListener('dblclick', function () {
                self.formBuilder.GeneratePropertiesFormForSources(this.children)
            });

            $('#' + i).on('keydown', function (key) {
                if (key.keyCode == ENTER_KEY) {
                    self.formBuilder.GeneratePropertiesFormForSources(this.children)
                }
            });
            /*
             prop --> When clicked on this icon, a definition and related information of the Source Element will
             be displayed in a form
            */<commit_msg>Fix bug - on drop of a source<commit_after>/*
 * Copyright (c) 2018, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
 *
 * WSO2 Inc. licenses this file to you under the Apache License,
 * Version 2.0 (the "License"); you may not use this file except
 * in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied. See the License for the
 * specific language governing permissions and limitations
 * under the License.
 */

define(['require', 'log', 'lodash', 'jquery', 'partition', 'stream', 'query', 'formBuilder', 'aggregation',
    'jsonValidator', 'sourceOrSinkAnnotation', 'stream', 'table', 'window', 'trigger', 'functionDefinition',
        'constants'],
    function (require, log, _, $, Partition, Stream, Query, FormBuilder, Aggregation, JSONValidator,
        SourceOrSinkAnnotation, Stream, Table, Window, Trigger, FunctionDefinition,Constants) {

        /**
         * @class DesignView
         * @constructor
         * @class DesignView  Wraps the Ace editor for design view
         * @param {Object} options Rendering options for the view
         */

        const ENTER_KEY = 13;
        const DELETE_KEY = 46;
        const MAC_COMMAND_KEY = 91;
        const MAC_DELETE_KEY = 8;

        var DropElements = function (options) {
            var errorMessage = 'unable to find design view container';
            if (!_.has(options, 'container')) {
                log.error(errorMessage);
                throw errorMessage;
            }
            var container = $(_.get(options, 'container'));
            if (!container.length > 0) {
                log.error(errorMessage);
                throw errorMessage;
            }
            this.configurationData = options.configurationData;
            this.container = options.container;
            this.application = options.application;
            this.designGrid = options.designGrid;
            this.jsPlumbInstance = options.jsPlumbInstance;
            var currentTabId = this.application.tabController.activeTab.cid;
            this.designViewContainer = $('#design-container-' + currentTabId);
            this.toggleViewButton = $('#toggle-view-button-' + currentTabId);

            var formBuilderOptions = {};
            _.set(formBuilderOptions, 'application', this.application);
            _.set(formBuilderOptions, 'configurationData', this.configurationData);
            _.set(formBuilderOptions, 'jsPlumbInstance', this.jsPlumbInstance);
            _.set(formBuilderOptions, 'dropElementInstance', this);
            this.formBuilder = new FormBuilder(formBuilderOptions);
        };

        /**
         * @function drop the source element on the canvas
         * @param newAgent new element
         * @param i id of the element
         * @param top top position of the element
         * @param left left position of the element
         * @param isCodeToDesignMode whether code to design mode is enable or not
         * @param sourceName name of the source
         */
        DropElements.prototype.dropSource = function (newAgent, i, top, left, isCodeToDesignMode, sourceName) {

            var self = this;
            var name;
            if (isCodeToDesignMode) {
                name = sourceName;
            } else {
                var sourceOptions = {};
                _.set(sourceOptions, 'id', i);
                _.set(sourceOptions, 'annotationType', 'SOURCE');
                _.set(sourceOptions, 'type', undefined);
                var source = new SourceOrSinkAnnotation(sourceOptions);
                self.configurationData.getSiddhiAppConfig().addSource(source);

                JSONValidator.prototype.validateSourceOrSinkAnnotation(source, 'Source', true)
            }
            var node = $('<div> ' + name + ' </div>');
            newAgent.append(node);
            node.attr('id', i + "-nodeInitial");
            node.attr('class', "sourceNameNode");

            var nodeId = $('#' + i)[0];
            nodeId.addEventListener('dblclick', function () {
                self.formBuilder.GeneratePropertiesFormForSources(this.children)
            });

            $('#' + i).on('keydown', function (key) {
                if (key.keyCode == ENTER_KEY) {
                    self.formBuilder.GeneratePropertiesFormForSources(this.children)
                }
            });
            /*
             prop --> When clicked on this icon, a definition and related information of the Source Element will
             be displayed in a form
            */
{'fraction_non_alphanumeric': 0.10391787135973182, 'fraction_numerical': 0.004190236748376284, 'mean_word_length': 2.198324958123953, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, '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': '5837039', 'n_tokens_mistral': 2395, 'n_tokens_neox': 2322, 'n_words': 710}