-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b505ac4
commit d28ce90
Showing
2 changed files
with
72 additions
and
0 deletions.
There are no files selected for viewing
54 changes: 54 additions & 0 deletions
54
...yui/src/app/modules/kiss/kiss-components/kiss-control-base/kiss-control-base.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import { ChangeDetectionStrategy, ChangeDetectorRef, Component, Injector, OnInit } from '@angular/core'; | ||
import { FormBuilder, FormGroup, Validators } from '@angular/forms'; | ||
import { VisibilityMode } from '../visibility-modes'; | ||
|
||
@Component({ | ||
selector: 'app-kiss-control-base', | ||
template: ``, | ||
changeDetection: ChangeDetectionStrategy.OnPush | ||
}) | ||
export class KissControlBaseComponent implements OnInit { | ||
visibilityMode!: VisibilityMode; | ||
form: FormGroup; | ||
|
||
protected formBuilder: FormBuilder; | ||
protected cdRef: ChangeDetectorRef; | ||
|
||
constructor(injector: Injector) { | ||
this.formBuilder = injector.get(FormBuilder); | ||
this.cdRef = injector.get(ChangeDetectorRef); | ||
this.form = this.buildForm(); | ||
} | ||
|
||
ngOnInit(): void { | ||
this.switchVisibilityMode(); | ||
} | ||
|
||
/** | ||
* switch over the visibility mode | ||
**/ | ||
private switchVisibilityMode(): void { | ||
switch (this.visibilityMode) { | ||
case VisibilityMode.Editor: | ||
this.form.disable(); | ||
this.cdRef.detectChanges(); | ||
break; | ||
case VisibilityMode.Preview: | ||
case VisibilityMode.Answering: | ||
case VisibilityMode.Closed: | ||
case VisibilityMode.Hidding: | ||
break; | ||
default: | ||
throw new Error('Unknown visibility mode: ' + this.visibilityMode); | ||
} | ||
} | ||
|
||
protected buildForm(): FormGroup { | ||
return this.formBuilder.group({ | ||
input: ['', [ | ||
Validators.required | ||
]] | ||
}); | ||
} | ||
|
||
} |
18 changes: 18 additions & 0 deletions
18
formlyui/src/app/modules/kiss/kiss-components/kiss-control-base/kiss-control-base.module.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { NgModule } from '@angular/core'; | ||
import { CommonModule } from '@angular/common'; | ||
import { KissControlBaseComponent } from './kiss-control-base.component'; | ||
|
||
|
||
|
||
@NgModule({ | ||
declarations: [ | ||
KissControlBaseComponent | ||
], | ||
exports: [ | ||
KissControlBaseComponent, | ||
], | ||
imports: [ | ||
CommonModule | ||
] | ||
}) | ||
export class KissControlBaseModule { } |