-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #31 from skynetigor/new_approach
New approach
- Loading branch information
Showing
143 changed files
with
2,348 additions
and
659 deletions.
There are no files selected for viewing
Binary file not shown.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
4 changes: 2 additions & 2 deletions
4
projects/bootstrap-controls/src/lib/models/bootstrap-textfield.model.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 |
---|---|---|
@@ -1,10 +1,10 @@ | ||
import { AbstractDynamicControl, IControlConfiguration } from 'dynamic-form'; | ||
import { AbstractDynamicControl, ControlConfiguration } from 'dynamic-form'; | ||
|
||
import { BootstrapTextfieldComponent } from '../components'; | ||
import { IBootstrapTextfieldInputs } from '../interfaces'; | ||
|
||
export class BootstrapTextFieldModel extends AbstractDynamicControl<BootstrapTextfieldComponent, IBootstrapTextfieldInputs, any, string> { | ||
constructor(config: IControlConfiguration<IBootstrapTextfieldInputs, any, string>) { | ||
constructor(config: ControlConfiguration<IBootstrapTextfieldInputs, any, string>) { | ||
super(config, BootstrapTextfieldComponent); | ||
} | ||
} |
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
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
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 |
---|---|---|
@@ -1,10 +1,12 @@ | ||
{ | ||
"name": "dynamic-form", | ||
"version": "0.0.1", | ||
"peerDependencies": { | ||
"@angular/common": "^7.0.0", | ||
"@angular/core": "^7.0.0", | ||
"@angular/forms": "~7.0.0", | ||
"rxjs": "~6.3.3" | ||
} | ||
"name": "dynamic-form", | ||
"version": "0.0.1", | ||
"peerDependencies": { | ||
"@angular/common": "^7.0.0", | ||
"@angular/core": "^7.0.0", | ||
"@angular/forms": "~7.0.0", | ||
"@angular/cdk": "~8.0.0", | ||
"@angular/material": "7.3.7", | ||
"rxjs": "~6.3.3" | ||
} | ||
} |
15 changes: 0 additions & 15 deletions
15
...ts/dynamic-form/src/lib/components/dynamic-form-outlet/dynamic-form-outlet.component.html
This file was deleted.
Oops, something went wrong.
81 changes: 0 additions & 81 deletions
81
...ects/dynamic-form/src/lib/components/dynamic-form-outlet/dynamic-form-outlet.component.ts
This file was deleted.
Oops, something went wrong.
126 changes: 126 additions & 0 deletions
126
projects/dynamic-form/src/lib/dynamic-form-wizard/components/abstract-value-accessor.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,126 @@ | ||
import { AfterViewInit, ElementRef, forwardRef, Injectable, Injector, Input, OnChanges, OnDestroy, SimpleChanges } from '@angular/core'; | ||
import { AbstractControl, ControlValueAccessor, NG_VALUE_ACCESSOR, NgControl } from '@angular/forms'; | ||
import { BehaviorSubject, Subscription } from 'rxjs'; | ||
|
||
@Injectable() | ||
export abstract class AbstractValueAccessor implements ControlValueAccessor, AfterViewInit, OnDestroy, OnChanges { | ||
private _isDisabled = false; | ||
private _value: any = null; | ||
|
||
protected hostNativeElement: HTMLElement; | ||
protected formControl: AbstractControl; | ||
|
||
@Input() | ||
label = ''; | ||
@Input() | ||
required: boolean; | ||
@Input() | ||
placeholder = ''; | ||
@Input() | ||
tooltipText = ''; | ||
|
||
@Input() | ||
set isDisabled(value: boolean) { | ||
if (this._isDisabled !== value) { | ||
if (value && this.formControl && this.formControl.enabled) { | ||
this.formControl.disable(); | ||
} else if (!value && this.formControl && this.formControl.disabled) { | ||
this.formControl.enable(); | ||
} | ||
|
||
this._isDisabled = value; | ||
this.isDisabled$.next(value); | ||
} | ||
} | ||
|
||
get isDisabled() { | ||
return this._isDisabled; | ||
} | ||
|
||
get dirty() { | ||
return this.formControl ? this.formControl.dirty : false; | ||
} | ||
|
||
get fieldName(): string { | ||
return this.hostNativeElement.id; | ||
} | ||
|
||
isDisabled$ = new BehaviorSubject<boolean>(this.isDisabled); | ||
|
||
subscriptions: Subscription[] = []; | ||
|
||
constructor(protected injector: Injector) { | ||
this.hostNativeElement = injector.get<ElementRef<HTMLElement>>(ElementRef as any).nativeElement; | ||
} | ||
|
||
get value(): any { | ||
return this._value; | ||
} | ||
set value(v: any) { | ||
if (v !== this._value) { | ||
this._value = v; | ||
this.onChange(v); | ||
} | ||
} | ||
|
||
markAsDirty() { | ||
if (!this.dirty) { | ||
this.formControl.markAsDirty(); | ||
this.onTouch(); | ||
} | ||
} | ||
|
||
writeValue(value: any) { | ||
this._value = value; | ||
} | ||
|
||
onChange = _ => {}; | ||
|
||
onTouch = () => {}; | ||
|
||
registerOnChange(fn: (_: any) => void): void { | ||
this.onChange = fn; | ||
} | ||
|
||
registerOnTouched(fn: () => void): void { | ||
this.onTouch = fn; | ||
} | ||
|
||
setDisabledState(isDisabled: boolean) { | ||
this.isDisabled = isDisabled; | ||
} | ||
|
||
ngOnChanges(simpleChanges: SimpleChanges) { | ||
const reqAttrName = 'required'; | ||
|
||
if (reqAttrName in simpleChanges) { | ||
if (simpleChanges.required.currentValue) { | ||
const attr = document.createAttribute(reqAttrName); | ||
this.hostNativeElement.attributes.setNamedItem(attr); | ||
} else { | ||
if (this.hostNativeElement.getAttribute(reqAttrName)) { | ||
this.hostNativeElement.attributes.removeNamedItem(reqAttrName); | ||
} | ||
} | ||
} | ||
} | ||
|
||
ngOnDestroy() { | ||
this.subscriptions.forEach(t => t.unsubscribe()); | ||
} | ||
|
||
ngAfterViewInit() { | ||
// It is used like this since we are not able to use abstract type as argument for get method of injector | ||
const ngControl = this.injector.get<NgControl>(NgControl as any); | ||
|
||
this.formControl = ngControl.control; | ||
} | ||
} | ||
|
||
export function MakeProvider(type: any) { | ||
return { | ||
provide: NG_VALUE_ACCESSOR, | ||
useExisting: forwardRef(() => type), | ||
multi: true | ||
}; | ||
} |
4 changes: 4 additions & 0 deletions
4
...dynamic-form-wizard/components/control-configuration/control-configuration.component.html
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,4 @@ | ||
<lib-dynamic-form-outlet [dynamicFormGroup]="formGroup"></lib-dynamic-form-outlet> | ||
<div class="flexbox"><button [disabled]="!formGroup.valid" mat-raised-button color="primary" (click)="submitForm()">Submit</button></div> | ||
|
||
<ng-template #section let-name="name">{{ name }}</ng-template> |
Oops, something went wrong.