<commit_before>/*
 *     DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER
 *
 *     Copyright (c) 2012-2013 Universidad Politécnica de Madrid
 *     Copyright (c) 2012-2013 the Center for Open Middleware
 *
 *     Licensed 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.
 */

/*global gettext, ngettext, interpolate, StyledElements, Wirecloud*/


Wirecloud.ui.WiringEditor.GenericInterface = (function () {

    "use strict";

    /*************************************************************************
     * Private functions
     *************************************************************************/

    var updateErrorInfo = function updateErrorInfo() {
        var label, errorCount = this.entity.logManager.getErrorCount();
        this.options.optionNotify.setDisabled(errorCount === 0);

        label = ngettext("%(errorCount)s error", "%(errorCount)s errors", errorCount);
        label = interpolate(label, {errorCount: errorCount}, true);
        this.options.optionNotify.setTitle(label);
    };

    // ==================================================================================
    // CLASS CONSTRUCTOR
    // ==================================================================================

    /**
     * Create a new instance of class GenericInterface.
     * @class
     *
     * @param {String} id
     * @param {Object.<String, *>} [options]
     */
    var GenericInterface = function GenericInterface(wiringEditor, entity, title, manager, className, isGhost) {
        var del_button, log_button, type, msg, ghostNotification;

        StyledElements.Container.call(this, {'class': 'component component-' + className}, ['dragstop', 'optremove', 'optshare', 'sortstop']);

        Object.defineProperty(this, 'entity', {value: entity});
        this.editingPos = false;
        this.targetAnchorsByName = {};
        this.sourceAnchorsByName = {};
        this.targetAnchors = [];
        this.sourceAnchors = [];
        this.wiringEditor = wiringEditor;
        this.title = title;
        this.className = className;
        this.initPos = {'x': 0, 'y': 0};
        this.draggableSources = [];
        this.draggableTargets = [];
        this.activatedTree = null;
        this.hollowConnections = {};
        this.fullConnections = {};
        this.subdataConnections = {};
        this.isMinimized = false;
        this.minWidth = '';
        this.movement = false;
        this.numberOfSources = 0;
        this.numberOfTargets = 0;
        this.potentialArrow = null;
        // Only for minimize maximize operators.
        this.initialPos = null;
        this.isGhost = isGhost;
        this.readOnlyEndpoints = 0;
        this.displayName = title;

        if (manager instanceof Wirecloud.ui.WiringEditor.ArrowCreator) {
            this.isMiniInterface = false;
            this.arrowCreator = manager;
        } else {
            this.isMiniInterface = true;
            this.arrowCreator = null;
        }

        // Interface buttons, not for miniInterface
        if (!this.isMiniInterface) {
            if (className == 'widget') {
                type = 'widget';
                this.version = this.entity.version;
                this.vendor = this.entity.vendor;
                this.name = this.entity.name;
            } else {
                type = 'operator';
                this.version = this.entity.meta.version;
                this.vendor = this.entity.meta.vendor;
                this.name = this.entity.meta.name;
            }

            this.componentType = className;
            this.componentId = this.entity.id;

            /* Component Properties */

            Object.defineProperty(this, 'position', {
                get: function () {
                    return {
                        'x': parseInt(this.wrapperElement.style.left, 10),
                        'y': parseInt(this.wrapperElement.style.top, 10)
                    };
                }
            });

            /* Application Status - List of States */

            var readOnly = false;

            Object.defineProperty(this, 'readOnly', {
                'get': function get() {
                    return readOnly;
                },
                'set': function set(state) {
                    if (typeof state === 'boolean') {
                        if ((readOnly=state)) {
                            this.options.optionRemove.hide();
                        } else {
                            this.options.optionRemove.show();
                        }
                    }
                }
            });

            var collapsed = false;

            Object.defineProperty(this, 'collapsed', {
                'get': function get() {
                    return collapsed;
                },
                'set': function set(state) {
                    if (typeof state === 'boolean') {
                        if ((collapsed=state)) {
                            this.wrapperElement.classList.add('collapsed');
                        } else {
                            this.wrapperElement.classList.remove('collapsed');
                        }
                    }
                }
            });

            var onbackground = false;

            Object.defineProperty(this, 'onbackground', {
                'get': function get() {
                    return onbackground;
                },
                'set': function set(state) {
                    if (typeof state === 'boolean') {
                        if ((onbackground=state)) {
                            this.options.optionRemove.hide();
                            this.options.optionShare.show();
                            this.wrapperElement.classList.add('on-background');
                        } else {
                            this.options.optionRemove.show();
                            this.options.optionShare.hide();
                            this.wrapperElement.classList.remove('on-background');
                        }
                    }
                }
            });

            // Ghost interface
            if (isGhost) {
                this.vendor = this.entity.name.split('/')[0];
                this.name = this.entity.name.split('/')[1];
                this.version = new Wirecloud.Version(this.entity.name.split('/')[2].trim());
                this.wrapperElement.classList.add('misplaced');
                ghostNotification = document.createElement("span");
                ghostNotification.classList.add('ghostNotification');
                msg = gettext('Warning: %(type)s not found!');
                msg = interpolate(msg, {type: type}, true);
                ghostNotification.textContent = msg;
                this.header.appendChild(ghostNotification);
            }

            // Version Status
            if (type == 'operator' &&
                this.wiringEditor.operatorVersions[this.vendor + '/' + this.name] &&
                this.wiringEditor.operatorVersions[this.vendor + '/' + this.name].lastVersion.compareTo(this.version) > 0) {
                    // Old Entity Version
                    this.versionStatus = document.createElement("span");
                    this.versionStatus.classList.add('status');
                    this.versionStatus.classList.add('icon-exclamation-sign');
                    this.versionStatus.setAttribute('title', 'Outdated Version (' + this.version.text + ')');
                    this.header.appendChild(this.versionStatus);
                    this.wrapperElement.classList.add('old')
            }

            var headingElement = this.wrapperElement.appendChild(document.createElement('div'));
                headingElement.className = 'component-heading';

            /* Application Heading - Title */

            var titleElement = headingElement.appendChild(document.createElement('div'));
                titleElement.className = 'component-title';

            var nameElement = document.createElement('span');
                nameElement.className = 'component-name';
                nameElement.textContent = this.displayName;

            var infoElement = document.createElement('span');
                infoElement.className = 'component-subtitle';

            this.heading = {

                'element': headingElement,

                'titlelement': titleElement,

                'nameElement': titleElement.appendChild(nameElement),

                'infoElement': titleElement.appendChild(infoElement)

            };

            /* Application Heading - List of Options */

            var optionsElement = headingElement.appendChild(document.createElement('div'));
                optionsElement.className = 'component-options';

            this.options = {

                'element': optionsElement,

                'optionNotify': new StyledElements.StyledButton({
                    'class': 'icon-exclamation-sign option-notify',
                    'plain': true
                }),

                'optionPreferences': new StyledElements.PopupButton({
                    'class': 'icon-cog option-preferences',
                    'title': gettext("Preferences"),
                    'plain': true
                }),<commit_msg>Fix the settings of missing components<commit_after>/*
 *     DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER
 *
 *     Copyright (c) 2012-2013 Universidad Politécnica de Madrid
 *     Copyright (c) 2012-2013 the Center for Open Middleware
 *
 *     Licensed 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.
 */

/*global gettext, ngettext, interpolate, StyledElements, Wirecloud*/


Wirecloud.ui.WiringEditor.GenericInterface = (function () {

    "use strict";

    /*************************************************************************
     * Private functions
     *************************************************************************/

    var updateErrorInfo = function updateErrorInfo() {
        var label, errorCount = this.entity.logManager.getErrorCount();
        this.options.optionNotify.setDisabled(errorCount === 0);

        label = ngettext("%(errorCount)s error", "%(errorCount)s errors", errorCount);
        label = interpolate(label, {errorCount: errorCount}, true);
        this.options.optionNotify.setTitle(label);
    };

    // ==================================================================================
    // CLASS CONSTRUCTOR
    // ==================================================================================

    /**
     * Create a new instance of class GenericInterface.
     * @class
     *
     * @param {String} id
     * @param {Object.<String, *>} [options]
     */
    var GenericInterface = function GenericInterface(wiringEditor, entity, title, manager, className, isGhost) {
        var del_button, log_button, type, msg, ghostNotification;

        StyledElements.Container.call(this, {'class': 'component component-' + className}, ['dragstop', 'optremove', 'optshare', 'sortstop']);

        Object.defineProperty(this, 'entity', {value: entity});
        this.editingPos = false;
        this.targetAnchorsByName = {};
        this.sourceAnchorsByName = {};
        this.targetAnchors = [];
        this.sourceAnchors = [];
        this.wiringEditor = wiringEditor;
        this.title = title;
        this.className = className;
        this.initPos = {'x': 0, 'y': 0};
        this.draggableSources = [];
        this.draggableTargets = [];
        this.activatedTree = null;
        this.hollowConnections = {};
        this.fullConnections = {};
        this.subdataConnections = {};
        this.isMinimized = false;
        this.minWidth = '';
        this.movement = false;
        this.numberOfSources = 0;
        this.numberOfTargets = 0;
        this.potentialArrow = null;
        // Only for minimize maximize operators.
        this.initialPos = null;
        this.isGhost = isGhost;
        this.readOnlyEndpoints = 0;

        if (manager instanceof Wirecloud.ui.WiringEditor.ArrowCreator) {
            this.isMiniInterface = false;
            this.arrowCreator = manager;
        } else {
            this.isMiniInterface = true;
            this.arrowCreator = null;
        }

        // Interface buttons, not for miniInterface
        if (!this.isMiniInterface) {
            if (className == 'widget') {
                type = 'widget';
                this.version = this.entity.version;
                this.vendor = this.entity.vendor;
                this.name = this.entity.name;
            } else {
                type = 'operator';
                this.version = this.entity.meta.version;
                this.vendor = this.entity.meta.vendor;
                this.name = this.entity.meta.name;
            }

            this.componentType = className;
            this.componentId = this.entity.id;

            /* Component Properties */

            Object.defineProperty(this, 'position', {
                get: function () {
                    return {
                        'x': parseInt(this.wrapperElement.style.left, 10),
                        'y': parseInt(this.wrapperElement.style.top, 10)
                    };
                }
            });

            /* Application Status - List of States */

            var readOnly = false;

            Object.defineProperty(this, 'readOnly', {
                'get': function get() {
                    return readOnly;
                },
                'set': function set(state) {
                    if (typeof state === 'boolean') {
                        if ((readOnly=state)) {
                            this.options.optionRemove.hide();
                        } else {
                            this.options.optionRemove.show();
                        }
                    }
                }
            });

            var collapsed = false;

            Object.defineProperty(this, 'collapsed', {
                'get': function get() {
                    return collapsed;
                },
                'set': function set(state) {
                    if (typeof state === 'boolean') {
                        if ((collapsed=state)) {
                            this.wrapperElement.classList.add('collapsed');
                        } else {
                            this.wrapperElement.classList.remove('collapsed');
                        }
                    }
                }
            });

            var onbackground = false;

            Object.defineProperty(this, 'onbackground', {
                'get': function get() {
                    return onbackground;
                },
                'set': function set(state) {
                    if (typeof state === 'boolean') {
                        if ((onbackground=state)) {
                            this.options.optionRemove.hide();
                            this.options.optionShare.show();
                            this.wrapperElement.classList.add('on-background');
                        } else {
                            this.options.optionRemove.show();
                            this.options.optionShare.hide();
                            this.wrapperElement.classList.remove('on-background');
                        }
                    }
                }
            });

            var is_missing = false;

            Object.defineProperty(this, 'missing', {
                'get': function get() {
                    return is_missing;
                },
                'set': function set(state) {
                    if (typeof state === 'boolean') {
                        if ((is_missing=state)) {
                            this.wrapperElement.classList.add('missing');
                        } else {
                            this.wrapperElement.classList.remove('missing');
                        }
                    }
                }
            });

            // Version Status
            if (type == 'operator' &&
                this.wiringEditor.operatorVersions[this.vendor + '/' + this.name] &&
                this.wiringEditor.operatorVersions[this.vendor + '/' + this.name].lastVersion.compareTo(this.version) > 0) {
                    // Old Entity Version
                    this.versionStatus = document.createElement("span");
                    this.versionStatus.classList.add('status');
                    this.versionStatus.classList.add('icon-exclamation-sign');
                    this.versionStatus.setAttribute('title', 'Outdated Version (' + this.version.text + ')');
                    this.header.appendChild(this.versionStatus);
                    this.wrapperElement.classList.add('old')
            }

            var headingElement = this.wrapperElement.appendChild(document.createElement('div'));
                headingElement.className = 'component-heading';

            /* Application Heading - Title */

            var titleElement = headingElement.appendChild(document.createElement('div'));
                titleElement.className = 'component-title';

            var nameElement = document.createElement('span');
                nameElement.className = 'component-name';
                nameElement.textContent = this.name;

            var infoElement = document.createElement('span');
                infoElement.className = 'component-subtitle';

            this.heading = {

                'element': headingElement,

                'titleElement': titleElement,

                'nameElement': titleElement.appendChild(nameElement),

                'infoElement': titleElement.appendChild(infoElement)

            };

            if (isGhost) {
                this.vendor = this.entity.name.split('/')[0];
                this.name = this.entity.name.split('/')[1];
                this.version = new Wirecloud.Version(this.entity.name.split('/')[2].trim());

                this.missing = true;
                this.heading.nameElement.textContent = this.name;
                this.heading.infoElement.textContent = "The component is misplaced";
            }

            /* Application Heading - List of Options */

            var optionsElement = headingElement.appendChild(document.createElement('div'));
                optionsElement.className = 'component-options';

            this.options = {

                'element': optionsElement,

                'optionNotify': new StyledElements.StyledButton({
                    'class': 'icon-exclamation-sign option-notify',
                    'plain': true
                }),

                'optionPreferences': new StyledElements.PopupButton({
                    'class': 'icon-cog option-preferences',
                    'title': gettext("Preferences"),
                    'plain': true
                }),
{'fraction_non_alphanumeric': 0.13660817537332193, 'fraction_numerical': 0.0034189753129870784, 'mean_word_length': 1.606473594548552, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '2279925', 'n_tokens_mistral': 4834, 'n_tokens_neox': 4494, 'n_words': 971}