/* ----------------------------------------------------------------------------- * NetAlertX * Open Source Network Guard / WIFI & LAN intrusion detector * * plugin_column_render.js - Shared, plugin-agnostic column-value renderer. * Extracted verbatim from pluginsCore.php so Plugin View and the Sources * tab's Field View render database_column_definitions-typed values * identically instead of duplicating this switch statement. *------------------------------------------------------------------------------- # jokob support@netalertx.com GNU GPLv3 ----------------------------------------------------------------------------- */ /** * The DataTables init options shared by every plugin-data table in the app * (Plugin View's Objects/Events/History tables, Field View's per-field * tables) - paging/searching/ordering/lengthMenu are identical everywhere a * plugin's rows get rendered into a table, so this is the one place that set * is defined. Callers spread this into their own config and add whatever * else they need (ajax/serverSide for a server-paginated table, plain * data/columns for a small client-side one, createdRow, etc). * @param {string|null} skelSelector - jQuery selector for this table's own loading skeleton, faded out after the first draw. Pass null if the table has no per-table skeleton (e.g. a shared tab-level one is used instead). * @returns {object} A partial DataTables options object. */ function getStandardDataTableOptions(skelSelector) { return { autoWidth: false, paging: true, searching: true, ordering: true, pageLength: 25, lengthMenu: [[10, 25, 50, 100], [10, 25, 50, 100]], language: { emptyTable: getString('Gen_No_Data') }, // Fade out the skeleton only after the first draw so there is no gap // between the skeleton disappearing and the table rows appearing. initComplete: function() { if (skelSelector) { $(skelSelector).fadeOut(0, function() { $(this).hide(); }); } }, }; } // ----------------------------------------------------------------------------- // Get form control according to the column definition from config.json > database_column_definitions function getFormControl(dbColumnDef, value, index) { result = '' // Check if mapped_to_column_data exists and has a value to override the supplied value which is most likely `undefined` if (dbColumnDef.mapped_to_column_data && dbColumnDef.mapped_to_column_data.value) { value = dbColumnDef.mapped_to_column_data.value; } result = processColumnValue(dbColumnDef, value, index, dbColumnDef.type) return result; } // ----------------------------------------------------------------------------- // Process column value function processColumnValue(dbColumnDef, value, index, type) { if (type.includes('.')) { const typeParts = type.split('.'); // recursion for (const typePart of typeParts) { value = processColumnValue(dbColumnDef, value, index, typePart) } } else{ // pick form control based on the supplied type switch(type) { case 'label': value = `${value}`; break; case 'none': value = `${value}`; break; case 'textarea_readonly': value = ``; break; case 'textbox_save': value = value == 'null' ? '' : value; // hide 'null' values id = `${dbColumnDef.column}_${index}` value = `
`; break; case 'url': value = `${value}`; break; case 'url_http_https': value = ` / `; break; case 'device_name_mac': value = `
${value}
${createDeviceLink(value)}
`; break; case 'device_mac': value = `${value}`; break; case 'device_ip': value = `${value}`; break; case 'threshold': valueTmp = '' $.each(dbColumnDef.options, function(index, obj) { if(Number(value) < Number(obj.maximum) && valueTmp == '') { valueTmp = `
${value}
` // return; } }); value = valueTmp; break; case 'replace': $.each(dbColumnDef.options, function(index, obj) { if(value == obj.equals) { value = `${obj.replacement}` } }); break; case 'regex': for (const option of dbColumnDef.options) { if (option.type === type) { const regexPattern = new RegExp(option.param); const match = value.match(regexPattern); if (match) { // Return the first match value = match[0]; } } } break; case 'eval': for (const option of dbColumnDef.options) { if (option.type === type) { // console.log(option.param) value = eval(option.param); } } break; default: value = value + `
` ; } } // Default behavior if no match is found return value; }