You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
abp/npm/ng-packs/dist/permission-management/esm5/lib/components/permission-management.compo...

493 lines
41 KiB

/**
* @fileoverview added by tsickle
* @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
import * as tslib_1 from "tslib";
import { Component, EventEmitter, Input, Output, Renderer2 } from '@angular/core';
import { Select, Store } from '@ngxs/store';
import { Observable } from 'rxjs';
import { map, pluck, take } from 'rxjs/operators';
import { GetPermissions, UpdatePermissions } from '../actions/permission-management.actions';
import { PermissionManagementState } from '../states/permission-management.state';
var PermissionManagementComponent = /** @class */ (function () {
function PermissionManagementComponent(store, renderer) {
this.store = store;
this.renderer = renderer;
this.visibleChange = new EventEmitter();
this.permissions = [];
this.selectThisTab = false;
this.selectAllTab = false;
this.modalBusy = false;
this.trackByFn = (/**
* @param {?} _
* @param {?} item
* @return {?}
*/
function (_, item) { return item.name; });
}
Object.defineProperty(PermissionManagementComponent.prototype, "visible", {
get: /**
* @return {?}
*/
function () {
return this._visible;
},
set: /**
* @param {?} value
* @return {?}
*/
function (value) {
if (!this.selectedGroup)
return;
this._visible = value;
this.visibleChange.emit(value);
if (!value) {
this.selectedGroup = null;
}
},
enumerable: true,
configurable: true
});
Object.defineProperty(PermissionManagementComponent.prototype, "selectedGroupPermissions$", {
get: /**
* @return {?}
*/
function () {
var _this = this;
return this.groups$.pipe(map((/**
* @param {?} groups
* @return {?}
*/
function (groups) {
return _this.selectedGroup ? groups.find((/**
* @param {?} group
* @return {?}
*/
function (group) { return group.name === _this.selectedGroup.name; })).permissions : [];
})), map((/**
* @param {?} permissions
* @return {?}
*/
function (permissions) {
return permissions.map((/**
* @param {?} permission
* @return {?}
*/
function (permission) {
return ((/** @type {?} */ (((/** @type {?} */ (tslib_1.__assign({}, permission, { margin: findMargin(permissions, permission), isGranted: _this.permissions.find((/**
* @param {?} per
* @return {?}
*/
function (per) { return per.name === permission.name; })).isGranted })))))));
}));
})));
},
enumerable: true,
configurable: true
});
/**
* @return {?}
*/
PermissionManagementComponent.prototype.ngOnInit = /**
* @return {?}
*/
function () { };
/**
* @param {?} name
* @return {?}
*/
PermissionManagementComponent.prototype.getChecked = /**
* @param {?} name
* @return {?}
*/
function (name) {
return (this.permissions.find((/**
* @param {?} per
* @return {?}
*/
function (per) { return per.name === name; })) || { isGranted: false }).isGranted;
};
/**
* @param {?} grantedProviders
* @return {?}
*/
PermissionManagementComponent.prototype.isGrantedByRole = /**
* @param {?} grantedProviders
* @return {?}
*/
function (grantedProviders) {
if (grantedProviders.length) {
return grantedProviders.findIndex((/**
* @param {?} p
* @return {?}
*/
function (p) { return p.providerName === 'Role'; })) > -1;
}
return false;
};
/**
* @param {?} clickedPermission
* @param {?} value
* @return {?}
*/
PermissionManagementComponent.prototype.onClickCheckbox = /**
* @param {?} clickedPermission
* @param {?} value
* @return {?}
*/
function (clickedPermission, value) {
var _this = this;
if (clickedPermission.isGranted && this.isGrantedByRole(clickedPermission.grantedProviders))
return;
setTimeout((/**
* @return {?}
*/
function () {
_this.permissions = _this.permissions.map((/**
* @param {?} per
* @return {?}
*/
function (per) {
if (clickedPermission.name === per.name) {
return tslib_1.__assign({}, per, { isGranted: !per.isGranted });
}
else if (clickedPermission.name === per.parentName && clickedPermission.isGranted) {
return tslib_1.__assign({}, per, { isGranted: false });
}
else if (clickedPermission.parentName === per.name && !clickedPermission.isGranted) {
return tslib_1.__assign({}, per, { isGranted: true });
}
return per;
}));
_this.setTabCheckboxState();
_this.setGrantCheckboxState();
}), 0);
};
/**
* @return {?}
*/
PermissionManagementComponent.prototype.setTabCheckboxState = /**
* @return {?}
*/
function () {
var _this = this;
this.selectedGroupPermissions$.pipe(take(1)).subscribe((/**
* @param {?} permissions
* @return {?}
*/
function (permissions) {
/** @type {?} */
var selectedPermissions = permissions.filter((/**
* @param {?} per
* @return {?}
*/
function (per) { return per.isGranted; }));
/** @type {?} */
var element = (/** @type {?} */ (document.querySelector('#select-all-in-this-tabs')));
if (selectedPermissions.length === permissions.length) {
element.indeterminate = false;
_this.selectThisTab = true;
}
else if (selectedPermissions.length === 0) {
element.indeterminate = false;
_this.selectThisTab = false;
}
else {
element.indeterminate = true;
}
}));
};
/**
* @return {?}
*/
PermissionManagementComponent.prototype.setGrantCheckboxState = /**
* @return {?}
*/
function () {
/** @type {?} */
var selectedAllPermissions = this.permissions.filter((/**
* @param {?} per
* @return {?}
*/
function (per) { return per.isGranted; }));
/** @type {?} */
var checkboxElement = (/** @type {?} */ (document.querySelector('#select-all-in-all-tabs')));
if (selectedAllPermissions.length === this.permissions.length) {
checkboxElement.indeterminate = false;
this.selectAllTab = true;
}
else if (selectedAllPermissions.length === 0) {
checkboxElement.indeterminate = false;
this.selectAllTab = false;
}
else {
checkboxElement.indeterminate = true;
}
};
/**
* @return {?}
*/
PermissionManagementComponent.prototype.onClickSelectThisTab = /**
* @return {?}
*/
function () {
var _this = this;
this.selectedGroupPermissions$.pipe(take(1)).subscribe((/**
* @param {?} permissions
* @return {?}
*/
function (permissions) {
permissions.forEach((/**
* @param {?} permission
* @return {?}
*/
function (permission) {
if (permission.isGranted && _this.isGrantedByRole(permission.grantedProviders))
return;
/** @type {?} */
var index = _this.permissions.findIndex((/**
* @param {?} per
* @return {?}
*/
function (per) { return per.name === permission.name; }));
_this.permissions = tslib_1.__spread(_this.permissions.slice(0, index), [
tslib_1.__assign({}, _this.permissions[index], { isGranted: !_this.selectThisTab })
], _this.permissions.slice(index + 1));
}));
}));
this.setGrantCheckboxState();
};
/**
* @return {?}
*/
PermissionManagementComponent.prototype.onClickSelectAll = /**
* @return {?}
*/
function () {
var _this = this;
this.permissions = this.permissions.map((/**
* @param {?} permission
* @return {?}
*/
function (permission) { return (tslib_1.__assign({}, permission, { isGranted: !_this.selectAllTab })); }));
this.selectThisTab = !this.selectAllTab;
};
/**
* @param {?} group
* @return {?}
*/
PermissionManagementComponent.prototype.onChangeGroup = /**
* @param {?} group
* @return {?}
*/
function (group) {
this.selectedGroup = group;
this.setTabCheckboxState();
};
/**
* @return {?}
*/
PermissionManagementComponent.prototype.submit = /**
* @return {?}
*/
function () {
var _this = this;
this.modalBusy = true;
/** @type {?} */
var unchangedPermissions = getPermissions(this.store.selectSnapshot(PermissionManagementState.getPermissionGroups));
/** @type {?} */
var changedPermissions = this.permissions
.filter((/**
* @param {?} per
* @return {?}
*/
function (per) {
return unchangedPermissions.find((/**
* @param {?} unchanged
* @return {?}
*/
function (unchanged) { return unchanged.name === per.name; })).isGranted === per.isGranted ? false : true;
}))
.map((/**
* @param {?} __0
* @return {?}
*/
function (_a) {
var name = _a.name, isGranted = _a.isGranted;
return ({ name: name, isGranted: isGranted });
}));
if (changedPermissions.length) {
this.store
.dispatch(new UpdatePermissions({
providerKey: this.providerKey,
providerName: this.providerName,
permissions: changedPermissions
}))
.subscribe((/**
* @return {?}
*/
function () {
_this.modalBusy = false;
_this.visible = false;
}));
}
else {
this.modalBusy = false;
this.visible = false;
}
};
/**
* @return {?}
*/
PermissionManagementComponent.prototype.openModal = /**
* @return {?}
*/
function () {
var _this = this;
if (!this.providerKey || !this.providerName) {
throw new Error('Provider Key and Provider Name are required.');
}
this.store
.dispatch(new GetPermissions({
providerKey: this.providerKey,
providerName: this.providerName
}))
.pipe(pluck('PermissionManagementState', 'permissionRes'))
.subscribe((/**
* @param {?} permissionRes
* @return {?}
*/
function (permissionRes) {
_this.selectedGroup = permissionRes.groups[0];
_this.permissions = getPermissions(permissionRes.groups);
_this.visible = true;
}));
};
/**
* @return {?}
*/
PermissionManagementComponent.prototype.initModal = /**
* @return {?}
*/
function () {
this.setTabCheckboxState();
this.setGrantCheckboxState();
};
/**
* @param {?} __0
* @return {?}
*/
PermissionManagementComponent.prototype.ngOnChanges = /**
* @param {?} __0
* @return {?}
*/
function (_a) {
var visible = _a.visible;
if (!visible)
return;
if (visible.currentValue) {
this.openModal();
}
else if (visible.currentValue === false && this.visible) {
this.visible = false;
}
};
PermissionManagementComponent.decorators = [
{ type: Component, args: [{
selector: 'abp-permission-management',
template: "<abp-modal [(visible)]=\"visible\" (init)=\"initModal()\" [busy]=\"modalBusy\">\n <ng-container *ngIf=\"{ entityName: entityName$ | async } as data\">\n <ng-template #abpHeader>\n <h4>{{ 'AbpPermissionManagement::Permissions' | abpLocalization }} - {{ data.entityName }}</h4>\n </ng-template>\n <ng-template #abpBody>\n <div class=\"custom-checkbox custom-control mb-2\">\n <input\n type=\"checkbox\"\n id=\"select-all-in-all-tabs\"\n name=\"select-all-in-all-tabs\"\n class=\"custom-control-input\"\n [(ngModel)]=\"selectAllTab\"\n (click)=\"onClickSelectAll()\"\n />\n <label class=\"custom-control-label\" for=\"select-all-in-all-tabs\">{{\n 'AbpPermissionManagement::SelectAllInAllTabs' | abpLocalization\n }}</label>\n </div>\n\n <hr class=\"mt-2 mb-2\" />\n <div class=\"row\">\n <div class=\"col-4\">\n <ul class=\"nav nav-pills flex-column\">\n <li *ngFor=\"let group of groups$ | async; trackBy: trackByFn\" class=\"nav-item\">\n <a\n class=\"nav-link pointer\"\n [class.active]=\"selectedGroup?.name === group?.name\"\n (click)=\"onChangeGroup(group)\"\n >{{ group?.displayName }}</a\n >\n </li>\n </ul>\n </div>\n <div class=\"col-8\">\n <h4>{{ selectedGroup?.displayName }}</h4>\n <hr class=\"mt-2 mb-3\" />\n <div class=\"pl-1 pt-1\">\n <div class=\"custom-checkbox custom-control mb-2\">\n <input\n type=\"checkbox\"\n id=\"select-all-in-this-tabs\"\n name=\"select-all-in-this-tabs\"\n class=\"custom-control-input\"\n [(ngModel)]=\"selectThisTab\"\n (click)=\"onClickSelectThisTab()\"\n />\n <label class=\"custom-control-label\" for=\"select-all-in-this-tabs\">{{\n 'AbpPermissionManagement::SelectAllInThisTab' | abpLocalization\n }}</label>\n </div>\n <hr class=\"mb-3\" />\n <div\n *ngFor=\"let permission of selectedGroupPermissions$ | async; let i = index; trackBy: trackByFn\"\n [style.margin-left]=\"permission.margin + 'px'\"\n class=\"custom-checkbox custom-control mb-2\"\n >\n <input\n #permissionCheckbox\n type=\"checkbox\"\n [checked]=\"getChecked(permission.name)\"\n [value]=\"getChecked(permission.name)\"\n [attr.id]=\"permission.name\"\n class=\"custom-control-input\"\n [disabled]=\"isGrantedByRole(permission.grantedProviders)\"\n />\n <label\n class=\"custom-control-label\"\n [attr.for]=\"permission.name\"\n (click)=\"onClickCheckbox(permission, permissionCheckbox.value)\"\n >{{ permission.displayName }}\n <span *ngFor=\"let provider of permission.grantedProviders\" class=\"badge badge-light\"\n >{{ provider.providerName }}: {{ provider.providerKey }}</span\n ></label\n >\n </div>\n </div>\n </div>\n </div>\n </ng-template>\n <ng-template #abpFooter>\n <button type=\"button\" class=\"btn btn-secondary\" #abpClose>\n {{ 'AbpIdentity::Cancel' | abpLocalization }}\n </button>\n <abp-button iconClass=\"fa fa-check\" (click)=\"submit()\">{{ 'AbpIdentity::Save' | abpLocalization }}</abp-button>\n </ng-template>\n </ng-container>\n</abp-modal>\n"
}] }
];
/** @nocollapse */
PermissionManagementComponent.ctorParameters = function () { return [
{ type: Store },
{ type: Renderer2 }
]; };
PermissionManagementComponent.propDecorators = {
providerName: [{ type: Input }],
providerKey: [{ type: Input }],
visible: [{ type: Input }],
visibleChange: [{ type: Output }]
};
tslib_1.__decorate([
Select(PermissionManagementState.getPermissionGroups),
tslib_1.__metadata("design:type", Observable)
], PermissionManagementComponent.prototype, "groups$", void 0);
tslib_1.__decorate([
Select(PermissionManagementState.getEntitiyDisplayName),
tslib_1.__metadata("design:type", Observable)
], PermissionManagementComponent.prototype, "entityName$", void 0);
return PermissionManagementComponent;
}());
export { PermissionManagementComponent };
if (false) {
/** @type {?} */
PermissionManagementComponent.prototype.providerName;
/** @type {?} */
PermissionManagementComponent.prototype.providerKey;
/**
* @type {?}
* @protected
*/
PermissionManagementComponent.prototype._visible;
/** @type {?} */
PermissionManagementComponent.prototype.visibleChange;
/** @type {?} */
PermissionManagementComponent.prototype.groups$;
/** @type {?} */
PermissionManagementComponent.prototype.entityName$;
/** @type {?} */
PermissionManagementComponent.prototype.selectedGroup;
/** @type {?} */
PermissionManagementComponent.prototype.permissions;
/** @type {?} */
PermissionManagementComponent.prototype.selectThisTab;
/** @type {?} */
PermissionManagementComponent.prototype.selectAllTab;
/** @type {?} */
PermissionManagementComponent.prototype.modalBusy;
/** @type {?} */
PermissionManagementComponent.prototype.trackByFn;
/**
* @type {?}
* @private
*/
PermissionManagementComponent.prototype.store;
/**
* @type {?}
* @private
*/
PermissionManagementComponent.prototype.renderer;
}
/**
* @param {?} permissions
* @param {?} permission
* @return {?}
*/
function findMargin(permissions, permission) {
/** @type {?} */
var parentPermission = permissions.find((/**
* @param {?} per
* @return {?}
*/
function (per) { return per.name === permission.parentName; }));
if (parentPermission && parentPermission.parentName) {
/** @type {?} */
var margin = 20;
return (margin += findMargin(permissions, parentPermission));
}
return parentPermission ? 20 : 0;
}
/**
* @param {?} groups
* @return {?}
*/
function getPermissions(groups) {
return groups.reduce((/**
* @param {?} acc
* @param {?} val
* @return {?}
*/
function (acc, val) { return tslib_1.__spread(acc, val.permissions); }), []);
}
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoicGVybWlzc2lvbi1tYW5hZ2VtZW50LmNvbXBvbmVudC5qcyIsInNvdXJjZVJvb3QiOiJuZzovL0BhYnAvbmcucGVybWlzc2lvbi1tYW5hZ2VtZW50LyIsInNvdXJjZXMiOlsibGliL2NvbXBvbmVudHMvcGVybWlzc2lvbi1tYW5hZ2VtZW50LmNvbXBvbmVudC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7OztBQUFBLE9BQU8sRUFDTCxTQUFTLEVBQ1QsWUFBWSxFQUNaLEtBQUssRUFHTCxNQUFNLEVBQ04sU0FBUyxFQUdWLE1BQU0sZUFBZSxDQUFDO0FBQ3ZCLE9BQU8sRUFBRSxNQUFNLEVBQUUsS0FBSyxFQUFFLE1BQU0sYUFBYSxDQUFDO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