Base framework for JSON Editor on Configuration in Super panel

build-default-monitor-config-from-definitions
Moe 2020-04-18 22:00:50 -07:00
parent 7a81679803
commit 605f227897
5 changed files with 7586 additions and 104 deletions

View File

@ -0,0 +1,51 @@
.better-json-editor h3 {
font-size: initial;
margin: 0 10px 10px 0;
}
.better-json-editor .well .well {
margin-left:20px;
}
.better-json-editor label, .better-json-editor .control-label {
color: #bd4147;
background-color: #f8f9fa;
padding: 7px 10px;
border-radius: .25rem;
font-family: Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
margin-bottom:5px;
}
.better-json-editor .floating-json {
padding: 10px;
border-radius: 5px;
border: 1px solid #E3E3E3;
}
.better-json-editor .form-group:nth-last-child(2) {
margin-bottom:0;
}
.better-json-editor table {
width: 100%!important;
margin-bottom: 10px;
}
.better-json-editor .floating-json textarea.form-control {
padding: 20px;
border-radius: 5px;
border: 1px solid #E3E3E3;
margin-bottom: 10px;
}
.better-json-editor [class*="json-editor-btn"].badge {
margin: 0;
margin-right: 5px;
}
.better-json-editor .badge {
cursor: pointer;
outline: none;
}
.better-json-editor .row {
margin: 0;
}
.better-json-editor .row > div {
border: 1px solid #eee;
border-radius: 5px;
padding-top: 15px;
padding-bottom: 15px;
margin-bottom: 10px;
}

7219
web/libs/js/jsonEditor.js Normal file

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,284 @@
var schema = {
"title": "Shinobi Configuration",
"type": "object",
"properties": {
"subscriptionId": {
"type": "string",
},
"port": {
"type": "integer",
"default": 8080
},
"passwordType": {
"type": "string",
"enum": [
"sha256",
"sha512",
"md5"
],
"default": "sha256"
},
"addStorage": {
"type": "array",
"format": "table",
"title": "Additional Storage",
"description": "Separate storage locations that can be set for different monitors.",
"uniqueItems": true,
"items": {
"type": "object",
"title": "Storage Array",
"properties": {
"name": {
"type": "string",
},
"path": {
"type": "string",
"default": "__DIR__/videos2"
}
}
},
"default": [
{
"name": "second",
"path": "__DIR__/videos2"
}
]
},
"plugins": {
"type": "array",
"format": "table",
"title": "Plugins",
"descripton": "Elaborate Plugin connection settings.",
"uniqueItems": true,
"items": {
"type": "object",
"title": "Plugin",
"properties": {
"plug": {
"type": "string",
"default": "pluginName"
},
"key": {
"type": "string"
},
"mode": {
"type": "string",
"enum": [
"host",
"client"
],
"default": "client"
},
"https": {
"type": "boolean",
"descripton": "Only for Host mode.",
"default": false
},
"host": {
"type": "string",
"descripton": "Only for Host mode.",
"default": "localhost"
},
"port": {
"type": "integer",
"descripton": "Only for Host mode.",
"default": 8082
},
"type": {
"type": "string",
"default": "detector"
}
}
},
"default": [
{
"name": "second",
"path": "__DIR__/videos2"
}
]
},
"pluginKeys": {
"type": "object",
"format": "table",
"title": "Plugin Keys",
"description": "Quick client connection setup for plugins. Just add the plugin key to make it ready for incoming connections.",
"uniqueItems": true,
"items": {
"type": "object",
"title": "Plugin Key",
"properties": {}
}
},
"db": {
"type": "object",
"format": "table",
"title": "Database Options",
"description": "Credentials to connect to where detailed information is stored.",
"properties": {
"host": {
"type": "string",
"default": "127.0.0.1"
},
"user": {
"type": "string",
"default": "majesticflame"
},
"password": {
"type": "string",
"default": ""
},
"database": {
"type": "string",
"default": "ccio"
},
"port": {
"type": "integer",
"default": 3306
}
},
"default": {
"host": "127.0.0.1",
"user": "majesticflame",
"password": "",
"database": "ccio",
"port":3306
}
},
"cron": {
"type": "object",
"format": "table",
"title": "CRON Options",
"properties": {
"key": {
"type": "string",
},
"deleteOld": {
"type": "boolean",
"description": "cron will delete videos older than Max Number of Days per account.",
"default": true
},
"deleteNoVideo": {
"type": "boolean",
"description": "cron will delete SQL rows that it thinks have no video files.",
"default": true
},
"deleteOverMax": {
"type": "boolean",
"description": "cron will delete files that are over the set maximum storage per account.",
"default": true
},
}
},
"mail": {
"type": "object",
"format": "table",
"title": "Email Options",
"properties": {
"service": {
"type": "string",
},
"host": {
"type": "string",
},
"auth": {
"type": "object",
"properties": {
"user": {
"type": "string",
},
"pass": {
"type": "string",
},
},
},
"secure": {
"type": "boolean",
"default": false
},
"ignoreTLS": {
"type": "boolean",
},
"requireTLS": {
"type": "boolean",
},
"port": {
"type": "integer",
}
}
},
"detectorMergePamRegionTriggers": {
"type": "boolean",
"default": true
},
"doSnapshot": {
"type": "boolean",
"default": true
},
"discordBot": {
"type": "boolean",
"default": false
},
"dropInEventServer": {
"type": "boolean",
"default": false
},
"ftpServer": {
"type": "boolean",
"default": false
},
"oldPowerVideo": {
"type": "boolean",
"default": false
},
"defaultMjpeg": {
"type": "string",
},
"streamDir": {
"type": "string",
},
"videosDir": {
"type": "string",
},
"windowsTempDir": {
"type": "string",
}
}
};
// Set default options
JSONEditor.defaults.options.theme = 'bootstrap3';
JSONEditor.defaults.options.iconlib = 'fontawesome4';
// Initialize the editor
var editor = new JSONEditor(document.getElementById("configForHumans"),{
theme: 'bootstrap3',
schema: schema,
//schema: {
// type: "object",
// properties: {
// name: { "type": "string" }
// }
//}
});
// Set the value
editor.setValue(shinobiConfig);
//editor.setValue({
// name: "John Smith"
//});
// Get the value
var data = editor.getValue();
console.log(data); // "John Smith"
// Validate
var errors = editor.validate();
if(errors.length) {
// Not valid
}
// Listen for changes
editor.on("change", function() {
// Do something...
});

View File

@ -0,0 +1,26 @@
<link rel="stylesheet" href="<%-window.libURL%>libs/css/super.configEditor.css" />
<small class="pull-right msg"></small>
<nav class="navbar navbar-rounded navbar-expand-lg bg-success">
<div class="container">
<div class="collapse navbar-collapse">
<ul class="navbar-nav">
<li class="nav-item">
<a class="nav-link submit">
<p><i class="fa fa-check"></i> <%-lang.Save%></p>
</a>
</li>
</ul>
</div>
</div>
</nav>
<form class="form-group-group red" id="conf_json">
<small class="pull-right msg"></small>
<div id="configForHumans" class="better-json-editor pt-3">
</div>
<div class="form-group">
<textarea name="json" style="height:300px;font-family: monospace;" class="form-control"></textarea>
</div>
</form>
<script src="<%-window.libURL%>libs/js/jsonEditor.js" type="text/javascript"></script>
<script src="<%-window.libURL%>libs/js/super.configEditor.js" type="text/javascript"></script>

View File

@ -32,6 +32,10 @@
.list-group li .form-group {margin:0}
a {cursor:pointer}
</style>
<script>
var superApiPrefix = "<%=originalURL%><%=config.webPaths.superApiPrefix%>"
var shinobiConfig = <%- JSON.stringify(plainConfig) %>
</script>
<% customAutoLoad.superLibsCss.forEach(function(lib){ %>
<link rel="stylesheet" href="<%-window.libURL%>libs/css/<%-lib%>">
<% }) %>
@ -103,28 +107,8 @@
</nav>
<table class="table table-striped"></table>
</div>
<div class="tab-pane" id="config" role="tabpanel">
<small class="pull-right msg"></small>
<nav class="navbar navbar-rounded navbar-expand-lg bg-success">
<div class="container">
<div class="collapse navbar-collapse">
<ul class="navbar-nav">
<li class="nav-item">
<a class="nav-link submit">
<p><i class="fa fa-check"></i> <%-lang.Save%></p>
</a>
</li>
</ul>
</div>
</div>
</nav>
<form class="form-group-group red" id="conf_json">
<small class="pull-right msg"></small>
<div id="configForHumans"></div>
<div class="form-group">
<textarea name="json" style="height:300px;font-family: monospace;" class="form-control"></textarea>
</div>
</form>
<div class="tab-pane text-left" id="config" role="tabpanel">
<% include blocks/superConfigEditor.ejs %>
</div>
<div class="tab-pane text-left" id="system" role="tabpanel">
<nav class="navbar navbar-rounded navbar-expand-lg bg-primary">
@ -182,9 +166,6 @@
</div>
<div id="temp" style="display:none"></div>
</body>
<script>
var superApiPrefix = "<%=originalURL%><%=config.webPaths.superApiPrefix%>"
</script>
<% include blocks/confirm.ejs %>
<% customAutoLoad.superPageBlocks.forEach(function(block){ %>
<%- include(block) %>
@ -290,28 +271,6 @@ $.ccio.tm=function(x,d,z,k){
if(!d.time){d.time=$.ccio.init('t')}
tmp+='<tr class="search-row"><td><span title="'+d.time+'" class="livestamp"></span><br><small>'+d.time+'</small><br><small>'+d.mid+'</small></td><td></td><td><pre class="pre-inline">'+$.ccio.init('jsontoblock',JSON.parse(d.info))+'</pre></td></tr>'
break;
case 5://config element
if(d.value instanceof Object){
tmp += '<div class="form-group config-row" layer="'+d.layer+'">\
<div><input class="form-control key" type="text" value="'+d.key+'"></div>\
<ul class="list-group valueObject" style="margin:0">'
++d.layer
$.each(d.value,function(key,value){
tmp += '<li class="list-group-item">'
tmp += $.ccio.tm(5,{key:key,value:value,layer:d.layer})
tmp += '</li>'
})
tmp += '</ul>'
tmp += '</div>'
}else{
tmp += '<div class="form-group config-row" layer="'+d.layer+'">\
<label>\
<div><input class="form-control key" type="text" value="'+d.key+'"></div>\
<div><input class="form-control value" type="text" value="'+d.value+'"></div>\
</label>\
</div>'
}
break;
}
if(z){
$(z).prepend(tmp)
@ -362,17 +321,8 @@ $.logs={e:$('#logs')}
var config = <%- JSON.stringify(plainConfig) || [] %>
$.conf={e:$('#config')};
$.conf.f = $.conf.e.find('form')
$.conf.configForHumans=$('#configForHumans')
$.conf.draw=$.conf.e.find('[name="json"]')
$.conf.valid=1;
$.conf.jsonToFields = function(){
// var tmp = ''
// $.each(config,function(key,value){
// var layer = 0
// tmp += $.ccio.tm(5,{key:key,value:value,layer:layer})
// })
// $.conf.configForHumans.html(tmp)
}
$.conf.draw.val(JSON.stringify(<%-stringedConfig%>,null,3))
$.conf.draw.keyup(function(){
var msg=''
@ -382,7 +332,6 @@ $.conf.draw.keyup(function(){
msg = 'Valid JSON'
color = 'success'
$.conf.valid = 1
$.conf.jsonToFields()
}catch(er){
msg = 'Not a valid JSON'
color = 'danger'
@ -414,53 +363,6 @@ $.conf.f.submit(function(e){
}
return false;
})
$.conf.e.on('keyup','.config-row input',function(){
var newConfig = {}
var checkRow = function(v,object){
var _this = $(v)
var key = _this.find('.key:first').val()
var layer = parseInt(_this.attr('layer'))
var list = _this.find('ul').first()
var isObject = list.length > 0
if(isObject){
if(!object[key]){
if(isNaN(key) === true){
object[key] = {}
}else{
object[key] = []
}
}
list.find('.config-row[layer="'+(layer+1)+'"]').each(function(n,v){
checkRow(v,object[key])
})
}else{
var value = _this.find('.value').val()
switch(value){
case'true':
value = true
break;
case'false':
value = false
break;
default:
if(isNaN(value) === false){
value = parseFloat(value)
}
break;
}
object[key] = value
}
}
$.conf.configForHumans.children('.config-row').each(function(n,v){
checkRow(v,newConfig)
})
$.conf.draw.val(JSON.stringify(newConfig,null,3))
console.log(newConfig)
})
$.conf.f.ready(function(){
$.conf.jsonToFields()
})
//sys controls
$.system={e:$('#system')}
$.system.e.find('[system]').click(function(e){