Validate that one CEC Event can only trigger one action

This commit is contained in:
LordGrey 2023-11-13 23:14:18 +01:00
parent 42619b27ea
commit 114282ff70
2 changed files with 37 additions and 0 deletions

View File

@ -267,6 +267,7 @@
"edt_conf_cec_actions_header_title": "Actions",
"edt_conf_cec_actions_header_expl": "Define which action should take place on a recognised CEC event",
"edt_conf_cec_actions_header_item_title": "Action",
"edt_conf_cec_action_record_validation_error": "One CEC Event can trigger only one action. Clean up Actions $1",
"edt_conf_cec_button_release_delay_ms_title": "Button release time",
"edt_conf_cec_button_release_delay_ms_expl": "Remote button press release time",
"edt_conf_cec_button_repeat_rate_ms_title": "Button repeat rate",

View File

@ -27,6 +27,42 @@ $(document).ready(function () {
}
}
function findDuplicateCecEventsIndices(data) {
const cecEventIndices = {};
data.forEach((item, index) => {
const cecEvent = item.cec_event;
if (!cecEventIndices[cecEvent]) {
cecEventIndices[cecEvent] = [index];
} else {
cecEventIndices[cecEvent].push(index);
}
});
return Object.values(cecEventIndices).filter(indices => indices.length > 1);
}
JSONEditor.defaults.custom_validators.push(function (schema, value, path) {
let errors = [];
if (schema.type === 'array' && Array.isArray(value)) {
const duplicateCecEventIndices = findDuplicateCecEventsIndices(value);
if (duplicateCecEventIndices.length > 0) {
let recs;
duplicateCecEventIndices.forEach(indices => {
const displayIndices = indices.map(index => index + 1);
recs = displayIndices.join(', ');
});
errors.push({
path: path,
message: $.i18n('edt_conf_cec_action_record_validation_error', recs)
});
}
}
return errors;
});
//Operating System Events
conf_editor_osEvents = createJsonEditor('editor_container_os_events', {
osEvents: window.schema.osEvents