var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __metadata = (this && this.__metadata) || function (k, v) {
    if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
    function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
var __generator = (this && this.__generator) || function (thisArg, body) {
    var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
    return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
    function verb(n) { return function (v) { return step([n, v]); }; }
    function step(op) {
        if (f) throw new TypeError("Generator is already executing.");
        while (g && (g = 0, op[0] && (_ = 0)), _) try {
            if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
            if (y = 0, t) op = [op[0] & 2, t.value];
            switch (op[0]) {
                case 0: case 1: t = op; break;
                case 4: _.label++; return { value: op[1], done: false };
                case 5: _.label++; y = op[1]; op = [0]; continue;
                case 7: op = _.ops.pop(); _.trys.pop(); continue;
                default:
                    if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
                    if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
                    if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
                    if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
                    if (t[2]) _.ops.pop();
                    _.trys.pop(); continue;
            }
            op = body.call(thisArg, _);
        } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
        if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
    }
};
var __values = (this && this.__values) || function(o) {
    var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
    if (m) return m.call(o);
    if (o && typeof o.length === "number") return {
        next: function () {
            if (o && i >= o.length) o = void 0;
            return { value: o && o[i++], done: !o };
        }
    };
    throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
};
var __read = (this && this.__read) || function (o, n) {
    var m = typeof Symbol === "function" && o[Symbol.iterator];
    if (!m) return o;
    var i = m.call(o), r, ar = [], e;
    try {
        while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
    }
    catch (error) { e = { error: error }; }
    finally {
        try {
            if (r && !r.done && (m = i["return"])) m.call(i);
        }
        finally { if (e) throw e.error; }
    }
    return ar;
};
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
    if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
        if (ar || !(i in from)) {
            if (!ar) ar = Array.prototype.slice.call(from, 0, i);
            ar[i] = from[i];
        }
    }
    return to.concat(ar || Array.prototype.slice.call(from));
};
import { Router } from 'aurelia-router';
import { ViewParameterBox } from './../../modules/dialogs/view-parameter-box';
import { EntityTypeNames } from './../../constants/constants';
import { AgGridViewBox } from './../../modules/dialogs/ag-grid-view-box';
import { BindableGridOptions } from './custom-ag-grid';
import { FilterViewBox } from './../../modules/dialogs/filter-view-box';
import { AgGridViewService } from './../../services/ag-grid-view-service';
import { AgGridSortingHelper } from './utilities/ag-grid-helpers';
import { autoinject, bindable, observable } from "aurelia-framework";
import { I18N } from 'aurelia-i18n';
import { BindingEngine, bindingMode } from 'aurelia-binding';
import { Config } from '../../config';
import { ServiceBase } from './../../data/service-base';
import { AgGridViewDetail } from './ag-grid-view-detail';
import { CustomLogger } from './../../modules/custom-logger';
import { ShowEditDialogOptions, Box } from './../../modules/box';
import { FieldType } from './../../model/common-model';
import { Datacontext } from './../../data/data-context';
import { AuthService } from '../../security/auth-service';
import moment from 'moment';
import { autoAdjustColumnsSize, getNewColumnStates } from './../../ag-grid/agUtils';
import { KeyboardShortcut } from './../../constants/constants';
export var GridHeaderBar = (function () {
    function GridHeaderBar(bindingEngine, i18n, box, router, logger, authService, config, element) {
        this.bindingEngine = bindingEngine;
        this.i18n = i18n;
        this.box = box;
        this.router = router;
        this.logger = logger;
        this.authService = authService;
        this.config = config;
        this.element = element;
        this.canAdd = true;
        this.canDelete = true;
        this.canBack = false;
        this.canUseView = true;
        this.canUseFilter = true;
        this.canUseParameters = true;
        this.canExport = true;
        this.canShowAllView = false;
        this.showAllView = false;
        this.fixedFiltersObserverDisabled = false;
        this.disposables = [];
        this.gridViewService = new AgGridViewService();
        this.agGridViewUserService = new ServiceBase(EntityTypeNames.AgGridViewUser);
        this.filterViewBox = new FilterViewBox(this);
        this.agGridViewBox = new AgGridViewBox(this, authService, config);
        this.viewParameterBox = new ViewParameterBox(this, config);
        this.firstTime = true;
    }
    GridHeaderBar.prototype.showAllViewChanged = function (newValue, oldValue) {
        return __awaiter(this, void 0, void 0, function () {
            return __generator(this, function (_a) {
                switch (_a.label) {
                    case 0:
                        if (!(newValue != oldValue && this.gridViewService != null)) return [3, 2];
                        return [4, this.loadAgGridViewData(true)];
                    case 1:
                        _a.sent();
                        _a.label = 2;
                    case 2: return [2];
                }
            });
        });
    };
    GridHeaderBar.prototype.attached = function () {
        var _this = this;
        var _a, _b;
        if (((_b = (_a = this.element) === null || _a === void 0 ? void 0 : _a.classList) === null || _b === void 0 ? void 0 : _b.add) != null) {
            this.element.classList.add('grid-header-bar');
        }
        if (this.gridOptions != null) {
            var propObs = this.bindingEngine.propertyObserver(this.gridOptions, "fixedFilters");
            if (propObs != null) {
                this.disposables.push(propObs.subscribe(function (newValue, oldValue) {
                    if (newValue !== oldValue && oldValue != undefined && _this.fixedFiltersObserverDisabled) {
                        _this.toggleFloatingRow();
                    }
                }));
            }
        }
        this.agGridSortingHelper = new AgGridSortingHelper(this.gridOptions);
        this.csvExportConfig = Object.assign({ useConfirmDialog: true }, this.csvExportConfig);
    };
    GridHeaderBar.prototype.bind = function () {
        var _a;
        (_a = this.agGridViewModuleView) !== null && _a !== void 0 ? _a : (this.agGridViewModuleView = this.router.currentInstruction.config.moduleId);
    };
    GridHeaderBar.prototype.onAdjustColumnsChanged = function () {
        autoAdjustColumnsSize(this.gridOptions);
    };
    GridHeaderBar.prototype.detached = function () {
        var _a;
        if ((_a = this.disposables) === null || _a === void 0 ? void 0 : _a.length) {
            this.disposables.forEach(function (x) {
                x.dispose();
            });
        }
    };
    Object.defineProperty(GridHeaderBar.prototype, "internalCanResetFilters", {
        get: function () {
            if (this.canResetFilters != null && !this.canResetFilters)
                return false;
            if (this.gridOptions && this.gridOptions.api) {
                return this.gridOptions.api.isAnyFilterPresent() || (this.agGridSortingHelper.hasAnySorting() && false == this.agGridSortingHelper.isCurrentSortDefault());
            }
            return false;
        },
        enumerable: false,
        configurable: true
    });
    GridHeaderBar.prototype.resetFilters = function () {
        var savedDs = this.gridOptions.api.rowModel.datasource;
        this.gridOptions.api.setDatasource(null);
        this.gridOptions.api.setFilterModel(null);
        this.gridOptions.columnApi.applyColumnState({
            defaultState: {
                sort: null
            }
        });
        this.agGridSortingHelper.applyDefaultSortModel();
        if (this.afterResetFilters != null) {
            this.afterResetFilters();
        }
        this.gridOptions.api.setDatasource(savedDs);
    };
    GridHeaderBar.prototype.addAgGridView = function () {
        var _a;
        return __awaiter(this, void 0, void 0, function () {
            var _this = this;
            return __generator(this, function (_b) {
                switch (_b.label) {
                    case 0:
                        (_a = this.dropView) === null || _a === void 0 ? void 0 : _a.closeDrop();
                        return [4, this.box.showEditDialog(AgGridViewDetail, -100, this.i18n.tr("grid.addNewView", { ns: "common" }), new ShowEditDialogOptions({
                                callback: function (createdEntity) {
                                    var _a, _b;
                                    createdEntity.moduleId = _this.agGridViewModuleView;
                                    createdEntity.columnState = JSON.stringify(_this.gridOptions.columnApi.getColumnState());
                                    createdEntity.filterModel = JSON.stringify(_this.gridOptions.api.getFilterModel());
                                    createdEntity.fixedFilters = (_a = _this.gridOptions.fixedFilters) !== null && _a !== void 0 ? _a : false;
                                    createdEntity.adjustColumns = (_b = _this.gridOptions.adjustColumns) !== null && _b !== void 0 ? _b : _this.config.agGridConfig.defaultAdjustColumns;
                                },
                                lock: false,
                                containerClass: "container-ag-grid-view-detail",
                                overlayClass: "overlay-ag-grid-view-detail",
                                size: "sm"
                            })).whenClosed(function (result) {
                                if (!result.wasCancelled) {
                                    var createdAgGridView = result.output;
                                    _this.agGridViewList.push(createdAgGridView);
                                    _this.logger.Log(_this.i18n.tr("grid.viewAdded", { ns: "common" }), null, 'CustomAgGrid', true);
                                    _this.setAgGridView(createdAgGridView);
                                }
                            })];
                    case 1:
                        _b.sent();
                        return [2];
                }
            });
        });
    };
    GridHeaderBar.prototype.setAgGridView = function (agGridView) {
        var _a;
        return __awaiter(this, void 0, void 0, function () {
            var routeName, savedDs, temp;
            return __generator(this, function (_b) {
                switch (_b.label) {
                    case 0:
                        routeName = this.router.currentInstruction.config.route;
                        savedDs = this.gridOptions.api.rowModel.datasource;
                        this.gridOptions.api.setDatasource(null);
                        this.gridOptions.columnApi.applyColumnState({
                            state: getNewColumnStates(this.gridOptions, JSON.parse(agGridView.columnState)),
                            defaultState: { sort: null },
                            applyOrder: true
                        });
                        if (agGridView.sortModel != null && agGridView.sortModel != '[]') {
                            temp = {
                                state: JSON.parse(agGridView.sortModel),
                                defaultState: { sort: null },
                                applyOrder: true
                            };
                            this.gridOptions.columnApi.applyColumnState(temp);
                        }
                        else {
                            if (false == this.agGridSortingHelper.hasAnySorting()) {
                                this.agGridSortingHelper.applyDefaultSortModel();
                            }
                        }
                        this.gridOptions.api.setFilterModel(JSON.parse(agGridView.filterModel));
                        this.fixedFiltersObserverDisabled = true;
                        this.gridOptions.fixedFilters = agGridView.fixedFilters;
                        this.gridOptions.adjustColumns = agGridView.adjustColumns;
                        this.fixedFiltersObserverDisabled = false;
                        this.agGridViewList.filter(function (x) { return x.used; }).forEach(function (view) { return view.used = false; });
                        agGridView.used = true;
                        if (!this.showFilterBox && agGridView.fixedFilters != null) {
                            this.toggleFloatingRow(agGridView.fixedFilters);
                        }
                        if (!this.authService.currentUser) return [3, 2];
                        if (agGridView.isDefaultView) {
                            delete this.authService.currentUser.settings.dataGridSettings[routeName];
                            autoAdjustColumnsSize(this.gridOptions);
                        }
                        else {
                            this.authService.currentUser.settings.dataGridSettings[routeName] = {
                                usedView: { id: agGridView.id, name: agGridView.name },
                                fixedFilters: false,
                                adjustColumns: null,
                                colsState: null,
                                filterModel: null
                            };
                        }
                        if (!(((_a = this.datacontext) === null || _a === void 0 ? void 0 : _a.saveUserSettings) != null)) return [3, 2];
                        return [4, this.datacontext.saveUserSettings(this.authService.currentUser.sanitizedSettings)];
                    case 1:
                        _b.sent();
                        _b.label = 2;
                    case 2:
                        if (this.afterSetAgGridView != null) {
                            this.afterSetAgGridView({ agGridView: agGridView });
                        }
                        this.gridOptions.api.setDatasource(savedDs);
                        this.logger.Log(this.i18n.tr("grid.viewSetted", { ns: "common" }), null, 'CustomAgGrid', true);
                        return [2];
                }
            });
        });
    };
    GridHeaderBar.prototype.toggleFloatingRow = function (floatingFilter) {
        if (floatingFilter === void 0) { floatingFilter = null; }
        return __awaiter(this, void 0, void 0, function () {
            var columnDefs;
            return __generator(this, function (_a) {
                switch (_a.label) {
                    case 0:
                        if (!this.gridOptions) return [3, 3];
                        if (!this.showFilterBox) return [3, 2];
                        return [4, this.box.showFloatingBox(this.filterViewBox)];
                    case 1:
                        _a.sent();
                        return [3, 3];
                    case 2:
                        columnDefs = this.gridOptions.api.getColumnDefs();
                        columnDefs.forEach(function (columnDef) {
                            columnDef.floatingFilter = floatingFilter !== null && floatingFilter !== void 0 ? floatingFilter : !columnDef.floatingFilter;
                        });
                        this.gridOptions.api.setColumnDefs(columnDefs);
                        this.gridOptions.api.refreshHeader();
                        _a.label = 3;
                    case 3: return [2];
                }
            });
        });
    };
    GridHeaderBar.prototype.showAgGridViewBox = function () {
        return __awaiter(this, void 0, void 0, function () {
            return __generator(this, function (_a) {
                switch (_a.label) {
                    case 0: return [4, this.loadAgGridViewData()];
                    case 1:
                        _a.sent();
                        return [4, this.box.showFloatingBox(this.agGridViewBox)];
                    case 2:
                        _a.sent();
                        return [2];
                }
            });
        });
    };
    GridHeaderBar.prototype.copyAgGridView = function (agGridView) {
        return __awaiter(this, void 0, void 0, function () {
            var _this = this;
            return __generator(this, function (_a) {
                switch (_a.label) {
                    case 0: return [4, this.box.showSelect(this.i18n.tr('grid.createdById', { ns: "common" }), this.i18n.tr('grid.userSelection', { ns: "common" }), new ServiceBase("User"), "fullName", "id", "digi-copy").then(function (dialogOpenResult) {
                            dialogOpenResult.closeResult.then(function (dialogCloseResult) { return __awaiter(_this, void 0, void 0, function () {
                                var userIds, copiedAgGridViews, userIds_1, userIds_1_1, userId, copiedAgGridView, e_1_1;
                                var e_1, _a, _b;
                                return __generator(this, function (_c) {
                                    switch (_c.label) {
                                        case 0:
                                            if (!!dialogCloseResult.wasCancelled) return [3, 10];
                                            userIds = dialogCloseResult.output;
                                            copiedAgGridViews = new Array();
                                            _c.label = 1;
                                        case 1:
                                            _c.trys.push([1, 6, 7, 8]);
                                            userIds_1 = __values(userIds), userIds_1_1 = userIds_1.next();
                                            _c.label = 2;
                                        case 2:
                                            if (!!userIds_1_1.done) return [3, 5];
                                            userId = userIds_1_1.value;
                                            return [4, this.gridViewService.createEntity({
                                                    name: agGridView.name,
                                                    moduleId: agGridView.moduleId,
                                                    fixedFilters: agGridView.fixedFilters,
                                                    adjustColumns: agGridView.adjustColumns,
                                                    columnState: agGridView.columnState,
                                                    filterModel: agGridView.filterModel,
                                                    visibility: "Private",
                                                    authorId: userId
                                                })];
                                        case 3:
                                            copiedAgGridView = _c.sent();
                                            copiedAgGridViews.push(copiedAgGridView);
                                            _c.label = 4;
                                        case 4:
                                            userIds_1_1 = userIds_1.next();
                                            return [3, 2];
                                        case 5: return [3, 8];
                                        case 6:
                                            e_1_1 = _c.sent();
                                            e_1 = { error: e_1_1 };
                                            return [3, 8];
                                        case 7:
                                            try {
                                                if (userIds_1_1 && !userIds_1_1.done && (_a = userIds_1.return)) _a.call(userIds_1);
                                            }
                                            finally { if (e_1) throw e_1.error; }
                                            return [7];
                                        case 8: return [4, this.gridViewService.saveEntities(copiedAgGridViews)];
                                        case 9:
                                            _c.sent();
                                            (_b = this.agGridViewList).push.apply(_b, __spreadArray([], __read(copiedAgGridViews), false));
                                            this.logger.Log(this.i18n.tr("grid.viewCopied", { ns: "common" }), null, 'CustomAgGrid', true);
                                            _c.label = 10;
                                        case 10: return [2];
                                    }
                                });
                            }); });
                        })];
                    case 1:
                        _a.sent();
                        return [2];
                }
            });
        });
    };
    GridHeaderBar.prototype.loadAgGridViewData = function (forceLoad) {
        if (forceLoad === void 0) { forceLoad = false; }
        return __awaiter(this, void 0, void 0, function () {
            var agGridViewData, defaultAgGridView, usedAgGridView, agGridViewData_1, agGridViewData_1_1, agGridView;
            var e_2, _a;
            return __generator(this, function (_b) {
                switch (_b.label) {
                    case 0:
                        if (!((this.firstTime && this.authService.currentUser) || forceLoad)) return [3, 5];
                        if (!(this.agGridViewList != null)) return [3, 5];
                        agGridViewData = void 0;
                        if (!this.config.agGridConfig.allowSharedView) return [3, 2];
                        return [4, this.gridViewService.getAllFromModuleIdWithShared(this.agGridViewModuleView, (this.showAllView ? null : this.authService.currentUser.id))];
                    case 1:
                        agGridViewData = _b.sent();
                        return [3, 4];
                    case 2: return [4, this.gridViewService.getAllFromModuleId(this.agGridViewModuleView, (this.showAllView ? null : this.authService.currentUser.id))];
                    case 3:
                        agGridViewData = _b.sent();
                        _b.label = 4;
                    case 4:
                        this.firstTime = false;
                        if (agGridViewData != null) {
                            this.defaultAgGridView = this.agGridViewList.find(function (x) { return x.isDefaultView && x.id == -100; });
                            defaultAgGridView = this.agGridViewList.find(function (x) { return x.isDefaultView; });
                            usedAgGridView = this.agGridViewList.find(function (x) { return x.used; });
                            this.agGridViewList.splice(0);
                            try {
                                for (agGridViewData_1 = __values(agGridViewData), agGridViewData_1_1 = agGridViewData_1.next(); !agGridViewData_1_1.done; agGridViewData_1_1 = agGridViewData_1.next()) {
                                    agGridView = agGridViewData_1_1.value;
                                    agGridView.hide = false;
                                    if (usedAgGridView != null && usedAgGridView.id == agGridView.id) {
                                        agGridView.used = true;
                                    }
                                    this.agGridViewList.push(agGridView);
                                }
                            }
                            catch (e_2_1) { e_2 = { error: e_2_1 }; }
                            finally {
                                try {
                                    if (agGridViewData_1_1 && !agGridViewData_1_1.done && (_a = agGridViewData_1.return)) _a.call(agGridViewData_1);
                                }
                                finally { if (e_2) throw e_2.error; }
                            }
                            if (!this.agGridViewList.some(function (x) { return x.isDefaultView; })) {
                                this.agGridViewList.push(defaultAgGridView);
                            }
                        }
                        this.agGridViewList.sortBy("isDefaultView", false);
                        _b.label = 5;
                    case 5: return [2];
                }
            });
        });
    };
    GridHeaderBar.prototype.getCsvExportParams = function () {
        var _this = this;
        return {
            columnSeparator: ';',
            fileName: this.i18n.tr(this.router.currentInstruction.config.title).replace('.', ''),
            processCellCallback: function (params) {
                if (params.value == null) {
                    return '';
                }
                else {
                    var colDef = params.column.getColDef();
                    switch (colDef.type) {
                        case FieldType.Date:
                        case FieldType.DateTime:
                            return moment(params.value).format(colDef.floatingFilterComponentParams.dateFormat);
                        case FieldType.Number:
                            return !isNaN(params.value) ? new Intl.NumberFormat(colDef.floatingFilterComponentParams.defaultLocale, { useGrouping: false }).format(params.value) : params.value;
                        default:
                            break;
                    }
                    if (colDef.field == "isSelected") {
                        if (params.value === true) {
                            return _this.i18n.tr("general.yes", { ns: "common" });
                        }
                        else {
                            return _this.i18n.tr("general.no", { ns: "common" });
                        }
                    }
                }
                return params.value;
            },
            processHeaderCallback: function (params) {
                var colDef = params.column.getColDef();
                if (colDef.field == "isSelected") {
                    return _this.i18n.tr("grid.isSelected", { ns: "common" });
                }
                return colDef.headerName;
            }
        };
    };
    GridHeaderBar.prototype.exportToCsv = function () {
        return __awaiter(this, void 0, void 0, function () {
            var buttonOk, buttonCancel, limit, nbUpdated_1;
            var _this = this;
            return __generator(this, function (_a) {
                switch (_a.label) {
                    case 0:
                        buttonOk = {
                            label: this.i18n.tr("grid.export", { ns: "common" }),
                            title: this.i18n.tr("grid.export", { ns: "common" }),
                            theme: 'primary',
                            type: 'solid',
                            disabled: false,
                            fn: function (thisBox) {
                                thisBox.controller.ok();
                            },
                            keyboardShortcut: this.config.globalConfig.keyboardShortcutFwBox ? KeyboardShortcut.Enter : null
                        };
                        buttonCancel = {
                            label: this.i18n.tr("general.cancel", { ns: "common" }),
                            title: this.i18n.tr("general.cancel", { ns: "common" }),
                            theme: 'dark',
                            type: 'ghost',
                            disabled: false,
                            fn: function (thisBox) {
                                thisBox.controller.cancel();
                            },
                            keyboardShortcut: this.config.globalConfig.keyboardShortcutFwBox ? [KeyboardShortcut.Escape, KeyboardShortcut.Backspace] : null
                        };
                        if (!this.csvExportConfig.useConfirmDialog) return [3, 2];
                        return [4, this.box.showQuestion(this.i18n.tr("general.csvExportConfirmation", { ns: "common" }), this.i18n.tr("grid.csvExport", { ns: "common" }), [buttonCancel, buttonOk]).whenClosed()];
                    case 1:
                        _a.sent();
                        _a.label = 2;
                    case 2:
                        if (!this.csvExportConfig.export) return [3, 4];
                        return [4, this.csvExportConfig.export()];
                    case 3:
                        _a.sent();
                        return [3, 5];
                    case 4:
                        this.gridOptions.api.showLoadingOverlay();
                        try {
                            limit = this.gridOptions.api.getModel().getRowCount();
                            if (limit > 100000) {
                                limit = 100000;
                            }
                            nbUpdated_1 = -1;
                            this.gridOptions.paginationPageSize = limit;
                            this.gridOptions.cacheBlockSize = limit;
                            this.gridOptions.onModelUpdated = function (event) {
                                nbUpdated_1++;
                                if (nbUpdated_1 == 1) {
                                    _this.gridOptions.api.exportDataAsCsv(_this.getCsvExportParams());
                                }
                            };
                            this.gridOptions.api.getModel().reset();
                        }
                        finally {
                            this.gridOptions.api.hideOverlay();
                        }
                        _a.label = 5;
                    case 5: return [2];
                }
            });
        });
    };
    GridHeaderBar.prototype.showParametersBox = function () {
        return __awaiter(this, void 0, void 0, function () {
            return __generator(this, function (_a) {
                switch (_a.label) {
                    case 0: return [4, this.box.showFloatingBox(this.viewParameterBox)];
                    case 1:
                        _a.sent();
                        return [2];
                }
            });
        });
    };
    __decorate([
        bindable,
        __metadata("design:type", String)
    ], GridHeaderBar.prototype, "title", void 0);
    __decorate([
        bindable,
        __metadata("design:type", Function)
    ], GridHeaderBar.prototype, "addFn", void 0);
    __decorate([
        bindable,
        __metadata("design:type", Function)
    ], GridHeaderBar.prototype, "deleteFn", void 0);
    __decorate([
        bindable,
        __metadata("design:type", Boolean)
    ], GridHeaderBar.prototype, "canAdd", void 0);
    __decorate([
        bindable,
        __metadata("design:type", Boolean)
    ], GridHeaderBar.prototype, "canDelete", void 0);
    __decorate([
        bindable,
        __metadata("design:type", Boolean)
    ], GridHeaderBar.prototype, "canBack", void 0);
    __decorate([
        bindable,
        __metadata("design:type", Boolean)
    ], GridHeaderBar.prototype, "canUseView", void 0);
    __decorate([
        bindable,
        __metadata("design:type", Boolean)
    ], GridHeaderBar.prototype, "canUseFilter", void 0);
    __decorate([
        bindable,
        __metadata("design:type", Boolean)
    ], GridHeaderBar.prototype, "canUseParameters", void 0);
    __decorate([
        bindable,
        __metadata("design:type", Boolean)
    ], GridHeaderBar.prototype, "canResetFilters", void 0);
    __decorate([
        bindable,
        __metadata("design:type", Boolean)
    ], GridHeaderBar.prototype, "canExport", void 0);
    __decorate([
        bindable,
        __metadata("design:type", Boolean)
    ], GridHeaderBar.prototype, "showViewBox", void 0);
    __decorate([
        bindable,
        __metadata("design:type", Boolean)
    ], GridHeaderBar.prototype, "canShowAllView", void 0);
    __decorate([
        bindable,
        __metadata("design:type", Array)
    ], GridHeaderBar.prototype, "agGridViewList", void 0);
    __decorate([
        bindable({ bindingMode: bindingMode.fromView }),
        __metadata("design:type", Object)
    ], GridHeaderBar.prototype, "gridOptions", void 0);
    __decorate([
        bindable,
        __metadata("design:type", Boolean)
    ], GridHeaderBar.prototype, "showFilterBox", void 0);
    __decorate([
        bindable,
        __metadata("design:type", Boolean)
    ], GridHeaderBar.prototype, "showParametersViewBox", void 0);
    __decorate([
        bindable,
        __metadata("design:type", Function)
    ], GridHeaderBar.prototype, "afterResetFilters", void 0);
    __decorate([
        bindable,
        __metadata("design:type", Datacontext)
    ], GridHeaderBar.prototype, "datacontext", void 0);
    __decorate([
        bindable,
        __metadata("design:type", Function)
    ], GridHeaderBar.prototype, "afterSetAgGridView", void 0);
    __decorate([
        bindable,
        __metadata("design:type", String)
    ], GridHeaderBar.prototype, "agGridViewModuleView", void 0);
    __decorate([
        bindable,
        __metadata("design:type", BindableGridOptions)
    ], GridHeaderBar.prototype, "options", void 0);
    __decorate([
        bindable,
        __metadata("design:type", Function)
    ], GridHeaderBar.prototype, "selectAll", void 0);
    __decorate([
        bindable,
        __metadata("design:type", Object)
    ], GridHeaderBar.prototype, "csvExportConfig", void 0);
    __decorate([
        observable,
        __metadata("design:type", Boolean)
    ], GridHeaderBar.prototype, "showAllView", void 0);
    GridHeaderBar = __decorate([
        autoinject,
        __metadata("design:paramtypes", [BindingEngine, I18N, Box, Router, CustomLogger, AuthService, Config, Element])
    ], GridHeaderBar);
    return GridHeaderBar;
}());

//# sourceMappingURL=grid-header-bar.js.map
