feat: Led Matrix Layout - Save/Restore (#669) (#697)

* Led Matrix Layout (#669)

* fix: ledConfig object missing

Co-authored-by: brindosch <edeltraud70@gmx.de>
This commit is contained in:
LordGrey 2020-02-23 00:51:58 +01:00 committed by GitHub
parent 81ef1163c1
commit a2dbbcdd0d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 230 additions and 96 deletions

View File

@ -306,6 +306,59 @@ function createMatrixLeds(){
createLedPreview(leds, 'matrix'); createLedPreview(leds, 'matrix');
} }
function migrateLedConfig(slConfig){
var newLedConfig = {classic:{}, matrix:{}};
//Default Classic layout
newLedConfig.classic = {
"top" : 8,
"bottom" : 8,
"left" : 5,
"right" : 5,
"glength" : 0,
"gpos" : 0,
"position" : 0,
"reverse" : false,
"hdepth" : 8,
"vdepth" : 5,
"overlap" : 0,
"edgegap" : 0
}
//Move Classic layout
newLedConfig.classic.top = slConfig.top;
newLedConfig.classic.bottom = slConfig.bottom;
newLedConfig.classic.left = slConfig.left;
newLedConfig.classic.right = slConfig.right;
newLedConfig.classic.glength = slConfig.glength;
newLedConfig.classic.position = slConfig.position;
newLedConfig.classic.reverse = slConfig.reverse;
newLedConfig.classic.hdepth = slConfig.hdepth;
newLedConfig.classic.vdepth = slConfig.vdepth;
newLedConfig.classic.overlap = slConfig.overlap;
//Default Matrix layout
newLedConfig["matrix"] = { "ledshoriz": 10,
"ledsvert" : 10,
"cabling" : "snake",
"start" : "top-left"
}
// Persit new structure
requestWriteConfig({ledConfig:newLedConfig})
return newLedConfig
}
function isEmpty(obj) {
for(var key in obj) {
if(obj.hasOwnProperty(key))
return false;
}
return true;
}
$(document).ready(function() { $(document).ready(function() {
// translate // translate
performTranslation(); performTranslation();
@ -320,28 +373,55 @@ $(document).ready(function() {
var slConfig = window.serverConfig.ledConfig; var slConfig = window.serverConfig.ledConfig;
//restore ledConfig //Check, if structure is not aligned to expected -> migrate structure
for(var key in slConfig) var newConfig = {};
if ( isEmpty(slConfig.classic) )
{ {
if(typeof(slConfig[key]) === "boolean") slConfig = migrateLedConfig( slConfig );
$('#ip_cl_'+key).prop('checked', slConfig[key]); }
//restore ledConfig - Classic
for(var key in slConfig.classic)
{
if(typeof(slConfig.classic[key]) === "boolean")
$('#ip_cl_'+key).prop('checked', slConfig.classic[key]);
else else
$('#ip_cl_'+key).val(slConfig[key]); $('#ip_cl_'+key).val(slConfig.classic[key]);
}
//restore ledConfig - Matrix
for(var key in slConfig.matrix)
{
if(typeof(slConfig.matrix[key]) === "boolean")
$('#ip_ma_'+key).prop('checked', slConfig.matrix[key]);
else
$('#ip_ma_'+key).val(slConfig.matrix[key]);
} }
function saveValues() function saveValues()
{ {
var ledConfig = {}; var ledConfig = {classic:{}, matrix:{}};
for(var key in slConfig)
for(var key in slConfig.classic)
{ {
if(typeof(slConfig[key]) === "boolean") if(typeof(slConfig.classic[key]) === "boolean")
ledConfig[key] = $('#ip_cl_'+key).is(':checked'); ledConfig.classic[key] = $('#ip_cl_'+key).is(':checked');
else if(Number.isInteger(slConfig[key])) else if(Number.isInteger(slConfig.classic[key]))
ledConfig[key] = parseInt($('#ip_cl_'+key).val()); ledConfig.classic[key] = parseInt($('#ip_cl_'+key).val());
else else
ledConfig[key] = $('#ip_cl_'+key).val(); ledConfig.classic[key] = $('#ip_cl_'+key).val();
} }
setTimeout(requestWriteConfig, 100, {ledConfig});
for(var key in slConfig.matrix)
{
if(typeof(slConfig.matrix[key]) === "boolean")
ledConfig.matrix[key] = $('#ip_ma_'+key).is(':checked');
else if(Number.isInteger(slConfig.matrix[key]))
ledConfig.matrix[key] = parseInt($('#ip_ma_'+key).val());
else
ledConfig.matrix[key] = $('#ip_ma_'+key).val();
}
requestWriteConfig({ledConfig});
} }
// check access level and adjust ui // check access level and adjust ui

View File

@ -186,6 +186,8 @@
}, },
"ledConfig" : "ledConfig" :
{
"classic":
{ {
"top" : 8, "top" : 8,
"bottom" : 8, "bottom" : 8,
@ -199,6 +201,16 @@
"vdepth" : 5, "vdepth" : 5,
"overlap" : 0, "overlap" : 0,
"edgegap" : 0 "edgegap" : 0
},
"matrix":
{
"ledshoriz": 10,
"ledsvert" : 10,
"cabling" : "snake",
"start" : "top-left"
}
}, },
"leds": "leds":

View File

@ -1,6 +1,12 @@
{ {
"type" : "object", "type" : "object",
"properties" : "properties" :
{
"classic" :
{
"type":"object",
"required" : true,
"properties":
{ {
"top" : "top" :
{ {
@ -77,4 +83,40 @@
} }
}, },
"additionalProperties" : false "additionalProperties" : false
},
"matrix" :
{
"type":"object",
"required" : true,
"properties":
{
"ledshoriz" :
{
"type" : "integer",
"minimum" : 0,
"maximum" : 50,
"default" : 0
},
"ledsvert" :
{
"type" : "integer",
"minimum" : 0,
"maximum" : 50,
"default" : 0
},
"cabling" :
{
"type": "string",
"enum" : ["snake", "parallel"]
},
"start" :
{
"type": "string",
"enum" : ["top-left", "top-right", "bottom-left", "bottom-right"]
}
},
"additionalProperties" : false
}
},
"additionalProperties" : true
} }