<commit_before>/**
 * Created with JetBrains RubyMine.
 * User: i061485
 * Date: 6/12/13
 * Time: 3:22 PM
 */

define([
], function defineLayoutEmptyRows() {


    /**
     * Define EmptyRows
     * @class EmptyRows
     * @param {Layout} layout
     * @constructor
     */
    var EmptyRows = function EmptyRows(layout) {

        /**
         * Define layout
         * @type {Layout}
         */
        this.layout = layout;
    };

    return EmptyRows.extend({

        findRows: function findRows() {
            var rows = [],
                widgets = this.layout.controller.getParent().model.getItems(),
                index, i;
            for (index in widgets) {
                if (widgets.hasOwnProperty(index)) {
                    var widget = widgets[index];
                    for (i = widget.row; i <= widget.relHeight + widget.row - 1; i++) {
                        rows[i] = this.layout.base.define(rows[i], [], true);
                        rows[i].push(widget);
                    }
                }
            }
            return rows;
        },

        /**
         *
         * @return {Boolean}
         */
        remove: function remove() {
            if (!this.layout.config.overlapping.removeEmptySpaces) {
                return false;
            }
            var rows = this.findRows(),
                moveIndex = 0,
                alreadyFixed = [],
                i;
            for (i = 0; i <= rows.length; i++) {
                if (App.base.isDefined(rows[i])) {
                    var widgets = rows[i],
                        y;
                    for (y = 0; y <= widgets.length; y++) {
                        if (widgets[y]) {
                            var uuid = widgets[y].uuid;
                            // TODO Check incorrect ID
                            if (jQuery.inArray(uuid, alreadyFixed) === -1) {
                                alreadyFixed.push(uuid);
                                this.page.model.updateCollectorByKey({
                                    uuid: uuid,
                                    key: 'row',
                                    value: this.page.model.getWidgetFromCollector(uuid).row - moveIndex
                                });
                            }
                        }
                    }
                } else {
                    moveIndex++;
                    alreadyFixed = [];
                }
            }
        }
<commit_msg>fix empty rows<commit_after>/**
 * Created with JetBrains RubyMine.
 * User: i061485
 * Date: 6/12/13
 * Time: 3:22 PM
 */

define([
], function defineLayoutEmptyRows() {

    /**
     * Define EmptyRows
     * @class EmptyRows
     * @param {Layout} layout
     * @constructor
     */
    var EmptyRows = function EmptyRows(layout) {

        /**
         * Define layout
         * @type {Layout}
         */
        this.layout = layout;

        this.page = layout.controller.getParent();

        this.allowed = layout.config.behavior.snap2grid.emptySpaces === 'row';

    };

    return EmptyRows.extend({

        findRows: function findRows() {
            var rows = [],
                widgets = this.page.model.getItems(),
                index, i;
            for (index in widgets) {
                if (widgets.hasOwnProperty(index)) {
                    var widget = widgets[index];
                    for (i = widget.dom.row; i <= widget.dom.relHeight + widget.dom.row - 1; i += 1) {
                        rows[i] = this.layout.base.define(rows[i], [], true);
                        rows[i].push(widget);
                    }
                }
            }
            return rows;
        },

        /**
         *
         * @return {Boolean}
         */
        remove: function remove() {
            var layout = this.layout;
            if (!this.allowed) {
                layout.logger.warn('Remove empty spaces by row does not allowed');
                return false;
            }
            var rows = this.findRows(),
                moveIndex = 0,
                alreadyFixed = [],
                i = 0;
            for (i; i <= rows.length; i += 1) {
                if (layout.base.isDefined(rows[i])) {
                    var widgets = rows[i],
                        y = 0;
                    for (y; y <= widgets.length; y += 1) {
                        if (widgets[y]) {
                            var widget = widgets[y],
                                uuid = widget.model.getUUID();
                            if ($.inArray(uuid, alreadyFixed) === -1) {
                                alreadyFixed.push(uuid);
                                this.page.model.updateItem(
                                    uuid, {
                                        dom: {
                                            row: widget.dom.row - moveIndex
                                        }
                                    }
                                );
                            }
                        }
                    }
                } else {
                    moveIndex += 1;
                    alreadyFixed = [];
                }
            }
        }

{'fraction_non_alphanumeric': 0.10978657950394155, 'fraction_numerical': 0.008267640838300326, 'mean_word_length': 0.8827361563517915, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 10, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5758591', 'n_tokens_mistral': 1350, 'n_tokens_neox': 1234, 'n_words': 270}