Skip to content

Commit e5914e8

Browse files
eneufeldsdirix
authored andcommitted
Update seed to new jsonforms root component
This updates the seed to use the new root component. - Removed the store - move necessary parameters into app.component - update to jsonform 2.5.0-alpha.0
1 parent 93ab0c3 commit e5914e8

File tree

7 files changed

+87
-125
lines changed

7 files changed

+87
-125
lines changed

package-lock.json

Lines changed: 12 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@
2323
"@angular/platform-browser": "^9.0.2",
2424
"@angular/platform-browser-dynamic": "^9.0.2",
2525
"@angular/router": "^9.0.2",
26-
"@jsonforms/angular": "^2.4.1",
27-
"@jsonforms/angular-material": "^2.4.1",
28-
"@jsonforms/core": "^2.4.1",
26+
"@jsonforms/angular": "^2.5.0-alpha.0",
27+
"@jsonforms/angular-material": "^2.5.0-alpha.0",
28+
"@jsonforms/core": "^2.5.0-alpha.0",
2929
"core-js": "^2.4.1",
3030
"json-refs": "^3.0.4",
3131
"libphonenumber-js": "^1.6.8",

src/app/app.component.html

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,11 @@ <h1>
55
</h1>
66
<img width="150" alt="Angular Logo" src="data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCAyNTAgMjUwIj4KICAgIDxwYXRoIGZpbGw9IiNERDAwMzEiIGQ9Ik0xMjUgMzBMMzEuOSA2My4ybDE0LjIgMTIzLjFMMTI1IDIzMGw3OC45LTQzLjcgMTQuMi0xMjMuMXoiIC8+CiAgICA8cGF0aCBmaWxsPSIjQzMwMDJGIiBkPSJNMTI1IDMwdjIyLjItLjFWMjMwbDc4LjktNDMuNyAxNC4yLTEyMy4xTDEyNSAzMHoiIC8+CiAgICA8cGF0aCAgZmlsbD0iI0ZGRkZGRiIgZD0iTTEyNSA1Mi4xTDY2LjggMTgyLjZoMjEuN2wxMS43LTI5LjJoNDkuNGwxMS43IDI5LjJIMTgzTDEyNSA1Mi4xem0xNyA4My4zaC0zNGwxNy00MC45IDE3IDQwLjl6IiAvPgogIDwvc3ZnPg==">
77
</div>
8-
<jsonforms-outlet></jsonforms-outlet>
8+
<jsonforms
9+
[data]="data"
10+
[schema]="schema"
11+
[uischema]="uischema"
12+
[renderers]="renderers"
13+
[locale]="'de-DE'"
14+
[ajv]="ajv"
15+
></jsonforms>

src/app/app.component.ts

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,68 @@
11
import { Component } from '@angular/core';
2+
import { angularMaterialRenderers } from '@jsonforms/angular-material';
3+
import { and, createAjv, isControl, optionIs, rankWith, schemaTypeIs, scopeEndsWith, Tester } from '@jsonforms/core';
4+
import { CustomAutocompleteControlRenderer } from './custom.autocomplete';
5+
import { DataDisplayComponent } from './data.control';
6+
import { LangComponent } from './lang.control';
7+
import uischemaAsset from '../assets/uischema.json';
8+
import schemaAsset from '../assets/schema.json';
9+
import dataAsset from './data';
10+
import AJV from 'ajv';
11+
import { parsePhoneNumber } from 'libphonenumber-js';
12+
13+
const departmentTester: Tester = and(
14+
schemaTypeIs('string'),
15+
scopeEndsWith('department')
16+
);
217

318
@Component({
419
selector: 'app-root',
520
templateUrl: './app.component.html',
621
styleUrls: ['./app.component.css']
722
})
823
export class AppComponent {
24+
renderers = [
25+
...angularMaterialRenderers,
26+
{ tester: rankWith(5, departmentTester), renderer: CustomAutocompleteControlRenderer },
27+
{
28+
renderer: DataDisplayComponent,
29+
tester: rankWith(
30+
6,
31+
and(
32+
isControl,
33+
scopeEndsWith('___data')
34+
)
35+
)
36+
},
37+
{
38+
renderer: LangComponent,
39+
tester: rankWith(
40+
6,
41+
and(
42+
isControl,
43+
optionIs('lang', true)
44+
)
45+
)
46+
},
47+
];
48+
uischema = uischemaAsset;
49+
schema = schemaAsset;
50+
data = dataAsset;
51+
ajv = createAjv({
52+
schemaId: 'auto',
53+
allErrors: true,
54+
jsonPointers: true,
55+
errorDataPath: 'property'
56+
});
57+
constructor() {
58+
this.ajv.addFormat('time', '^([0-1][0-9]|2[0-3]):[0-5][0-9]$');
59+
this.ajv.addFormat('tel', maybePhoneNumber => {
60+
try {
61+
parsePhoneNumber(maybePhoneNumber, 'DE');
62+
return true;
63+
} catch (_) {
64+
return false;
65+
}
66+
});
67+
}
968
}

src/app/app.module.ts

Lines changed: 3 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -1,63 +1,17 @@
1-
import { HttpClient, HttpClientModule } from '@angular/common/http';
2-
import { APP_INITIALIZER, NgModule } from '@angular/core';
1+
import { HttpClientModule } from '@angular/common/http';
2+
import { NgModule } from '@angular/core';
33
import { MatAutocompleteModule } from '@angular/material/autocomplete';
44
import { MatProgressSpinnerModule } from '@angular/material/progress-spinner';
55
import { BrowserModule } from '@angular/platform-browser';
66
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
7-
import { JsonFormsAngularService, JsonFormsModule } from '@jsonforms/angular';
7+
import { JsonFormsModule } from '@jsonforms/angular';
88
import { JsonFormsAngularMaterialModule } from '@jsonforms/angular-material';
9-
import { Actions, setLocale, UISchemaElement } from '@jsonforms/core';
10-
import AJV from 'ajv';
11-
import JsonRefs from 'json-refs';
12-
import { parsePhoneNumber } from 'libphonenumber-js';
13-
import { forkJoin } from 'rxjs';
149
import { AppComponent } from './app.component';
1510
import { CustomAutocompleteControlRenderer } from './custom.autocomplete';
16-
import data from './data';
1711
import { DataDisplayComponent } from './data.control';
1812
import { LangComponent } from './lang.control';
19-
import { initialState } from './store';
2013

21-
export const loadCore = (jsonformsService: JsonFormsAngularService, http: HttpClient): () => Promise<void> => {
22-
return () => {
23-
const ajv = new AJV({
24-
schemaId: 'auto',
25-
allErrors: true,
26-
jsonPointers: true,
27-
errorDataPath: 'property'
28-
});
29-
ajv.addFormat('time', '^([0-1][0-9]|2[0-3]):[0-5][0-9]$');
30-
ajv.addFormat('tel', maybePhoneNumber => {
31-
try {
32-
parsePhoneNumber(maybePhoneNumber, 'DE');
33-
return true;
34-
} catch (_) {
35-
return false;
36-
}
37-
});
3814

39-
return forkJoin({
40-
uischema: http.get('./assets/uischema.json'),
41-
schema: http.get('./assets/schema.json')
42-
}).toPromise().then(result => {
43-
const { schema, uischema } = result;
44-
return JsonRefs.resolveRefs(schema)
45-
.then(
46-
(res: any) => {
47-
jsonformsService.updateCore(
48-
Actions.init(
49-
data,
50-
res.resolved,
51-
uischema as UISchemaElement,
52-
ajv as any
53-
)
54-
);
55-
}
56-
57-
);
58-
});
59-
};
60-
};
6115
@NgModule({
6216
declarations: [
6317
AppComponent,
@@ -75,23 +29,8 @@ export const loadCore = (jsonformsService: JsonFormsAngularService, http: HttpCl
7529
HttpClientModule
7630
],
7731
schemas: [],
78-
providers: [
79-
{
80-
provide: APP_INITIALIZER,
81-
useFactory: loadCore,
82-
deps: [JsonFormsAngularService, HttpClient],
83-
multi: true
84-
}
85-
],
8632
entryComponents: [CustomAutocompleteControlRenderer, LangComponent, DataDisplayComponent],
8733
bootstrap: [AppComponent]
8834
})
8935
export class AppModule {
90-
constructor(jsonformsService: JsonFormsAngularService) {
91-
jsonformsService.init(initialState.jsonforms);
92-
93-
jsonformsService.updateLocale(setLocale('de-DE'));
94-
95-
96-
}
9736
}

src/app/store.ts

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

tsconfig.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@
1818
"es2018",
1919
"dom"
2020
],
21-
"allowSyntheticDefaultImports": true
21+
"allowSyntheticDefaultImports": true,
22+
"resolveJsonModule": true
2223
},
2324
"angularCompilerOptions": {
2425
"fullTemplateTypeCheck": true,

0 commit comments

Comments
 (0)