<commit_before>/*
 * Copyright (C) 2014 Vanderbilt University, All rights reserved.
 *
 * Authors: <NAME>
 *          <NAME>
 */

define(['js/Panels/ModelEditor/ModelEditorControl',
    'js/Constants',
    './NetLabelControl.EventHandlers', 'js/Utils/PreferencesHelper'], function (ModelEditorControl, CONSTANTS, NetLabelControlEventHandlers, PreferencesHelper) {

    "use strict";

    var NetLabelControl;

    NetLabelControl = function (options) {
        ModelEditorControl.call(this, options);
    };

    _.extend(NetLabelControl.prototype, ModelEditorControl.prototype);
    _.extend(NetLabelControl.prototype, NetLabelControlEventHandlers.prototype);

    NetLabelControl.prototype.getConnectionDescriptor = function (gmeID) {

        var self = this,
            CONSTS =  CONSTANTS, // CONSTANTS can only be loaded by assigning it to a var
            gmeClient = self._client,
            connectionObj = gmeClient.getNode(gmeID),
            srcID = connectionObj.getPointer(CONSTANTS.POINTER_SOURCE).to,
            dstID = connectionObj.getPointer(CONSTANTS.POINTER_TARGET).to,
            srcObj = gmeClient.getNode(srcID),
            dstObj = gmeClient.getNode(dstID),
            srcName = srcObj.getAttribute('name'),
            dstName = dstObj.getAttribute('name'),
            srcParentId = srcObj.getParentId(),
            dstParentId = dstObj.getParentId(),
            srcParentName = gmeClient.getNode(srcParentId).getAttribute('name'),
            dstParentName = gmeClient.getNode(dstParentId).getAttribute('name'),
            isSrcAPort = srcID.match(/\//g).length > 3,
            isDstAPort = dstID.match(/\//g).length > 3,
            srcObjPos = srcObj.getRegistry('position'),
            dstObjPos = dstObj.getRegistry('position'),
            srcText = isSrcAPort ? srcParentName + "." + srcName : srcName,
            dstText = isDstAPort ? dstParentName + "." + dstName : dstName;
        return {'srcText': srcText,
                'dstText': dstText,
                'srcObjPos': srcObjPos,
                'dstObjPos': dstObjPos,
                'srcID': srcID,
                'dstID': dstID};
    };

    NetLabelControl.prototype._onUpdate = function (gmeID, objDesc) {
        var componentID,
            len,
            decClass,
            objId,
            sCompId;

        //self or child updated
        //check if the updated object is the opened node
        if (gmeID === this.currentNodeInfo.id) {
            //the updated object is the parent whose children are displayed here
            //the interest about the parent is:
            // - name change
            this._updateSheetName(objDesc.name);
            this._updateAspects();
        } else {
            if (objDesc) {
                if (objDesc.parentId === this.currentNodeInfo.id) {
                    if (objDesc.kind === "MODEL") {
                        if(this._GmeID2ComponentID[gmeID]){
                            len = this._GmeID2ComponentID[gmeID].length;
                            while (len--) {
                                componentID = this._GmeID2ComponentID[gmeID][len];

                                decClass = this._getItemDecorator(objDesc.decorator);

                                objDesc.decoratorClass = decClass;
                                objDesc.preferencesHelper = PreferencesHelper.getPreferences();
                                objDesc.aspect = this._selectedAspect;

                                this.designerCanvas.updateDesignerItem(componentID, objDesc);
                                var connections2update = this.designerCanvas.connectionIDbyEndID[componentID];
                                if (connections2update) {
                                    if (connections2update.__SELF__) {
                                        var counter = connections2update.__SELF__.length,
                                            connComponentId,
                                            item,
                                            labels2update,
                                            ctr,
                                            results;
                                        while (counter--) {
                                            connComponentId = connections2update.__SELF__[counter];
                                            item = this.designerCanvas.items[connComponentId];
                                            labels2update = item.diagramDesigner.$el.find('[connid^="' + connComponentId + '"]');
                                            ctr = labels2update.length;
                                            while (ctr--) {
                                                if (labels2update[ctr].getAttribute("id") === componentID) {
                                                    labels2update[ctr].textContent = objDesc.name;
                                                }
                                            }
                                        }

                                    }
                                }
                            }
                        }
                    }

                    //there is a connection associated with this GMEID
                    if (this._GMEConnections.indexOf(gmeID) !== -1) {
                        len = this._GmeID2ComponentID[gmeID].length;
                        var srcDst = this._getAllSourceDestinationPairsForConnection(objDesc.source, objDesc.target);
                        var sources = srcDst.sources;
                        var destinations = srcDst.destinations;
<commit_msg>GH-18 Made label name updates work with items with subcomponents/ports<commit_after>/*
 * Copyright (C) 2014 Vanderbilt University, All rights reserved.
 *
 * Authors: <NAME>
 *          <NAME>
 */

define(['js/Panels/ModelEditor/ModelEditorControl',
    'js/Constants',
    './NetLabelControl.EventHandlers', 'js/Utils/PreferencesHelper'], function (ModelEditorControl, CONSTANTS, NetLabelControlEventHandlers, PreferencesHelper) {

    "use strict";

    var NetLabelControl;

    NetLabelControl = function (options) {
        ModelEditorControl.call(this, options);
    };

    _.extend(NetLabelControl.prototype, ModelEditorControl.prototype);
    _.extend(NetLabelControl.prototype, NetLabelControlEventHandlers.prototype);

    NetLabelControl.prototype.getConnectionDescriptor = function (gmeID) {

        var self = this,
            CONSTS =  CONSTANTS, // CONSTANTS can only be loaded by assigning it to a var
            gmeClient = self._client,
            connectionObj = gmeClient.getNode(gmeID),
            srcID = connectionObj.getPointer(CONSTANTS.POINTER_SOURCE).to,
            dstID = connectionObj.getPointer(CONSTANTS.POINTER_TARGET).to,
            srcObj = gmeClient.getNode(srcID),
            dstObj = gmeClient.getNode(dstID),
            srcName = srcObj.getAttribute('name'),
            dstName = dstObj.getAttribute('name'),
            srcParentId = srcObj.getParentId(),
            dstParentId = dstObj.getParentId(),
            srcParentName = gmeClient.getNode(srcParentId).getAttribute('name'),
            dstParentName = gmeClient.getNode(dstParentId).getAttribute('name'),
            isSrcAPort = srcID.match(/\//g).length > 3,
            isDstAPort = dstID.match(/\//g).length > 3,
            srcObjPos = srcObj.getRegistry('position'),
            dstObjPos = dstObj.getRegistry('position'),
            srcText = isSrcAPort ? srcParentName + "." + srcName : srcName,
            dstText = isDstAPort ? dstParentName + "." + dstName : dstName;
        return {'srcText': srcText,
                'dstText': dstText,
                'srcObjPos': srcObjPos,
                'dstObjPos': dstObjPos,
                'srcID': srcID,
                'dstID': dstID};
    };

    NetLabelControl.prototype._onUpdate = function (gmeID, objDesc) {
        var componentID,
            len,
            decClass,
            objId,
            sCompId;

        //self or child updated
        //check if the updated object is the opened node
        if (gmeID === this.currentNodeInfo.id) {
            //the updated object is the parent whose children are displayed here
            //the interest about the parent is:
            // - name change
            this._updateSheetName(objDesc.name);
            this._updateAspects();
        } else {
            if (objDesc) {
                if (objDesc.parentId === this.currentNodeInfo.id) {
                    if (objDesc.kind === "MODEL") {
                        if(this._GmeID2ComponentID[gmeID]){
                            len = this._GmeID2ComponentID[gmeID].length;
                            while (len--) {
                                componentID = this._GmeID2ComponentID[gmeID][len];

                                decClass = this._getItemDecorator(objDesc.decorator);

                                objDesc.decoratorClass = decClass;
                                objDesc.preferencesHelper = PreferencesHelper.getPreferences();
                                objDesc.aspect = this._selectedAspect;

                                this.designerCanvas.updateDesignerItem(componentID, objDesc);

                                // ***************updating netLabels when components names change*********************
                                // todo: refinement
                                var connections2update = this.designerCanvas.connectionIDbyEndID[componentID];
                                if (connections2update) {
                                    var counter,
                                        connComponentId,
                                        item,
                                        labels2update,
                                        ctr;
                                    if (connections2update.__SELF__) {
                                        counter = connections2update.__SELF__.length;
                                        while (counter--) {
                                            connComponentId = connections2update.__SELF__[counter];
                                            item = this.designerCanvas.items[connComponentId];
                                            labels2update = item.diagramDesigner.$el.find('[connid^="' + connComponentId + '"]');
                                            ctr = labels2update.length;
                                            while (ctr--) {
                                                if (labels2update[ctr].getAttribute("id") === componentID) {
                                                    labels2update[ctr].textContent = objDesc.name;
                                                }
                                            }
                                        }
                                    }

                                    // update label names when a subcomponent's parent name changes
                                    for (sCompId in connections2update) {
                                        if (connections2update.hasOwnProperty(sCompId)) {
                                            var cObjArray = connections2update[sCompId];
                                            counter = cObjArray.length;
                                            while (counter--) {
                                                connComponentId = cObjArray[counter];
                                                item = this.designerCanvas.items[connComponentId];
                                                labels2update = item.diagramDesigner.$el.find('[connid^="' + connComponentId + '"]');
                                                ctr = labels2update.length;
                                                while (ctr--) {
                                                    if (labels2update[ctr].getAttribute("id") === sCompId) {
                                                        var subStr = labels2update[ctr].textContent.substr(labels2update[ctr].textContent.indexOf('.'), labels2update[ctr].textContent.length);
                                                        labels2update[ctr].textContent = objDesc.name + subStr;
                                                    }
                                                }
                                            }

                                        }
                                    }
                                    counter = connections2update.length;
                                    while (counter--) {
                                        connComponentId = connections2update.__SELF__[counter];
                                        item = this.designerCanvas.items[connComponentId];
                                        labels2update = item.diagramDesigner.$el.find('[connid^="' + connComponentId + '"]');
                                        ctr = labels2update.length;
                                        while (ctr--) {
                                            if (labels2update[ctr].getAttribute("id") === componentID) {
                                                labels2update[ctr].textContent = objDesc.name;
                                            }
                                        }
                                    }
                                }
                                // ***********************************************************************************
                            }
                        }
                    }

                    //there is a connection associated with this GMEID
                    if (this._GMEConnections.indexOf(gmeID) !== -1) {
                        len = this._GmeID2ComponentID[gmeID].length;
                        var srcDst = this._getAllSourceDestinationPairsForConnection(objDesc.source, objDesc.target);
                        var sources = srcDst.sources;
                        var destinations = srcDst.destinations;

{'fraction_non_alphanumeric': 0.09124555160142349, 'fraction_numerical': 0.004270462633451958, 'mean_word_length': 1.1557226142988646, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 120, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '352996', 'n_tokens_mistral': 3056, 'n_tokens_neox': 2973, 'n_words': 558}