-
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.
feat: display a simple hidden input (#6)
* feat: hidden component * refactor: move button to input folder * feat: service to fetch Widgets * refactor: force layout to be loaded from example * refactor: replace widget with type * feat: set name on widget control * refactor: convert div container to template * refactor: remove formControl until its ready * fix: error being thrown in demo * fix: lint error for unused variable * fix: missed _id renaming to id * fix: logic error in parsing examples * test: adds missing test cases
- Loading branch information
Showing
29 changed files
with
243 additions
and
42 deletions.
There are no files selected for viewing
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
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
3 changes: 2 additions & 1 deletion
3
projects/ngx-json-schema-form/src/assests/example-layouts/jsf-layout-basic.json
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,4 +1,5 @@ | ||
[ { | ||
"key": "comment", | ||
"type": "textarea" | ||
"type": "textarea", | ||
"name": "control" | ||
} ] |
2 changes: 1 addition & 1 deletion
2
projects/ngx-json-schema-form/src/lib/json-schema-form.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 |
---|---|---|
@@ -1,5 +1,5 @@ | ||
<form (ngSubmit)="submitForm()"> | ||
<div *ngFor="let layoutItem of layoutService.layout; trackBy: trackByFn;"> | ||
<jsf-select-widget [layoutNode]=layoutItem></jsf-select-widget> | ||
<jsf-select-widget [layoutNode]="layoutItem"></jsf-select-widget> | ||
</div> | ||
</form> |
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
9 changes: 4 additions & 5 deletions
9
projects/ngx-json-schema-form/src/lib/json-schema-form.service.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,17 +1,16 @@ | ||
import { Injectable } from '@angular/core'; | ||
import { Widget } from './widget-library'; | ||
|
||
@Injectable() | ||
export class JsonSchemaFormService { | ||
private x = false; | ||
|
||
initializeControl(ctx: any, bind = true): boolean { | ||
// TODO | ||
|
||
return this.x; | ||
initializeControl(control: Widget, bind = true): void { | ||
control.controlName = control.layoutNode.name; | ||
} | ||
|
||
updateValue(ctx: any, value: any): void { | ||
// TODO | ||
this.x = value; | ||
this.x = !this.x; | ||
} | ||
} |
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
2 changes: 1 addition & 1 deletion
2
...n-schema-form/src/lib/widget-library/container/select-widget/select-widget.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 |
---|---|---|
@@ -1 +1 @@ | ||
<div #widgetContainer></div> | ||
<ng-template #widgetContainer></ng-template> |
60 changes: 59 additions & 1 deletion
60
...chema-form/src/lib/widget-library/container/select-widget/select-widget.component.spec.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,25 +1,83 @@ | ||
import { CommonModule } from '@angular/common'; | ||
import { Component, ComponentRef, NgModule } from '@angular/core'; | ||
import { ComponentFixture, TestBed } from '@angular/core/testing'; | ||
|
||
import { JsonSchemaFormService } from '../../../json-schema-form.service'; | ||
|
||
import { WidgetLibraryService } from '../../widget-library.service'; | ||
|
||
import { SelectWidgetComponent } from './select-widget.component'; | ||
|
||
describe('SelectWidgetComponent', () => { | ||
let component: SelectWidgetComponent; | ||
let fixture: ComponentFixture<SelectWidgetComponent>; | ||
let newComponent: ComponentRef<any>; | ||
|
||
@Component({ | ||
selector: 'jsf-component', | ||
template: '<div>Hello World</div>' | ||
}) | ||
class TestComponent {} | ||
|
||
@NgModule({ | ||
declarations: [ TestComponent ], | ||
entryComponents: [ TestComponent ], | ||
imports: [ CommonModule ] | ||
}) | ||
class TestModule {} // tslint:disable-line | ||
|
||
beforeEach(async () => { | ||
const mockFormService: JsonSchemaFormService = jasmine.createSpyObj('JsonSchemaFormService', { | ||
initializeControl: true | ||
}); | ||
const mockWidgetService: WidgetLibraryService = jasmine.createSpyObj('WidgetLibraryService', { | ||
getWidget: TestComponent | ||
}); | ||
|
||
return TestBed.configureTestingModule({ | ||
declarations: [ SelectWidgetComponent ] | ||
declarations: [ SelectWidgetComponent ], | ||
imports: [ TestModule ], | ||
providers: [{ | ||
provide: JsonSchemaFormService, | ||
useValue: mockFormService | ||
}, { | ||
provide: WidgetLibraryService, | ||
useValue: mockWidgetService | ||
}] | ||
}) | ||
.compileComponents(); | ||
}); | ||
|
||
beforeEach(() => { | ||
fixture = TestBed.createComponent(SelectWidgetComponent); | ||
component = fixture.componentInstance; | ||
component.layoutNode = {id: '0', options: {}, type: 'hidden'}; | ||
const original = component.widgetContainer.createComponent; | ||
spyOn(component.widgetContainer, 'createComponent').and.callFake((...args) => { | ||
newComponent = original.apply(component.widgetContainer, args); | ||
|
||
return newComponent; | ||
}); | ||
fixture.detectChanges(); | ||
}); | ||
|
||
it('should create', () => { | ||
expect(component).toBeTruthy(); | ||
}); | ||
|
||
it('should instantiate widget', () => { | ||
expect(newComponent.componentType).toEqual(TestComponent); | ||
}); | ||
|
||
it('should set properties', () => { | ||
expect(newComponent.instance.layoutNode).toEqual(component.layoutNode); | ||
expect(newComponent.instance.layoutIndex).toEqual(component.layoutIndex); | ||
expect(newComponent.instance.dataIndex).toEqual(component.dataIndex); | ||
}); | ||
|
||
it('should update component when input changes', () => { | ||
component.dataIndex = [1 + 1]; | ||
component[`ngOnChanges`](); | ||
expect(newComponent.instance.dataIndex).toEqual(component.dataIndex); | ||
}); | ||
}); |
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
11 changes: 8 additions & 3 deletions
11
projects/ngx-json-schema-form/src/lib/widget-library/index.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,11 +1,16 @@ | ||
import { ButtonComponent } from './button/button.component'; | ||
import { ButtonComponent } from './input/button/button.component'; | ||
import { HiddenComponent } from './input/hidden/hidden.component'; | ||
|
||
import { SelectWidgetComponent } from './container/select-widget/select-widget.component'; | ||
|
||
export const BASIC_WIDGETS = [ | ||
ButtonComponent, SelectWidgetComponent | ||
ButtonComponent, HiddenComponent, | ||
SelectWidgetComponent | ||
]; | ||
|
||
export { Widget } from './widget'; | ||
|
||
export { ButtonComponent } from './button/button.component'; | ||
export { ButtonComponent } from './input/button/button.component'; | ||
export { HiddenComponent } from './input/hidden/hidden.component'; | ||
|
||
export { SelectWidgetComponent } from './container/select-widget/select-widget.component'; |
2 changes: 1 addition & 1 deletion
2
...dget-library/button/button.component.html → ...ibrary/input/button/button.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
File renamed without changes.
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
...widget-library/button/button.component.ts → ...-library/input/button/button.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
4 changes: 4 additions & 0 deletions
4
projects/ngx-json-schema-form/src/lib/widget-library/input/hidden/hidden.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 @@ | ||
<input | ||
[id]="'control' + layoutNode.id" | ||
[name]="controlName" | ||
type="hidden"> |
Empty file.
Oops, something went wrong.