<commit_before>/*globals define, _, WebGMEGlobal*/
/*jshint browser: true*/
/**
 * @author rkereskenyi / https://github.com/rkereskenyi
 */

define(['js/logger',
    'js/RegistryKeys',
    'js/Constants',
    './CrosscutConstants',
    'js/DragDrop/DragHelper',
    'js/Utils/GMEConcepts',
    'js/Panels/ControllerBase/DiagramDesignerWidgetMultiTabMemberListControllerBase',
    'js/Panels/MetaEditor/MetaRelations',
    'js/NodePropertyNames',
    'js/Utils/ComponentSettings'
], function (Logger,
             REGISTRY_KEYS,
             CONSTANTS,
             CrosscutConstants,
             DragHelper,
             GMEConcepts,
             DiagramDesignerWidgetMultiTabMemberListControllerBase,
             MetaRelations,
             nodePropertyNames,
             ComponentSettings) {

    'use strict';

    var CrosscutController,
        DEFAULT_DECORATOR = 'ModelDecorator',
        WIDGET_NAME = 'DiagramDesigner';
    //CONNECTION_DECORATOR = 'CircleDecorator';

    CrosscutController = function (options) {
        options = options || {};
        options.loggerName = 'gme:Panels:CrossCut:CrosscutController';

        this._config = CrosscutController.getDefaultConfig();
        ComponentSettings.resolveWithWebGMEGlobal(this._config, CrosscutController.getComponentId());

        DiagramDesignerWidgetMultiTabMemberListControllerBase.call(this, options);

        this._filteredOutConnTypes = [];
        this._filteredOutConnectionDescriptors = {};
        this._activeCrosscutId = null;
        this._initActiveTab = false;
        this._tabsHasBeenRequested = false;
        this._autoCreateCrosscut = this._config.autoCreateCrosscut === true;

        this._initFilterPanel();
        this.logger.debug('CrosscutController ctor finished');
    };

    _.extend(CrosscutController.prototype, DiagramDesignerWidgetMultiTabMemberListControllerBase.prototype);

    CrosscutController.prototype._attachDiagramDesignerWidgetEventHandlers = function () {
        var self = this,
            oldTabChangefn;

        //cal base classes _attachDiagramDesignerWidgetEventHandlers
        DiagramDesignerWidgetMultiTabMemberListControllerBase.prototype
            ._attachDiagramDesignerWidgetEventHandlers.call(this);

        //add own event handlers

        this._widget.onFilterNewConnectionDroppableEnds = function (params) {
            return self._onFilterNewConnectionDroppableEnds(params);
        };

        this._widget.onCreateNewConnection = function (params) {
            self._onCreateNewConnection(params);
        };

        this._widget.onModifyConnectionEnd = function (params) {
            self._onModifyConnectionEnd(params);
        };

        this._widget.onCheckChanged = function (value, isChecked) {
            self._onConnectionTypeFilterCheckChanged(value, isChecked);
        };

        oldTabChangefn = this._widget.onSelectedTabChanged;
        this._widget.onSelectedTabChanged = function (tabID) {
            oldTabChangefn(tabID);
            self._selectedTabChanged(tabID);
        };
    };

    //enable every node
    CrosscutController.prototype._validateNodeId = function (nodeId) {
        return nodeId;
    };

    CrosscutController.prototype._canAddTab = function () {
        var memberListContainerID = this._memberListContainerID;

        return (memberListContainerID || memberListContainerID === CONSTANTS.PROJECT_ROOT_ID);
    };

    CrosscutController.prototype._updateSelectedMemberListMembersTerritoryPatterns = function () {
        var currentlyDisplayedMembers = (this._selectedMemberListMembers || []).slice(0),
            actualMembers = (this._memberListMembers[this._selectedMemberListID] || []).slice(0),
            diff,
            len,
            territoryChanged = false,
            territoryId = this._selectedMemberListMembersTerritoryId,
            territoryPatterns = this._selectedMemberListMembersTerritoryPatterns,
            client = this._client,
            putConnectionsToBeHandledLast = function (list) {
                var boxes = [],
                    connections = [],
                    i, node;
                for (i = 0; i < list.length; i += 1) {
                    node = client.getNode(list[i]);
                    if (node && node.isConnection()) {
                        connections.push(list[i]);
                    } else {
                        boxes.push(list[i]);
                    }
                }
                return connections.concat(boxes);
            };

        //let's see who has been deleted
        diff = putConnectionsToBeHandledLast(_.difference(currentlyDisplayedMembers, actualMembers));
        len = diff.length;
        while (len--) {
            delete territoryPatterns[diff[len]];
            territoryChanged = true;
        }

        //let's see who has been added
        diff = putConnectionsToBeHandledLast(_.difference(actualMembers, currentlyDisplayedMembers));
        len = diff.length;
        while (len--) {
            territoryPatterns[diff[len]] = {children: 0};
            territoryChanged = true;
        }

        //let's update the one that has not been changed but their position might have
        //diff = putConnectionsToBeHandledLast(_.intersection(actualMembers, currentlyDisplayedMembers));
        //len = diff.length;
        //this._widget.beginUpdate();
        //while (len--) {
        //    this._onUpdate(diff[len]);
        //}
        //this._widget.endUpdate();

        //save current list of members
        this._selectedMemberListMembers = actualMembers;

        if (territoryChanged) {
            setTimeout(function () {
                client.updateTerritory(territoryId, territoryPatterns);
            }, 10);
        }
    };

    CrosscutController.prototype._initializeSelectedMemberList = function () {
        this._nodePointers = {};
        this._nodeSets = {};

        this._connectionListByType = {};

        this._filteredOutConnectionDescriptors = {}; //we should clear this
        this._connectionWaitingListByDstGMEID = {};
        this._connectionWaitingListBySrcGMEID = {};

        DiagramDesignerWidgetMultiTabMemberListControllerBase.prototype._initializeSelectedMemberList.call(this);
    };

    CrosscutController.prototype._memberListTerritoryCallback = function (events) {<commit_msg>Make sure regular item updates are handled in XCuts (#1499)<commit_after>/*globals define, _, WebGMEGlobal*/
/*jshint browser: true*/
/**
 * @author rkereskenyi / https://github.com/rkereskenyi
 */

define(['js/logger',
    'js/RegistryKeys',
    'js/Constants',
    './CrosscutConstants',
    'js/DragDrop/DragHelper',
    'js/Utils/GMEConcepts',
    'js/Panels/ControllerBase/DiagramDesignerWidgetMultiTabMemberListControllerBase',
    'js/Panels/MetaEditor/MetaRelations',
    'js/NodePropertyNames',
    'js/Utils/ComponentSettings'
], function (Logger,
             REGISTRY_KEYS,
             CONSTANTS,
             CrosscutConstants,
             DragHelper,
             GMEConcepts,
             DiagramDesignerWidgetMultiTabMemberListControllerBase,
             MetaRelations,
             nodePropertyNames,
             ComponentSettings) {

    'use strict';

    var CrosscutController,
        DEFAULT_DECORATOR = 'ModelDecorator',
        WIDGET_NAME = 'DiagramDesigner';
    //CONNECTION_DECORATOR = 'CircleDecorator';

    CrosscutController = function (options) {
        options = options || {};
        options.loggerName = 'gme:Panels:CrossCut:CrosscutController';

        this._config = CrosscutController.getDefaultConfig();
        ComponentSettings.resolveWithWebGMEGlobal(this._config, CrosscutController.getComponentId());

        DiagramDesignerWidgetMultiTabMemberListControllerBase.call(this, options);

        this._filteredOutConnTypes = [];
        this._filteredOutConnectionDescriptors = {};
        this._activeCrosscutId = null;
        this._initActiveTab = false;
        this._tabsHasBeenRequested = false;
        this._autoCreateCrosscut = this._config.autoCreateCrosscut === true;

        this._initFilterPanel();
        this.logger.debug('CrosscutController ctor finished');
    };

    _.extend(CrosscutController.prototype, DiagramDesignerWidgetMultiTabMemberListControllerBase.prototype);

    CrosscutController.prototype._attachDiagramDesignerWidgetEventHandlers = function () {
        var self = this,
            oldTabChangefn;

        //cal base classes _attachDiagramDesignerWidgetEventHandlers
        DiagramDesignerWidgetMultiTabMemberListControllerBase.prototype
            ._attachDiagramDesignerWidgetEventHandlers.call(this);

        //add own event handlers

        this._widget.onFilterNewConnectionDroppableEnds = function (params) {
            return self._onFilterNewConnectionDroppableEnds(params);
        };

        this._widget.onCreateNewConnection = function (params) {
            self._onCreateNewConnection(params);
        };

        this._widget.onModifyConnectionEnd = function (params) {
            self._onModifyConnectionEnd(params);
        };

        this._widget.onCheckChanged = function (value, isChecked) {
            self._onConnectionTypeFilterCheckChanged(value, isChecked);
        };

        oldTabChangefn = this._widget.onSelectedTabChanged;
        this._widget.onSelectedTabChanged = function (tabID) {
            oldTabChangefn(tabID);
            self._selectedTabChanged(tabID);
        };
    };

    //enable every node
    CrosscutController.prototype._validateNodeId = function (nodeId) {
        return nodeId;
    };

    CrosscutController.prototype._canAddTab = function () {
        var memberListContainerID = this._memberListContainerID;

        return (memberListContainerID || memberListContainerID === CONSTANTS.PROJECT_ROOT_ID);
    };

    CrosscutController.prototype._updateSelectedMemberListMembersTerritoryPatterns = function () {
        var currentlyDisplayedMembers = (this._selectedMemberListMembers || []).slice(0),
            actualMembers = (this._memberListMembers[this._selectedMemberListID] || []).slice(0),
            diff,
            len,
            territoryChanged = false,
            territoryId = this._selectedMemberListMembersTerritoryId,
            territoryPatterns = this._selectedMemberListMembersTerritoryPatterns,
            client = this._client,
            putConnectionsToBeHandledLast = function (list) {
                var boxes = [],
                    connections = [],
                    i, node;
                for (i = 0; i < list.length; i += 1) {
                    node = client.getNode(list[i]);
                    if (node && node.isConnection()) {
                        connections.push(list[i]);
                    } else {
                        boxes.push(list[i]);
                    }
                }
                return connections.concat(boxes);
            };

        //let's see who has been deleted
        diff = putConnectionsToBeHandledLast(_.difference(currentlyDisplayedMembers, actualMembers));
        len = diff.length;
        while (len--) {
            delete territoryPatterns[diff[len]];
            territoryChanged = true;
        }

        //let's see who has been added
        diff = putConnectionsToBeHandledLast(_.difference(actualMembers, currentlyDisplayedMembers));
        len = diff.length;
        while (len--) {
            territoryPatterns[diff[len]] = {children: 0};
            territoryChanged = true;
        }

        //let's update the one that has not been changed but their position might have
        diff = putConnectionsToBeHandledLast(_.intersection(actualMembers, currentlyDisplayedMembers));
        len = diff.length;
        this._widget.beginUpdate();
        while (len--) {
           this._onUpdate(diff[len]);
        }
        this._widget.endUpdate();

        //save current list of members
        this._selectedMemberListMembers = actualMembers;

        if (territoryChanged) {
            setTimeout(function () {
                client.updateTerritory(territoryId, territoryPatterns);
            }, 10);
        }
    };

    CrosscutController.prototype._initializeSelectedMemberList = function () {
        this._nodePointers = {};
        this._nodeSets = {};

        this._connectionListByType = {};

        this._filteredOutConnectionDescriptors = {}; //we should clear this
        this._connectionWaitingListByDstGMEID = {};
        this._connectionWaitingListBySrcGMEID = {};

        DiagramDesignerWidgetMultiTabMemberListControllerBase.prototype._initializeSelectedMemberList.call(this);
    };

    CrosscutController.prototype._memberListTerritoryCallback = function (events) {
{'fraction_non_alphanumeric': 0.09434259186403336, 'fraction_numerical': 0.0014163191439137619, 'mean_word_length': 2.4679399727148703, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 2, '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': '7315325', 'n_tokens_mistral': 3324, 'n_tokens_neox': 3185, 'n_words': 531}