<commit_before>/*globals define, _*/
/*jshint browser: true, camelcase: false*/

/**
 * @author brollb / https://github.com/brollb
 */

define([
    'js/Constants',
    'decorators/OperationDecorator/EasyDAG/OperationDecorator.EasyDAGWidget',
    'css!./DcOpDecorator.EasyDAGWidget.css'
], function (
    CONSTANTS,
    DecoratorBase
) {

    'use strict';

    var DcOpDecorator,
        DECORATOR_ID = 'DcOpDecorator';

    // DcOp nodes need to be able to...
    //     - dynamically change their outputs (downcast)
    DcOpDecorator = function (options) {
        options.color = options.color || '#78909c';
        DecoratorBase.call(this, options);
    };

    _.extend(DcOpDecorator.prototype, DecoratorBase.prototype);

    DcOpDecorator.prototype.DECORATOR_ID = DECORATOR_ID;

    DcOpDecorator.prototype.getTargetFilterFnFor = function() {
        return id => {
            var node = this.client.getNode(id);
            return node.getId() !== node.getMetaTypeId();  // not meta node
        };
    };

    DcOpDecorator.prototype.castOutputType = function(baseId) {
        var output = this._node.outputs[0];

        if (!output) {
            // create the output node
            this._createOutputNode(baseId);
        } else {
            this.client.makePointer(output.id, CONSTANTS.POINTER_BASE, baseId);
        }
    };

    DcOpDecorator.prototype._createOutputNode = function(baseId) {
        var n = this.client.getNode(this._node.id),
            outputCntrId;

        outputCntrId = n.getChildrenIds().find(id => {
            var metaTypeId = this.client.getNode(id).getMetaTypeId(),
                metaType = this.client.getNode(metaTypeId);

            if (!metaType) {
                this.logger.error(`Could not check the type of ${id}!`);
                return false;
            }
            return metaType.getAttribute('name') === 'Outputs';
        });

        this.client.createChild({
            baseId: baseId,
            parentId: outputCntrId
        });
    };

    return DcOpDecorator;
});
<commit_msg>Changed downcasting to set base and copy content. Fixes #283 (#284)<commit_after>/*globals define, _*/
/*jshint browser: true, camelcase: false*/

/**
 * @author brollb / https://github.com/brollb
 */

define([
    'js/Constants',
    'decorators/OperationDecorator/EasyDAG/OperationDecorator.EasyDAGWidget',
    'css!./DcOpDecorator.EasyDAGWidget.css'
], function (
    CONSTANTS,
    DecoratorBase
) {

    'use strict';

    var DcOpDecorator,
        DECORATOR_ID = 'DcOpDecorator';

    // DcOp nodes need to be able to...
    //     - dynamically change their outputs (downcast)
    DcOpDecorator = function (options) {
        options.color = options.color || '#78909c';
        DecoratorBase.call(this, options);
    };

    _.extend(DcOpDecorator.prototype, DecoratorBase.prototype);

    DcOpDecorator.prototype.DECORATOR_ID = DECORATOR_ID;

    DcOpDecorator.prototype.getTargetFilterFnFor = function() {
        return id => {
            var node = this.client.getNode(id);
            return node.getId() !== node.getMetaTypeId();  // not meta node
        };
    };

    DcOpDecorator.prototype.castOutputType = function(targetId) {
        var target = this.client.getNode(targetId),
            baseId = target.getBaseId(),
            output = this._node.outputs[0],
            hash;

        if (!output) {
            // create the output node
            this._createOutputNode(baseId);
        } else {
            this.client.makePointer(output.id, CONSTANTS.POINTER_BASE, baseId);
        }
        // Copy the data content to the output node
        hash = target.getAttribute('data');
        this.client.setAttributes(this._node.id, 'data', hash);
    };

    DcOpDecorator.prototype._createOutputNode = function(baseId) {
        var n = this.client.getNode(this._node.id),
            outputCntrId;

        outputCntrId = n.getChildrenIds().find(id => {
            var metaTypeId = this.client.getNode(id).getMetaTypeId(),
                metaType = this.client.getNode(metaTypeId);

            if (!metaType) {
                this.logger.error(`Could not check the type of ${id}!`);
                return false;
            }
            return metaType.getAttribute('name') === 'Outputs';
        });

        this.client.createChild({
            baseId: baseId,
            parentId: outputCntrId
        });
    };

    return DcOpDecorator;
});

{'fraction_non_alphanumeric': 0.1235095613048369, 'fraction_numerical': 0.0040494938132733405, 'mean_word_length': 2.207792207792208, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, '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': '7250247', 'n_tokens_mistral': 1412, 'n_tokens_neox': 1368, 'n_words': 248}