UNPKG

@cause-911/management

Version:

Run `npm install @cause-911/management --save` to add this library to your project

2 lines 15 kB
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("@angular/core"),require("@angular/common/http"),require("@cause-911/core"),require("@angular/cdk/layout"),require("rxjs/operators"),require("@angular/platform-browser"),require("devextreme-angular"),require("@cause-911/devextreme")):"function"==typeof define&&define.amd?define("@cause-911/management",["exports","@angular/core","@angular/common/http","@cause-911/core","@angular/cdk/layout","rxjs/operators","@angular/platform-browser","devextreme-angular","@cause-911/devextreme"],t):t(((e=e||self)["cause-911"]=e["cause-911"]||{},e["cause-911"].management={}),e.ng.core,e.ng.common.http,e.core$1,e.ng.cdk.layout,e.rxjs.operators,e.ng.platformBrowser,e.devextremeAngular,e.devextreme)}(this,function(e,t,n,i,o,r,s,a,u){"use strict";var p=function(){function e(e,t){this.http=t,this.config=e.getConfig()}return e.prototype.getAll=function(){return this.http.get(this.config.apiUrl+"UserManagement")},e.prototype.get=function(e){return this.http.get(this.config.apiUrl+"UserManagement/"+e)},e.prototype.getGroup=function(e){return this.http.get(this.config.apiUrl+"UserManagement/"+e+"/groups")},e.prototype.addGroup=function(e){return this.http.post(this.config.apiUrl+"UserManagement/group",e)},e.prototype.deleteGroup=function(e){return this.http.delete(this.config.apiUrl+"UserManagement/groups/"+e)},e.prototype.addPermission=function(e){return this.http.post(this.config.apiUrl+"UserManagement/permission",e)},e.prototype.deletePermission=function(e){return this.http.delete(this.config.apiUrl+"UserManagement/groups/"+e)},e.prototype.save=function(e){return this.http.post(this.config.apiUrl+"UserManagement",e)},e.prototype.delete=function(e){return this.http.delete(this.config.apiUrl+"UserManagement/"+e)},e.prototype.hasExistingUserName=function(e){return this.http.post(this.config.apiUrl+"UserManagement/UserNameAlreadyExist",e)},e.decorators=[{type:t.Injectable,args:[{providedIn:"root"}]}],e.ctorParameters=function(){return[{type:i.CoreService},{type:n.HttpClient}]},e.ngInjectableDef=t.ɵɵdefineInjectable({factory:function(){return new e(t.ɵɵinject(i.CoreService),t.ɵɵinject(n.HttpClient))},token:e,providedIn:"root"}),e}(),d=function(){function e(e,t){this.http=t,this.config=e.getConfig()}return e.prototype.getAll=function(){return this.http.get(this.config.apiUrl+"GroupManagement")},e.prototype.get=function(e){return this.http.get(this.config.apiUrl+"GroupManagement/"+e)},e.prototype.save=function(e){return this.http.post(this.config.apiUrl+"GroupManagement",e)},e.prototype.delete=function(e){return this.http.delete(this.config.apiUrl+"GroupManagement/"+e)},e.prototype.hasExistingGroupName=function(e){return this.http.post(this.config.apiUrl+"GroupManagement/GroupNameAlreadyExist",e)},e.decorators=[{type:t.Injectable,args:[{providedIn:"root"}]}],e.ctorParameters=function(){return[{type:i.CoreService},{type:n.HttpClient}]},e.ngInjectableDef=t.ɵɵdefineInjectable({factory:function(){return new e(t.ɵɵinject(i.CoreService),t.ɵɵinject(n.HttpClient))},token:e,providedIn:"root"}),e}(),l=function(){this.userName="",this.firstName="",this.lastName="",this.password="",this.email="",this.isActive=!0},c=function(){this.idUserGroup="",this.idGroup="",this.idUser=""},m=function(){this.idUserPermission="",this.isAllowed=!1,this.idUser="",this.idModulePermission=""},f=function(){this.name="",this.users=[],this.permissions=[]},g=function(){this.idGroupPermission="",this.isAllowed=!1,this.idGroup="",this.idModulePermission=""},h=function(){function e(e,t){this.http=t,this.config=e.getConfig()}return e.prototype.getAll=function(){return this.http.get(this.config.apiUrl+"PermissionManagement")},e.prototype.get=function(e){return this.http.get(this.config.apiUrl+"PermissionManagement/"+e)},e.prototype.save=function(e){return this.http.post(this.config.apiUrl+"PermissionManagement",e)},e.prototype.delete=function(e){return this.http.delete(this.config.apiUrl+"PermissionManagement/"+e)},e.decorators=[{type:t.Injectable,args:[{providedIn:"root"}]}],e.ctorParameters=function(){return[{type:i.CoreService},{type:n.HttpClient}]},e.ngInjectableDef=t.ɵɵdefineInjectable({factory:function(){return new e(t.ɵɵinject(i.CoreService),t.ɵɵinject(n.HttpClient))},token:e,providedIn:"root"}),e}(),v=function(){function e(e,t,n,i){var o=this;this.managementGroupService=e,this.managementUserService=t,this.managementPermissionService=n,this.hoverStatePermission=!0,this.groups=[],this.users=[],this.permissions=[],this.userFullName={},this.showColumn=!0,this.showColumnXS=!0,this.translations=[],this.calculateUsersCellValue=function(e){var t=e.users?e.users:[],n=[];return t.forEach(function(e){var t=o.users.filter(function(t){return t.id===e.idUser});t&&t[0]&&n.push(t[0].firstName+" "+t[0].lastName)}),(n=n.sort(function(e,t){return e<t?-1:1})).join(", ")},this.groupNameAlreadyUsedValidation=function(e){return o.managementGroupService.hasExistingGroupName(e.data).pipe(r.map(function(e){return!e})).toPromise()},i.observe(["(max-width: 1000px)"]).subscribe(function(e){o.showColumn=!e.matches}),i.observe(["(max-width: 600px)"]).subscribe(function(e){o.showColumnXS=!e.matches})}return e.prototype.ngOnInit=function(){var e=this;this.managementUserService.getAll().subscribe(function(t){e.users=t,e.users.forEach(function(t){t.isActive&&""!==t.firstName&&""!==t.lastName&&(e.userFullName[t.id]=t.firstName+" "+t.lastName)})}),this.managementPermissionService.getAll().subscribe(function(t){var n=t.findIndex(function(e){return"CanAccessPermissions"===e.tag});-1!==n&&t.splice(n,1),t.sort(function(e,t){return e.name<t.name?-1:e.name>t.name?1:0}),e.permissions=t}),this.getGroups()},e.prototype.fullName=function(e){return e?e.firstName+" "+e.lastName:""},e.prototype.getGroupUser=function(e,t){var n=[];this.groupUsers&&this.groupUsers.forEach(function(e){n.push(e.idUser)}),t.component.option("value",n)},e.prototype.setGroupUser=function(e,t){var n=[];t.value.forEach(function(t){var i=(e.data.users||[]).findIndex(function(e){return e.idUser===t});-1===i?n.push({idUser:t}):n.push(e.data.users[i])}),e.setValue(JSON.parse(JSON.stringify(n)))},e.prototype.setGroupPermission=function(e,t){var n=[];t.value.forEach(function(e){n.push({idUser:e})}),e.setValue(JSON.parse(JSON.stringify(n)))},e.prototype.getPermissionStatus=function(e,t,n){var i=(e.value||[]).find(function(e){return e.idModulePermission===t.id});i?n.component.option("value",i.isAllowed):n.component.option("value",void 0)},e.prototype.checkBoxToggled=function(e,t,n){if(n.component.skipOnValueChanged)n.component.skipOnValueChanged=!1;else{if(n.component.setUndefinedNextTime)return n.component.setUndefinedNextTime=!1,n.component.skipOnValueChanged=!0,n.component.option("value",void 0),void this.setPermissionStatus(e,t,void 0);!1===n.value&&(n.component.setUndefinedNextTime=!0),this.setPermissionStatus(e,t,n.value)}},e.prototype.onRowInserted=function(e){this.saveGroup(e.data)},e.prototype.onRowUpdated=function(e){this.saveGroup(e.data)},e.prototype.onRowRemoved=function(e){var t=this,n=e.data;this.managementGroupService.delete(n.id).subscribe(function(e){t.getGroups()})},e.prototype.onEditingStart=function(e){this.groupUsers=e.data.users},e.prototype.onInitNewRow=function(){this.groupUsers=[]},e.prototype.setPermissionStatus=function(e,t,n){var i=e.value||[],o=i.findIndex(function(e){return e.idModulePermission===t.id});o>-1?i[o].isAllowed=n:i.push({idModulePermission:t.id,isAllowed:n}),e.setValue(JSON.parse(JSON.stringify(i)))},e.prototype.saveGroup=function(e){var t=this;this.removePermissionUndefined(e),e.users&&e.users.forEach(function(t){t.idGroup=e.id}),e.permissions&&e.permissions.forEach(function(t){t.idGroup=e.id}),this.managementGroupService.save(e).subscribe(function(){t.getGroups()}),this.groupUsers=[]},e.prototype.removePermissionUndefined=function(e){e.permissions=e.permissions.filter(function(e){return void 0!==e.isAllowed})},e.prototype.getGroups=function(){var e=this;this.managementGroupService.getAll().subscribe(function(t){return e.groups=t})},e.decorators=[{type:t.Component,args:[{selector:"cause-management-group",template:'<cause-dx-data-grid\n keyExpr="id"\n [dataSource]="groups"\n (onRowInserted)="onRowInserted($event)"\n (onInitNewRow)="onInitNewRow()"\n (onRowUpdated)="onRowUpdated($event)"\n (onEditingStart)="onEditingStart($event)"\n (onRowRemoved)="onRowRemoved($event)">\n\n <dxi-column dataField="name" [caption]="\'management.name\' | translate">\n <dxi-validation-rule type="async" [message]="\'management.groupNameAlreadyUsed\' | translate" [validationCallback]="groupNameAlreadyUsedValidation"></dxi-validation-rule>\n </dxi-column>\n <dxi-column\n dataField="users"\n [caption]="\'management.users\' | translate"\n editCellTemplate="usersEditTemplate"\n [calculateCellValue]="calculateUsersCellValue">\n </dxi-column>\n <dxi-column\n dataField="permissions"\n [caption]="\'management.permissions\' | translate"\n [visible]="false"\n editCellTemplate="permissionsEditTemplate">\n </dxi-column>\n <dxo-export [enabled]="false"></dxo-export>\n <dxo-editing mode="popup" [allowAdding]="true" [allowUpdating]="true" [allowDeleting]="true" [useIcons]="true">\n <dxo-popup [showTitle]="true" [title]="\'management.group\' | translate" [fullScreen]="!showColumn"></dxo-popup>\n <dxo-form colCount="1" [labelLocation]="showColumnXS ? \'left\' : \'top\'">\n <dxi-item dataField="name" [isRequired]="true"></dxi-item>\n <dxi-item dataField="users"></dxi-item>\n <dxi-item dataField="permissions"></dxi-item>\n </dxo-form>\n </dxo-editing>\n\n <div *dxTemplate="let field of \'usersEditTemplate\'">\n <dx-tag-box\n valueExpr="id"\n [displayExpr]="fullName"\n [dataSource]="users"\n (onInitialized)="getGroupUser(field, $event)"\n (onValueChanged)="setGroupUser(field, $event)">\n </dx-tag-box>\n </div>\n <div *dxTemplate="let field of \'permissionsEditTemplate\'">\n <dx-list\n [dataSource]="permissions"\n itemTemplate="rowTemplate"\n [searchEnabled]="true"\n [searchExpr]="[\'name\', \'tag\']"\n [hoverStateEnabled]="hoverStatePermission">\n <div *dxTemplate="let permission of \'rowTemplate\'">\n <dx-check-box\n [dataSource]="[true, false, undefined]"\n [text]="permission.name"\n (onInitialized)="getPermissionStatus(field, permission, $event)"\n (onValueChanged)="checkBoxToggled(field, permission, $event)">\n </dx-check-box>\n </div>\n </dx-list>\n </div>\n</cause-dx-data-grid>\n',styles:[""]}]}],e.ctorParameters=function(){return[{type:d},{type:p},{type:h},{type:o.BreakpointObserver}]},e.propDecorators={hoverStatePermission:[{type:t.Input}]},e}(),x=function(){function e(){}return e.decorators=[{type:t.Injectable,args:[{providedIn:"root"}]}],e.ctorParameters=function(){return[]},e.ngInjectableDef=t.ɵɵdefineInjectable({factory:function(){return new e},token:e,providedIn:"root"}),e}(),y=function(){function e(){}return e.prototype.ngOnInit=function(){},e.decorators=[{type:t.Component,args:[{selector:"cause-management",template:"<div>{{'core.noGenericComponentOnThisLibrary' | translate}}</div>"}]}],e.ctorParameters=function(){return[]},e}(),U=function(){function e(e,t){var n=this;this.managementUserService=e,this.users=[new l],this.showColumnXS=!0,this.userNameAlreadyUsedValidation=function(e){return n.managementUserService.hasExistingUserName(e.data).pipe(r.map(function(e){return!e})).toPromise()},t.observe(["(max-width: 600px)"]).subscribe(function(e){n.showColumnXS=!e.matches})}return e.prototype.ngOnInit=function(){this.getUsers()},e.prototype.onRowInserted=function(e){this.saveGroup(e.data)},e.prototype.onRowUpdated=function(e){this.saveGroup(e.key)},e.prototype.onRowRemoved=function(e){var t=this,n=e.data;this.managementUserService.delete(n.id).subscribe(function(e){t.getUsers()})},e.prototype.saveGroup=function(e){var t=this;this.managementUserService.save(e).subscribe(function(){t.getUsers()})},e.prototype.getUsers=function(){var e=this;this.managementUserService.getAll().subscribe(function(t){return e.users=t})},e.decorators=[{type:t.Component,args:[{selector:"cause-management-user",template:'<cause-dx-data-grid\n keyExpr="id"\n [dataSource]="users"\n (onRowInserted)="onRowInserted($event)"\n (onRowUpdated)="onRowUpdated($event)"\n (onRowRemoved)="onRowRemoved($event)">\n\n <dxi-column dataField="userName" [caption]="\'management.userName\' | translate">\n <dxi-validation-rule type="async" [message]="\'management.userNameAlreadyUsed\' | translate" [validationCallback]="userNameAlreadyUsedValidation"></dxi-validation-rule>\n </dxi-column>\n <dxi-column dataField="isActive" [caption]="\'management.isActive\' | translate" [visible]="false"></dxi-column>\n <dxi-column dataField="firstName" [caption]="\'management.firstName\' | translate"></dxi-column>\n <dxi-column dataField="lastName" [caption]="\'management.lastName\' | translate"></dxi-column>\n <dxi-column dataField="groups" [caption]="\'management.group\' | translate"></dxi-column>\n\n <dxo-editing mode="popup" [allowAdding]="true" [allowUpdating]="true" [allowDeleting]="true" [useIcons]="true">\n <dxo-popup [showTitle]="true" [title]="\'management.group\' | translate"></dxo-popup>\n <dxo-form colCount="2" [labelLocation]="showColumnXS ? \'left\' : \'top\'">\n <dxi-item dataField="userName" [isRequired]="true"></dxi-item>\n <dxi-item dataField="isActive"></dxi-item>\n <dxi-item dataField="firstName"></dxi-item>\n <dxi-item dataField="lastName"></dxi-item>\n <dxi-item dataField="group"></dxi-item>\n </dxo-form>\n </dxo-editing>\n</cause-dx-data-grid>\n',styles:[""]}]}],e.ctorParameters=function(){return[{type:p},{type:o.BreakpointObserver}]},e}(),w=function(){function e(){}return e.decorators=[{type:t.NgModule,args:[{declarations:[y,U,v],exports:[y,U,v],imports:[s.BrowserModule,i.CauseCoreModule,u.CauseDxModule,a.DxListModule,a.DxTagBoxModule,a.DxCheckBoxModule],schemas:[t.CUSTOM_ELEMENTS_SCHEMA]}]}],e}();e.CauseManagementComponent=y,e.CauseManagementGroupComponent=v,e.CauseManagementModule=w,e.GroupModel=f,e.GroupPermissionModel=g,e.ManagementGroupService=d,e.ManagementService=x,e.ManagementUserService=p,e.UserGroupModel=c,e.UserModel=l,e.UserPermissionModel=m,e.ɵa=h,e.ɵb=U,Object.defineProperty(e,"__esModule",{value:!0})}); //# sourceMappingURL=cause-911-management.umd.min.js.map