|
|
@ -14,19 +14,11 @@ |
|
|
/// limitations under the License.
|
|
|
/// limitations under the License.
|
|
|
///
|
|
|
///
|
|
|
|
|
|
|
|
|
import { Component, Inject, OnInit, SkipSelf } from '@angular/core'; |
|
|
import { Component, Inject, OnInit } from '@angular/core'; |
|
|
import { ErrorStateMatcher } from '@angular/material/core'; |
|
|
|
|
|
import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material/dialog'; |
|
|
import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material/dialog'; |
|
|
import { Store } from '@ngrx/store'; |
|
|
import { Store } from '@ngrx/store'; |
|
|
import { AppState } from '@core/core.state'; |
|
|
import { AppState } from '@core/core.state'; |
|
|
import { |
|
|
import { FormBuilder, FormGroup, Validators } from '@angular/forms'; |
|
|
FormGroupDirective, |
|
|
|
|
|
NgForm, |
|
|
|
|
|
UntypedFormBuilder, |
|
|
|
|
|
UntypedFormControl, |
|
|
|
|
|
UntypedFormGroup, |
|
|
|
|
|
Validators |
|
|
|
|
|
} from '@angular/forms'; |
|
|
|
|
|
import { Router } from '@angular/router'; |
|
|
import { Router } from '@angular/router'; |
|
|
import { DialogComponent } from '@shared/components/dialog.component'; |
|
|
import { DialogComponent } from '@shared/components/dialog.component'; |
|
|
|
|
|
|
|
|
@ -37,22 +29,18 @@ export interface ColorPickerDialogData { |
|
|
@Component({ |
|
|
@Component({ |
|
|
selector: 'tb-color-picker-dialog', |
|
|
selector: 'tb-color-picker-dialog', |
|
|
templateUrl: './color-picker-dialog.component.html', |
|
|
templateUrl: './color-picker-dialog.component.html', |
|
|
providers: [{provide: ErrorStateMatcher, useExisting: ColorPickerDialogComponent}], |
|
|
|
|
|
styleUrls: [] |
|
|
styleUrls: [] |
|
|
}) |
|
|
}) |
|
|
export class ColorPickerDialogComponent extends DialogComponent<ColorPickerDialogComponent, string> |
|
|
export class ColorPickerDialogComponent extends DialogComponent<ColorPickerDialogComponent, string> |
|
|
implements OnInit, ErrorStateMatcher { |
|
|
implements OnInit { |
|
|
|
|
|
|
|
|
colorPickerFormGroup: UntypedFormGroup; |
|
|
colorPickerFormGroup: FormGroup; |
|
|
|
|
|
|
|
|
submitted = false; |
|
|
|
|
|
|
|
|
|
|
|
constructor(protected store: Store<AppState>, |
|
|
constructor(protected store: Store<AppState>, |
|
|
protected router: Router, |
|
|
protected router: Router, |
|
|
@Inject(MAT_DIALOG_DATA) public data: ColorPickerDialogData, |
|
|
@Inject(MAT_DIALOG_DATA) public data: ColorPickerDialogData, |
|
|
@SkipSelf() private errorStateMatcher: ErrorStateMatcher, |
|
|
|
|
|
public dialogRef: MatDialogRef<ColorPickerDialogComponent, string>, |
|
|
public dialogRef: MatDialogRef<ColorPickerDialogComponent, string>, |
|
|
public fb: UntypedFormBuilder,) { |
|
|
public fb: FormBuilder) { |
|
|
super(store, router, dialogRef); |
|
|
super(store, router, dialogRef); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@ -62,18 +50,11 @@ export class ColorPickerDialogComponent extends DialogComponent<ColorPickerDialo |
|
|
}); |
|
|
}); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
isErrorState(control: UntypedFormControl | null, form: FormGroupDirective | NgForm | null): boolean { |
|
|
|
|
|
const originalErrorState = this.errorStateMatcher.isErrorState(control, form); |
|
|
|
|
|
const customErrorState = !!(control && control.invalid && this.submitted); |
|
|
|
|
|
return originalErrorState || customErrorState; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
cancel(): void { |
|
|
cancel(): void { |
|
|
this.dialogRef.close(null); |
|
|
this.dialogRef.close(null); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
select(): void { |
|
|
select(): void { |
|
|
this.submitted = true; |
|
|
|
|
|
const color: string = this.colorPickerFormGroup.get('color').value; |
|
|
const color: string = this.colorPickerFormGroup.get('color').value; |
|
|
this.dialogRef.close(color); |
|
|
this.dialogRef.close(color); |
|
|
} |
|
|
} |
|
|
|