@ -1,15 +1,15 @@
import {
import {
ChangeDetectionStrategy ,
ChangeDetectionStrategy ,
ChangeDetectorRef ,
Component ,
Component ,
Inject ,
OnDestroy ,
OnDestroy ,
OnInit
OnInit
} from '@angular/core' ;
} from '@angular/core' ;
import {
import {
AbstractControl ,
FormBuilder ,
FormBuilder ,
FormControl ,
FormControl ,
FormGroup ,
FormGroup ,
ValidationErrors ,
Validators
Validators
} from '@angular/forms' ;
} from '@angular/forms' ;
import { MatDialogRef } from '@angular/material/dialog' ;
import { MatDialogRef } from '@angular/material/dialog' ;
@ -19,35 +19,75 @@ import { AdminService } from '@ghostfolio/client/services/admin.service';
changeDetection : ChangeDetectionStrategy.OnPush ,
changeDetection : ChangeDetectionStrategy.OnPush ,
host : { class : 'h-100' } ,
host : { class : 'h-100' } ,
selector : 'gf-create-asset-profile-dialog' ,
selector : 'gf-create-asset-profile-dialog' ,
styleUrls : [ './create-asset-profile-dialog.component.scss' ] ,
templateUrl : 'create-asset-profile-dialog.html'
templateUrl : 'create-asset-profile-dialog.html'
} )
} )
export class CreateAssetProfileDialog implements OnInit , OnDestroy {
export class CreateAssetProfileDialog implements OnInit , OnDestroy {
public createAssetProfileForm : FormGroup ;
public createAssetProfileForm : FormGroup ;
public mode : 'auto' | 'manual' ;
public constructor (
public constructor (
public readonly adminService : AdminService ,
public readonly adminService : AdminService ,
public readonly changeDetectorRef : ChangeDetectorRef ,
public readonly dialogRef : MatDialogRef < CreateAssetProfileDialog > ,
public readonly dialogRef : MatDialogRef < CreateAssetProfileDialog > ,
public readonly formBuilder : FormBuilder
public readonly formBuilder : FormBuilder
) { }
) { }
public ngOnInit() {
public ngOnInit() {
this . createAssetProfileForm = this . formBuilder . group ( {
this . createAssetProfileForm = this . formBuilder . group (
searchSymbol : new FormControl ( null , [ Validators . required ] )
{
} ) ;
addSymbol : new FormControl ( null , [ Validators . required ] ) ,
searchSymbol : new FormControl ( null , [ Validators . required ] )
} ,
{
validators : this.atLeastOneValid
}
) ;
this . mode = 'auto' ;
}
}
public onCancel() {
public onCancel() {
this . dialogRef . close ( ) ;
this . dialogRef . close ( ) ;
}
}
public onRadioChange ( mode : 'auto' | 'manual' ) {
this . mode = mode ;
}
public onSubmit() {
public onSubmit() {
this . dialogRef . close ( {
this . mode === 'auto'
dataSource :
? this . dialogRef . close ( {
this . createAssetProfileForm . controls [ 'searchSymbol' ] . value . dataSource ,
dataSource :
symbol : this . createAssetProfileForm . controls [ 'searchSymbol' ] . value . symbol
this . createAssetProfileForm . controls [ 'searchSymbol' ] . value
} ) ;
. dataSource ,
symbol :
this . createAssetProfileForm . controls [ 'searchSymbol' ] . value . symbol
} )
: this . dialogRef . close ( {
dataSource : 'MANUAL' ,
symbol : this . createAssetProfileForm . controls [ 'addSymbol' ] . value
} ) ;
}
}
public ngOnDestroy() { }
public ngOnDestroy() { }
private atLeastOneValid ( control : AbstractControl ) : ValidationErrors {
const addSymbolControl = control . get ( 'addSymbol' ) ;
const searchSymbolControl = control . get ( 'searchSymbol' ) ;
if ( addSymbolControl . valid && searchSymbolControl . valid ) {
return { atLeastOneValid : true } ;
}
if (
addSymbolControl . valid ||
! addSymbolControl ||
searchSymbolControl . valid ||
! searchSymbolControl
) {
return { atLeastOneValid : false } ;
}
return { atLeastOneValid : true } ;
}
}
}