import { Injectable } from "@angular/core" ; import { MatDialog } from "@angular/material/dialog" ; import { Router } from "@angular/router" ; import { getSet , FilesSet } from "../../data/set" ; import { AppFile } from "../../data/file" ; import { DialogComponent } from "../../shared/components/dialog/dialog.component" ; @ Injectable ( { providedIn : "root" , } ) export class DialogService { constructor ( private router , private dialog ) { } public moveToSet ( files , setFrom , removeFiles ) { const dialogRef = this . dialog . open ( DialogComponent , { width : "350px" , data : { currentSet : setFrom } , } ) ; dialogRef . afterClosed ( ) . subscribe ( ( setId ) => { if ( setId . length ) { const setTo = getSet ( setId ) ; files . forEach ( ( file ) => ( file . selected = false ) ) ; setTo . files . push ( ... files ) ; if ( removeFiles ) { files . forEach ( ( file ) => { setFrom . files = setFrom . files . filter ( ( source ) => { return source . id !== file . id ; } ) ; } ) ; } this . router . navigate ( [ "/sets/" + setTo . id ] ) ; } } ) ; } public closeDialog ( ) { this . dialog . closeAll ( ) ; } }