Files
eveAI/nginx/frontend_src/js/tabulator-setup.js

68 lines
3.1 KiB
JavaScript

// JavaScript imports
import { TabulatorFull } from 'tabulator-tables';
/**
* Basis Tabulator Setup
* Dit bestand bevat configuratie voor Tabulator tabellen
*/
// Algemene instellingen voor Tabulator
document.addEventListener('DOMContentLoaded', function() {
if (typeof TabulatorFull === 'function') {
console.log('Tabulator bibliotheek is geladen en geconfigureerd');
} else {
console.error('Tabulator bibliotheek is niet beschikbaar');
}
});
// Maak Tabulator globaal beschikbaar
window.Tabulator = TabulatorFull;
// Zorg ervoor dat de formattermodule correct is geregistreerd
if (typeof TabulatorFull.prototype.moduleRegistered !== 'function' ||
!TabulatorFull.prototype.moduleRegistered('format')) {
console.warn('Format module niet gevonden in Tabulator, wordt toegevoegd');
// Basismodule definiëren indien niet aanwezig
TabulatorFull.prototype.moduleRegistered = function(name) {
return this.modules && this.modules[name];
};
TabulatorFull.modules = TabulatorFull.modules || {};
TabulatorFull.modules.format = TabulatorFull.modules.format || {};
TabulatorFull.modules.format.formatters = TabulatorFull.modules.format.formatters || {};
}
// Registreer een universele formatter 'typeBadge' zodat string-formatters altijd werken
try {
if (typeof TabulatorFull.prototype.extendModule === 'function') {
TabulatorFull.prototype.extendModule('format', 'formatters', {
typeBadge: function(cell) {
const raw = (cell.getValue() || '').toString();
const val = raw.toLowerCase();
const map = {
'agent': { cls: 'badge text-bg-primary', label: raw || 'Agent' },
'task': { cls: 'badge text-bg-warning', label: raw || 'Task' },
'tool': { cls: 'badge text-bg-info', label: raw || 'Tool' },
};
const conf = map[val] || { cls: 'badge text-bg-secondary', label: raw };
return `<span class="${conf.cls}">${conf.label}</span>`;
}
});
} else {
// Fallback voor oudere Tabulator builds zonder extendModule
TabulatorFull.modules = TabulatorFull.modules || {};
TabulatorFull.modules.format = TabulatorFull.modules.format || {};
TabulatorFull.modules.format.formatters = TabulatorFull.modules.format.formatters || {};
TabulatorFull.modules.format.formatters.typeBadge = function(cell) {
const raw = (cell.getValue() || '').toString();
const val = raw.toLowerCase();
const map = {
'agent': { cls: 'badge text-bg-primary', label: raw || 'Agent' },
'task': { cls: 'badge text-bg-warning', label: raw || 'Task' },
'tool': { cls: 'badge text-bg-info', label: raw || 'Tool' },
};
const conf = map[val] || { cls: 'badge text-bg-secondary', label: raw };
return `<span class="${conf.cls}">${conf.label}</span>`;
};
}
} catch (e) {
console.warn('Kon typeBadge formatter niet registreren:', e);
}