"use strict";
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));
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.AgGridViewList = void 0;
var aurelia_router_1 = require("aurelia-router");
var aurelia_framework_1 = require("aurelia-framework");
var ui_anchor_tab_1 = require("../../../../ui/anchor-tab/ui-anchor-tab");
var box_1 = require("../../../../modules/box");
var custom_logger_1 = require("../../../../modules/custom-logger");
var data_context_1 = require("../../../../data/data-context");
var service_base_1 = require("../../../../data/service-base");
var constants_1 = require("../../../../constants/constants");
var aurelia_dependency_injection_1 = require("aurelia-dependency-injection");
var aurelia_templating_1 = require("aurelia-templating");
var aurelia_i18n_1 = require("aurelia-i18n");
var ag_grid_view_detail_1 = require("../../ag-grid-view-detail");
var ag_grid_view_service_1 = require("../../../../services/ag-grid-view-service");
var auth_service_1 = require("../../../../security/auth-service");
var config_1 = require("../../../../config");
var constants_2 = require("./../../../../constants/constants");
var AgGridViewList = exports.AgGridViewList = (function () {
    function AgGridViewList(i18n, config, authService, box, logger, bindingEngine, router, element) {
        var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
        this.i18n = i18n;
        this.config = config;
        this.authService = authService;
        this.box = box;
        this.logger = logger;
        this.bindingEngine = bindingEngine;
        this.router = router;
        this.element = element;
        this.allowSharedViews = false;
        this.viewsSeparatedByVisibility = false;
        this.showViewVisibiliyInList = true;
        this.showSystemViewOnlyAsPublicView = true;
        this.allViews = [];
        this.privateViews = [];
        this.publicViews = [];
        this.sharedViews = [];
        this.disposables = [];
        this.allowSharedViews = (_b = (_a = this.config) === null || _a === void 0 ? void 0 : _a.agGridConfig) === null || _b === void 0 ? void 0 : _b.allowSharedView;
        this.tabList = [
            new ui_anchor_tab_1.AnchorTab('Private', this.i18n.tr('common:aggridview.private'), true),
            new ui_anchor_tab_1.AnchorTab('Shared', this.i18n.tr('common:aggridview.shared'), this.allowSharedViews),
            new ui_anchor_tab_1.AnchorTab('Public', this.i18n.tr('common:aggridview.public'), true),
        ];
        this.gridViewService = new ag_grid_view_service_1.AgGridViewService();
        this.agGridViewUserService = new service_base_1.ServiceBase(constants_1.EntityTypeNames.AgGridViewUser);
        this.viewsSeparatedByVisibility = (_e = (_d = (_c = this.config) === null || _c === void 0 ? void 0 : _c.agGridConfig) === null || _d === void 0 ? void 0 : _d.separateViewsByVisibility) !== null && _e !== void 0 ? _e : false;
        this.showViewVisibiliyInList = (_h = (_g = (_f = this.config) === null || _f === void 0 ? void 0 : _f.agGridConfig) === null || _g === void 0 ? void 0 : _g.repeatViewVisibilityInListItem) !== null && _h !== void 0 ? _h : true;
        this.showSystemViewOnlyAsPublicView = (_l = (_k = (_j = this.config) === null || _j === void 0 ? void 0 : _j.agGridConfig) === null || _k === void 0 ? void 0 : _k.showSystemViewOnlyAsPublicView) !== null && _l !== void 0 ? _l : true;
    }
    AgGridViewList.prototype.agGridViewListChanged = function (newValue, oldValue) {
        this.viewsConstruct();
        if (newValue != null && newValue != oldValue) {
            this.addAgGridViewListObserver();
        }
    };
    AgGridViewList.prototype.bind = function () {
        if (this.agGridViewList != null) {
            this.viewsConstruct();
            this.addAgGridViewListObserver();
        }
    };
    AgGridViewList.prototype.detached = function () {
        var _a;
        if ((_a = this.disposables) === null || _a === void 0 ? void 0 : _a.length) {
            this.disposables.forEach(function (x) {
                x.dispose();
            });
        }
    };
    AgGridViewList.prototype.addAgGridViewListObserver = function () {
        var _this = this;
        this.disposables.push(this.bindingEngine.collectionObserver(this.agGridViewList).subscribe(function (changeRecords) {
            if ((changeRecords === null || changeRecords === void 0 ? void 0 : changeRecords.length) > 0) {
                _this.viewsConstruct();
            }
        }));
    };
    AgGridViewList.prototype.viewsConstruct = function () {
        var e_1, _a;
        var _b, _c, _d, _e;
        (_b = this.allViews) === null || _b === void 0 ? void 0 : _b.splice(0);
        (_c = this.privateViews) === null || _c === void 0 ? void 0 : _c.splice(0);
        (_d = this.publicViews) === null || _d === void 0 ? void 0 : _d.splice(0);
        (_e = this.sharedViews) === null || _e === void 0 ? void 0 : _e.splice(0);
        try {
            for (var _f = __values(this.agGridViewList), _g = _f.next(); !_g.done; _g = _f.next()) {
                var agGridView = _g.value;
                if (agGridView != null) {
                    var menuItems = new Array();
                    var canModifyView = this.canModifyAgGridView(agGridView);
                    if (canModifyView) {
                        menuItems.push.apply(menuItems, __spreadArray([], __read(this.menuItemAuthor(agGridView)), false));
                    }
                    else {
                        if (!agGridView.isDefaultView) {
                            menuItems.push(this.menuItemDuplicate(agGridView));
                        }
                    }
                    var newViewFilter = {
                        name: agGridView.name,
                        agGridView: agGridView,
                        visibility: this.getVisibilityTranslation(agGridView.visibility),
                        menuItems: menuItems,
                    };
                    switch (agGridView.visibility) {
                        case 'Public':
                            this.publicViews.push(newViewFilter);
                            break;
                        case 'Private':
                            this.privateViews.push(newViewFilter);
                            break;
                        case 'Shared':
                            if (this.allowSharedViews) {
                                this.sharedViews.push(newViewFilter);
                            }
                            break;
                        case 'System':
                            this.publicViews.push(newViewFilter);
                            if (!this.showSystemViewOnlyAsPublicView) {
                                this.privateViews.push(newViewFilter);
                                if (this.allowSharedViews) {
                                    this.sharedViews.push(newViewFilter);
                                }
                            }
                            break;
                    }
                    this.allViews.push(newViewFilter);
                }
            }
        }
        catch (e_1_1) { e_1 = { error: e_1_1 }; }
        finally {
            try {
                if (_g && !_g.done && (_a = _f.return)) _a.call(_f);
            }
            finally { if (e_1) throw e_1.error; }
        }
    };
    AgGridViewList.prototype.canModifyAgGridView = function (agGridView) {
        var _this = this;
        var _a, _b;
        if (this.showAllView) {
            return true;
        }
        else if (agGridView.visibility == 'System' &&
            this.config.agGridConfig.administratorRoles != null &&
            ((_a = this.authService.currentUser) === null || _a === void 0 ? void 0 : _a.roles) != null &&
            this.authService.currentUser.roles.some(function (role) { return _this.config.agGridConfig.administratorRoles.includes(role); })) {
            return true;
        }
        return ((_b = this.authService.currentUser) === null || _b === void 0 ? void 0 : _b.id) == agGridView.authorId && (agGridView.visibility == 'Public' || agGridView.visibility == 'Private' || agGridView.visibility == 'Shared');
    };
    AgGridViewList.prototype.menuItemAuthor = function (agGridView) {
        var _this = this;
        var menuItemsAuthor = [
            {
                group: '1',
                hiddenLabel: true,
                items: [
                    {
                        label: this.i18n.tr('common:general.edit'),
                        icon: 'digi-edit',
                        handler: function () { return __awaiter(_this, void 0, void 0, function () {
                            return __generator(this, function (_a) {
                                switch (_a.label) {
                                    case 0: return [4, this.modifyAgGridView(agGridView)];
                                    case 1:
                                        _a.sent();
                                        return [2];
                                }
                            });
                        }); },
                    },
                    !agGridView.isDefaultView ? this.menuItemDuplicate(agGridView) : null,
                    agGridView.visibility == 'Private' && this.showAllView ? this.menuItemCanShowAll(agGridView) : null,
                ],
            },
        ];
        if (!this.isDefaultView(agGridView)) {
            menuItemsAuthor.push({
                label: this.i18n.tr('common:general.remove'),
                icon: 'digi-trash',
                handler: function (data) { return __awaiter(_this, void 0, void 0, function () {
                    return __generator(this, function (_a) {
                        switch (_a.label) {
                            case 0: return [4, this.deleteAgGridView(agGridView)];
                            case 1:
                                _a.sent();
                                this.viewsConstruct();
                                return [2];
                        }
                    });
                }); },
            });
        }
        return menuItemsAuthor;
    };
    AgGridViewList.prototype.menuItemDuplicate = function (agGridView) {
        var _this = this;
        return {
            label: this.i18n.tr('common:general.duplicate'),
            icon: 'digi-copy',
            handler: function (data) { return __awaiter(_this, void 0, void 0, function () {
                return __generator(this, function (_a) {
                    switch (_a.label) {
                        case 0: return [4, this.duplicateAgGridView(agGridView)];
                        case 1:
                            _a.sent();
                            this.viewsConstruct();
                            return [2];
                    }
                });
            }); },
        };
    };
    AgGridViewList.prototype.menuItemCanShowAll = function (agGridView) {
        var _this = this;
        return {
            label: this.i18n.tr('common:general.specificCopy'),
            icon: 'digi-copy',
            handler: function (data) { return __awaiter(_this, void 0, void 0, function () {
                return __generator(this, function (_a) {
                    switch (_a.label) {
                        case 0: return [4, this.copyAgGridView(agGridView)];
                        case 1:
                            _a.sent();
                            this.viewsConstruct();
                            return [2];
                    }
                });
            }); },
        };
    };
    AgGridViewList.prototype.getVisibilityTranslation = function (visibility) {
        if (visibility == 'Private') {
            return this.i18n.tr('common:aggridview.private');
        }
        else if (visibility == 'Public') {
            return this.i18n.tr('common:aggridview.public');
        }
        else if (visibility == 'Shared') {
            return this.i18n.tr('common:aggridview.shared');
        }
        else if (visibility == 'System') {
            return '';
        }
    };
    AgGridViewList.prototype.modifyAgGridView = function (agGridView) {
        return __awaiter(this, void 0, void 0, function () {
            var buttonSave, buttonCancel;
            var _this = this;
            return __generator(this, function (_a) {
                if (this.canModifyAgGridView(agGridView)) {
                    buttonSave = {
                        label: this.i18n.tr('general.save', { ns: 'common' }),
                        title: this.i18n.tr('general.save', { ns: 'common' }),
                        theme: 'primary',
                        type: 'solid',
                        disabled: false,
                        fn: function (thisBox) {
                            thisBox.controller.ok();
                        },
                        keyboardShortcut: this.config.globalConfig.keyboardShortcutFwBox ? constants_2.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 ? [constants_2.KeyboardShortcut.Escape, constants_2.KeyboardShortcut.Backspace] : null
                    };
                    this.box.showQuestion(this.i18n.tr('general.doYouWantToSave', { ns: 'common' }), this.i18n.tr('view.view', { ns: 'common' }), [buttonCancel, buttonSave]).then(function (selectedOption) {
                        selectedOption.closeResult.then(function (result) { return __awaiter(_this, void 0, void 0, function () {
                            var isDefaultModified, defaultView;
                            var _a, _b;
                            return __generator(this, function (_c) {
                                switch (_c.label) {
                                    case 0:
                                        if (!!result.wasCancelled) return [3, 4];
                                        isDefaultModified = this.isDefaultView(agGridView);
                                        if (!isDefaultModified) return [3, 2];
                                        return [4, this.gridViewService.createEntity({
                                                name: agGridView.name,
                                                moduleId: agGridView.moduleId,
                                                visibility: agGridView.visibility,
                                                authorId: agGridView.authorId,
                                                isDefaultView: true,
                                            })];
                                    case 1:
                                        defaultView = _c.sent();
                                        this.agGridViewList.splice(this.agGridViewList.indexOf(agGridView), 1, defaultView);
                                        agGridView = defaultView;
                                        _c.label = 2;
                                    case 2:
                                        agGridView.columnState = JSON.stringify(this.gridOptions.columnApi.getColumnState());
                                        agGridView.filterModel = JSON.stringify(this.gridOptions.api.getFilterModel());
                                        agGridView.fixedFilters = (_a = this.gridOptions.fixedFilters) !== null && _a !== void 0 ? _a : false;
                                        agGridView.adjustColumns = (_b = this.gridOptions.adjustColumns) !== null && _b !== void 0 ? _b : this.config.agGridConfig.defaultAdjustColumns;
                                        return [4, this.gridViewService.saveEntity(agGridView, true)];
                                    case 3:
                                        _c.sent();
                                        this.logger.Log(this.i18n.tr('grid.viewModified', { ns: 'common' }), null, 'CustomAgGrid', true);
                                        if (isDefaultModified) {
                                            this.setAgGridView(agGridView);
                                        }
                                        _c.label = 4;
                                    case 4: return [2];
                                }
                            });
                        }); });
                    });
                }
                return [2];
            });
        });
    };
    AgGridViewList.prototype.deleteAgGridView = function (agGridView) {
        var _a;
        return __awaiter(this, void 0, void 0, function () {
            var isDeleted, _b;
            return __generator(this, function (_c) {
                switch (_c.label) {
                    case 0:
                        if (!this.canModifyAgGridView(agGridView)) return [3, 7];
                        if (!(((_a = agGridView.agGridViewUsers) === null || _a === void 0 ? void 0 : _a.length) > 0)) return [3, 2];
                        return [4, this.agGridViewUserService.deleteEntities(__spreadArray([], __read(agGridView.agGridViewUsers), false), true, null)];
                    case 1:
                        _c.sent();
                        _c.label = 2;
                    case 2: return [4, this.gridViewService.deleteEntities([agGridView], true)];
                    case 3:
                        isDeleted = _c.sent();
                        if (!isDeleted) return [3, 7];
                        if (!agGridView.isDefaultView) return [3, 6];
                        if (!(this.defaultAgGridView == null)) return [3, 5];
                        _b = this;
                        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 4:
                        _b.defaultAgGridView = _c.sent();
                        _c.label = 5;
                    case 5:
                        this.agGridViewList.unshift(this.defaultAgGridView);
                        this.defaultAgGridView.entityAspect.setDetached();
                        _c.label = 6;
                    case 6:
                        this.agGridViewList.remove(agGridView);
                        this.logger.Log(this.i18n.tr('grid.viewDeleted', { ns: 'common' }), null, 'CustomAgGrid', true);
                        if (agGridView.used) {
                            this.setAgGridView(this.defaultAgGridView);
                        }
                        _c.label = 7;
                    case 7: return [2];
                }
            });
        });
    };
    AgGridViewList.prototype.duplicateAgGridView = 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
                            .showEditDialog(ag_grid_view_detail_1.AgGridViewDetail, -100, this.i18n.tr('common:grid.duplicate', { ns: 'common' }), new box_1.ShowEditDialogOptions({
                            callback: function (createdEntity) { return __awaiter(_this, void 0, void 0, function () {
                                var _a;
                                return __generator(this, function (_b) {
                                    switch (_b.label) {
                                        case 0:
                                            (createdEntity.name = agGridView.name + '_Copy'), (createdEntity.moduleId = agGridView.moduleId), (createdEntity.fixedFilters = agGridView.fixedFilters), (createdEntity.adjustColumns = agGridView.adjustColumns), (createdEntity.columnState = agGridView.columnState), (createdEntity.filterModel = agGridView.filterModel), (createdEntity.visibility = agGridView.visibility);
                                            _a = createdEntity;
                                            return [4, this.duplicateAgGridViewUser(agGridView, createdEntity)];
                                        case 1:
                                            (_a.agGridViewUsers = _b.sent());
                                            return [2];
                                    }
                                });
                            }); },
                            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.setAgGridView({ agGridView: createdAgGridView });
                            }
                        })];
                    case 1:
                        _a.sent();
                        return [2];
                }
            });
        });
    };
    AgGridViewList.prototype.duplicateAgGridViewUser = function (oldAgGridView, newEntity) {
        return __awaiter(this, void 0, void 0, function () {
            var _a, _b, agGridViewUser, newAgGridViewUser, e_2_1;
            var e_2, _c;
            return __generator(this, function (_d) {
                switch (_d.label) {
                    case 0:
                        if (!(oldAgGridView.agGridViewUsers != null)) return [3, 8];
                        _d.label = 1;
                    case 1:
                        _d.trys.push([1, 6, 7, 8]);
                        _a = __values(oldAgGridView.agGridViewUsers), _b = _a.next();
                        _d.label = 2;
                    case 2:
                        if (!!_b.done) return [3, 5];
                        agGridViewUser = _b.value;
                        return [4, this.agGridViewUserService.createEntity()];
                    case 3:
                        newAgGridViewUser = _d.sent();
                        newAgGridViewUser.agGridView = newEntity;
                        newAgGridViewUser.userId = agGridViewUser.userId;
                        newAgGridViewUser.user = agGridViewUser.user;
                        _d.label = 4;
                    case 4:
                        _b = _a.next();
                        return [3, 2];
                    case 5: return [3, 8];
                    case 6:
                        e_2_1 = _d.sent();
                        e_2 = { error: e_2_1 };
                        return [3, 8];
                    case 7:
                        try {
                            if (_b && !_b.done && (_c = _a.return)) _c.call(_a);
                        }
                        finally { if (e_2) throw e_2.error; }
                        return [7];
                    case 8: return [2, newEntity.agGridViewUsers];
                }
            });
        });
    };
    AgGridViewList.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 service_base_1.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_3_1;
                                var e_3, _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_3_1 = _c.sent();
                                            e_3 = { error: e_3_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_3) throw e_3.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];
                }
            });
        });
    };
    AgGridViewList.prototype.isDefaultView = function (agGridView) {
        return agGridView != null && agGridView.isDefaultView && agGridView.id == -100;
    };
    __decorate([
        aurelia_templating_1.bindable,
        __metadata("design:type", Boolean)
    ], AgGridViewList.prototype, "showAllView", void 0);
    __decorate([
        aurelia_templating_1.bindable,
        __metadata("design:type", Object)
    ], AgGridViewList.prototype, "gridOptions", void 0);
    __decorate([
        aurelia_templating_1.bindable,
        __metadata("design:type", Object)
    ], AgGridViewList.prototype, "defaultAgGridView", void 0);
    __decorate([
        aurelia_templating_1.bindable,
        __metadata("design:type", Boolean)
    ], AgGridViewList.prototype, "fixedFiltersObserverDisabled", void 0);
    __decorate([
        aurelia_templating_1.bindable,
        __metadata("design:type", Boolean)
    ], AgGridViewList.prototype, "showFilterBox", void 0);
    __decorate([
        aurelia_templating_1.bindable,
        __metadata("design:type", data_context_1.Datacontext)
    ], AgGridViewList.prototype, "datacontext", void 0);
    __decorate([
        aurelia_templating_1.bindable,
        __metadata("design:type", String)
    ], AgGridViewList.prototype, "agGridSearch", void 0);
    __decorate([
        aurelia_templating_1.bindable,
        __metadata("design:type", Array)
    ], AgGridViewList.prototype, "agGridViewList", void 0);
    __decorate([
        aurelia_templating_1.bindable,
        __metadata("design:type", Function)
    ], AgGridViewList.prototype, "setAgGridView", void 0);
    __decorate([
        aurelia_templating_1.bindable,
        __metadata("design:type", Function)
    ], AgGridViewList.prototype, "afterSetAgGridView", void 0);
    AgGridViewList = __decorate([
        aurelia_dependency_injection_1.autoinject,
        (0, aurelia_templating_1.customElement)('ag-grid-view-list'),
        __metadata("design:paramtypes", [aurelia_i18n_1.I18N,
            config_1.Config,
            auth_service_1.AuthService,
            box_1.Box,
            custom_logger_1.CustomLogger,
            aurelia_framework_1.BindingEngine,
            aurelia_router_1.Router,
            Element])
    ], AgGridViewList);
    return AgGridViewList;
}());

//# sourceMappingURL=ag-grid-view-list.js.map
