-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathapp.js
More file actions
62 lines (62 loc) · 1.84 KB
/
app.js
File metadata and controls
62 lines (62 loc) · 1.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
App = function(options){
return {
$cell: true,
class: "horizontal layout",
_schema: null,
_data: null,
_run: function(){
if(this._schema && this._data){
var ajv = new Ajv({ allErrors: true, verbose: true });
var validate = ajv.compile(this._schema)
var valid = validate(this._data);
var log = this.querySelector("#console");
if(valid){
log._refresh([{keyword: "", message: "It's Valid!", valid: true}]);
} else {
log._refresh(validate.errors);
}
}
},
$components: [
{
class: "col",
$components: [
label("Schema"),
cm({
_url: (options && options.schema && options.schema.url) ? options.schema.url : null,
value: (options && options.schema && options.schema.value) ? JSON.stringify(options.schema.value, null, 2) : null,
_afterInit: function(){ this._update(this.value) },
_update: function(content){
this.value = content;
this._schema = JSON.parse(content);
this._run()
}
})
]
},
{
class: "col",
$components: [
label("Data"),
cm({
_url: (options && options.data && options.data.url) ? options.data.url : null,
value: (options && options.data && options.data.value) ? JSON.stringify(options.data.value, null, 2) : "{}",
_afterInit: function(){ this._update(this.value) },
_update: function(content){
this.value = content;
try { this._data = JSON.parse(content); } catch (e) { }
this._run();
}
})
]
},
{
class: "col",
$components: [
label("Console"),
Log
]
}
]
}
}