import { Component , OnInit , Inject , ViewEncapsulation } from '@angular/core' ; import { CollectionService } from '../../../services/collection/collection.service' ; import { MatDialogRef , MAT_DIALOG_DATA , MatDialog } from '@angular/material/dialog' ; import { ErrorDialogComponent } from '../error-dialog/error-dialog.component' ; import { Operation } from '../../../core/enums' ; import { SnackBarService } from '../../../services/snack-bar/snack-bar.service' ; import { TranslatorService } from '../../../services/translator/translator.service' ; @ Component ( { selector : 'app-rename-collection-dialog' , templateUrl : './rename-collection-dialog.component.html' , styleUrls : [ './rename-collection-dialog.component.scss' ] , encapsulation : ViewEncapsulation . None } ) export class RenameCollectionDialogComponent implements OnInit { constructor ( private collection , private dialogRef , private translator , @ Inject ( MAT_DIALOG_DATA ) public data , private dialog , private snackBar ) { dialogRef . disableClose = true ; } public oldCollection : string = this . data . oldCollection ; public newCollection : string = this . data . oldCollection ; public ngOnInit ( ) { } public async renameCollectionAsync ( ) { const operation = await this . collection . renameCollectionAsync ( this . oldCollection , this . newCollection ) ; if ( operation === Operation . Error ) { const errorText = ( await this . translator . getAsync ( 'ErrorTexts.RenameCollectionError' , { collection : this . newCollection } ) ) ; this . dialog . open ( ErrorDialogComponent , { width : '450px' , data : { errorText : errorText } } ) ; } else if ( operation === Operation . Duplicate ) { this . snackBar . duplicateCollectionAsync ( this . newCollection ) ; } } public async renameCollectionAndCloseAsync ( ) { await this . renameCollectionAsync ( ) ; this . dialogRef . close ( ) ; } }