import { Component , Inject , OnInit , ViewChild } from '@angular/core' ; import { MatDialogRef , MAT_DIALOG_DATA } from '@angular/material/dialog' ; export class CertificationInfo { constructor ( public isValid , public domain , public issuerName , public validThru ) { } } export class UpdateInfo { constructor ( public currentVersion , public newVersion , public os , public assets , public releaseUrl , public certInfo ) { } } interface AssetOption { value : number ; viewValue : string ; } @ Component ( { selector : 'app-new-version-dialog' , templateUrl : './new-version-dialog.component.html' , styleUrls : [ './new-version-dialog.component.scss' ] } ) export class NewVersionDialogComponent implements OnInit { public selectedAssetIndex : string ; assets : AssetOption [ ] ; constructor ( public dialogRef , @ Inject ( MAT_DIALOG_DATA ) public updateInfo ) { this . assets = this . updateInfo . assets . map ( ( url , index ) => ( { viewValue : this . getViewValue ( url ) , value : index } ) ) ; } ngOnInit ( ) { } get platform ( ) : string { switch ( this . updateInfo . os ) { case 'win32' : return 'Windows' ; case 'darwin' : return 'MacOS' ; case 'linux' : return 'Linux' ; default : return 'Unknown Platform' ; } } private getViewValue ( url ) { const u = new URL ( url ) ; return u . pathname . substr ( u . pathname . lastIndexOf ( '/' ) + 1 ) ; } }