{% extends "base.html" %} {% block title %}Panel Audyt GBP - Norda Biznes Partner{% endblock %} {% block extra_css %} {% endblock %} {% block content %}

Panel Audyt GBP

Analiza kompletnosci profili Google Business Profile czlonkow Norda Biznes

Dane z Google Business Profile (via Places API)
Dopasuj Place ID API
{{ stats.excellent_count }} Doskonaly (90-100%)
{{ stats.good_count }} Dobry (70-89%)
{{ stats.poor_count }} Slaby (0-69%)
{{ stats.not_audited_count }} Niezbadane
{{ stats.avg_completeness|default('-', true) }}{% if stats.avg_completeness %}%{% endif %} Srednia kompletnosc
{{ stats.avg_rating|default('-', true) }}{% if stats.avg_rating %}/5{% endif %} Srednia ocena Google
{{ stats.total_reviews }} Lacznie recenzji

Pokrycie pol GBP

{% set fields = [ ('name', 'Nazwa firmy', stats.field_coverage.name), ('address', 'Adres', stats.field_coverage.address), ('phone', 'Telefon', stats.field_coverage.phone), ('website', 'Strona WWW', stats.field_coverage.website), ('hours', 'Godziny otwarcia', stats.field_coverage.hours), ('categories', 'Kategorie', stats.field_coverage.categories), ('photos', 'Zdjecia', stats.field_coverage.photos), ('description', 'Opis', stats.field_coverage.description), ('services', 'Uslugi', stats.field_coverage.services), ('reviews', 'Recenzje', stats.field_coverage.reviews) ] %} {% for field_id, field_name, percent in fields %}
{{ field_name }} {{ percent }}%
{% endfor %}
90-100% (doskonaly)
70-89% (dobry)
0-69% (slaby)
{% if companies %}
{% for company in companies %} {% endfor %}
Firma Kategoria Kompletnosc Ocena Recenzje Zdjecia Ostatni audyt Akcje
{{ company.name }} {{ company.category or 'Inne' }} {% if company.completeness_score is not none %} {{ company.completeness_score }}% {% else %} - {% endif %} {% if company.average_rating %}
{{ company.average_rating }}
{% else %} - {% endif %}
{{ company.review_count }} {{ company.photo_count }} {% if company.audit_date %} {% set days_ago = (now - company.audit_date).days %} {{ company.audit_date|local_time('%d.%m.%Y') }} {% else %} Nigdy {% endif %}
{% else %}

Brak firm do wyswietlenia

Nie znaleziono firm z danymi GBP.

{% endif %} {% endblock %} {% block extra_js %} // Sorting state let currentSort = { column: 'completeness', direction: 'desc' }; // Sort table function sortTable(column) { const tbody = document.getElementById('gbpTableBody'); const rows = Array.from(tbody.querySelectorAll('tr')); const headers = document.querySelectorAll('.gbp-table th[data-sort]'); // Toggle direction if same column if (currentSort.column === column) { currentSort.direction = currentSort.direction === 'asc' ? 'desc' : 'asc'; } else { currentSort.column = column; currentSort.direction = 'desc'; } // Update header classes headers.forEach(h => { h.classList.remove('sorted', 'sorted-asc', 'sorted-desc'); if (h.dataset.sort === column) { h.classList.add('sorted', `sorted-${currentSort.direction}`); } }); // Sort rows rows.sort((a, b) => { let aVal, bVal; if (column === 'name') { aVal = a.dataset.name || ''; bVal = b.dataset.name || ''; } else if (column === 'category') { aVal = a.dataset.category || ''; bVal = b.dataset.category || ''; } else if (column === 'date') { aVal = new Date(a.dataset.date).getTime(); bVal = new Date(b.dataset.date).getTime(); } else { aVal = parseFloat(a.dataset[column]) || -1; bVal = parseFloat(b.dataset[column]) || -1; } if (aVal < bVal) return currentSort.direction === 'asc' ? -1 : 1; if (aVal > bVal) return currentSort.direction === 'asc' ? 1 : -1; return 0; }); // Re-append rows rows.forEach(row => tbody.appendChild(row)); } // Setup sorting click handlers document.querySelectorAll('.gbp-table th[data-sort]').forEach(th => { th.addEventListener('click', () => sortTable(th.dataset.sort)); }); // Filtering function applyFilters() { const category = document.getElementById('filterCategory').value; const score = document.getElementById('filterScore').value; const search = document.getElementById('filterSearch').value.toLowerCase(); const rows = document.querySelectorAll('#gbpTableBody tr'); rows.forEach(row => { let show = true; // Category filter if (category && row.dataset.category !== category) { show = false; } // Score filter if (score && show) { const completenessScore = parseFloat(row.dataset.completeness); if (score === 'excellent' && (completenessScore < 90 || completenessScore < 0)) show = false; else if (score === 'good' && (completenessScore < 70 || completenessScore >= 90)) show = false; else if (score === 'poor' && (completenessScore < 0 || completenessScore >= 70)) show = false; else if (score === 'none' && completenessScore >= 0) show = false; } // Search filter if (search && show) { if (!row.dataset.name.includes(search)) { show = false; } } row.style.display = show ? '' : 'none'; }); } function resetFilters() { document.getElementById('filterCategory').value = ''; document.getElementById('filterScore').value = ''; document.getElementById('filterSearch').value = ''; applyFilters(); } // ============================================================ // GBP Batch Audit // ============================================================ var _gbpBatchSince = 0; function startGbpBatch() { document.getElementById('gbpBatchConfirm').style.display = 'flex'; } function doStartGbpBatch() { var btn = document.getElementById('gbpBatchBtn'); btn.disabled = true; btn.textContent = 'Uruchamianie...'; _gbpBatchSince = 0; var fetchGoogle = document.getElementById('gbpFetchGoogle').checked ? '1' : '0'; fetch('{{ url_for("admin.admin_gbp_audit_run_batch") }}', { method: 'POST', headers: {'Content-Type': 'application/x-www-form-urlencoded', 'X-CSRFToken': '{{ csrf_token() }}'}, body: 'fetch_google=' + fetchGoogle }) .then(function(r) { return r.json(); }) .then(function(data) { if (data.status === 'started') { document.getElementById('gbpBatchPanel').style.display = 'block'; document.getElementById('gbpBatchCounter').textContent = '0 / ' + data.total; document.getElementById('gbpBatchFeed').innerHTML = ''; pollGbpBatch(); } else { document.getElementById('gbpBatchPanel').style.display = 'block'; document.getElementById('gbpBatchTitle').textContent = data.error || 'Blad uruchamiania'; document.getElementById('gbpBatchTitle').style.color = '#dc2626'; document.getElementById('gbpBatchSpinner').style.display = 'none'; btn.disabled = false; btn.textContent = 'Uruchom audyt'; } }) .catch(function(e) { document.getElementById('gbpBatchPanel').style.display = 'block'; document.getElementById('gbpBatchTitle').textContent = 'Blad polaczenia: ' + e.message; document.getElementById('gbpBatchTitle').style.color = '#dc2626'; document.getElementById('gbpBatchSpinner').style.display = 'none'; btn.disabled = false; btn.textContent = 'Uruchom audyt'; }); } function pollGbpBatch() { fetch('{{ url_for("admin.admin_gbp_audit_batch_status") }}?since=' + _gbpBatchSince) .then(function(r) { return r.json(); }) .then(function(data) { document.getElementById('gbpBatchCounter').textContent = data.completed + ' / ' + data.total; document.getElementById('gbpBatchProgressBar').style.width = data.progress + '%'; if (data.errors > 0) { document.getElementById('gbpBatchErrors').textContent = data.errors + ' bledow'; } // Append new feed entries var feed = document.getElementById('gbpBatchFeed'); data.results.forEach(function(r) { var line = document.createElement('div'); line.style.padding = '3px 0'; line.style.borderBottom = '1px solid #f3f4f6'; if (r.status === 'changes' || r.status === 'no_changes' || r.status === 'ok') { var scoreColor = r.score >= 90 ? '#166534' : (r.score >= 70 ? '#92400e' : '#991b1b'); var scoreBg = r.score >= 90 ? '#dcfce7' : (r.score >= 70 ? '#fef3c7' : '#fee2e2'); var changeInfo = ''; if (r.status === 'changes') { var diff = r.old_score !== null ? (r.score - r.old_score) : null; changeInfo = diff !== null ? (' (' + (diff > 0 ? '+' : '') + diff + ')') : ' nowy'; } line.innerHTML = ' ' + r.company_name + ' ' + r.score + '%' + changeInfo; } else { line.innerHTML = ' ' + r.company_name + ' ' + (r.error || 'blad') + ''; } feed.appendChild(line); }); feed.scrollTop = feed.scrollHeight; _gbpBatchSince += data.results.length; if (data.running) { setTimeout(pollGbpBatch, 2000); } else { // Completed document.getElementById('gbpBatchSpinner').style.animation = 'none'; document.getElementById('gbpBatchSpinner').style.borderColor = '#22c55e'; var pendingCount = data.pending_count || 0; if (pendingCount > 0) { document.getElementById('gbpBatchTitle').innerHTML = 'Audyt zakończony — Przejrzyj ' + pendingCount + ' wyników przed zapisem'; document.getElementById('gbpBatchTitle').style.color = '#1e40af'; document.getElementById('gbpBatchSubtitle').textContent = 'Dane NIE zostały jeszcze zapisane — wymagają Twojej akceptacji'; } else { document.getElementById('gbpBatchTitle').textContent = 'Audyt zakończony — brak zmian do zatwierdzenia'; document.getElementById('gbpBatchTitle').style.color = '#166534'; document.getElementById('gbpBatchSubtitle').textContent = 'Wszystkie firmy zbadane pomyślnie'; } var btn = document.getElementById('gbpBatchBtn'); btn.disabled = false; btn.innerHTML = ' Uruchom audyt'; } }) .catch(function() { setTimeout(pollGbpBatch, 5000); }); } // Check if batch is already running on page load (function() { fetch('{{ url_for("admin.admin_gbp_audit_batch_status") }}?since=0') .then(function(r) { return r.json(); }) .then(function(data) { if (data.running) { document.getElementById('gbpBatchPanel').style.display = 'block'; document.getElementById('gbpBatchCounter').textContent = data.completed + ' / ' + data.total; document.getElementById('gbpBatchProgressBar').style.width = data.progress + '%'; document.getElementById('gbpBatchBtn').disabled = true; document.getElementById('gbpBatchBtn').textContent = 'Audyt w toku...'; _gbpBatchSince = data.results_total; pollGbpBatch(); } }) .catch(function() {}); })(); {% endblock %}