<commit_before>define(function() {
    'use strict';

    var models = {};
    var collections = {};

    models.Release = Backbone.Model.extend({
        constructorName: 'Release',
        urlRoot: '/api/releases'
    });

    models.Releases = Backbone.Collection.extend({
        constructorName: 'Releases',
        model: models.Release,
        url: '/api/releases'
    });

    models.Cluster = Backbone.Model.extend({
        constructorName: 'Cluster',
        urlRoot: '/api/clusters',
        validate: function(attrs) {
            var errors = {};
            if (!attrs.name || attrs.name.length == 0) {
                errors.name = 'Installation name cannot be empty';
            } else if (attrs.name.length > 100) {
                errors.name = 'Installation name is too long';
            }
            if (!attrs.release) {
                errors.release = 'Please choose OpenStack release';
            }
            return _.isEmpty(errors) ? null : errors;
        },
        task: function(taskName, status) {
            var options = {name: taskName};
            if (status) {
                options.status = status;
            }
            return this.get('tasks') && this.get('tasks').where(options)[0];
        },
        hasChanges: function() {
            return this.get('nodes').hasChanges();
        },
        canChangeMode: function() {
            return !this.get('nodes').nodesAfterDeployment().length;
        },
        canChangeType: function(typeToChangeTo) {
            // FIXME: algorithmic complexity is very high
            var canChange;
            if (this.get('mode') == 'singlenode') {
                canChange = false;
            } else {
                if (!typeToChangeTo) {
                    canChange = false;
                    _.each(this.availableTypes(), function(type) {
                        if (type == this.get('type')) {return;}
                        canChange = canChange || this.canChangeType(type);
                    }, this);
                } else {
                    canChange = true;
                    var clusterTypesToNodesRoles = {'both': [], 'compute': ['storage'], 'storage': ['compute']};
                    _.each(clusterTypesToNodesRoles[typeToChangeTo], function(nodeRole) {
                        if (this.get('nodes').where({role: nodeRole}).length) {
                            canChange = false;
                        }
                    }, this);
                    if (this.get('nodes').where({role: 'controller'}).length > 1) {
                        canChange = false;
                    }
                }<commit_msg>Fix for canChangeType cluster function<commit_after>define(function() {
    'use strict';

    var models = {};
    var collections = {};

    models.Release = Backbone.Model.extend({
        constructorName: 'Release',
        urlRoot: '/api/releases'
    });

    models.Releases = Backbone.Collection.extend({
        constructorName: 'Releases',
        model: models.Release,
        url: '/api/releases'
    });

    models.Cluster = Backbone.Model.extend({
        constructorName: 'Cluster',
        urlRoot: '/api/clusters',
        validate: function(attrs) {
            var errors = {};
            if (!attrs.name || attrs.name.length == 0) {
                errors.name = 'Installation name cannot be empty';
            } else if (attrs.name.length > 100) {
                errors.name = 'Installation name is too long';
            }
            if (!attrs.release) {
                errors.release = 'Please choose OpenStack release';
            }
            return _.isEmpty(errors) ? null : errors;
        },
        task: function(taskName, status) {
            var options = {name: taskName};
            if (status) {
                options.status = status;
            }
            return this.get('tasks') && this.get('tasks').where(options)[0];
        },
        hasChanges: function() {
            return this.get('nodes').hasChanges();
        },
        canChangeMode: function() {
            return !this.get('nodes').nodesAfterDeployment().length;
        },
        canChangeType: function(typeToChangeTo) {
            // FIXME: algorithmic complexity is very high
            var canChange;
            if (this.get('mode') == 'singlenode') {
                canChange = false;
            } else if (!typeToChangeTo) {
                canChange = false;
                _.each(this.availableTypes(), function(type) {
                    if (type == this.get('type')) {return;}
                    canChange = canChange || this.canChangeType(type);
                }, this);
            } else {
                canChange = true;
                var clusterTypesToNodesRoles = {'both': [], 'compute': ['storage'], 'storage': ['compute']};
                _.each(clusterTypesToNodesRoles[typeToChangeTo], function(nodeRole) {
                    if (this.get('nodes').where({role: nodeRole}).length) {
                        canChange = false;
                    }
                }, this);
                if (canChange && this.get('nodes').where({role: 'controller'}).length > 1) {
                    canChange = false;
                }
{'fraction_non_alphanumeric': 0.130451415455241, 'fraction_numerical': 0.0022953328232593728, 'mean_word_length': 1.5322033898305085, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, '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': '5600950', 'n_tokens_mistral': 1349, 'n_tokens_neox': 1283, 'n_words': 283}