Skip to content

Commit 6e641d7

Browse files
committed
Merge remote-tracking branch 'makinacorpus/master' into arrayBugFix
2 parents ae48c7d + 7a180b9 commit 6e641d7

13 files changed

+163
-44
lines changed

CHANGELOG.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,26 @@
1+
# 1.0.0-beta.8 (unreleased)
2+
3+
## Bug Fixes
4+
5+
- Restore has-success/has-error class
6+
7+
# 1.0.0-beta.7 (2017-04-24)
8+
9+
## New features
10+
11+
- Upgrade to Angular 4
12+
13+
## Bug Fixes
14+
15+
- Clean up existing elements on schema changes
16+
- Fix AOT build
17+
18+
# 1.0.0-beta.6 (2017-04-21)
19+
20+
## Bug Fixes
21+
22+
- Re-render form on schema change [ZheyangSong]
23+
124
# 1.0.0-beta.5 (2017-03-18)
225

326
## Bug Fixes

package.json

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "angular2-schema-form",
3-
"version": "1.0.0-beta.5",
3+
"version": "1.0.0-beta.7",
44
"description": "Angular2 Schema Form (DISCLAIMER: it is not related to angular-schema-form)",
55
"main": "dist/index.js",
66
"typings": "dist/index.d.ts",
@@ -42,20 +42,20 @@
4242
"z-schema": "^3.17.0"
4343
},
4444
"peerDependencies": {
45-
"@angular/common": "^2.4.0",
46-
"@angular/forms": "^2.4.0",
47-
"@angular/compiler": "^2.4.0",
48-
"@angular/core": "^2.4.0",
49-
"@angular/http": "^2.4.0",
50-
"@angular/platform-browser": "^2.4.0",
45+
"@angular/common": "^4.0.3",
46+
"@angular/forms": "^4.0.3",
47+
"@angular/compiler": "^4.0.3",
48+
"@angular/core": "^4.0.3",
49+
"@angular/http": "^4.0.3",
50+
"@angular/platform-browser": "^4.0.3",
5151
"core-js": "2.4.1",
5252
"rxjs": "^5.1.0",
53-
"typescript": "2.0.10",
53+
"typescript": "2.2.2",
5454
"zone.js": "^0.7.6"
5555
},
5656
"devDependencies": {
57-
"@angular/compiler-cli": "^2.4.0",
58-
"@angular/platform-server": "^2.4.0",
57+
"@angular/compiler-cli": "^4.0.3",
58+
"@angular/platform-server": "^4.0.3",
5959
"@types/jasmine": "2.5.38",
6060
"@types/node": "6.0.60",
6161
"npm-install-peers": "^1.1.0",

src/default.widget.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@ import { Component } from '@angular/core';
22

33
@Component({
44
selector: 'sf-default-field',
5-
template: `
6-
<p>Cannot find valid type for {{name}}
7-
`
5+
template: `<p>Unknow type</p>`
86
})
97
export class DefaultWidget {}

src/form.component.ts

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,16 @@ import {
1919

2020
import { SchemaValidatorFactory, ZSchemaValidatorFactory } from './schemavalidatorfactory';
2121
import { WidgetFactory } from './widgetfactory';
22+
import { TerminatorService } from './terminator.service';
2223

2324
export function useFactory(schemaValidatorFactory, validatorRegistry) {
2425
return new FormPropertyFactory(schemaValidatorFactory, validatorRegistry);
2526
};
2627

2728
@Component({
2829
selector: 'sf-form',
29-
template: `<sf-form-element
30-
*ngIf="rootProperty" [formProperty]="rootProperty"></sf-form-element>`,
30+
template: `<form><sf-form-element
31+
*ngIf="rootProperty" [formProperty]="rootProperty"></sf-form-element></form>`,
3132
providers: [
3233
ActionRegistry,
3334
ValidatorRegistry,
@@ -40,7 +41,8 @@ export function useFactory(schemaValidatorFactory, validatorRegistry) {
4041
provide: FormPropertyFactory,
4142
useFactory: useFactory,
4243
deps: [SchemaValidatorFactory, ValidatorRegistry]
43-
}
44+
},
45+
TerminatorService,
4446
]
4547
})
4648
export class FormComponent implements OnChanges {
@@ -61,11 +63,11 @@ export class FormComponent implements OnChanges {
6163
private formPropertyFactory: FormPropertyFactory,
6264
private actionRegistry: ActionRegistry,
6365
private validatorRegistry: ValidatorRegistry,
64-
private cdr: ChangeDetectorRef
66+
private cdr: ChangeDetectorRef,
67+
private terminator: TerminatorService,
6568
) { }
6669

6770
ngOnChanges(changes: any) {
68-
console.log(changes);
6971
if (changes.validators) {
7072
this.setValidators();
7173
}
@@ -74,12 +76,14 @@ export class FormComponent implements OnChanges {
7476
this.setActions();
7577
}
7678

77-
if (!this.schema.type) {
79+
if (this.schema && !this.schema.type) {
7880
this.schema.type = 'object';
7981
}
8082

8183
if (this.schema && changes.schema) {
82-
console.log(this.schema, changes.schema);
84+
if (!changes.schema.firstChange) {
85+
this.terminator.destroy();
86+
}
8387
SchemaPreprocessor.preprocess(this.schema);
8488
this.rootProperty = this.formPropertyFactory.createProperty(this.schema);
8589
this.rootProperty.valueChanges.subscribe(value => { this.onChange.emit({value: value}); });

src/formelement.component.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ import {
1717

1818
@Component({
1919
selector: 'sf-form-element',
20-
template: `<div *ngIf="formProperty.visible">
20+
template: `<div *ngIf="formProperty.visible"
21+
[class.has-error]="!control.valid"
22+
[class.has-success]="control.valid">
2123
<sf-widget-chooser
2224
(widgetInstanciated)="onWidgetInstanciated($event)"
2325
[widgetInfo]="formProperty.schema.widget">
@@ -32,9 +34,9 @@ export class FormElementComponent implements OnInit {
3234
@Input() formProperty: FormProperty;
3335
control: FormControl = new FormControl('', () => null);
3436

35-
private widget: Widget<any> = null;
37+
widget: Widget<any> = null;
3638

37-
private buttons = [];
39+
buttons = [];
3840

3941

4042
constructor(private actionRegistry: ActionRegistry) {}

src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ export { FormElementComponent } from './formelement.component';
33
export { WidgetChooserComponent } from './widgetchooser.component';
44
export { WidgetRegistry } from './widgetregistry';
55
export { Validator } from './model/validator';
6+
export { TerminatorService } from './terminator.service';
67

78
export {
89
Widget,

src/terminator.service.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { Injectable } from '@angular/core';
2+
import { Subject } from 'rxjs/Rx';
3+
4+
@Injectable()
5+
export class TerminatorService {
6+
public onDestroy: Subject<boolean>;
7+
8+
constructor() {
9+
this.onDestroy = new Subject();
10+
}
11+
12+
destroy() {
13+
this.onDestroy.next(true);
14+
}
15+
}

src/widgetchooser.component.spec.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { ChangeDetectorRef } from '@angular/core';
22
import { TestBed } from '@angular/core/testing';
33

4+
import { TerminatorService } from './terminator.service';
45
import { WidgetFactory } from './widgetfactory';
56
import { WidgetRegistry } from './widgetregistry';
67

@@ -14,7 +15,8 @@ describe('WidgetChooserComponent', () => {
1415
providers: [
1516
WidgetFactory,
1617
WidgetRegistry,
17-
ChangeDetectorRef
18+
ChangeDetectorRef,
19+
TerminatorService,
1820
]
1921
});
2022
});

src/widgetchooser.component.ts

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,22 @@
11
import {
22
Component,
3+
ComponentRef,
34
ChangeDetectorRef,
45
EventEmitter,
56
Input,
6-
OnInit,
7+
OnChanges,
78
Output,
89
ViewChild,
910
ViewContainerRef,
1011
} from '@angular/core';
11-
12+
import { TerminatorService } from './terminator.service';
1213
import { WidgetFactory } from './widgetfactory';
1314

1415
@Component({
1516
selector: 'sf-widget-chooser',
1617
template: `<div #target></div>`,
1718
})
18-
export class WidgetChooserComponent implements OnInit {
19+
export class WidgetChooserComponent implements OnChanges {
1920

2021
@Input() widgetInfo: any;
2122

@@ -24,14 +25,26 @@ export class WidgetChooserComponent implements OnInit {
2425
@ViewChild('target', {read: ViewContainerRef}) container: ViewContainerRef;
2526

2627
private widgetInstance: any;
28+
private ref: ComponentRef<any>;
2729

28-
29-
constructor(private widgetFactory: WidgetFactory = null, private cdr: ChangeDetectorRef) {}
30+
constructor(
31+
private widgetFactory: WidgetFactory = null,
32+
private cdr: ChangeDetectorRef,
33+
private terminator: TerminatorService,
34+
) { }
3035

3136
ngOnInit() {
32-
let ref = this.widgetFactory.createWidget(this.container, this.widgetInfo.id);
33-
this.widgetInstanciated.emit(ref.instance);
34-
this.widgetInstance = ref.instance;
37+
this.terminator.onDestroy.subscribe(destroy => {
38+
if (destroy) {
39+
this.ref.destroy();
40+
}
41+
})
42+
}
43+
44+
ngOnChanges() {
45+
this.ref = this.widgetFactory.createWidget(this.container, this.widgetInfo.id);
46+
this.widgetInstanciated.emit(this.ref.instance);
47+
this.widgetInstance = this.ref.instance;
3548
this.cdr.detectChanges();
3649
}
3750
}

tests/package.json

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,14 @@
1313
},
1414
"private": true,
1515
"dependencies": {
16-
"@angular/common": "^2.4.0",
17-
"@angular/compiler": "^2.4.0",
18-
"@angular/core": "^2.4.0",
19-
"@angular/forms": "^2.4.0",
20-
"@angular/http": "^2.4.0",
21-
"@angular/platform-browser": "^2.4.0",
22-
"@angular/platform-browser-dynamic": "^2.4.0",
23-
"@angular/router": "^3.4.0",
16+
"@angular/common": "^4.0.3",
17+
"@angular/compiler": "^4.0.3",
18+
"@angular/core": "^4.0.3",
19+
"@angular/forms": "^4.0.3",
20+
"@angular/http": "^4.0.3",
21+
"@angular/platform-browser": "^4.0.3",
22+
"@angular/platform-browser-dynamic": "^4.0.3",
23+
"@angular/router": "^4.0.3",
2424
"body-parser": "^1.17.1",
2525
"bootstrap": "^3.3.7",
2626
"core-js": "^2.4.1",
@@ -31,8 +31,8 @@
3131
"zone.js": "^0.7.6"
3232
},
3333
"devDependencies": {
34-
"@angular/cli": "1.0.0-rc.1",
35-
"@angular/compiler-cli": "^2.4.0",
34+
"@angular/cli": "^1.0.0",
35+
"@angular/compiler-cli": "^4.0.3",
3636
"@types/jasmine": "2.5.38",
3737
"@types/node": "~6.0.60",
3838
"codelyzer": "~2.0.0",
@@ -41,12 +41,12 @@
4141
"karma": "~1.4.1",
4242
"karma-chrome-launcher": "~2.0.0",
4343
"karma-cli": "~1.0.1",
44+
"karma-coverage-istanbul-reporter": "^0.2.0",
4445
"karma-jasmine": "~1.1.0",
4546
"karma-jasmine-html-reporter": "^0.2.2",
46-
"karma-coverage-istanbul-reporter": "^0.2.0",
4747
"protractor": "~5.1.0",
4848
"ts-node": "~2.0.0",
4949
"tslint": "~4.4.2",
50-
"typescript": "~2.0.0"
50+
"typescript": "^2.2.2"
5151
}
5252
}

0 commit comments

Comments
 (0)