Skip to content

Commit 399d2a1

Browse files
committed
add editor
1 parent 9bedb12 commit 399d2a1

3 files changed

Lines changed: 180 additions & 0 deletions

File tree

models/index.html

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="utf-8"/>
5+
<title>Deebot Models Editor</title>
6+
<script src="jsoneditor.min.js"></script>
7+
<link rel='stylesheet' href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css">
8+
<link rel='stylesheet' href="https://use.fontawesome.com/releases/v5.6.1/css/all.css">
9+
</head>
10+
<body>
11+
<h1>Editor</h1>
12+
<p>Below is the editor generated from the JSON Schema.</p>
13+
<div id="json-editor-form"></div>
14+
15+
<script>
16+
var data = {
17+
iconlib: 'fontawesome5',
18+
object_layout: 'normal',
19+
show_errors: 'always',
20+
theme: 'bootstrap4',
21+
disable_properties: true,
22+
no_additional_properties: true,
23+
disable_collapse: true
24+
}
25+
26+
//load schema
27+
fetch('v1/schema.json')
28+
.then(response => response.json())
29+
.then(schema => data.schema = schema);
30+
31+
var jsoneditor = null
32+
33+
/* --------------------------------------------------------- initJsoneditor */
34+
35+
var initJsonEditor = function () {
36+
// destroy old JSONEditor instance if exists
37+
if (jsoneditor) {
38+
jsoneditor.destroy()
39+
}
40+
41+
// new instance of JSONEditor
42+
jsoneditor = new window.JSONEditor(document.querySelector('#json-editor-form'), data)
43+
44+
// listen for changes
45+
jsoneditor.on('change', function () {
46+
// output
47+
/*var json = jsoneditor.getValue()
48+
outputTextarea.value = JSON.stringify(json, null, 2)
49+
50+
// validate
51+
var validationErrors = jsoneditor.validate()
52+
if (validationErrors.length) {
53+
validateTextarea.value = JSON.stringify(validationErrors, null, 2)
54+
} else {
55+
validateTextarea.value = 'valid'
56+
}*/
57+
})
58+
}
59+
60+
initJsonEditor()
61+
62+
</script>
63+
</body>
64+
</html>

models/jsoneditor.min.js

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

models/v1/schema.json

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
{
2+
"$schema": "http://json-schema.org/draft-04/schema#",
3+
"title": "Deebot model",
4+
"description": "Describe a deebot model",
5+
"type": "object",
6+
"required": ["name", "class", "protocol"],
7+
"properties": {
8+
"name": {
9+
"type": "string",
10+
"description": "Name of the model",
11+
"minLength": 1
12+
},
13+
"class": {
14+
"type": "string",
15+
"description": "Class of the model",
16+
"minLength": 1
17+
},
18+
"protocol": {
19+
"enum": ["mqtt/json", "mqtt/xml", "xmpp"],
20+
"type": "string",
21+
"description": "Protocol used by the robot"
22+
},
23+
"components": {
24+
"type": "array",
25+
"uniqueItems": true,
26+
"items": {
27+
"type": "string",
28+
"enum": ["main_brush", "side_brush", "filter"],
29+
"options": {
30+
"enum_titles": ["Main brush", "Side brush", "Filter"]
31+
}
32+
},
33+
"description": "Available components",
34+
"title": "Components"
35+
},
36+
"features": {
37+
"type": "array",
38+
"uniqueItems": true,
39+
"title": "Features",
40+
"description": "Avialable features",
41+
"items": {
42+
"type": "string",
43+
"enum": [
44+
"advanced_mode",
45+
"mop_reminder",
46+
"carpet_auto_fan_speed_boost",
47+
"continuous_cleaning",
48+
"do_not_disturb",
49+
"cleaning_schedule",
50+
"voice_report"
51+
],
52+
"options": {
53+
"enum_titles": [
54+
"Advanced mode",
55+
"Mop reminder",
56+
"Carpet auto fan speed boost",
57+
"Continuous cleaning",
58+
"Do not disturb",
59+
"Cleaning schedule",
60+
"Voice report/volume"
61+
]
62+
}
63+
}
64+
},
65+
"cleaning_modes": {
66+
"type": "array",
67+
"uniqueItems": true,
68+
"description": "Available cleaning types",
69+
"items": {
70+
"enum": ["spot_area", "custom_area"],
71+
"type": "string"
72+
},
73+
"title": "Cleaning modes"
74+
},
75+
"water_levels": {
76+
"type": "array",
77+
"uniqueItems": true,
78+
"title": "Water level",
79+
"description": "Avialable water levels",
80+
"items": {
81+
"type": "string",
82+
"enum": ["low", "medium", "high", "ultra_high"],
83+
"options": {
84+
"enum_titles": ["Low", "Medium", "High", "Ultra high"]
85+
}
86+
}
87+
},
88+
"fan_speeds": {
89+
"title": "Fan speed",
90+
"type": "array",
91+
"description": "Available fan speeds",
92+
"items": {
93+
"type": "string",
94+
"enum": ["quiet", "standard", "max", "max+"],
95+
"options": {
96+
"enum_titles": ["Quiet", "Standard", "Max", "Max+"]
97+
}
98+
},
99+
"uniqueItems": true
100+
}
101+
}
102+
}

0 commit comments

Comments
 (0)