11import { Component , Inject , OnInit } from "@angular/core" ;
22import { UntypedFormControl } from "@angular/forms" ;
33import { MAT_DIALOG_DATA , MatDialogRef } from "@angular/material/dialog" ;
4+ import { MatSnackBar } from "@angular/material/snack-bar" ;
45import { Organisation } from "@app/admin/organisation/organisation.model" ;
56import { OrganisationService } from "@app/admin/organisation/organisation.service" ;
67import { PermissionResponse } from "@app/admin/permission/permission.model" ;
@@ -21,7 +22,6 @@ export class ChangeOrganizationDialogComponent implements OnInit {
2122 public applicationsSubscription : Subscription ;
2223 public permissionsSubscription : Subscription ;
2324 public organizationsSubscription : Subscription ;
24- public permissionMultiCtrl : UntypedFormControl = new UntypedFormControl ( ) ;
2525 public application : UpdateApplicationOrganization ;
2626 public permissions : PermissionResponse [ ] ;
2727 public organizations : Organisation [ ] ;
@@ -34,14 +34,14 @@ export class ChangeOrganizationDialogComponent implements OnInit {
3434 private permissionService : PermissionService ,
3535 private organizationService : OrganisationService ,
3636 private sharedVariableService : SharedVariableService ,
37+ private snackBar : MatSnackBar ,
3738 private dialog : MatDialogRef < ChangeOrganizationDialogComponent > ,
3839 @Inject ( MAT_DIALOG_DATA ) public dialogModel : ApplicationDialogModel
3940 ) {
4041 this . application = {
4142 organizationId : this . dialogModel . organizationId ?? this . sharedVariableService . getSelectedOrganisationId ( ) ,
4243 permissionIds : [ ] ,
4344 } ;
44- this . permissionMultiCtrl . setValue ( this . application . permissionIds ) ;
4545 }
4646
4747 ngOnInit ( ) : void {
@@ -56,7 +56,6 @@ export class ChangeOrganizationDialogComponent implements OnInit {
5656 getApplication ( id : number ) : void {
5757 this . applicationsSubscription = this . applicationService . getApplication ( id ) . subscribe ( ( application : Application ) => {
5858 this . application . permissionIds = application . permissionIds ;
59- this . permissionMultiCtrl . setValue ( this . application . permissionIds ) ;
6059 } ) ;
6160 }
6261
@@ -85,17 +84,27 @@ export class ChangeOrganizationDialogComponent implements OnInit {
8584 this . permissions . filter ( p => p ?. organization ?. id === this ?. application ?. organizationId )
8685 ) ;
8786 this . filteredPermissionsMulti . subscribe ( res => {
88- this . permissionMultiCtrl . setValue (
89- res . filter ( permission => permission . automaticallyAddNewApplications ) . map ( permission => permission . id )
90- ) ;
87+ this . application . permissionIds = res
88+ . filter ( permission => permission . automaticallyAddNewApplications )
89+ . map ( permission => permission . id ) ;
9190 } ) ;
9291 }
9392
9493 onSubmit ( ) {
9594 this . applicationsSubscription = this . applicationService
9695 . updateApplicationOrganization ( this . application , this . dialogModel . id )
97- . subscribe ( ( ) => {
98- this . dialog . close ( ) ;
96+ . subscribe ( savedApplication => {
97+ this . snackBar . open (
98+ this . translate . instant ( "APPLICATION.CHANGE-ORGANIZATION.SNACKBAR-SAVED" , {
99+ applicationName : savedApplication . name ,
100+ organizationName : savedApplication . belongsTo . name ,
101+ } ) ,
102+ "" ,
103+ {
104+ duration : 10000 ,
105+ }
106+ ) ;
107+ this . dialog . close ( true ) ;
99108 } ) ;
100109 }
101110}
0 commit comments