Fix super config default values

cycling-live-grid
Elad Bar 2023-04-06 17:11:25 +00:00 committed by Moe
parent b2b6d4b3f8
commit 12151602ef
2 changed files with 360 additions and 304 deletions

1
.gitignore vendored
View File

@ -14,3 +14,4 @@ dist
generatedLanguageFiles generatedLanguageFiles
faces faces
unknownFaces unknownFaces
.idea/

View File

@ -4,17 +4,22 @@ $(document).ready(function(){
"type": "object", "type": "object",
"properties": { "properties": {
"debugLog": { "debugLog": {
"title": "Enable Debug Log",
"type": "boolean", "type": "boolean",
"default": false "default": false
}, },
"subscriptionId": { "subscriptionId": {
"title": "Fill in subscription ID",
"type": "string", "type": "string",
"default": null
}, },
"port": { "port": {
"title": "Server port",
"type": "integer", "type": "integer",
"default": 8080 "default": 8080
}, },
"passwordType": { "passwordType": {
"title": "Password type",
"type": "string", "type": "string",
"enum": [ "enum": [
"sha256", "sha256",
@ -94,13 +99,7 @@ $(document).ready(function(){
"default": "detector" "default": "detector"
} }
} }
},
"default": [
{
"name": "second",
"path": "__DIR__/videos2"
} }
]
}, },
"pluginKeys": { "pluginKeys": {
"type": "object", "type": "object",
@ -121,14 +120,17 @@ $(document).ready(function(){
"description": "Credentials to connect to where detailed information is stored.", "description": "Credentials to connect to where detailed information is stored.",
"properties": { "properties": {
"host": { "host": {
"title": "Hostname / IP",
"type": "string", "type": "string",
"default": "127.0.0.1" "default": "127.0.0.1"
}, },
"user": { "user": {
"title": "Username",
"type": "string", "type": "string",
"default": "majesticflame" "default": "majesticflame"
}, },
"password": { "password": {
"title": "Password",
"type": "string", "type": "string",
"default": "" "default": ""
}, },
@ -250,31 +252,82 @@ $(document).ready(function(){
}, },
"windowsTempDir": { "windowsTempDir": {
"type": "string", "type": "string",
},
"enableFaceManager": {
"type": "boolean",
"default": false,
"title": "Enable Face Manager",
"description": "Enable / Disable face manager for face recognition plugins in the dashboard."
} }
} }
}; };
var configurationTab = $('#config') const configurationTab = $("#config");
var configurationForm = configurationTab.find('form') const configurationForm = configurationTab.find("form");
// Set default options const moduleData = {
JSONEditor.defaults.options.theme = 'bootstrap3'; endpoint: null,
JSONEditor.defaults.options.iconlib = 'fontawesome4'; configurationEditor: null
}
// Initialize the editor const handleGetConfigurationData = data => {
var configurationEditor = new JSONEditor(document.getElementById("configForHumans"),{ const dataConfig = data.config;
theme: 'bootstrap3', const dataConfigKeys = Object.keys(dataConfig);
schema: schema const schemaItemsKeys = Object.keys(schema.properties);
const schemaWithoutData = schemaItemsKeys.filter(
(sk) => !dataConfigKeys.includes(sk)
);
const dataWithoutSchema = dataConfigKeys.filter(
(dk) => !schemaItemsKeys.includes(dk)
);
schemaWithoutData.forEach((sk) => {
const schemaItem = schema.properties[sk];
const defaultConfig = schemaItem.default;
data.config[sk] = defaultConfig;
}); });
function loadConfiguationIntoEditor(){ if (dataWithoutSchema.length > 0) {
$.get(superApiPrefix + $user.sessionKey + '/system/configure',function(data){ dataWithoutSchema.forEach((dk) => {
configurationEditor.setValue(data.config); const schemaItem = {
}) title: dk,
options: {
hidden: true,
},
};
schema.properties[dk] = schemaItem;
});
// Set default options
JSONEditor.defaults.options.theme = "bootstrap3";
JSONEditor.defaults.options.iconlib = "fontawesome4";
} }
// configurationEditor.on("change", function() {
// // Do something... const configurationEditor = new JSONEditor(
// }); document.getElementById("configForHumans"), {
schema: schema,
}
);
configurationEditor.setValue(data.config);
moduleData.configurationEditor = configurationEditor;
window.configurationEditor = configurationEditor;
};
const handlePostConfigurationData = data => {
// console.log(data);
}
function loadConfiguationIntoEditor(d) {
moduleData.endpoint = `${superApiPrefix}${$user.sessionKey}/system/configure`;
$.get(moduleData.endpoint, handleGetConfigurationData);
}
var submitConfiguration = function () { var submitConfiguration = function () {
var errors = configurationEditor.validate(); var errors = configurationEditor.validate();
console.log(errors.length) console.log(errors.length)
@ -291,31 +344,33 @@ $(document).ready(function(){
title: lang.Save, title: lang.Save,
}, },
clickCallback: function () { clickCallback: function () {
$.post(superApiPrefix + $user.sessionKey + '/system/configure',{ const requestData = {
data: newConfiguration data: newConfiguration
},function(data){ };
// console.log(data)
}) $.post(moduleData.endpoint, requestData, handlePostConfigurationData);
} }
}) })
} else { } else {
new PNotify({text:'Invalid JSON Syntax, Cannot Save.',type:'error'}) new PNotify({ text: 'Invalid JSON Syntax, Cannot Save.', type: 'error' });
}
} }
};
configurationTab.find('.submit').click(function () { configurationTab.find('.submit').click(function () {
submitConfiguration() submitConfiguration();
}) });
configurationForm.submit(function (e) { configurationForm.submit(function (e) {
e.preventDefault() e.preventDefault();
submitConfiguration() submitConfiguration();
return false; return false;
}) });
$.ccio.ws.on('f',function(d){
switch(d.f){ $.ccio.ws.on("f", d => {
case'init_success': if (d.f === "init_success") {
loadConfiguationIntoEditor() loadConfiguationIntoEditor();
break;
} }
}) });
window.configurationEditor = configurationEditor
window.configurationEditor = configurationEditor;
}) })