Refactor TableManager to improve data transformation logic for indexed and direct formats
This commit is contained in:
parent
d110a106ad
commit
897eb490f9
1 changed files with 24 additions and 24 deletions
22
dist/js/app.js
vendored
22
dist/js/app.js
vendored
|
|
@ -167,14 +167,8 @@ class TableManager {
|
|||
|
||||
// New method to transform indexed data to regular format
|
||||
_transformIndexedData(indexedData) {
|
||||
// Check if data is in the new direct format (host -> service -> ✅/❌)
|
||||
const firstHost = Object.values(indexedData)[0];
|
||||
if (firstHost && typeof firstHost === 'object' && !firstHost.hasOwnProperty('services') && !firstHost.hasOwnProperty('supported')) {
|
||||
// Data is already in the new direct format
|
||||
this.state.isIndexedFormat = false;
|
||||
return indexedData;
|
||||
}
|
||||
|
||||
// Check if data is in indexed format (has services and supported properties)
|
||||
if (indexedData.services && indexedData.supported) {
|
||||
// Handle indexed format
|
||||
const { services, supported } = indexedData;
|
||||
const transformed = {};
|
||||
|
|
@ -191,19 +185,24 @@ class TableManager {
|
|||
this.state.isIndexedFormat = true;
|
||||
|
||||
return transformed;
|
||||
} else {
|
||||
// Data is already in the direct format (host -> service -> ✅/❌)
|
||||
this.state.isIndexedFormat = false;
|
||||
return indexedData;
|
||||
}
|
||||
}
|
||||
|
||||
// Modified method to handle both formats
|
||||
generateTable(data = {}) {
|
||||
if (!this.elements.container) return;
|
||||
|
||||
// Handle both old and new indexed formats
|
||||
// Handle both indexed and direct formats
|
||||
let processedData;
|
||||
if (data.services && data.supported) {
|
||||
// New indexed format
|
||||
// Indexed format
|
||||
processedData = this._transformIndexedData(data);
|
||||
} else {
|
||||
// Old format
|
||||
// Direct format
|
||||
processedData = data;
|
||||
this.state.isIndexedFormat = false;
|
||||
// Try to extract services from first entry
|
||||
|
|
@ -1010,6 +1009,7 @@ document.addEventListener('DOMContentLoaded', async () => {
|
|||
|
||||
results.forEach((result, index) => {
|
||||
const containers = ['#file-hosts-table-container', '#adult-hosts-table-container'];
|
||||
|
||||
loadingManager.hide(containers[index], loaders[index]);
|
||||
|
||||
if (result.status === 'fulfilled') {
|
||||
|
|
|
|||
Loading…
Reference in a new issue