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/bundles/abp-ng.permission-managemen...

453 lines
18 KiB

!(function(e, n) {
'object' == typeof exports && 'undefined' != typeof module
? n(
exports,
require('@abp/ng.core'),
require('@abp/ng.theme.shared'),
require('@angular/core'),
require('@ngxs/store'),
require('rxjs'),
require('rxjs/operators'),
)
: 'function' == typeof define && define.amd
? define('@abp/ng.permission-management', [
'exports',
'@abp/ng.core',
'@abp/ng.theme.shared',
'@angular/core',
'@ngxs/store',
'rxjs',
'rxjs/operators',
], n)
: n(
(((e = e || self).abp = e.abp || {}), (e.abp.ng = e.abp.ng || {}), (e.abp.ng['permission-management'] = {})),
e.ng_core,
e.ng_theme_shared,
e.ng.core,
e.store,
e.rxjs,
e.rxjs.operators,
);
})(this, function(e, n, t, i, r, s, o) {
'use strict';
/*! *****************************************************************************
Copyright (c) Microsoft Corporation. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
this file except in compliance with the License. You may obtain a copy of the
License at http://www.apache.org/licenses/LICENSE-2.0
THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
MERCHANTABLITY OR NON-INFRINGEMENT.
See the Apache Version 2.0 License for specific language governing permissions
and limitations under the License.
***************************************************************************** */ var a = function() {
return (a =
Object.assign ||
function(e) {
for (var n, t = 1, i = arguments.length; t < i; t++)
for (var r in (n = arguments[t])) Object.prototype.hasOwnProperty.call(n, r) && (e[r] = n[r]);
return e;
}).apply(this, arguments);
};
function c(e, n, t, i) {
var r,
s = arguments.length,
o = s < 3 ? n : null === i ? (i = Object.getOwnPropertyDescriptor(n, t)) : i;
if ('object' == typeof Reflect && 'function' == typeof Reflect.decorate) o = Reflect.decorate(e, n, t, i);
else for (var a = e.length - 1; a >= 0; a--) (r = e[a]) && (o = (s < 3 ? r(o) : s > 3 ? r(n, t, o) : r(n, t)) || o);
return s > 3 && o && Object.defineProperty(n, t, o), o;
}
function p(e, n) {
if ('object' == typeof Reflect && 'function' == typeof Reflect.metadata) return Reflect.metadata(e, n);
}
function l(e, n) {
var t = 'function' == typeof Symbol && e[Symbol.iterator];
if (!t) return e;
var i,
r,
s = t.call(e),
o = [];
try {
for (; (void 0 === n || n-- > 0) && !(i = s.next()).done; ) o.push(i.value);
} catch (e) {
r = { error: e };
} finally {
try {
i && !i.done && (t = s.return) && t.call(s);
} finally {
if (r) throw r.error;
}
}
return o;
}
function u() {
for (var e = [], n = 0; n < arguments.length; n++) e = e.concat(l(arguments[n]));
return e;
}
var m = (function() {
function e(e) {
this.payload = e;
}
return (e.type = '[PermissionManagement] Get Permissions'), e;
})();
var d = (function() {
function e(e) {
this.payload = e;
}
return (e.type = '[PermissionManagement] Update Permissions'), e;
})();
var b = (function() {
function e(e) {
this.rest = e;
}
return (
(e.prototype.getPermissions = function(e) {
var n = { method: 'GET', url: '/api/abp/permissions', params: e };
return this.rest.request(n);
}),
(e.prototype.updatePermissions = function(e) {
var n = {
method: 'PUT',
url: '/api/abp/permissions',
body: { permissions: e.permissions },
params: { providerKey: e.providerKey, providerName: e.providerName },
};
return this.rest.request(n);
}),
(e.decorators = [{ type: i.Injectable, args: [{ providedIn: 'root' }] }]),
(e.ctorParameters = function() {
return [{ type: n.RestService }];
}),
(e.ngInjectableDef = i.ɵɵdefineInjectable({
factory: function() {
return new e(i.ɵɵinject(n.RestService));
},
token: e,
providedIn: 'root',
})),
e
);
})();
var f = (function() {
function e(e) {
this.permissionManagementService = e;
}
return (
(e.getPermissionGroups = function(e) {
return e.permissionRes.groups || [];
}),
(e.getEntitiyDisplayName = function(e) {
return e.permissionRes.entityDisplayName;
}),
(e.prototype.permissionManagementGet = function(e, n) {
var t = e.patchState,
i = n.payload;
return this.permissionManagementService.getPermissions(i).pipe(
o.tap(function(e) {
return t({ permissionRes: e });
}),
);
}),
(e.prototype.permissionManagementUpdate = function(e, n) {
var t = n.payload;
return this.permissionManagementService.updatePermissions(t);
}),
(e.ctorParameters = function() {
return [{ type: b }];
}),
c(
[r.Action(m), p('design:type', Function), p('design:paramtypes', [Object, m]), p('design:returntype', void 0)],
e.prototype,
'permissionManagementGet',
null,
),
c(
[r.Action(d), p('design:type', Function), p('design:paramtypes', [Object, d]), p('design:returntype', void 0)],
e.prototype,
'permissionManagementUpdate',
null,
),
c(
[r.Selector(), p('design:type', Function), p('design:paramtypes', [Object]), p('design:returntype', void 0)],
e,
'getPermissionGroups',
null,
),
c(
[r.Selector(), p('design:type', Function), p('design:paramtypes', [Object]), p('design:returntype', String)],
e,
'getEntitiyDisplayName',
null,
),
(e = c(
[r.State({ name: 'PermissionManagementState', defaults: { permissionRes: {} } }), p('design:paramtypes', [b])],
e,
))
);
})();
var h = (function() {
function e(e, n) {
(this.store = e),
(this.renderer = n),
(this.visibleChange = new i.EventEmitter()),
(this.permissions = []),
(this.selectThisTab = !1),
(this.selectAllTab = !1),
(this.modalBusy = !1),
(this.trackByFn = function(e, n) {
return n.name;
});
}
return (
Object.defineProperty(e.prototype, 'visible', {
get: function() {
return this._visible;
},
set: function(e) {
this.selectedGroup && ((this._visible = e), this.visibleChange.emit(e), e || (this.selectedGroup = null));
},
enumerable: !0,
configurable: !0,
}),
Object.defineProperty(e.prototype, 'selectedGroupPermissions$', {
get: function() {
var e = this;
return this.groups$.pipe(
o.map(function(n) {
return e.selectedGroup
? n.find(function(n) {
return n.name === e.selectedGroup.name;
}).permissions
: [];
}),
o.map(function(n) {
return n.map(function(t) {
return a({}, t, {
margin: y(n, t),
isGranted: e.permissions.find(function(e) {
return e.name === t.name;
}).isGranted,
});
});
}),
);
},
enumerable: !0,
configurable: !0,
}),
(e.prototype.ngOnInit = function() {}),
(e.prototype.getChecked = function(e) {
return (
this.permissions.find(function(n) {
return n.name === e;
}) || { isGranted: !1 }
).isGranted;
}),
(e.prototype.isGrantedByRole = function(e) {
return (
!!e.length &&
e.findIndex(function(e) {
return 'Role' === e.providerName;
}) > -1
);
}),
(e.prototype.onClickCheckbox = function(e, n) {
var t = this;
(e.isGranted && this.isGrantedByRole(e.grantedProviders)) ||
setTimeout(function() {
(t.permissions = t.permissions.map(function(n) {
return e.name === n.name
? a({}, n, { isGranted: !n.isGranted })
: e.name === n.parentName && e.isGranted
? a({}, n, { isGranted: !1 })
: e.parentName !== n.name || e.isGranted
? n
: a({}, n, { isGranted: !0 });
})),
t.setTabCheckboxState(),
t.setGrantCheckboxState();
}, 0);
}),
(e.prototype.setTabCheckboxState = function() {
var e = this;
this.selectedGroupPermissions$.pipe(o.take(1)).subscribe(function(n) {
var t = n.filter(function(e) {
return e.isGranted;
}),
i = document.querySelector('#select-all-in-this-tabs');
t.length === n.length
? ((i.indeterminate = !1), (e.selectThisTab = !0))
: 0 === t.length
? ((i.indeterminate = !1), (e.selectThisTab = !1))
: (i.indeterminate = !0);
});
}),
(e.prototype.setGrantCheckboxState = function() {
var e = this.permissions.filter(function(e) {
return e.isGranted;
}),
n = document.querySelector('#select-all-in-all-tabs');
e.length === this.permissions.length
? ((n.indeterminate = !1), (this.selectAllTab = !0))
: 0 === e.length
? ((n.indeterminate = !1), (this.selectAllTab = !1))
: (n.indeterminate = !0);
}),
(e.prototype.onClickSelectThisTab = function() {
var e = this;
this.selectedGroupPermissions$.pipe(o.take(1)).subscribe(function(n) {
n.forEach(function(n) {
if (!n.isGranted || !e.isGrantedByRole(n.grantedProviders)) {
var t = e.permissions.findIndex(function(e) {
return e.name === n.name;
});
e.permissions = u(
e.permissions.slice(0, t),
[a({}, e.permissions[t], { isGranted: !e.selectThisTab })],
e.permissions.slice(t + 1),
);
}
});
}),
this.setGrantCheckboxState();
}),
(e.prototype.onClickSelectAll = function() {
var e = this;
(this.permissions = this.permissions.map(function(n) {
return a({}, n, { isGranted: !e.selectAllTab });
})),
(this.selectThisTab = !this.selectAllTab);
}),
(e.prototype.onChangeGroup = function(e) {
(this.selectedGroup = e), this.setTabCheckboxState();
}),
(e.prototype.submit = function() {
var e = this;
this.modalBusy = !0;
var n = g(this.store.selectSnapshot(f.getPermissionGroups)),
t = this.permissions
.filter(function(e) {
return (
n.find(function(n) {
return n.name === e.name;
}).isGranted !== e.isGranted
);
})
.map(function(e) {
return { name: e.name, isGranted: e.isGranted };
});
t.length
? this.store
.dispatch(new d({ providerKey: this.providerKey, providerName: this.providerName, permissions: t }))
.subscribe(function() {
(e.modalBusy = !1), (e.visible = !1);
})
: ((this.modalBusy = !1), (this.visible = !1));
}),
(e.prototype.openModal = function() {
var e = this;
if (!this.providerKey || !this.providerName) throw new Error('Provider Key and Provider Name are required.');
this.store
.dispatch(new m({ providerKey: this.providerKey, providerName: this.providerName }))
.pipe(o.pluck('PermissionManagementState', 'permissionRes'))
.subscribe(function(n) {
(e.selectedGroup = n.groups[0]), (e.permissions = g(n.groups)), (e.visible = !0);
});
}),
(e.prototype.initModal = function() {
this.setTabCheckboxState(), this.setGrantCheckboxState();
}),
(e.prototype.ngOnChanges = function(e) {
var n = e.visible;
n && (n.currentValue ? this.openModal() : !1 === n.currentValue && this.visible && (this.visible = !1));
}),
(e.decorators = [
{
type: i.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',
},
],
},
]),
(e.ctorParameters = function() {
return [{ type: r.Store }, { type: i.Renderer2 }];
}),
(e.propDecorators = {
providerName: [{ type: i.Input }],
providerKey: [{ type: i.Input }],
visible: [{ type: i.Input }],
visibleChange: [{ type: i.Output }],
}),
c([r.Select(f.getPermissionGroups), p('design:type', s.Observable)], e.prototype, 'groups$', void 0),
c([r.Select(f.getEntitiyDisplayName), p('design:type', s.Observable)], e.prototype, 'entityName$', void 0),
e
);
})();
function y(e, n) {
var t = e.find(function(e) {
return e.name === n.parentName;
});
return t && t.parentName ? 20 + y(e, t) : t ? 20 : 0;
}
function g(e) {
return e.reduce(function(e, n) {
return u(e, n.permissions);
}, []);
}
var v,
G = (function() {
function e() {}
return (
(e.decorators = [
{
type: i.NgModule,
args: [
{
declarations: [h],
imports: [n.CoreModule, t.ThemeSharedModule, r.NgxsModule.forFeature([f])],
exports: [h],
},
],
},
]),
e
);
})();
!(function(e) {
function n() {}
function t() {}
function i() {}
function r() {}
function s() {}
function o() {}
function a() {}
(e.State = n),
(e.Response = t),
(e.Group = i),
(e.MinimumPermission = r),
(e.Permission = s),
(e.GrantedProvider = o),
(e.UpdateRequest = a);
})(v || (v = {})),
(e.GetPermissions = m),
(e.PermissionManagementComponent = h),
(e.PermissionManagementModule = G),
(e.PermissionManagementService = b),
(e.PermissionManagementState = f),
(e.UpdatePermissions = d),
(e.ɵa = h),
(e.ɵb = f),
(e.ɵc = b),
(e.ɵd = m),
(e.ɵe = d),
Object.defineProperty(e, '__esModule', { value: !0 });
});
//# sourceMappingURL=abp-ng.permission-management.umd.min.js.map