mirror of https://github.com/abpframework/abp
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.
16 lines
14 KiB
16 lines
14 KiB
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(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"],t):t(((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,t,n,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 t,n=1,i=arguments.length;n<i;n++)for(var r in t=arguments[n])Object.prototype.hasOwnProperty.call(t,r)&&(e[r]=t[r]);return e}).apply(this,arguments)};function c(e,t,n,i){var r,s=arguments.length,o=s<3?t:null===i?i=Object.getOwnPropertyDescriptor(t,n):i;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)o=Reflect.decorate(e,t,n,i);else for(var a=e.length-1;a>=0;a--)(r=e[a])&&(o=(s<3?r(o):s>3?r(t,n,o):r(t,n))||o);return s>3&&o&&Object.defineProperty(t,n,o),o}function p(e,t){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(e,t)}function l(e,t){var n="function"==typeof Symbol&&e[Symbol.iterator];if(!n)return e;var i,r,s=n.call(e),o=[];try{for(;(void 0===t||t-- >0)&&!(i=s.next()).done;)o.push(i.value)}catch(e){r={error:e}}finally{try{i&&!i.done&&(n=s.return)&&n.call(s)}finally{if(r)throw r.error}}return o}function u(){for(var e=[],t=0;t<arguments.length;t++)e=e.concat(l(arguments[t]));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 t={method:"GET",url:"/api/abp/permissions",params:e};return this.rest.request(t)},e.prototype.updatePermissions=function(e){var t={method:"PUT",url:"/api/abp/permissions",body:{permissions:e.permissions},params:{providerKey:e.providerKey,providerName:e.providerName}};return this.rest.request(t)},e.decorators=[{type:i.Injectable,args:[{providedIn:"root"}]}],e.ctorParameters=function(){return[{type:t.RestService}]},e.ngInjectableDef=i.ɵɵdefineInjectable({factory:function(){return new e(i.ɵɵinject(t.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,t){var n=e.patchState,i=t.payload;return this.permissionManagementService.getPermissions(i).pipe(o.tap((function(e){return n({permissionRes:e})})))},e.prototype.permissionManagementUpdate=function(e,t){var n=t.payload;return this.permissionManagementService.updatePermissions(n)},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,t){this.store=e,this.renderer=t,this.visibleChange=new i.EventEmitter,this.permissions=[],this.selectThisTab=!1,this.selectAllTab=!1,this.modalBusy=!1,this.trackByFn=function(e,t){return t.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(t){return e.selectedGroup?t.find((function(t){return t.name===e.selectedGroup.name})).permissions:[]})),o.map((function(t){return t.map((function(n){return a({},n,{margin:y(t,n),isGranted:e.permissions.find((function(e){return e.name===n.name})).isGranted})}))})))},enumerable:!0,configurable:!0}),e.prototype.ngOnInit=function(){},e.prototype.getChecked=function(e){return(this.permissions.find((function(t){return t.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,t){var n=this;e.isGranted&&this.isGrantedByRole(e.grantedProviders)||setTimeout((function(){n.permissions=n.permissions.map((function(t){return e.name===t.name?a({},t,{isGranted:!t.isGranted}):e.name===t.parentName&&e.isGranted?a({},t,{isGranted:!1}):e.parentName!==t.name||e.isGranted?t:a({},t,{isGranted:!0})})),n.setTabCheckboxState(),n.setGrantCheckboxState()}),0)},e.prototype.setTabCheckboxState=function(){var e=this;this.selectedGroupPermissions$.pipe(o.take(1)).subscribe((function(t){var n=t.filter((function(e){return e.isGranted})),i=document.querySelector("#select-all-in-this-tabs");n.length===t.length?(i.indeterminate=!1,e.selectThisTab=!0):0===n.length?(i.indeterminate=!1,e.selectThisTab=!1):i.indeterminate=!0}))},e.prototype.setGrantCheckboxState=function(){var e=this.permissions.filter((function(e){return e.isGranted})),t=document.querySelector("#select-all-in-all-tabs");e.length===this.permissions.length?(t.indeterminate=!1,this.selectAllTab=!0):0===e.length?(t.indeterminate=!1,this.selectAllTab=!1):t.indeterminate=!0},e.prototype.onClickSelectThisTab=function(){var e=this;this.selectedGroupPermissions$.pipe(o.take(1)).subscribe((function(t){t.forEach((function(t){if(!t.isGranted||!e.isGrantedByRole(t.grantedProviders)){var n=e.permissions.findIndex((function(e){return e.name===t.name}));e.permissions=u(e.permissions.slice(0,n),[a({},e.permissions[n],{isGranted:!e.selectThisTab})],e.permissions.slice(n+1))}}))})),this.setGrantCheckboxState()},e.prototype.onClickSelectAll=function(){var e=this;this.permissions=this.permissions.map((function(t){return a({},t,{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 t=g(this.store.selectSnapshot(f.getPermissionGroups)),n=this.permissions.filter((function(e){return t.find((function(t){return t.name===e.name})).isGranted!==e.isGranted})).map((function(e){return{name:e.name,isGranted:e.isGranted}}));n.length?this.store.dispatch(new d({providerKey:this.providerKey,providerName:this.providerName,permissions:n})).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(t){e.selectedGroup=t.groups[0],e.permissions=g(t.groups),e.visible=!0}))},e.prototype.initModal=function(){this.setTabCheckboxState(),this.setGrantCheckboxState()},e.prototype.ngOnChanges=function(e){var t=e.visible;t&&(t.currentValue?this.openModal():!1===t.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,t){var n=e.find((function(e){return e.name===t.parentName}));return n&&n.parentName?20+y(e,n):n?20:0}function g(e){return e.reduce((function(e,t){return u(e,t.permissions)}),[])}var v,G=function(){function e(){}return e.decorators=[{type:i.NgModule,args:[{declarations:[h],imports:[t.CoreModule,n.ThemeSharedModule,r.NgxsModule.forFeature([f])],exports:[h]}]}],e}();!function(e){function t(){}function n(){}function i(){}function r(){}function s(){}function o(){}function a(){}e.State=t,e.Response=n,e.Group=i,e.MinimumPermission=r,e.Permission=s,e.GrantedProvider=o,e.UpdateRequest=a}(v||(v={}));var P=function(){function e(e){this.store=e}return e.prototype.getPermissionGroups=function(){return this.store.selectSnapshot(f.getPermissionGroups)},e.prototype.getEntityDisplayName=function(){return this.store.selectSnapshot(f.getPermissionGroups)},e.decorators=[{type:i.Injectable,args:[{providedIn:"root"}]}],e.ctorParameters=function(){return[{type:r.Store}]},e.ngInjectableDef=i.ɵɵdefineInjectable({factory:function(){return new e(i.ɵɵinject(r.Store))},token:e,providedIn:"root"}),e}();e.GetPermissions=m,e.PermissionManagementComponent=h,e.PermissionManagementModule=G,e.PermissionManagementService=b,e.PermissionManagementState=f,e.PermissionManagementStateService=P,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
|