"use strict";
var __extends = (this && this.__extends) || (function () {
    var extendStatics = function (d, b) {
        extendStatics = Object.setPrototypeOf ||
            ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
            function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
        return extendStatics(d, b);
    };
    return function (d, b) {
        if (typeof b !== "function" && b !== null)
            throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
        extendStatics(d, b);
        function __() { this.constructor = d; }
        d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
    };
})();
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    var desc = Object.getOwnPropertyDescriptor(m, k);
    if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
      desc = { enumerable: true, get: function() { return m[k]; } };
    }
    Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
    Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
    o["default"] = v;
});
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 __importStar = (this && this.__importStar) || function (mod) {
    if (mod && mod.__esModule) return mod;
    var result = {};
    if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
    __setModuleDefault(result, mod);
    return result;
};
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));
};
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.ListViewModelBase = exports.SelectAllHeaderComponent = void 0;
var translated_property_helper_1 = require("./../utils/translated-property-helper");
var custom_ag_grid_options_1 = require("../resources/elements/ag-grid/custom-ag-grid-options");
var entity_manager_1 = require("./../data/entity-manager");
var view_model_base_1 = require("./view-model-base");
var breeze = __importStar(require("breeze-client"));
var aurelia_framework_1 = require("aurelia-framework");
var box_1 = require("../modules/box");
var common_model_1 = require("../model/common-model");
var ag_grid_view_service_1 = require("../services/ag-grid-view-service");
var ag_grid_helpers_1 = require("../resources/elements/utilities/ag-grid-helpers");
var config_1 = require("../config");
var agUtils_1 = require("./../ag-grid/agUtils");
var moment_1 = __importDefault(require("moment"));
var came_case_1 = require("../utils/came-case");
var SelectAllHeaderComponent = (function () {
    function SelectAllHeaderComponent() {
    }
    SelectAllHeaderComponent.prototype.init = function (params) {
        this.params = params.VM;
        this.eGui = this.params.headerCellRendererSelectAll();
    };
    SelectAllHeaderComponent.prototype.getGui = function () {
        return this.eGui;
    };
    SelectAllHeaderComponent.prototype.destroy = function () {
    };
    return SelectAllHeaderComponent;
}());
exports.SelectAllHeaderComponent = SelectAllHeaderComponent;
var ListViewModelBase = exports.ListViewModelBase = (function (_super) {
    __extends(ListViewModelBase, _super);
    function ListViewModelBase(router, logger, serviceInstance) {
        var _this = _super.call(this, router, logger) || this;
        _this.idSuffix = "".concat(Date.now());
        _this.useUserSettingFilter = true;
        _this.useUserSettingSorter = true;
        _this.canSelectAll = true;
        _this.useExperimentalProjection = false;
        _this.additionalSelectPropertyPaths = new Array();
        _this.service = serviceInstance;
        _this.manager = aurelia_framework_1.Container.instance.get(entity_manager_1.EntityManager).manager;
        _this.box = aurelia_framework_1.Container.instance.get(box_1.Box);
        _this.viewCompiler = aurelia_framework_1.Container.instance.get(aurelia_framework_1.ViewCompiler);
        _this.gridViewService = new ag_grid_view_service_1.AgGridViewService();
        _this.showUsedViewInList = aurelia_framework_1.Container.instance.get(config_1.Config).agGridConfig.showUsedViewInList;
        _this.translatedPropertyHelper = aurelia_framework_1.Container.instance.get(translated_property_helper_1.TranslatedPropertyHelper);
        _this.localeChangedSubscription = _this.eventAggregator.subscribe('i18n:locale:changed', function (payload) {
            var fragment = _this.router.currentInstruction.fragment;
            if (_this.router.currentInstruction.queryString != null) {
                fragment += '?' + _this.router.currentInstruction.queryString;
            }
            _this.router.navigate(fragment, { replace: true, trigger: true });
        });
        _this.initializeGridOptions(_this.config.agGridConfig.showFixedFilter);
        _this.agGridSortingHelper = new ag_grid_helpers_1.AgGridSortingHelper(_this.gridOptions);
        return _this;
    }
    ListViewModelBase.prototype.unselectAll = function () {
        var _a, _b;
        (_b = (_a = this.gridOptions) === null || _a === void 0 ? void 0 : _a.api) === null || _b === void 0 ? void 0 : _b.forEachNode(function (rowNode) {
            if (rowNode.data != null && false != rowNode.data.isSelected) {
                rowNode.data.isSelected = false;
            }
        });
    };
    ListViewModelBase.prototype.attached = function () {
        return __awaiter(this, void 0, void 0, function () {
            var _this = this;
            return __generator(this, function (_a) {
                this.routeName = this.router.currentInstruction.config.route;
                this.isViewsEnabled = this.router.currentInstruction.config.settings.isViewsEnabled;
                if (this.isViewsEnabled == null)
                    this.isViewsEnabled = true;
                window.addEventListener('beforeunload', function () { return _this.saveGridColumnsState(); });
                return [2];
            });
        });
    };
    ListViewModelBase.prototype.detached = function () {
        return __awaiter(this, void 0, void 0, function () {
            var _this = this;
            return __generator(this, function (_a) {
                switch (_a.label) {
                    case 0:
                        _super.prototype.detached.call(this);
                        return [4, this.saveGridColumnsState()];
                    case 1:
                        _a.sent();
                        window.removeEventListener('beforeunload', function () { return _this.saveGridColumnsState(); });
                        return [2];
                }
            });
        });
    };
    Object.defineProperty(ListViewModelBase.prototype, "ribbonHeaderText", {
        get: function () {
            var _a;
            this.usedView = (_a = this.agGridViewList) === null || _a === void 0 ? void 0 : _a.find(function (x) { return x.used; });
            var title = this.i18n.tr(this.router.currentInstruction.config.navModel.title);
            if (this.showUsedViewInList) {
                var viewName = (this.usedView != null && !this.usedView.isDefaultView) ? " - ".concat(this.i18n.tr("view.view", { ns: "common" }), " : ").concat(this.usedView.name) : '';
                return title + viewName;
            }
            return title;
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(ListViewModelBase.prototype, "selectedEntities", {
        get: function () {
            if (this.gridOptions == null || this.gridOptions.api == null)
                return [];
            var selectedEntities = [];
            this.gridOptions.api.forEachNode(function (rowNode) {
                if (rowNode.data != null)
                    if (rowNode.data.isSelected == true)
                        selectedEntities.push(rowNode.data);
            });
            this.selectedEntitiesCount = selectedEntities.length;
            return selectedEntities;
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(ListViewModelBase.prototype, "entitiesCount", {
        get: function () {
            if (this.gridOptions == null || this.gridOptions.api == null)
                return 0;
            return this.gridOptions.api.getInfiniteRowCount();
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(ListViewModelBase.prototype, "canDelete", {
        get: function () {
            return this.selectedEntities.length > 0 && this.authService.checkAccess(this.ressourceName, 'delete');
        },
        enumerable: false,
        configurable: true
    });
    ListViewModelBase.prototype.getSelectedEntitiesFromCache = function () {
        return __awaiter(this, void 0, void 0, function () {
            var entitiesFromCache;
            return __generator(this, function (_a) {
                switch (_a.label) {
                    case 0: return [4, this.service.getEntitiesFromLocalCache()];
                    case 1:
                        entitiesFromCache = _a.sent();
                        return [2, entitiesFromCache.filter(function (x) { return x.isSelected; })];
                }
            });
        });
    };
    ListViewModelBase.prototype.delete = function (detachInverseFKEntities) {
        if (detachInverseFKEntities === void 0) { detachInverseFKEntities = true; }
        return __awaiter(this, void 0, void 0, function () {
            var isDeleted, entitiesToDelete;
            return __generator(this, function (_a) {
                switch (_a.label) {
                    case 0:
                        isDeleted = false;
                        if (!(this.selectedEntities.length > 0)) return [3, 4];
                        entitiesToDelete = this.selectedEntities;
                        if (!(this.useExperimentalProjection && entitiesToDelete[0].hasOwnProperty("id"))) return [3, 2];
                        return [4, this.service.getEntities(breeze.Predicate.or(this.selectedEntities.map(function (selectedEntity) { return new breeze.Predicate("id", breeze.FilterQueryOp.Equals, selectedEntity.id); })))];
                    case 1:
                        entitiesToDelete = _a.sent();
                        _a.label = 2;
                    case 2: return [4, this.service.deleteEntities(entitiesToDelete, detachInverseFKEntities)];
                    case 3:
                        isDeleted = _a.sent();
                        if (isDeleted) {
                            this.refreshAfterDelete();
                        }
                        _a.label = 4;
                    case 4: return [2, isDeleted];
                }
            });
        });
    };
    ListViewModelBase.prototype.refreshAfterDelete = function () {
        this.gridOptions.api.forEachNode(function (rowNode) {
            if (rowNode.data != null)
                if (rowNode.data.isSelected == true)
                    rowNode.data.isSelected = false;
        });
        this.gridOptions.api.refreshInfiniteCache();
    };
    ListViewModelBase.prototype.deactivate = function () {
        this.unselectAll();
        this.localeChangedSubscription.dispose();
    };
    ListViewModelBase.prototype.filterChanged = function (newValue, oldValue) {
        this.service.gridDataSource.quickFilter = newValue;
        this.gridOptions.api.onFilterChanged();
    };
    ListViewModelBase.prototype.selectAllChanged = function (newValue, oldValue) {
        var _this = this;
        if (this.gridOptions.api && newValue != oldValue) {
            var MAX_SELECTION = 1000;
            var infiniteRowCount_1 = this.gridOptions.api.getInfiniteRowCount();
            if (newValue) {
                if (infiniteRowCount_1 > MAX_SELECTION) {
                    var titleWarning = this.i18n.tr('grid.warning', { ns: "common" });
                    var str = this.i18n.tr('grid.selectionRejected', { ns: "common", amount: infiniteRowCount_1, max: MAX_SELECTION });
                    this.box.showWarning(str, titleWarning);
                    this.selectAll = false;
                    return;
                }
                if (!this.allDataLoaded()) {
                    this.gridOptions.cacheBlockSize = infiniteRowCount_1;
                    var infiniteModel_1 = this.gridOptions.api.getModel();
                    var initialFnUpdate_1 = this.gridOptions.onModelUpdated;
                    this.gridOptions.onModelUpdated = function (event) {
                        console.log(event);
                        var currentRowCount = _this.gridOptions.api.getModel().getRowCount();
                        if (infiniteRowCount_1 <= currentRowCount) {
                            _this.gridOptions.api.hideOverlay();
                            _this.actualizeCheckboxes();
                            var str = _this.i18n.tr('grid.elementsSelected', { ns: "common", amount: _this.getSelectableRows().length });
                            _this.log(str, null, true);
                            infiniteModel_1.onCacheUpdated = initialFnUpdate_1;
                        }
                    };
                    this.gridOptions.api.getModel().reset();
                }
            }
            this.actualizeCheckboxes();
        }
    };
    ListViewModelBase.prototype.gotoDetails = function (self, entity) {
        var url = self.getDetailsUrl(self, entity);
        if (url) {
            self.router.navigate(url);
        }
    };
    ListViewModelBase.prototype.gotoDetailInNewWindow = function (self, entity) {
        var url = self.getDetailsUrl(self, entity);
        if (url) {
            window.open(url, "blank");
        }
    };
    ListViewModelBase.prototype.openInNewTab = function (self, entity) {
        var url = this.getDetailsUrl(self, entity);
        if (url) {
            window.open(url, "_blank");
        }
    };
    ListViewModelBase.prototype.getDetailsUrl = function (self, entity) {
        return null;
    };
    ListViewModelBase.prototype.onCellClicked = function (entity) {
        return true;
    };
    ListViewModelBase.prototype.initializeGridOptions = function (fixedFilters, hasHyperlinkColumn) {
        var _this = this;
        if (fixedFilters === void 0) { fixedFilters = false; }
        if (hasHyperlinkColumn === void 0) { hasHyperlinkColumn = null; }
        if (!this.service)
            return;
        this.gridOptions = {};
        this.gridOptions.rowModelType = 'infinite';
        this.gridOptions.pagination = true;
        this.gridOptions.paginationAutoPageSize = true;
        this.gridOptions.fixedFilters = fixedFilters;
        this.gridOptions.suppressDragLeaveHidesColumns = true;
        this.gridOptions.maxConcurrentDatasourceRequests = 3;
        this.gridOptions.rowHeight = 40;
        this.gridOptions.headerHeight = 45;
        this.gridOptions.floatingFiltersHeight = 45;
        this.gridOptions.animateRows = true;
        this.gridOptions.rowSelection = 'multiple';
        this.gridOptions.suppressRowClickSelection = true;
        this.gridOptions.enableBrowserTooltips = true;
        this.gridOptions.multiSortKey = 'ctrl';
        this.gridOptions.components = custom_ag_grid_options_1.CustomAgGridOptions.Components;
        this.gridOptions.columnTypes = custom_ag_grid_options_1.CustomAgGridOptions.ColumnTypeDefinitions(this.i18n, this.config.globalConfig.defaultLocale);
        var colDefs = this.getDataGridColumns();
        if (this.useExperimentalProjection) {
            this.applySelect(colDefs);
        }
        this.gridOptions.columnDefs = colDefs;
        hasHyperlinkColumn = hasHyperlinkColumn === null ? this.config.agGridConfig.hasHyperlinkColumn : hasHyperlinkColumn;
        if (this.gridOptions.columnDefs != null && hasHyperlinkColumn) {
            this.gridOptions.columnDefs.push({
                headerName: "",
                field: "hyperlink",
                maxWidth: 40,
                minWidth: 40,
                cellRendererSelector: function (params) {
                    return {
                        component: "hyperlinkRenderer",
                        params: { value: _this.getDetailsUrl(_this, params.data), linkInNewTab: _this.config.agGridConfig.hyperlinkInNewTab }
                    };
                },
                suppressColumnsToolPanel: true,
                suppressMenu: true,
                sortable: false,
                resizable: false,
                filter: false,
                lockPosition: "right",
                pinned: "right"
            });
        }
        this.gridOptions.columnDefs.forEach(function (columnDef) {
            columnDef.headerTooltip = columnDef.headerName;
        });
        this.gridOptions.onCellClicked = function (event) { _this.onCellClickedInternal(event); };
        this.gridOptions.onModelUpdated = function (event) { _this.onModelUpdated(event); };
        this.gridOptions.onSelectionChanged = function (event) { _this.onSelectionChanged(event); };
        this.gridOptions.onGridReady = function (event) { _this.onGridReady(event); };
        this.gridOptions.getLocaleText = function (input) { return _this.i18n.tr("grid." + input.key, { ns: "common" }); };
        if (this.config.agGridConfig.suppressMenu) {
            this.gridOptions.defaultColDef = {
                suppressMenu: true
            };
        }
        else {
            this.gridOptions.defaultColDef = {
                suppressMenu: false,
                menuTabs: ['filterMenuTab']
            };
        }
        this.gridOptions.enableCellTextSelection = true;
    };
    ListViewModelBase.prototype.onCellClickedInternal = function (event) {
        var _this = this;
        var mouseEvent = event.event;
        if (event.colDef.onCellClicked == null) {
            if (event.colDef.pinned == null || event.colDef.pinned === false) {
                if (this.onCellClicked(event.data) !== false) {
                    this.gotoDetails(this, event.data);
                }
            }
            else if (event.colDef.field == 'isSelected') {
                var inputs = mouseEvent.target.getElementsByTagName("input");
                if (inputs.length > 0 && inputs.item(0).getAttribute("type") == "checkbox") {
                    if (!mouseEvent.shiftKey || this.firstIndex == null) {
                        this.firstIndex = event.rowIndex;
                        this.isFirstTimeSelection = true;
                    }
                    else {
                        var secondIndex_1 = event.rowIndex;
                        this.gridOptions.api.forEachNode(function (rowNode, index) {
                            if (rowNode.data != null) {
                                if (_this.firstIndex >= secondIndex_1) {
                                    if (rowNode.rowIndex > secondIndex_1 && ((_this.isFirstTimeSelection && rowNode.rowIndex < _this.firstIndex) || (!_this.isFirstTimeSelection && rowNode.rowIndex <= _this.firstIndex))) {
                                        rowNode.data.isSelected = !rowNode.data.isSelected;
                                    }
                                }
                                else {
                                    if (((_this.isFirstTimeSelection && rowNode.rowIndex > _this.firstIndex) || (!_this.isFirstTimeSelection && rowNode.rowIndex >= _this.firstIndex)) && rowNode.rowIndex < secondIndex_1) {
                                        rowNode.data.isSelected = !rowNode.data.isSelected;
                                    }
                                }
                                if (rowNode.rowIndex - 1 == _this.firstIndex)
                                    _this.isFirstTimeSelection = false;
                            }
                        });
                    }
                }
            }
        }
        if (event.colDef.field == 'isSelected')
            this.onSelectionChanged(event);
    };
    ListViewModelBase.prototype.onModelUpdated = function (event) {
        var _a;
        if (((_a = this.gridOptions) === null || _a === void 0 ? void 0 : _a.adjustColumns) === true && this.gridOptions.api) {
            this.gridOptions.api.sizeColumnsToFit();
        }
        this.actualizeCheckboxes();
    };
    ListViewModelBase.prototype.onSelectionChanged = function (event) {
        this.checkHeaderCheckBoxIfNeeded();
        this.handleSingleRowSelectionMode(event);
    };
    ListViewModelBase.prototype.handleSingleRowSelectionMode = function (event) {
        if (this.gridOptions.rowSelection != 'multiple' && event.data.isSelected === true) {
            this.gridOptions.api.forEachNode(function (rowNode) {
                if (rowNode.data != null && rowNode.data != event.data)
                    if (rowNode.data.isSelected == true)
                        rowNode.data.isSelected = false;
            });
        }
    };
    ListViewModelBase.prototype.checkHeaderCheckBoxIfNeeded = function () {
        var selCount = this.selectedEntities.length;
        var rowCount = this.getSelectableRows().length;
        if (selCount == rowCount) {
            this.selectAll = true;
        }
        else {
            this.selectAll = false;
        }
    };
    ListViewModelBase.prototype.applyViewById = function (viewId) {
        return __awaiter(this, void 0, void 0, function () {
            var usedView;
            return __generator(this, function (_a) {
                switch (_a.label) {
                    case 0: return [4, this.gridViewService.getEntityById(viewId)];
                    case 1:
                        usedView = _a.sent();
                        if (usedView != null && this.agGridViewList != null) {
                            usedView.used = true;
                            this.agGridViewList.push(usedView);
                            this.applyView(usedView);
                        }
                        else {
                            this.applyDefaultView();
                        }
                        return [2];
                }
            });
        });
    };
    ListViewModelBase.prototype.applyDefaultView = function () {
        var _a, _b;
        if (((_a = this.agGridViewList) === null || _a === void 0 ? void 0 : _a.length) > 0) {
            this.applyView((_b = this.agGridViewList.find(function (x) { return x.isDefaultView; })) !== null && _b !== void 0 ? _b : this.agGridViewList[0]);
            (0, agUtils_1.autoAdjustColumnsSize)(this.gridOptions);
        }
    };
    ListViewModelBase.prototype.applyView = function (view) {
        if (view != null) {
            this.gridOptions.columnApi.applyColumnState({
                state: (0, agUtils_1.getNewColumnStates)(this.gridOptions, JSON.parse(view.columnState)),
                defaultState: { sort: null },
                applyOrder: true
            });
            this.gridOptions.api.setFilterModel(JSON.parse(view.filterModel));
            this.gridOptions.fixedFilters = view.fixedFilters && !this.config.agGridConfig.showFilterBox;
            this.gridOptions.adjustColumns = view.adjustColumns;
        }
    };
    ListViewModelBase.prototype.applyCustomSettings = function (settings) {
        var _a;
        if (((_a = settings.colsState) === null || _a === void 0 ? void 0 : _a.length) > 0) {
            this.gridOptions.columnApi.applyColumnState({
                state: (0, agUtils_1.getNewColumnStates)(this.gridOptions, settings.colsState),
                defaultState: { sort: null },
                applyOrder: true
            });
        }
        var forceOpenFilterRow = false;
        if (this.useUserSettingFilter && settings.filterModel) {
            this.gridOptions.api.setFilterModel(settings.filterModel);
            if (Object.keys(settings.filterModel || {}).length > 0) {
                forceOpenFilterRow = !this.config.agGridConfig.showFilterBox;
            }
        }
        if (settings.fixedFilters != null) {
            this.gridOptions.fixedFilters = settings.fixedFilters && !this.config.agGridConfig.showFilterBox;
        }
        if (settings.adjustColumns != null) {
            this.gridOptions.adjustColumns = settings.adjustColumns;
        }
        return forceOpenFilterRow;
    };
    ListViewModelBase.prototype.onGridReady = function (event) {
        var _a, _b, _c;
        return __awaiter(this, void 0, void 0, function () {
            var forcedViewId, savedSettings, forceOpenFilterRow, onDisplayedColumnsChangedHandler;
            return __generator(this, function (_d) {
                switch (_d.label) {
                    case 0:
                        if (!(this.router.currentInstruction != null)) return [3, 7];
                        return [4, this.initAgGridView()];
                    case 1:
                        _d.sent();
                        forcedViewId = (_a = this.usedViewId) !== null && _a !== void 0 ? _a : this.router.currentInstruction.queryParams["usedViewId"];
                        if (!forcedViewId) return [3, 3];
                        return [4, this.applyViewById(forcedViewId)];
                    case 2:
                        _d.sent();
                        _d.label = 3;
                    case 3:
                        savedSettings = this.authService.currentUser ? this.authService.currentUser.sanitizedSettings.dataGridSettings[this.routeName] : null;
                        forceOpenFilterRow = false;
                        if (!(savedSettings != null)) return [3, 6];
                        if (!(savedSettings.usedView != null)) return [3, 5];
                        return [4, this.applyViewById(savedSettings.usedView.id)];
                    case 4:
                        _d.sent();
                        _d.label = 5;
                    case 5:
                        forceOpenFilterRow = this.applyCustomSettings(savedSettings);
                        _d.label = 6;
                    case 6:
                        if (forcedViewId || savedSettings) {
                            if (false == this.agGridSortingHelper.hasAnySorting()) {
                                this.agGridSortingHelper.applyDefaultSortModel();
                            }
                        }
                        else {
                            this.applyDefaultView();
                        }
                        this.gridOptions.fixedFilters = (_b = this.gridOptions.fixedFilters) !== null && _b !== void 0 ? _b : false;
                        this.toggleFloatingRow(forceOpenFilterRow || this.gridOptions.fixedFilters);
                        this.gridOptions.adjustColumns = (_c = this.gridOptions.adjustColumns) !== null && _c !== void 0 ? _c : this.config.agGridConfig.defaultAdjustColumns;
                        _d.label = 7;
                    case 7:
                        onDisplayedColumnsChangedHandler = this.gridOptions.onDisplayedColumnsChanged;
                        this.gridOptions.onDisplayedColumnsChanged = function (ev) {
                            if (onDisplayedColumnsChangedHandler != null)
                                onDisplayedColumnsChangedHandler(ev);
                        };
                        if (this.gridOptions.api) {
                            this.gridOptions.api.refreshHeader();
                            this.gridOptions.api.setDatasource(this.service.gridDataSource);
                        }
                        return [2];
                }
            });
        });
    };
    ListViewModelBase.prototype.toggleFloatingRow = function (floatingFilter) {
        if (floatingFilter === void 0) { floatingFilter = null; }
        if (this.gridOptions) {
            var 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();
        }
    };
    ListViewModelBase.prototype.saveUserSettings = function (settings) {
        return __awaiter(this, void 0, void 0, function () {
            return __generator(this, function (_a) {
                switch (_a.label) {
                    case 0:
                        if (!this.authService.currentUser) return [3, 2];
                        this.authService.currentUser.settings.dataGridSettings[this.routeName] = settings;
                        return [4, this.datacontext.saveUserSettings(this.authService.currentUser)];
                    case 1:
                        _a.sent();
                        _a.label = 2;
                    case 2: return [2];
                }
            });
        });
    };
    ListViewModelBase.prototype.saveGridColumnsState = function () {
        var _a, _b;
        return __awaiter(this, void 0, void 0, function () {
            var selectedView, savedSettings, currentSettings;
            return __generator(this, function (_c) {
                switch (_c.label) {
                    case 0:
                        if (!this.authService.currentUser) return [3, 2];
                        selectedView = this.isViewsEnabled ? (_b = (_a = this.agGridViewList) === null || _a === void 0 ? void 0 : _a.find(function (x) { return x.used; })) !== null && _b !== void 0 ? _b : this.agGridViewList.find(function (x) { return x.isDefaultView; }) : null;
                        savedSettings = this.authService.currentUser.settings.dataGridSettings[this.routeName];
                        currentSettings = {
                            usedView: selectedView && selectedView.id > 0 ? { id: selectedView.id, name: selectedView.name } : null,
                            fixedFilters: this.gridOptions.fixedFilters,
                            adjustColumns: this.gridOptions.adjustColumns
                        };
                        if (this.gridOptions.columnApi != null) {
                            currentSettings.colsState = this.filterColStateForSaving(this.gridOptions.columnApi.getColumnState());
                        }
                        if (this.gridOptions.api != null) {
                            currentSettings.filterModel = JSON.parse(JSON.stringify(this.gridOptions.api.getFilterModel()));
                        }
                        if (selectedView != null) {
                            if (this.isFixedFiltersEqual(currentSettings, selectedView)) {
                                currentSettings.fixedFilters = null;
                            }
                            if (this.isAdjustColumnsEqual(currentSettings, selectedView)) {
                                currentSettings.adjustColumns = null;
                            }
                            if (this.isColStateEqual(currentSettings, { colsState: this.filterColStateForSaving(JSON.parse(selectedView.columnState)) })) {
                                currentSettings.colsState = null;
                            }
                            if (this.isFilterModelEqual(currentSettings, { filterModel: JSON.parse(selectedView.filterModel) })) {
                                currentSettings.filterModel = null;
                            }
                        }
                        if (Object.keys(currentSettings.filterModel || {}).length == 0) {
                            currentSettings.filterModel = null;
                        }
                        if (!(savedSettings == null || this.isSavedDifferentFromCurrent(savedSettings, currentSettings))) return [3, 2];
                        return [4, this.saveUserSettings(currentSettings)];
                    case 1:
                        _c.sent();
                        _c.label = 2;
                    case 2: return [2];
                }
            });
        });
    };
    ListViewModelBase.prototype.filterColStateForSaving = function (colState) {
        return (colState || []).filter(function (x) {
            return (x.pinned == null || x.pinned === false) && x.colId != 'isSelected' && x.colId != 'hyperlink';
        });
    };
    ListViewModelBase.prototype.isSavedDifferentFromCurrent = function (settingsA, settingsB) {
        var _a, _b;
        return ((_a = settingsA.usedView) === null || _a === void 0 ? void 0 : _a.id) != ((_b = settingsB.usedView) === null || _b === void 0 ? void 0 : _b.id)
            || false == this.isFixedFiltersEqual(settingsA, settingsB)
            || false == this.isAdjustColumnsEqual(settingsA, settingsB)
            || false == this.isColStateEqual(settingsA, settingsB)
            || false == this.isFilterModelEqual(settingsA, settingsB);
    };
    ListViewModelBase.prototype.isFixedFiltersEqual = function (settingsA, settingsB) {
        return settingsA.fixedFilters == settingsB.fixedFilters;
    };
    ListViewModelBase.prototype.isAdjustColumnsEqual = function (settingsA, settingsB) {
        return settingsA.adjustColumns == settingsB.adjustColumns;
    };
    ListViewModelBase.prototype.isColStateEqual = function (settingsA, settingsB) {
        var _a, _b;
        return this.arrayOfObjectsMatch((_a = settingsA.colsState) !== null && _a !== void 0 ? _a : [], (_b = settingsB.colsState) !== null && _b !== void 0 ? _b : []);
    };
    ListViewModelBase.prototype.isFilterModelEqual = function (settingsA, settingsB) {
        var _a, _b;
        return JSON.stringify((_a = settingsA.filterModel) !== null && _a !== void 0 ? _a : {}) == JSON.stringify((_b = settingsB.filterModel) !== null && _b !== void 0 ? _b : {});
    };
    ListViewModelBase.prototype.arrayOfObjectsMatch = function (arr1, arr2, excludedProperties) {
        return (arr1.length === arr2.length) && arr1.every(function (val, index) {
            var e_1, _a;
            try {
                for (var _b = __values(Object.keys(val)), _c = _b.next(); !_c.done; _c = _b.next()) {
                    var key = _c.value;
                    if ((excludedProperties == null || !excludedProperties.includes(key)) && val[key] !== arr2[index][key]) {
                        return false;
                    }
                }
            }
            catch (e_1_1) { e_1 = { error: e_1_1 }; }
            finally {
                try {
                    if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
                }
                finally { if (e_1) throw e_1.error; }
            }
            return true;
        });
    };
    ListViewModelBase.prototype.getDataGridColumns = function () {
        return null;
    };
    ListViewModelBase.prototype.headerCellRendererComp = function () {
        var _this = this;
        var comp = {
            init: function () { },
            getGui: function (p) {
                return _this.headerCellRendererSelectAll();
            },
            destroy: function () { }
        };
        var p = new Promise(function () { return comp; });
        return p;
    };
    ListViewModelBase.prototype.isSelectedChanged = function (entity) {
        if (entity != null && entity.isSelected && false == this.isSelectable(entity)) {
            entity.isSelected = false;
        }
    };
    ListViewModelBase.prototype.isSelectable = function (entity) {
        return true;
    };
    ListViewModelBase.prototype.headerCellRendererSelectAll = function () {
        var eGui = document.createElement('div');
        eGui.style.width = '100%';
        eGui.style.height = '100%';
        var content = "<span class=\"select-all-container\"><ui-checkbox if.bind=\"canSelectAll\" checked.bind=\"selectAll\"></ui-checkbox></span>";
        var html = "<template>".concat(content, "</template>");
        var viewCompiler = aurelia_framework_1.Container.instance.get(aurelia_framework_1.ViewCompiler);
        var viewResources = aurelia_framework_1.Container.instance.get(aurelia_framework_1.ViewResources);
        var viewFactory = viewCompiler.compile(html, viewResources);
        var view = viewFactory.create(aurelia_framework_1.Container.instance);
        var viewSlot = new aurelia_framework_1.ViewSlot(eGui, true);
        viewSlot.add(view);
        view.bind(this, (0, aurelia_framework_1.createOverrideContext)(this));
        viewSlot.attached();
        return eGui;
    };
    ListViewModelBase.prototype.getSelectableRows = function () {
        var _this = this;
        var _a, _b;
        var rows = [];
        (_b = (_a = this.gridOptions) === null || _a === void 0 ? void 0 : _a.api) === null || _b === void 0 ? void 0 : _b.forEachNode(function (rowNode) {
            if (rowNode.data != null && _this.isSelectable(rowNode.data)) {
                rows.push(rowNode.data);
            }
        });
        return rows;
    };
    ListViewModelBase.prototype.actualizeCheckboxes = function () {
        var _this = this;
        if (this.allDataLoaded()) {
            if (this.selectAll) {
                this.getSelectableRows().forEach(function (entry) { return entry.isSelected = _this.selectAll; });
            }
            else {
                var rowNotSelected = this.getSelectableRows().find(function (x) { return !x.isSelected; });
                if (rowNotSelected != null) {
                    return;
                }
                else {
                    this.getSelectableRows().forEach(function (entry) { return entry.isSelected = false; });
                }
            }
            this.selectedEntitiesCount = this.selectedEntities.length;
        }
    };
    ListViewModelBase.prototype.allDataLoaded = function () {
        var infiniteRowCount = this.gridOptions.api && this.gridOptions.api.getInfiniteRowCount();
        var cacheBlockState = this.gridOptions.api && this.gridOptions.api.getCacheBlockState();
        var cptr = 0;
        if (cacheBlockState == null) {
            return false;
        }
        for (var i = 0; i < Object.keys(cacheBlockState).length; i++)
            if (cacheBlockState[i] && cacheBlockState[i].pageStatus == 'loaded')
                cptr = cptr + (cacheBlockState[i].endRow - cacheBlockState[i].startRow);
        return infiniteRowCount <= cptr;
    };
    ListViewModelBase.prototype.initAgGridView = function () {
        return __awaiter(this, void 0, void 0, function () {
            var defaultView;
            return __generator(this, function (_a) {
                switch (_a.label) {
                    case 0:
                        if (!(this.isViewsEnabled && this.router.currentInstruction.config.moduleId != null)) return [3, 4];
                        this.agGridViewList = new Array();
                        return [4, this.gridViewService.getDefaultViewFromModuleId(this.router.currentInstruction.config.moduleId)];
                    case 1:
                        defaultView = _a.sent();
                        if (!(defaultView == null)) return [3, 3];
                        return [4, this.gridViewService.createEntity({
                                id: -100,
                                name: this.i18n.tr("general.default", { ns: "common" }), moduleId: this.router.currentInstruction.config.moduleId,
                                fixedFilters: false, adjustColumns: this.config.agGridConfig.defaultAdjustColumns, columnState: JSON.stringify(this.gridOptions.columnApi.getColumnState()),
                                filterModel: null, sortModel: null, visibility: "System", author: null, authorId: this.authService.currentUser.id,
                                isDefaultView: true, createdBy: null, createdById: null, createdTime: null, updatedBy: null, updatedById: null,
                                updatedTime: null, entityAspect: null, entityType: null, hide: false, used: false
                            })];
                    case 2:
                        defaultView = _a.sent();
                        defaultView.entityAspect.setDetached();
                        _a.label = 3;
                    case 3:
                        this.agGridViewList.push(defaultView);
                        _a.label = 4;
                    case 4: return [2];
                }
            });
        });
    };
    ListViewModelBase.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.gridOptions.api.setDatasource(savedDs);
    };
    ListViewModelBase.prototype.applySelect = function (colDefs) {
        var _this = this;
        this.service.gridDataSource.selectPropertyPaths = this.getSelectPropertyPaths(colDefs);
        this.service.gridDataSource.onSuccessGetRowsCallback = function (result) { return __awaiter(_this, void 0, void 0, function () {
            var serviceExpands, successResult;
            var _this = this;
            return __generator(this, function (_a) {
                switch (_a.label) {
                    case 0:
                        serviceExpands = new Array();
                        successResult = Object
                            .entries(result)
                            .reduce(function (object, _a) {
                            var _b = __read(_a, 2), key = _b[0], value = _b[1];
                            var obj = {};
                            object[key] = obj;
                            var properties = Object.keys(value);
                            var _loop_1 = function (indexProperty) {
                                var property = properties[indexProperty];
                                var propertyPaths = property.split("_").map(function (propertyPath) {
                                    return came_case_1.CamelCase.toCamelCase(propertyPath);
                                });
                                var colDef = colDefs.find(function (x) { return x.field.startsWith(propertyPaths.join(".")); });
                                var tempObj = obj;
                                for (var index = 0; index < propertyPaths.length; index++) {
                                    var propertyPath = propertyPaths[index];
                                    if (!tempObj.hasOwnProperty("entityAspect")) {
                                        if (tempObj[propertyPath] == undefined) {
                                            if (index == propertyPaths.length - 1) {
                                                tempObj[propertyPath] = value[property];
                                                if (colDef != null) {
                                                    if (isString(value[property])) {
                                                        tempObj[propertyPath] = _this.convertFromString(value[property], colDef);
                                                    }
                                                    else if (isObject(tempObj[propertyPath])) {
                                                        if (colDef.type == common_model_1.FieldType.ManyToMany) {
                                                            _this.buildArrayForManyToManyExpand(serviceExpands, tempObj, propertyPath, colDef);
                                                        }
                                                        else {
                                                            _this.convertFromObject(tempObj[propertyPath], colDef);
                                                        }
                                                    }
                                                }
                                            }
                                            else {
                                                tempObj[propertyPath] = {};
                                            }
                                        }
                                        tempObj = tempObj[propertyPath];
                                    }
                                }
                            };
                            for (var indexProperty = 0; indexProperty < properties.length; indexProperty++) {
                                _loop_1(indexProperty);
                            }
                            return object;
                        }, {});
                        return [4, this.fetchServiceExpands(serviceExpands)];
                    case 1:
                        _a.sent();
                        return [2, successResult];
                }
            });
        }); };
    };
    ListViewModelBase.prototype.getSelectPropertyPaths = function (colDefs) {
        var e_2, _a;
        var _b;
        var selectPaths = new Array("id");
        var _loop_2 = function (colDef) {
            if (colDef.hasOwnProperty("field") && colDef.type != null && colDef.type != common_model_1.FieldType.Base) {
                if (colDef.type != common_model_1.FieldType.ManyToMany) {
                    var fieldName = colDef.field;
                    if (fieldName.includes("._translation")) {
                        fieldName = fieldName.replace("._translation", "");
                    }
                    selectPaths.push(fieldName);
                    if (colDef.type == common_model_1.FieldType.Enumeration) {
                        var fieldPaths = fieldName.split('.');
                        if (fieldPaths.length > 1) {
                            var enumerationPath = fieldPaths.slice(0, fieldPaths.length - 1).join('.');
                            selectPaths.push(enumerationPath + ".textColor", enumerationPath + ".backgroundColor");
                        }
                    }
                }
                else {
                    if (colDef.floatingFilterComponentParams == null)
                        throw Error("Cannot use projection with many-to-many column without specifying floatingFilterComponentParams parameters");
                    var fieldPaths = colDef.field.split('.');
                    if (fieldPaths.includes("_translation")) {
                        fieldPaths.remove("_translation");
                    }
                    var arrayField_1 = (_b = colDef.floatingFilterComponentParams.arrayField) !== null && _b !== void 0 ? _b : fieldPaths[0];
                    var arrayIndex = fieldPaths.findIndex(function (x) { return x == arrayField_1; });
                    var arrayName = fieldPaths.slice(0, arrayIndex + 1);
                    selectPaths.push(arrayName.join('.'));
                }
            }
        };
        try {
            for (var colDefs_1 = __values(colDefs), colDefs_1_1 = colDefs_1.next(); !colDefs_1_1.done; colDefs_1_1 = colDefs_1.next()) {
                var colDef = colDefs_1_1.value;
                _loop_2(colDef);
            }
        }
        catch (e_2_1) { e_2 = { error: e_2_1 }; }
        finally {
            try {
                if (colDefs_1_1 && !colDefs_1_1.done && (_a = colDefs_1.return)) _a.call(colDefs_1);
            }
            finally { if (e_2) throw e_2.error; }
        }
        if (this.additionalSelectPropertyPaths.length > 0) {
            selectPaths.push.apply(selectPaths, __spreadArray([], __read(this.additionalSelectPropertyPaths), false));
        }
        return selectPaths;
    };
    ListViewModelBase.prototype.convertFromString = function (variable, colDef) {
        try {
            if (colDef.type == common_model_1.FieldType.Number) {
                return parseFloat(variable);
            }
            else if (colDef.type == common_model_1.FieldType.Date) {
                return moment_1.default.utc(variable).local().toDate();
            }
        }
        catch (_a) {
            console.warn("Value '" + (variable === null || variable === void 0 ? void 0 : variable.toString()) + "' cannot be casted into number or date, fall back to string value");
        }
        return variable;
    };
    ListViewModelBase.prototype.convertFromObject = function (variable, colDef) {
        try {
            if (variable.hasOwnProperty("lang1")) {
                this.translatedPropertyHelper.addNecessaryProperties(variable, false);
            }
        }
        catch (_a) {
            console.warn((variable === null || variable === void 0 ? void 0 : variable.toString()) + " is not a valid translatedProperty");
        }
    };
    ListViewModelBase.prototype.buildArrayForManyToManyExpand = function (serviceExpands, tempObj, propertyPath, colDef) {
        var _a;
        if (((_a = colDef.floatingFilterComponentParams) === null || _a === void 0 ? void 0 : _a.service) != null) {
            var foreignKeyName = colDef.field.substring(colDef.field.indexOf(propertyPath + ".") + propertyPath.length + 1);
            foreignKeyName = foreignKeyName.substring(0, foreignKeyName.indexOf("."));
            var foreignKeyPropertyName_1 = foreignKeyName + "Id";
            var _loop_3 = function (indexM) {
                var element = tempObj[propertyPath][indexM];
                if (element[foreignKeyPropertyName_1] != null) {
                    var serviceExpand = serviceExpands.find(function (x) { return x.service.entityTypeName == colDef.floatingFilterComponentParams.service.entityTypeName; });
                    if (serviceExpand == null) {
                        serviceExpands.push({ service: colDef.floatingFilterComponentParams.service, neededIds: [{ neededId: element[foreignKeyPropertyName_1], entities: [element[foreignKeyName]] }] });
                    }
                    else {
                        var neededId = serviceExpand.neededIds.find(function (x) { return x.neededId == element[foreignKeyPropertyName_1]; });
                        if (neededId == null) {
                            serviceExpand.neededIds.push({ neededId: element[foreignKeyPropertyName_1], entities: [element[foreignKeyName]] });
                        }
                        else {
                            neededId.entities.push(element[foreignKeyName]);
                        }
                    }
                }
            };
            for (var indexM = 0; indexM < tempObj[propertyPath].length; indexM++) {
                _loop_3(indexM);
            }
        }
    };
    ListViewModelBase.prototype.fetchServiceExpands = function (serviceExpands) {
        return __awaiter(this, void 0, void 0, function () {
            var serviceExpands_1, serviceExpands_1_1, serviceExpand, neededIds, _a, _b, neededId, result, index, e_3_1, predicates, neededIds_1, neededIds_1_1, neededId, result, index, e_4_1, e_5_1;
            var e_5, _c, e_3, _d, e_4, _e;
            return __generator(this, function (_f) {
                switch (_f.label) {
                    case 0:
                        _f.trys.push([0, 20, 21, 22]);
                        serviceExpands_1 = __values(serviceExpands), serviceExpands_1_1 = serviceExpands_1.next();
                        _f.label = 1;
                    case 1:
                        if (!!serviceExpands_1_1.done) return [3, 19];
                        serviceExpand = serviceExpands_1_1.value;
                        neededIds = new Array();
                        _f.label = 2;
                    case 2:
                        _f.trys.push([2, 7, 8, 9]);
                        _a = (e_3 = void 0, __values(serviceExpand.neededIds)), _b = _a.next();
                        _f.label = 3;
                    case 3:
                        if (!!_b.done) return [3, 6];
                        neededId = _b.value;
                        return [4, serviceExpand.service.getEntityByIdFromLocalCache(neededId.neededId)];
                    case 4:
                        result = _f.sent();
                        if (result == null) {
                            neededIds.push(neededId);
                        }
                        else {
                            for (index = 0; index < neededId.entities.length; index++) {
                                neededId.entities[index] = result;
                            }
                        }
                        _f.label = 5;
                    case 5:
                        _b = _a.next();
                        return [3, 3];
                    case 6: return [3, 9];
                    case 7:
                        e_3_1 = _f.sent();
                        e_3 = { error: e_3_1 };
                        return [3, 9];
                    case 8:
                        try {
                            if (_b && !_b.done && (_d = _a.return)) _d.call(_a);
                        }
                        finally { if (e_3) throw e_3.error; }
                        return [7];
                    case 9:
                        if (!(neededIds.length > 0)) return [3, 18];
                        predicates = breeze.Predicate.or(neededIds.map(function (neededId) { return new breeze.Predicate("id", breeze.FilterQueryOp.Equals, neededId.neededId); }));
                        return [4, serviceExpand.service.getEntities(predicates)];
                    case 10:
                        _f.sent();
                        _f.label = 11;
                    case 11:
                        _f.trys.push([11, 16, 17, 18]);
                        neededIds_1 = (e_4 = void 0, __values(neededIds)), neededIds_1_1 = neededIds_1.next();
                        _f.label = 12;
                    case 12:
                        if (!!neededIds_1_1.done) return [3, 15];
                        neededId = neededIds_1_1.value;
                        return [4, serviceExpand.service.getEntityByIdFromLocalCache(neededId.neededId)];
                    case 13:
                        result = _f.sent();
                        for (index = 0; index < neededId.entities.length; index++) {
                            neededId.entities[index] = result;
                        }
                        _f.label = 14;
                    case 14:
                        neededIds_1_1 = neededIds_1.next();
                        return [3, 12];
                    case 15: return [3, 18];
                    case 16:
                        e_4_1 = _f.sent();
                        e_4 = { error: e_4_1 };
                        return [3, 18];
                    case 17:
                        try {
                            if (neededIds_1_1 && !neededIds_1_1.done && (_e = neededIds_1.return)) _e.call(neededIds_1);
                        }
                        finally { if (e_4) throw e_4.error; }
                        return [7];
                    case 18:
                        serviceExpands_1_1 = serviceExpands_1.next();
                        return [3, 1];
                    case 19: return [3, 22];
                    case 20:
                        e_5_1 = _f.sent();
                        e_5 = { error: e_5_1 };
                        return [3, 22];
                    case 21:
                        try {
                            if (serviceExpands_1_1 && !serviceExpands_1_1.done && (_c = serviceExpands_1.return)) _c.call(serviceExpands_1);
                        }
                        finally { if (e_5) throw e_5.error; }
                        return [7];
                    case 22: return [2];
                }
            });
        });
    };
    __decorate([
        aurelia_framework_1.observable,
        __metadata("design:type", Boolean)
    ], ListViewModelBase.prototype, "selectAll", void 0);
    __decorate([
        (0, aurelia_framework_1.computedFrom)("authService", "selectedEntities"),
        __metadata("design:type", Object),
        __metadata("design:paramtypes", [])
    ], ListViewModelBase.prototype, "canDelete", null);
    __decorate([
        aurelia_framework_1.observable,
        __metadata("design:type", String)
    ], ListViewModelBase.prototype, "filter", void 0);
    return ListViewModelBase;
}(view_model_base_1.ViewModelBase));

//# sourceMappingURL=list-view-model-base.js.map
