!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=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-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:'\n \n \n

{{ \'AbpPermissionManagement::Permissions\' | abpLocalization }} - {{ data.entityName }}

\n
\n \n
\n \n \n
\n\n
\n
\n
\n \n
\n
\n

{{ selectedGroup?.displayName }}

\n
\n
\n
\n \n \n
\n
\n \n \n {{ permission.displayName }}\n {{ provider.providerName }}: {{ provider.providerKey }}\n
\n
\n
\n \n
\n \n \n {{ \'AbpIdentity::Save\' | abpLocalization }}\n \n
\n
\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