// Sample data for demonstration const filtersData = { "Post1": { "filter1": ["Field1", "Field2"], "filter2": ["Field3"], "filter3": [] }, "Post2": { "filter1": ["Field4"], "filter2": [], "filter3": ["Field5", "Field6"] } }; const allFields = ["Poste", "Field1", "Field2", "Field3", "Field4", "Field5", "Field6", "Field7", "Field8"]; const sampleData = { "Post1": { "Field1": ["Value1", "Value2", "Value1", "Value3"], "Field2": ["A", "B", "C", "A"], "Field3": ["X", "Y", "Z"] }, "Post2": { "Field4": ["One", "Two", "Three"], "Field5": ["1", "2", "3", "2"], "Field6": ["Alpha", "Beta", "Alpha"] } }; const selectedPosts = ["Post1", "Post2"]; // Initialize the page $(document).ready(function() { renderPosts(); renderFilters(); }); function renderPosts() { const postsContainer = $('#postsContainer'); postsContainer.empty(); allFields.filter(field => field === 'Poste').forEach(poste => { const isChecked = selectedPosts.includes(poste); postsContainer.append(` `); }); } function renderFilters() { const filtersContainer = $('#filtersContainer'); filtersContainer.empty(); selectedPosts.forEach((post, idx) => { const filters = filtersData[post] || {filter1: [], filter2: [], filter3: []}; filtersContainer.append(`

Filters for ${post}

${[1, 2, 3].map(c => { const filterName = `${post}_filter${c}_fields`; const currentFields = filters[`filter${c}`] || []; const otherFields = c === 1 ? (filters.filter2 || []).concat(filters.filter3 || []) : (c === 2 ? (filters.filter1 || []).concat(filters.filter3 || []) : (filters.filter1 || []).concat(filters.filter2 || [])); const isAdded = currentFields.length > 0; return `

Filter ${c}

${allFields.filter(field => field !== 'Poste').map(field => { const checked = currentFields.includes(field); const disabled = otherFields.includes(field); return `
`; }).join('')}
`; }).join('')}
`); }); feather.replace(); } function deselectAllPosts() { $('input[name="postes"]:checked').prop('checked', false); updateSelectedPosts(); } function updateSelectedPosts() { const selected = $('input[name="postes"]:checked').map(function() { return $(this).val(); }).get(); $('#selectedPostsHidden').val(JSON.stringify(selected)); // In a real app, you would update the filters section here } function deselectAllFilters(postIndex) { $(`.filtersContainer[data-index="${postIndex}"] input[type="checkbox"]:checked`).prop('checked', false); } function addFilter(postIndex) { const emptyFilter = $(`.filtersContainer[data-index="${postIndex}"] .cacher`).first(); if (emptyFilter.length) { emptyFilter.removeClass('cacher'); } } function showFieldStats(post, field) { const statsElement = $(`#stats_${post}_${field}`); const isChecked = $(`input[id^="${field}_"]:checked`).length > 0; if (!isChecked) { statsElement.addClass('hidden'); return; } const values = sampleData[post]?.[field] || []; const totalCount = values.length; // Count occurrences of each value const valueCounts = {}; values.forEach(value => { valueCounts[value] = (valueCounts[value] || 0) + 1; }); // Sort all values by count (descending) const sortedValues = Object.entries(valueCounts) .sort((a, b) => b[1] - a[1]); let statsHTML = `
${field} - ${post}
Total entries: ${totalCount}
${sortedValues.map(([value, count]) => { const percentage = ((count / totalCount) * 100).toFixed(1); const isDuplicate = count > 1; return ` `; }).join('')}
Value Count %
${value} ${count} ${percentage}%
${sortedValues.some(([_, count]) => count > 1) ? `
${sortedValues.filter(([_, count]) => count > 1).length} duplicate values found
` : `
No duplicates found
` }
`; statsElement.html(statsHTML).removeClass('hidden'); feather.replace(); }