Skip to content

Commit c86bdd6

Browse files
committed
added support for schema promises and updating schema.
bumped dependency versions. updated demo
1 parent a2e6ef2 commit c86bdd6

File tree

11 files changed

+102
-55
lines changed

11 files changed

+102
-55
lines changed

.jscs.json

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,6 @@
2020
"disallowKeywordsOnNewLine": ["else"],
2121
"safeContextKeyword": ["self"],
2222
"requireLineFeedAtFileEnd": true,
23-
"validateJSDoc": {
24-
"checkParamNames": true,
25-
"checkRedundantParams": true
26-
},
2723
"disallowSpacesInNamedFunctionExpression": {
2824
"beforeOpeningRoundBrace": true
2925
},

.jshintrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"eqeqeq": true,
55
"forin": true,
66
"immed": true,
7-
"latedef": true,
7+
"latedef": false,
88
"newcap": true,
99
"noarg": true,
1010
"noempty": true,

bower.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
"node_modules"
2121
],
2222
"dependencies": {
23-
"json-editor": "^0.7.18",
23+
"json-editor": "^0.7.28",
2424
"angular": "1.*"
2525
}
2626
}

demo/app.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ angular.module('demoApp', ['angular-json-editor']).config(function (JSONEditorPr
4040
console.dir(data);
4141
};
4242

43-
}).controller('AsyncAppController', function ($scope, $http, $timeout) {
43+
}).controller('AsyncAppController', function ($scope, $http) {
4444

4545
// Load with $http
4646
$scope.mySchema = $http.get('schema.json');
@@ -70,10 +70,12 @@ angular.module('demoApp', ['angular-json-editor']).config(function (JSONEditorPr
7070
};
7171
};
7272

73-
}).controller('AsyncButtonsController', function ($scope) {
74-
73+
}).controller('AsyncButtonsController', function ($scope, $http) {
7574
$scope.onSubmit = function () {
7675
console.log('onSubmit data in async controller', $scope.editor.getValue());
7776
};
7877

78+
$scope.changeSchema = function () {
79+
$scope.schema = $http.get('schema2.json');
80+
};
7981
});

demo/index.html

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,10 @@ <h2>Asynchronous values</h2>
4545
<span class="glyphicon glyphicon-check"></span>
4646
Submit
4747
</button>
48-
48+
<button type="button" class="btn btn-primary" ng-click="changeSchema($event)">
49+
<span class="glyphicon glyphicon-plus"></span>
50+
Update Schema
51+
</button>
4952
</json-editor>
5053
</div>
5154

demo/schema2.json

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
{
2+
"type": "object",
3+
"title": "Item Object Schema 2",
4+
"required": true,
5+
"additionalProperties": false,
6+
"properties": {
7+
"thingname": {
8+
"type": "string",
9+
"title": "Thing name",
10+
"required": true,
11+
"minLength": 1
12+
},
13+
"length": {
14+
"type": "integer",
15+
"title": "Length",
16+
"required": true,
17+
"min": 0
18+
},
19+
"isCool": {
20+
"type": "boolean",
21+
"title": "Is cool?",
22+
"required": true
23+
},
24+
"info": {
25+
"type": "object",
26+
"name": "Information",
27+
"properties": {
28+
"phone": {
29+
"type": "integer",
30+
"name": "phone"
31+
}
32+
}
33+
}
34+
}
35+
}

demo/startval.json

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
{
2-
"name": "myname",
2+
"name": "",
33
"age": 20,
4-
"isCool": true,
5-
"info": {
6-
"phone": 1234
7-
}
4+
"isCool": false
85
}

dist/angular-json-editor.js

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -69,22 +69,14 @@ angular.module('angular-json-editor', []).provider('JSONEditor', function () {
6969
}
7070
}],
7171
link: function (scope, element, attrs, controller, transclude) {
72-
var startValPromise = $q.when({}),
73-
schemaPromise = $q.when(null);
72+
var startValPromise = $q.when(scope.startval),
73+
schemaPromise = $q.when(scope.schema);
7474

7575
scope.isValid = false;
7676

7777
if (!angular.isString(attrs.schema)) {
7878
throw new Error('angular-json-editor: schema attribute has to be defined.');
7979
}
80-
if (angular.isObject(scope.schema)) {
81-
schemaPromise = $q.when(scope.schema);
82-
}
83-
if (angular.isObject(scope.startval)) {
84-
// Support both $http (i.e. $q) and $resource promises, and also normal object.
85-
startValPromise = $q.when(scope.startval);
86-
}
87-
8880
// Wait for the start value and schema to resolve before building the editor.
8981
$q.all([schemaPromise, startValPromise]).then(function (result) {
9082

@@ -129,21 +121,36 @@ angular.module('angular-json-editor', []).provider('JSONEditor', function () {
129121
});
130122
}
131123

132-
restart(startVal, schema);
124+
restart();
133125

134-
scope.$watch('schema', function (newVal, oldVal) {
126+
// update schema if changed
127+
scope.$watch('schema', function (newVal) {
135128
//update newScheme
136-
if (newVal.success) {
137-
newVal.success(function (data) {
129+
if (newVal.then) {
130+
newVal.then(function (data) {
138131
schema = data;
132+
restart();
139133
});
140134
} else {
141135
schema = newVal;
136+
restart();
142137
}
143-
144-
restart();
145138
}, true);
146139

140+
// update schema if promise
141+
scope.$watchCollection('schema', function (newVal) {
142+
if (newVal instanceof $q) {
143+
newVal.then(function (data) {
144+
if (data.data) {
145+
schema = data.data;
146+
}else {
147+
schema = data;
148+
}
149+
restart();
150+
});
151+
}
152+
});
153+
147154
// Transclude the buttons at the bottom.
148155
var buttons = transclude(scope, function (clone) {
149156
return clone;

dist/angular-json-editor.min.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.

package.json

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@
77
},
88
"main": "dist/angular-json-editor.js",
99
"devDependencies": {
10-
"grunt": "0.4.*",
11-
"grunt-contrib-jshint": "0.10.*",
12-
"grunt-jscs": "1.1.*",
13-
"grunt-contrib-uglify": "0.7.*",
14-
"grunt-contrib-concat": "0.5.*",
15-
"grunt-contrib-clean": "0.6.*",
16-
"grunt-contrib-connect": "0.9.*"
10+
"grunt": "1.0.*",
11+
"grunt-contrib-jshint": "1.1.*",
12+
"grunt-jscs": "3.0.*",
13+
"grunt-contrib-uglify": "2.2.*",
14+
"grunt-contrib-concat": "1.0.*",
15+
"grunt-contrib-clean": "1.0.*",
16+
"grunt-contrib-connect": "1.0.*"
1717
}
1818
}

0 commit comments

Comments
 (0)