<commit_before>﻿module Vidyano.WebComponents {
    @Dialog.register({
        properties: {
            grid: Object,
            _columnElements: {
                type: Object,
                readOnly: true
            }
        },
        listeners: {
            "distribute-columns": "_distributeColumns",
            "reorder-columns": "_reorderColumns"
        }
    })
    export class QueryGridConfigureDialog extends Dialog {
        private _columnElements: QueryGridConfigureDialogColumn[];
        private _set_columnElements: (columns: QueryGridConfigureDialogColumn[]) => void;

        constructor(public grid: QueryGrid, private _settings: QueryGridUserSettings) {
            super();

            this._set_columnElements(this._settings.columns.filter(c => c.width != "0").map(c => new Vidyano.WebComponents.QueryGridConfigureDialogColumn(c)));
            this._distributeColumns();
        }

        private _distributeColumns(e?: CustomEvent) {
            var columns = Enumerable.from(this._columnElements).orderBy(c => c.column.offset).memoize();

            requestAnimationFrame(() => {
                this._updateColumns(this.$["pinned"], columns.where(c => c.isPinned).toArray());
                this._updateColumns(this.$["unpinned"], columns.where(c => !c.isPinned).toArray());
            });

            if (e)
                e.stopPropagation();
        }

        private _updateColumns(target: HTMLElement, columns: QueryGridConfigureDialogColumn[]) {
            columns.forEach(col => target.appendChild(col));
        }

        private _reorderColumns(e: CustomEvent) {
            var children = <QueryGridConfigureDialogColumn[]>Polymer.dom(e.srcElement).children;
            var offsets = Enumerable.from(children).orderBy(c => c.column.offset).select(c => c.column.offset).toArray();

            children.forEach((child: QueryGridConfigureDialogColumn, index: number) => {
                child.offset = offsets[index];
            });

            e.stopPropagation();
        }

        private _save() {
            this._columnElements.forEach(c => {
                c.column.isPinned = c.isPinned;
                c.column.isHidden = c.isHidden;
                c.column.offset = c.offset;

                if (c.calculatedWidth !== c.column.calculatedWidth) {
                    c.column.calculatedWidth = c.calculatedWidth;
                    c.column.width = c.column.column.width;
                }
            });

            this._settings.save().then(() => {
                this.instance.resolve();
            });
        }<commit_msg>Fixed reset button on query columns config dialog not reordering columns<commit_after>﻿module Vidyano.WebComponents {
    @Dialog.register({
        properties: {
            grid: Object,
            _columnElements: {
                type: Object,
                readOnly: true
            }
        },
        listeners: {
            "distribute-columns": "_distributeColumns",
            "reorder-columns": "_reorderColumns"
        }
    })
    export class QueryGridConfigureDialog extends Dialog {
        private _columnElements: QueryGridConfigureDialogColumn[];
        private _set_columnElements: (columns: QueryGridConfigureDialogColumn[]) => void;

        constructor(public grid: QueryGrid, private _settings: QueryGridUserSettings) {
            super();

            this._set_columnElements(this._settings.columns.filter(c => c.width != "0").map(c => new Vidyano.WebComponents.QueryGridConfigureDialogColumn(c)));
            this._distributeColumns();
        }

        private _distributeColumns(e?: CustomEvent) {
            var columns = Enumerable.from(this._columnElements).orderBy(c => c.column.offset).memoize();

            requestAnimationFrame(() => {
                this._updateColumns(this.$["pinned"], columns.where(c => c.isPinned).toArray());
                this._updateColumns(this.$["unpinned"], columns.where(c => !c.isPinned).toArray());
            });

            if (e)
                e.stopPropagation();
        }

        private _updateColumns(target: HTMLElement, columns: QueryGridConfigureDialogColumn[]) {
            Enumerable.from(columns).orderBy(c => c.offset).forEach(col => target.appendChild(col));
        }

        private _reorderColumns(e: CustomEvent) {
            var children = <QueryGridConfigureDialogColumn[]>Polymer.dom(e.srcElement).children;
            var offsets = Enumerable.from(children).orderBy(c => c.column.offset).select(c => c.column.offset).toArray();

            children.forEach((child: QueryGridConfigureDialogColumn, index: number) => {
                child.offset = offsets[index];
            });

            e.stopPropagation();
        }

        private _save() {
            this._columnElements.forEach(c => {
                c.column.isPinned = c.isPinned;
                c.column.isHidden = c.isHidden;
                c.column.offset = c.offset;

                if (c.calculatedWidth !== c.column.calculatedWidth) {
                    c.column.calculatedWidth = c.calculatedWidth;
                    c.column.width = c.column.column.width;
                }
            });

            this._settings.save().then(() => {
                this.instance.resolve();
            });
        }
{'fraction_non_alphanumeric': 0.12149180636654737, 'fraction_numerical': 0.00037671877943115466, 'mean_word_length': 2.0067950169875424, 'pattern_counts': {'":': 4, '<': 5, '<?xml version=': 0, '>': 32, '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': '1085071', 'n_tokens_mistral': 1420, 'n_tokens_neox': 1357, 'n_words': 215}