Skip to content
This repository was archived by the owner on Aug 25, 2020. It is now read-only.

Commit 8733e27

Browse files
committed
chore(structure): reorganized file structure, added modules
1 parent 9d930f6 commit 8733e27

File tree

61 files changed

+307
-191
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+307
-191
lines changed

dist/ngx-forms.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

index.d.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
export { FieldConfig, Field } from "./src/app/types";
2-
export { NgxFormModule } from "./src/app";
3-
export { DynamicFormComponent } from "./src/app/containers/dynamic-form/dynamic-form.component";
1+
export { FieldConfig, Field } from "./src/types";
2+
export { NgxFormModule } from "./src/app/app.module";
3+
export { DynamicFormDirective } from "./src/app/dynamic-form/dynamic-form.component";

src/app.ts

Lines changed: 0 additions & 106 deletions
This file was deleted.

src/app/app.module.ts

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
import { NgModule, NO_ERRORS_SCHEMA, ModuleWithProviders } from '@angular/core';
2+
import { CommonModule } from '@angular/common';
3+
import { ReactiveFormsModule, FormsModule } from '@angular/forms';
4+
import { DynamicFormDirective } from './dynamic-form/dynamic-form.component';
5+
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
6+
import { FIELD_DICT_TOKEN, LAYOUTS_TOKEN, FormsExtensions } from '../types';
7+
import { FormFieldsModule, defaultInputs } from './fields/fields.module';
8+
import { FormLayoutsModule, defaultLayouts } from './layouts/layouts.module';
9+
import { DynamicFieldModule } from './dynamic-field/dynamic-field.module';
10+
11+
@NgModule({
12+
imports: [
13+
CommonModule,
14+
BrowserAnimationsModule,
15+
ReactiveFormsModule,
16+
FormsModule,
17+
FormLayoutsModule,
18+
FormFieldsModule,
19+
DynamicFieldModule
20+
],
21+
declarations: [
22+
DynamicFormDirective
23+
],
24+
exports: [
25+
DynamicFormDirective
26+
],
27+
providers: [
28+
{
29+
provide: FIELD_DICT_TOKEN,
30+
useValue: defaultInputs
31+
},
32+
{
33+
provide: LAYOUTS_TOKEN,
34+
useValue: defaultLayouts
35+
}
36+
],
37+
schemas: [
38+
NO_ERRORS_SCHEMA
39+
]
40+
})
41+
export class NgxFormModule {
42+
public static forRoot({ fieldDictionary, layoutDictionary }: FormsExtensions): ModuleWithProviders {
43+
if (fieldDictionary) { Object.keys(fieldDictionary).forEach(key => defaultInputs[key] = fieldDictionary[key]); }
44+
if (layoutDictionary) { Object.keys(layoutDictionary).forEach(key => defaultLayouts[key] = layoutDictionary[key]); }
45+
46+
return {
47+
ngModule: NgxFormModule,
48+
providers: [
49+
{
50+
provide: FIELD_DICT_TOKEN,
51+
useValue: defaultInputs
52+
},
53+
{
54+
provide: LAYOUTS_TOKEN,
55+
useValue: defaultLayouts
56+
}
57+
]
58+
};
59+
}
60+
}
61+
62+
63+
// TODO: next
64+
// break down Nav module into Groups module
65+
// unit tests
66+
// create different default layouts for ngx-forms
67+
// make nav part of group-layout

src/app/containers/dynamic-form/dynamic-form.component.ts

Lines changed: 0 additions & 33 deletions
This file was deleted.

src/app/containers/dynamic-panel/dynamic-panel.component.ts

Lines changed: 0 additions & 13 deletions
This file was deleted.

src/app/components/dynamic-field/dynamic-field.directive.spec.ts renamed to src/app/dynamic-field/dynamic-field.directive.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { DynamicFieldDirective } from "./dynamic-field.directive"
77
import { By } from '@angular/platform-browser';
88
import { FieldConfig, FieldDictionary, FIELD_DICT_TOKEN } from "../../types";
99
import { FormInputComponent } from "../form-input/form-input.component";
10-
import { FormInputHiddenComponent } from '../form-hidden/form-hidden.component';
10+
import { FormInputHiddenComponent } from '../form-hidden/form-hidden.component'; // mock this inputs instead of importing
1111

1212
const defaultInputs: FieldDictionary = {
1313
text: FormInputComponent,

src/app/components/dynamic-field/dynamic-field.directive.ts renamed to src/app/dynamic-field/dynamic-field.directive.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,15 @@ export class DynamicFieldDirective implements Field, OnInit, OnDestroy {
2121
ngOnInit() {
2222
if (!this.group) { throw new Error('group is not set'); }
2323
if (!this.inputs[this.field.type]) { throw new Error(`Input with type "${this.field.type}" was not found`); }
24-
24+
2525
const componentReference = this.inputs[this.field.type];
2626
const component = this.resolver.resolveComponentFactory<Field>(componentReference);
2727
this.component = this.container.createComponent(component);
2828
this.component.instance.field = this.field;
2929
this.component.instance.group = this.group;
3030

31+
console.log('creating control ', this.field.type)
32+
3133
this.component.instance.model = this.model;
3234
this.group.addControl(this.field.name, this.createControl(this.field));
3335

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { NgModule, NO_ERRORS_SCHEMA } from '@angular/core';
2+
import { DynamicFieldDirective } from './dynamic-field.directive';
3+
import { CommonModule } from '@angular/common';
4+
5+
@NgModule({
6+
imports: [
7+
CommonModule
8+
],
9+
declarations: [
10+
DynamicFieldDirective
11+
],
12+
exports: [
13+
DynamicFieldDirective
14+
],
15+
schemas: [
16+
NO_ERRORS_SCHEMA
17+
]
18+
})
19+
export class DynamicFieldModule { }

src/app/containers/dynamic-form/dynamic-form.component.spec.ts renamed to src/app/dynamic-form/dynamic-form.component.spec.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
2-
import { DynamicPanelComponent } from '../dynamic-panel/dynamic-panel.component';
2+
import { PanelComponent } from '../layout-group-panel/layout-group-panel.component';
33
import { DynamicFieldDirective } from '../../components/dynamic-field/dynamic-field.directive';
44
import { Component, NgModule } from "@angular/core";
5-
import { DynamicFormComponent } from "./dynamic-form.component";
5+
import { DynamicFormDirective } from "./dynamic-form.component";
66
import { ReactiveFormsModule, FormsModule } from '@angular/forms';
77
import { FormInputComponent } from '../../components/form-input/form-input.component';
88
import { CommonModule } from '@angular/common';
@@ -47,14 +47,14 @@ class TestComponent implements IDynamicForm {
4747
})
4848
class TestModule { }
4949

50-
describe('DynamicFormComponent', () => {
50+
describe('DynamicFormDirective', () => {
5151
let component: TestComponent;
5252
let fixture: ComponentFixture<TestComponent>;
5353
let directiveEl;
5454

5555
beforeEach(async(() => {
5656
TestBed.configureTestingModule({
57-
declarations: [DynamicFieldDirective, TestComponent, DynamicFormComponent, DynamicPanelComponent],
57+
declarations: [DynamicFieldDirective, TestComponent, DynamicFormDirective, PanelComponent],
5858
imports: [FormsModule, ReactiveFormsModule, TestModule, FormNavModule],
5959
providers: [{ provide: FIELD_DICT_TOKEN, useValue: defaultInputs }]
6060
})
@@ -87,8 +87,8 @@ describe('DynamicFormComponent', () => {
8787
expect(directiveEl).not.toBeNull();
8888
});
8989

90-
it('loads dynamic-panel component', () => {
91-
directiveEl = fixture.debugElement.query(By.directive(DynamicPanelComponent));
90+
it('loads layout-group-panel component', () => {
91+
directiveEl = fixture.debugElement.query(By.directive(PanelComponent));
9292
expect(directiveEl).not.toBeNull();
9393
});
9494

@@ -107,21 +107,21 @@ describe('DynamicFormComponent', () => {
107107
});
108108
});
109109

110-
describe('DynamicFormComponent Core', () => {
111-
let component: DynamicFormComponent;
112-
let fixture: ComponentFixture<DynamicFormComponent>;
110+
describe('DynamicFormDirective Core', () => {
111+
let component: DynamicFormDirective;
112+
let fixture: ComponentFixture<DynamicFormDirective>;
113113
let model = { test: 'test', title: 'title' };
114114

115115
beforeEach(() => {
116116
TestBed.configureTestingModule({
117-
declarations: [DynamicFieldDirective, TestComponent, DynamicFormComponent, DynamicPanelComponent],
117+
declarations: [DynamicFieldDirective, TestComponent, DynamicFormDirective, PanelComponent],
118118
imports: [FormsModule, ReactiveFormsModule, TestModule, FormNavModule],
119119
providers: [{ provide: FIELD_DICT_TOKEN, useValue: defaultInputs }]
120120
}).compileComponents();
121121
});
122122

123123
beforeEach(() => {
124-
fixture = TestBed.createComponent(DynamicFormComponent);
124+
fixture = TestBed.createComponent(DynamicFormDirective);
125125
component = fixture.componentInstance;
126126
component.formConfig = {
127127
form: [

0 commit comments

Comments
 (0)