Skip to content

Commit eb9ec6e

Browse files
committed
Merge branch 'async-load' of git://github.com/pancho111203/jsonforms into pancho111203-async-load
2 parents 082dc08 + 8f86826 commit eb9ec6e

Some content is hidden

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

41 files changed

+620
-434
lines changed

.babelrc

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

examples/app/app.js

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,7 @@
1-
'use strict';
1+
import angular from 'angular';
2+
3+
var app = angular.module('makeithappen', [
4+
'ngRoute',
5+
'jsonforms'
6+
]);
27

3-
import "./init.js";
4-
import "./index/index.controller.js";
5-
import "./editor/editor.controller.js";
6-
import "./resolve/resolve.controller.js";
7-
import "./person/person.controller.js";
8-
import "./default-ui/default-ui.controller.js";
9-
import "./default/default-schema.controller.js";
10-
import "./placeholder/placeholder.controller.js";
11-
import "./arrays/arrays.controller.js";
12-
import "./custom/custom.controller.js";
13-
import "./custom/custom.jsf.js";
14-
import "./polymer/polymer.controller.js";
15-
import "./polymer/polymer.jsf.js";
16-
import "./table/app.js";
17-
import "./routeconfig.js";
Lines changed: 250 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,250 @@
1+
'use strict';
2+
3+
var app = angular.module('makeithappen');
4+
5+
angular.module('makeithappen').controller('AsyncController', function($q) {
6+
var vm = this;
7+
8+
9+
var dataDefer = $q.defer();
10+
var UIDefer = $q.defer();
11+
var schemaDefer = $q.defer();
12+
13+
vm.dataAsync = dataDefer.promise;
14+
vm.UIAsync = UIDefer.promise;
15+
vm.schemaAsync = schemaDefer.promise;
16+
17+
vm.loadData = function(){
18+
dataDefer.resolve(data);
19+
};
20+
21+
vm.loadUI = function(){
22+
UIDefer.resolve(uischema);
23+
};
24+
25+
vm.loadSchema = function(){
26+
schemaDefer.resolve(schema);
27+
};
28+
29+
vm.data = data;
30+
vm.uischema = uischema;
31+
vm.schema = schema;
32+
33+
vm.formattedData = function() {
34+
return JSON.stringify(vm.users, null, 4);
35+
};
36+
37+
vm.loadDataFunc = function(){
38+
return data;
39+
};
40+
41+
vm.loadUIFunc = function(){
42+
return uischema;
43+
};
44+
45+
vm.loadSchemaFunc = function(){
46+
return schema;
47+
};
48+
49+
});
50+
51+
52+
var data = {
53+
name: 'John Doe',
54+
vegetarian: false,
55+
birthDate: "1985-06-02"
56+
};
57+
58+
var schema = {
59+
"type": "object",
60+
"properties": {
61+
"id": "user.json",
62+
"name": {
63+
"type": "string",
64+
"minLength": 3
65+
},
66+
"personalData": {
67+
"type": "object",
68+
"properties": {
69+
"age": {
70+
"type": "integer"
71+
},
72+
"height": {
73+
"type": "number"
74+
}
75+
},
76+
"required": ["age", "height"]
77+
},
78+
"vegetarian": {
79+
"type": "boolean"
80+
},
81+
"birthDate": {
82+
"type": "string",
83+
"format": "date-time"
84+
},
85+
"nationality": {
86+
"type": "string",
87+
"enum": ["DE", "IT", "JP", "US", "RU", "Other"]
88+
},
89+
"occupation": {
90+
"type": "string"
91+
},
92+
/* FIXME: disabling arrays for primitive types */
93+
/*"test_wrong": {
94+
"type": "array",
95+
"items": {"type":"string"}
96+
},*/
97+
"hobbies": {
98+
"type": "array",
99+
"items": {"type":"object","properties": {"name": {"type": "string"}}}
100+
}
101+
},
102+
"required": ["occupation", "nationality"]
103+
};
104+
105+
var uischema = {
106+
"type": "VerticalLayout",
107+
"elements": [
108+
{
109+
"type": "VerticalLayout",
110+
"elements": [
111+
],
112+
"rule":{
113+
"effect":"HIDE",
114+
"condition":{
115+
"type":"LEAF" ,
116+
"scope": {
117+
"$ref": "#/properties/personalData/properties/age"
118+
},
119+
"expectedValue":36
120+
}
121+
}
122+
},
123+
124+
{
125+
"type": "HorizontalLayout",
126+
"elements": [
127+
{
128+
"type": "Control",
129+
"label": {
130+
"text": "Name",
131+
"show": true
132+
},
133+
"scope": {
134+
"$ref": "#/properties/name"
135+
},
136+
"rule":{
137+
"effect":"HIDE",
138+
"condition":{
139+
"type":"LEAF" ,
140+
"scope": {
141+
"$ref": "#/properties/personalData/properties/age"
142+
},
143+
"expectedValue":36
144+
}
145+
}
146+
},
147+
{
148+
"type": "Control",
149+
"label": {
150+
"text": "Age"
151+
},
152+
"scope": {
153+
"$ref": "#/properties/personalData/properties/age"
154+
}
155+
},
156+
{
157+
"type": "Control",
158+
"label": "Height",
159+
"scope": {
160+
"$ref": "#/properties/personalData/properties/height"
161+
}
162+
},
163+
{
164+
"type": "Control",
165+
"label": "Vegetarian",
166+
"scope": {
167+
"$ref": "#/properties/vegetarian"
168+
}
169+
},
170+
{
171+
"type": "Control",
172+
"label": "Nationality",
173+
"scope": {
174+
"$ref": "#/properties/nationality"
175+
}
176+
},
177+
{
178+
"type": "Control",
179+
"label": "Occupation",
180+
"scope": {
181+
"$ref": "#/properties/occupation"
182+
},
183+
"suggestion": ["Accountant", "Engineer", "Freelancer", "Journalism", "Physician", "Student", "Teacher", "Other"]
184+
},
185+
{
186+
"type": "Control",
187+
"label": "Birthday",
188+
"scope": {
189+
"$ref": "#/properties/birthDate"
190+
}
191+
}
192+
]
193+
},
194+
{
195+
"type": "Categorization",
196+
"rule":{
197+
"effect":"SHOW",
198+
"condition":{
199+
"type":"LEAF" ,
200+
"scope": {
201+
"$ref": "#/properties/personalData/properties/age"
202+
},
203+
"expectedValue":36
204+
}
205+
},
206+
"elements": [
207+
{
208+
"type": "Category",
209+
"label":"Private",
210+
"elements": [
211+
{
212+
"type": "Control",
213+
"label": "Name",
214+
"scope": {
215+
"$ref": "#/properties/name"
216+
}
217+
},
218+
{
219+
"type": "Control",
220+
"label": "Age",
221+
"scope": {
222+
"$ref": "#/properties/personalData/properties/age"
223+
}
224+
}
225+
]
226+
},
227+
{
228+
"type": "Category",
229+
"label":"Additional",
230+
"elements": [
231+
{
232+
"type": "Control",
233+
"label": "Height",
234+
"scope": {
235+
"$ref": "#/properties/personalData/properties/height"
236+
}
237+
},
238+
{
239+
"type": "Control",
240+
"label": "Vegetarian",
241+
"scope": {
242+
"$ref": "#/properties/vegetarian"
243+
}
244+
}
245+
]
246+
}
247+
]
248+
}
249+
]
250+
};

examples/app/async/async.html

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<div class="panel">
2+
<div class="panel-heading">
3+
<h3>Asynchronous Form</h3>
4+
</div>
5+
<div class="panel-body">
6+
<button ng-click="vm.loadData()">Load Data</button>
7+
<button ng-click="vm.loadSchema()">Load Schema</button>
8+
<button ng-click="vm.loadUI()">Load UI</button>
9+
<jsonforms schema="vm.schemaAsync" uischema="vm.UIAsync" data="vm.dataAsync"></jsonforms>
10+
</div>
11+
<div class="panel-body">
12+
<jsonforms data="vm.loadDataFunc" uischema="vm.loadUIFunc" schema="vm.loadSchemaFunc"></jsonforms>
13+
</div>
14+
15+
</div>

examples/app/custom/custom.jsf.js

Lines changed: 11 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4,29 +4,19 @@ function customDirective() {
44
template : '<jsonforms-control>' +
55
'<input type="text" style="background-color: #3278b3; color: #8dd0ff" class="jsf-control-string jsf-control form-control" ng-change="vm.propagateChanges()" ng-model="vm.modelValue[vm.fragment]" />' +
66
'</jsonforms-control>',
7-
controller : customController,
7+
controller : function($controller, $scope) {
8+
$controller('BaseController', {scope: $scope})
9+
},
810
controllerAs : 'vm'
911
};
1012
}
11-
/**
12-
* @return {number}
13-
*/
14-
function CustomControlRendererTester (element, dataSchema, dataObject,pathResolver ) {
15-
if(element.type !== 'Control')
16-
return -1;
17-
var schemaPath = element['scope']['$ref'];
18-
if(schemaPath !== undefined && schemaPath.endsWith("firstName"))
19-
return 100;
20-
return -1;
21-
}
22-
var customController = ['$scope','PathResolver', function ($scope,refResolver) {
23-
var vm = this;
24-
vm.fragment = refResolver.lastFragment($scope.uischema.scope.$ref);
25-
vm.modelValue = refResolver.resolveToLastModel($scope.data,$scope.uischema.scope.$ref);
26-
}];
2713

2814
var app = angular.module('makeithappen');
29-
app.directive('customControl', customDirective);
30-
app.run(['RendererService', function(RendererService) {
31-
RendererService.register("custom-control", CustomControlRendererTester);
32-
}]);
15+
app.directive('customControl', customDirective)
16+
.run(['RendererService', 'JSONFormsTesters', function(RendererService, testers) {
17+
RendererService.register("custom-control",
18+
testers.and(
19+
testers.uiTypeIs('Control'),
20+
testers.schemaPropertyName('firstName')
21+
), 3);
22+
}]);

examples/app/init.js

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

examples/app/routeconfig.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22
angular.module('makeithappen').config(['$routeProvider',
33
function($routeProvider) {
44
$routeProvider.when('/person', {
5-
template: require('./person/person.html'),
5+
templateUrl: 'app/person/person.html',
66
controller: 'PersonController',
77
controllerAs: 'vm'
88
}).when('/resolve', {
9-
template: require('./resolve/resolve.html'),
9+
templateUrl: 'app/resolve/resolve.html',
1010
controller: 'ResolveController',
1111
controllerAs: 'vm'
12-
})/*.when('/editor', {
12+
}).when('/editor', {
1313
templateUrl: 'app/editor/editor.html',
1414
controller: 'EditorController',
1515
controllerAs: 'vm'
@@ -45,11 +45,11 @@ angular.module('makeithappen').config(['$routeProvider',
4545
templateUrl: 'app/arrays/arrays.html',
4646
controller: 'ArraysController',
4747
controllerAs: 'vm'
48-
}).when('/table', {
49-
templateUrl: 'app/table/index.html',
50-
controller: 'MyTableController',
48+
}).when('/async', {
49+
templateUrl: 'app/async/async.html',
50+
controller: 'AsyncController',
5151
controllerAs: 'vm'
52-
})*/.otherwise({
52+
}).otherwise({
5353
redirectTo: '/person'
5454
});
5555
}

examples/index.html

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@
3434
<script src="app/resolve/resolve.contrimport '/bower_components/angular-route/angular-route.js';
3535
oller.js" type="text/javascript"></script>
3636
<script src="app/person/person.controller.js" type="text/javascript"></script>
37+
38+
<script src="app/async/async.controller.js" type="text/javascript"></script>
39+
3740
<script src="app/default-ui/default-ui.controller.js" type="text/javascript"></script>
3841
<script src="app/default/default-schema.controller.js" type="text/javascript"></script>
3942
<script src="app/placeholder/placeholder.controller.js" type="text/javascript"></script>
@@ -62,6 +65,7 @@
6265
<a ng-href="{{index.getPath()}}" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">Select example<span class="caret"></span></a>
6366
<ul class="dropdown-menu">
6467
<li ng-class="index.isActive('/person')"><a href="#/person">Person example</a></li>
68+
<li ng-class="index.isActive('/async')"><a href="#/async">Asynchronous example</a></li>
6569
<li ng-class="index.isActive('/resolve')"><a href="#/resolve">Resolve example</a></li>
6670
<li ng-class="index.isActive('/arrays')"><a href="#/arrays">Array controls</a></li>
6771
<li ng-class="index.isActive('/editor')"><a href="#/editor">Live edit</a></li>

0 commit comments

Comments
 (0)