import { __assign, __decorate, __metadata } from "tslib";
import { Component } from '@angular/core';
import { PersistedGrantVO } from '../vo/persisted-grant.vo';
import { NzMessageService } from 'ng-zorro-antd/message';
import { TranslateService } from '@ngx-translate/core';
import { API } from '../../../api';
var IdentityPersistedGrantsComponent = /** @class */ (function () {
    function IdentityPersistedGrantsComponent(nzMessageService, translateService) {
        this.nzMessageService = nzMessageService;
        this.translateService = translateService;
        this.listParam = new API.Identity.PersistedGrantController.ListParam({
            pageIndex: 1,
            pageSize: 10,
        });
        this.persistedGrantsFetching = false;
        this.persistedGrantsTotal = 0;
        this.persistedGrants = [];
    }
    IdentityPersistedGrantsComponent.prototype.ngOnInit = function () {
        this.fetchPersistedGrants(true);
    };
    IdentityPersistedGrantsComponent.prototype.fetchPersistedGrants = function (fromStart) {
        var _this = this;
        if (fromStart === void 0) { fromStart = false; }
        if (fromStart) {
            this.listParam.pageIndex = 1;
        }
        this.persistedGrantsFetching = true;
        API.Identity.PersistedGrantController.List(__assign(__assign({}, this.listParam), { pageIndex: this.listParam.pageIndex === undefined ? 0 : this.listParam.pageIndex - 1 })).subscribe({
            next: function (_a) {
                var items = _a.items, total = _a.total;
                _this.persistedGrantsTotal = total;
                _this.persistedGrants = PersistedGrantVO.fromArray(items);
                _this.persistedGrantsFetching = false;
            },
            error: function () {
                _this.persistedGrantsFetching = false;
            },
        });
    };
    IdentityPersistedGrantsComponent.prototype.deletePersistedGrant = function (item) {
        var _this = this;
        item.deleting = true;
        API.Identity.PersistedGrantController.Remove({
            id: item.key,
        }).subscribe({
            next: function () {
                item.deleting = false;
                _this.nzMessageService.success(_this.translateService.instant('projects/fe-ng/src/lib/page/identity/persisted-grants/identity--persisted-grants.delete_successfully'));
                _this.fetchPersistedGrants(true);
            },
            error: function () {
                item.deleting = false;
            },
        });
    };
    IdentityPersistedGrantsComponent.prototype.handlePageIndexChange = function (pageIndex) {
        this.listParam.pageIndex = pageIndex;
        this.fetchPersistedGrants();
    };
    IdentityPersistedGrantsComponent.prototype.handlePageSizeChange = function (pageSize) {
        this.listParam.pageSize = pageSize;
        this.fetchPersistedGrants(true);
    };
    IdentityPersistedGrantsComponent.ctorParameters = function () { return [
        { type: NzMessageService },
        { type: TranslateService }
    ]; };
    IdentityPersistedGrantsComponent = __decorate([
        Component({
            selector: 'kg---identity--persisted-grants',
            template: "<page-header title=\"\"></page-header>\r\n\r\n<nz-card\r\n  [ngStyle]=\"{\r\n    marginBottom: '0px',\r\n    height: 'calc(100% - 42px)'\r\n  }\"\r\n  [nzBodyStyle]=\"{\r\n    padding: '10px',\r\n    height: '100%'\r\n  }\"\r\n  [nzBordered]=\"false\"\r\n>\r\n  <div>\r\n    <button\r\n      (click)=\"fetchPersistedGrants(true)\"\r\n      [ngStyle]=\"{\r\n        float: 'left',\r\n        marginBottom: '10px'\r\n      }\"\r\n      [nzLoading]=\"persistedGrantsFetching\"\r\n      class=\"btn-outline-primary\"\r\n      nz-button\r\n    >\r\n      <i nz-icon nzType=\"reload\" nzTheme=\"outline\"></i>\r\n      {{ 'app.common.refresh' | i18n }}\r\n    </button>\r\n  </div>\r\n\r\n  <nz-table\r\n    #table\r\n    (nzPageIndexChange)=\"handlePageIndexChange($event)\"\r\n    (nzPageSizeChange)=\"handlePageSizeChange($event)\"\r\n    [className]=\"'table-responsive'\"\r\n    [ngStyle]=\"{ marginTop: '10px', clear: 'both' }\"\r\n    [nzData]=\"persistedGrants\"\r\n    [nzFrontPagination]=\"false\"\r\n    [nzLoadingIndicator]=\"loadingIndicatorTpl\"\r\n    [nzLoading]=\"persistedGrantsFetching\"\r\n    [nzPageIndex]=\"listParam.pageIndex\"\r\n    [nzPageSize]=\"listParam.pageSize\"\r\n    [nzScroll]=\"{ x: '1800px', y: 'auto' }\"\r\n    [nzShowQuickJumper]=\"true\"\r\n    [nzShowSizeChanger]=\"true\"\r\n    [nzShowTotal]=\"totalTpl\"\r\n    [nzTotal]=\"persistedGrantsTotal\"\r\n    [nzWidthConfig]=\"['160px', '300px', '200px', '140px', '160px', '200px', '300px', '140px', '200px']\"\r\n    nzSize=\"small\"\r\n  >\r\n    <thead>\r\n      <tr>\r\n        <th>\r\n          {{ 'projects/fe-ng/src/lib/page/identity/persisted-grants/identity--persisted-grants.creation_time' | i18n }}\r\n        </th>\r\n        <th>\r\n          {{ 'projects/fe-ng/src/lib/page/identity/persisted-grants/identity--persisted-grants.client_id' | i18n }}\r\n        </th>\r\n        <th>\r\n          {{ 'projects/fe-ng/src/lib/page/identity/persisted-grants/identity--persisted-grants.data' | i18n }}\r\n        </th>\r\n        <th>\r\n          {{ 'projects/fe-ng/src/lib/page/identity/persisted-grants/identity--persisted-grants.email' | i18n }}\r\n        </th>\r\n        <th>\r\n          {{ 'projects/fe-ng/src/lib/page/identity/persisted-grants/identity--persisted-grants.expiration' | i18n }}\r\n        </th>\r\n        <th>\r\n          {{ 'projects/fe-ng/src/lib/page/identity/persisted-grants/identity--persisted-grants.key' | i18n }}\r\n        </th>\r\n        <th>\r\n          {{ 'projects/fe-ng/src/lib/page/identity/persisted-grants/identity--persisted-grants.subject_id' | i18n }}\r\n        </th>\r\n        <th>\r\n          {{ 'projects/fe-ng/src/lib/page/identity/persisted-grants/identity--persisted-grants.type' | i18n }}\r\n        </th>\r\n        <th [nzRight]=\"'0px'\" class=\"text-center\">{{ 'app.common.action' | i18n }}</th>\r\n      </tr>\r\n    </thead>\r\n\r\n    <tbody>\r\n      <ng-container *ngFor=\"let item of table.data\">\r\n        <tr>\r\n          <td>{{ item.creationTime | kgDate }}</td>\r\n\r\n          <td>{{ item.clientId }}</td>\r\n\r\n          <td>{{ item.data }}</td>\r\n\r\n          <td>{{ item.email }}</td>\r\n\r\n          <td>{{ item.expiration | kgDate }}</td>\r\n\r\n          <td>{{ item.key }}</td>\r\n\r\n          <td>{{ item.subjectId }}</td>\r\n\r\n          <td>{{ item.type }}</td>\r\n\r\n          <td class=\"text-right\" [nzRight]=\"'0px'\">\r\n            <button\r\n              (nzOnConfirm)=\"deletePersistedGrant(item)\"\r\n              [ngStyle]=\"{ height: '28px' }\"\r\n              [nzLoading]=\"item.deleting\"\r\n              [nzPopconfirmTitle]=\"'app.common.confirm-deletion' | i18n\"\r\n              class=\"btn-outline-warning\"\r\n              nz-button\r\n              nz-popconfirm\r\n              nzPopconfirmPlacement=\"topRight\"\r\n              nzSize=\"small\"\r\n            >\r\n              <i nz-icon nzType=\"delete\" nzTheme=\"outline\"></i>\r\n              {{ 'app.common.delete' | i18n }}\r\n            </button>\r\n          </td>\r\n        </tr>\r\n      </ng-container>\r\n    </tbody>\r\n\r\n    <ng-template #loadingIndicatorTpl>\r\n      <i\r\n        [ngStyle]=\"{\r\n          fontSize: '24px',\r\n          marginTop: '10px'\r\n        }\"\r\n        nz-icon\r\n        nzTheme=\"outline\"\r\n        nzType=\"loading\"\r\n      ></i>\r\n    </ng-template>\r\n\r\n    <ng-template #totalTpl let-range=\"range\" let-total>\r\n      {{ 'app.common.st-page-total' | i18n: { total: total, 'range[0]': range[0], 'range[1]': range[1] } }}\r\n    </ng-template>\r\n  </nz-table>\r\n</nz-card>\r\n",
            styles: [":host ::ng-deep .ant-card{margin-bottom:10px}:host ::ng-deep .ant-card .ant-card-head{min-height:auto;padding:0 12px}:host ::ng-deep nz-table.table-responsive{height:calc(100% - 83px)}:host ::ng-deep nz-table.table-responsive .ant-table-placeholder{height:calc(100% - 90px)}:host ::ng-deep nz-table.table-responsive .ant-spin-nested-loading .ant-spin-container .ant-table .ant-table-content .ant-table-scroll .ant-table-body{height:calc(100% - 37px)!important}:host ::ng-deep nz-table.table-responsive.table-responsive.ant-table-empty .ant-spin-nested-loading .ant-spin-container .ant-table .ant-table-content .ant-table-scroll .ant-table-body{height:0!important}"]
        }),
        __metadata("design:paramtypes", [NzMessageService, TranslateService])
    ], IdentityPersistedGrantsComponent);
    return IdentityPersistedGrantsComponent;
}());
export { IdentityPersistedGrantsComponent };
//# sourceMappingURL=data:application/json;base64, 