implement a function for easy json editor creation (#264)

* implement a function for easy json editor creation

* grabber and kodi moved to new editor func

* webui: implement conf editors

* add missing files and remove debug code
This commit is contained in:
redPanther
2016-10-09 10:23:04 +02:00
committed by GitHub
parent b42f3453b4
commit 0a142b0e7d
16 changed files with 249 additions and 273 deletions

View File

@@ -0,0 +1,34 @@
var conf_editor = null;
$(hyperion).one("cmd-config-getschema", function(event) {
parsedConfSchemaJSON = event.response.result;
schema = parsedConfSchemaJSON.properties;
conf_editor = createJsonEditor('editor_container',
{
title:'',
properties: {
color : schema.color,
smoothing : schema.smoothing,
blackborderdetector: schema.blackborderdetector,
}
});
$('#editor_container .well').css("background-color","white");
$('#editor_container .well').css("border","none");
$('#editor_container .well').css("box-shadow","none");
$('#editor_container .btn').addClass("btn-primary");
$('#editor_container h3').first().remove();
});
$(document).ready( function() {
requestServerConfigSchema();
document.getElementById('btn_submit').addEventListener('click',function() {
// Get the value from the editor
console.log(conf_editor.getValue());
});
});

View File

@@ -0,0 +1,42 @@
$(hyperion).one("cmd-config-getschema", function(event) {
parsedConfSchemaJSON = event.response.result;
schema = parsedConfSchemaJSON.properties;
var general_conf_editor = createJsonEditor('editor_container',
{
title:'',
properties: {
effects : schema.effects,
initialEffect : schema.initialEffect
}
});
$('#editor_container .well').css("background-color","white");
// $('#editor_container .well').css("border","none");
// $('#editor_container .well').css("box-shadow","none");
$('#editor_container .btn').addClass("btn-primary");
$('#editor_container h3').first().remove();
//Called everytime a Input Field is changed = No need for save button
// general_conf_editor.off().on('change',function() {
// console.log(JSON.stringify(general_conf_editor.getValue()));
// requestWriteConfig(general_conf_editor.getValue());
// });
//Alternative Function with submit button to get Values
$('#btn_submit').off().on('click',function() {
console.log(general_conf_editor.getValue());
});
$(hyperion).on("cmd-config-setconfig",function(event){
parsedServerInfoJSON = event.response;
console.log(parsedServerInfoJSON);
});
});
$(document).ready( function() {
requestServerConfigSchema();
//$("[type='checkbox']").bootstrapSwitch();
});

View File

@@ -1,83 +0,0 @@
/*
function removeAdvanced(obj,searchStack)
{
searchStack = [];
$.each(obj, function(key, val) {
if ( typeof(val) == 'object' )
{
searchStack.push(key);
if (! removeAdvanced(val,searchStack) )
searchStack.pop();
}
else if ( key == "advanced" && val == true )
{
console.log(searchStack);
return true;
}
});
return false;
}
*/
$(hyperion).one("cmd-config-getschema", function(event) {
parsedConfSchemaJSON = event.response.result;
schema = parsedConfSchemaJSON.properties;
var element = document.getElementById('editor_container');
var general_conf_editor = new JSONEditor(element,{
theme: 'bootstrap3',
iconlib: "fontawesome4",
disable_collapse: 'true',
form_name_root: 'sa',
disable_edit_json: 'true',
disable_properties: 'true',
no_additional_properties: 'true',
schema: {
title:'',
properties: {
blackborderdetector: schema.blackborderdetector,
color : schema.color,
effects : schema.effects,
forwarder : schema.forwarder,
initialEffect : schema.initialEffect,
kodiVideoChecker : schema.kodiVideoChecker,
smoothing : schema.smoothing,
logger : schema.logger,
jsonServer : schema.jsonServer,
protoServer : schema.protoServer,
boblightServer : schema.boblightServer,
udpListener : schema.udpListener,
webConfig : schema.webConfig
}
}
});
// $('#editor_container .well').css("background-color","white");
// $('#editor_container .well').css("border","none");
// $('#editor_container .well').css("box-shadow","none");
$('#editor_container .btn').addClass("btn-primary");
$('#editor_container h3').first().remove();
//Called everytime a Input Field is changed = No need for save button
// general_conf_editor.off().on('change',function() {
// console.log(JSON.stringify(general_conf_editor.getValue()));
// requestWriteConfig(general_conf_editor.getValue());
// });
//Alternative Function with submit button to get Values
$('#btn_submit').off().on('click',function() {
console.log(general_conf_editor.getValue());
});
$(hyperion).on("cmd-config-setconfig",function(event){
parsedServerInfoJSON = event.response;
console.log(parsedServerInfoJSON);
});
});
$(document).ready( function() {
requestServerConfigSchema();
//$("[type='checkbox']").bootstrapSwitch();
});

View File

@@ -1,49 +1,19 @@
/*
function removeAdvanced(obj,searchStack)
{
searchStack = [];
$.each(obj, function(key, val) {
if ( typeof(val) == 'object' )
{
searchStack.push(key);
if (! removeAdvanced(val,searchStack) )
searchStack.pop();
}
else if ( key == "advanced" && val == true )
{
console.log(searchStack);
return true;
}
});
return false;
}
*/
var grabber_conf_editor = null;
var conf_editor = null;
$(hyperion).one("cmd-config-getschema", function(event) {
parsedConfSchemaJSON = event.response.result;
schema = parsedConfSchemaJSON.properties;
var element = document.getElementById('editor_container');
grabber_conf_editor = new JSONEditor(element,{
theme: 'bootstrap3',
iconlib: "fontawesome4",
disable_collapse: 'true',
form_name_root: 'sa',
disable_edit_json: 'true',
disable_properties: 'true',
no_additional_properties: 'true',
schema: {
conf_editor = createJsonEditor('editor_container',
{
title:'',
properties: {
framegrabber: schema.framegrabber,
grabberV4L2 : schema["grabberV4L2"]
grabberV4L2 : schema.grabberV4L2
}
}
});
});
$('#editor_container .well').css("background-color","white");
$('#editor_container .well').css("border","none");
$('#editor_container .well').css("box-shadow","none");
@@ -58,8 +28,7 @@ $(document).ready( function() {
document.getElementById('btn_submit').addEventListener('click',function() {
// Get the value from the editor
console.log(grabber_conf_editor.getValue());
console.log(conf_editor.getValue());
});
// $("[type='checkbox']").bootstrapSwitch();
});

View File

@@ -9,9 +9,11 @@ $(document).ready( function() {
bindNavToContent("#load_support","support",false);
bindNavToContent("#load_confKodi","kodiconf",false);
bindNavToContent("#load_update","update",false);
bindNavToContent("#load_confGeneral","generalconf",false);
bindNavToContent("#load_confEffects","effects",false);
bindNavToContent("#load_confLeds","leds",false);
bindNavToContent("#load_confGrabber","grabber",false);
bindNavToContent("#load_confColors","colors",false);
bindNavToContent("#load_confNetwork","network",false);
//Change all Checkboxes to Switches

View File

@@ -1 +1,32 @@
var conf_editor = null;
$(hyperion).one("cmd-config-getschema", function(event) {
parsedConfSchemaJSON = event.response.result;
schema = parsedConfSchemaJSON.properties;
conf_editor = createJsonEditor('editor_container',
{
title:'',
properties: {
kodiVideoChecker: schema.kodiVideoChecker,
}
});
$('#editor_container .well').css("background-color","white");
$('#editor_container .well').css("border","none");
$('#editor_container .well').css("box-shadow","none");
$('#editor_container .btn').addClass("btn-primary");
$('#editor_container h3').remove();
});
$(document).ready( function() {
requestServerConfigSchema();
document.getElementById('btn_submit').addEventListener('click',function() {
// Get the value from the editor
console.log(conf_editor.getValue());
});
});

View File

@@ -138,27 +138,15 @@ $(document).ready(function() {
generalOptions = parsedConfSchemaJSON.properties.device;
specificOptions = parsedConfSchemaJSON.properties.alldevices[$(this).val()];
//$('#ledDeviceOptions').html(JSON.stringify(generalOptions)+"<br>"+JSON.stringify(specificOptions));
$('#editor_container').off();
$('#editor_container').html("");
var element = document.getElementById('editor_container');
grabber_conf_editor = new JSONEditor(element,{
theme: 'bootstrap3',
iconlib: "fontawesome4",
disable_collapse: 'true',
form_name_root: 'sa',
disable_edit_json: 'true',
disable_properties: 'true',
no_additional_properties: 'true',
schema: {
grabber_conf_editor = createJsonEditor('editor_container',
{
title:' ',
properties: {
generalOptions : generalOptions,
specificOptions : specificOptions,
}
}
});
values_general = {};
values_specific = {};
isCurrentDevice = (server.info.ledDevices.active == $(this).val());

View File

@@ -0,0 +1,36 @@
var conf_editor = null;
$(hyperion).one("cmd-config-getschema", function(event) {
parsedConfSchemaJSON = event.response.result;
schema = parsedConfSchemaJSON.properties;
conf_editor = createJsonEditor('editor_container',
{
title:'',
properties: {
jsonServer : schema.jsonServer,
protoServer : schema.protoServer,
boblightServer : schema.boblightServer,
udpListener : schema.udpListener,
forwarder : schema.forwarder,
}
});
$('#editor_container .well').css("background-color","white");
$('#editor_container .well').css("border","none");
$('#editor_container .well').css("box-shadow","none");
$('#editor_container .btn').addClass("btn-primary");
$('#editor_container h3').first().remove();
});
$(document).ready( function() {
requestServerConfigSchema();
document.getElementById('btn_submit').addEventListener('click',function() {
// Get the value from the editor
console.log(conf_editor.getValue());
});
});

View File

@@ -54,11 +54,34 @@ function showErrorDialog(header,message)
$('#error_dialog').modal('show');
}
function isJsonString(str) {
try {
function isJsonString(str)
{
try
{
JSON.parse(str);
} catch (e) {
}
catch (e)
{
return e;
}
return "";
}
function createJsonEditor(container,schema)
{
$('#'+container).off();
$('#'+container).html("");
return new JSONEditor(document.getElementById(container),
{
theme: 'bootstrap3',
iconlib: "fontawesome4",
disable_collapse: 'true',
form_name_root: 'sa',
disable_edit_json: 'true',
disable_properties: 'true',
no_additional_properties: 'true',
schema: schema
});
}