diff --git a/blueprints/__init__.py b/blueprints/__init__.py index 890701f..e96de3f 100644 --- a/blueprints/__init__.py +++ b/blueprints/__init__.py @@ -330,7 +330,6 @@ def register_blueprints(app): 'admin_status': 'admin.admin_status', 'admin_health': 'admin.admin_health', # Social Media (Phase 6.2e) - 'admin_social_media': 'admin.admin_social_media', 'admin_social_audit': 'admin.admin_social_audit', # Digital Maturity & KRS Audit (Phase 6.2f) 'digital_maturity_dashboard': 'admin.digital_maturity_dashboard', diff --git a/blueprints/admin/routes_social.py b/blueprints/admin/routes_social.py index 9a7283f..7957c55 100644 --- a/blueprints/admin/routes_social.py +++ b/blueprints/admin/routes_social.py @@ -181,98 +181,6 @@ def _compute_social_health_score(platform_details): # ============================================================ # SOCIAL MEDIA ANALYTICS DASHBOARD -# ============================================================ - -@bp.route('/social-media') -@login_required -@role_required(SystemRole.OFFICE_MANAGER) -def admin_social_media(): - """Admin dashboard for social media analytics""" - db = SessionLocal() - try: - # Total counts per platform - platform_stats = db.query( - CompanySocialMedia.platform, - func.count(CompanySocialMedia.id).label('count'), - func.count(distinct(CompanySocialMedia.company_id)).label('companies') - ).filter( - CompanySocialMedia.is_valid == True - ).group_by(CompanySocialMedia.platform).all() - - # Companies with each platform combination - company_platforms = db.query( - Company.id, - Company.name, - Company.slug, - func.array_agg(distinct(CompanySocialMedia.platform)).label('platforms') - ).outerjoin( - CompanySocialMedia, - (Company.id == CompanySocialMedia.company_id) & (CompanySocialMedia.is_valid == True) - ).group_by(Company.id, Company.name, Company.slug).all() - - # Analysis - total_companies = len(company_platforms) - companies_with_sm = [c for c in company_platforms if c.platforms and c.platforms[0] is not None] - companies_without_sm = [c for c in company_platforms if not c.platforms or c.platforms[0] is None] - - # Platform combinations - platform_combos_raw = {} - for c in companies_with_sm: - platforms = sorted([p for p in c.platforms if p]) if c.platforms else [] - key = ', '.join(platforms) if platforms else 'Brak' - if key not in platform_combos_raw: - platform_combos_raw[key] = [] - platform_combos_raw[key].append({'id': c.id, 'name': c.name, 'slug': c.slug}) - - # Sort by number of companies (descending) - platform_combos = dict(sorted(platform_combos_raw.items(), key=lambda x: len(x[1]), reverse=True)) - - # Only Facebook - only_facebook = [c for c in companies_with_sm if set(c.platforms) == {'facebook'}] - # Only LinkedIn - only_linkedin = [c for c in companies_with_sm if set(c.platforms) == {'linkedin'}] - # Only Instagram - only_instagram = [c for c in companies_with_sm if set(c.platforms) == {'instagram'}] - # Has all major (FB + LI + IG) - has_all_major = [c for c in companies_with_sm if {'facebook', 'linkedin', 'instagram'}.issubset(set(c.platforms or []))] - - # Get all social media entries with company info for detailed view - all_entries = db.query( - CompanySocialMedia, - Company.name.label('company_name'), - Company.slug.label('company_slug') - ).join(Company).order_by( - Company.name, CompanySocialMedia.platform - ).all() - - # Freshness analysis - now = datetime.now() - fresh_30d = db.query(func.count(CompanySocialMedia.id)).filter( - CompanySocialMedia.verified_at >= now - timedelta(days=30) - ).scalar() - stale_90d = db.query(func.count(CompanySocialMedia.id)).filter( - CompanySocialMedia.verified_at < now - timedelta(days=90) - ).scalar() - - return render_template('admin/social_media.html', - platform_stats=platform_stats, - total_companies=total_companies, - companies_with_sm=len(companies_with_sm), - companies_without_sm=companies_without_sm, - platform_combos=platform_combos, - only_facebook=only_facebook, - only_linkedin=only_linkedin, - only_instagram=only_instagram, - has_all_major=has_all_major, - all_entries=all_entries, - fresh_30d=fresh_30d, - stale_90d=stale_90d, - now=now - ) - finally: - db.close() - - # ============================================================ # SOCIAL MEDIA AUDIT DASHBOARD # ============================================================ diff --git a/blueprints/admin/routes_status.py b/blueprints/admin/routes_status.py index 155fb62..f3f05da 100644 --- a/blueprints/admin/routes_status.py +++ b/blueprints/admin/routes_status.py @@ -637,7 +637,7 @@ def admin_health(): ('/health', 'Health check', 'api'), ('/admin/security', 'Bezpieczeństwo', 'admin'), ('/admin/seo', 'SEO Audit', 'admin'), - ('/admin/social-media', 'Social Media', 'admin'), + ('/admin/social-audit', 'Audyt social media', 'admin'), ('/admin/analytics', 'Analityka', 'admin'), ('/admin/forum', 'Forum', 'admin'), ('/admin/kalendarz', 'Kalendarz', 'admin'), diff --git a/templates/admin/social_audit_dashboard.html b/templates/admin/social_audit_dashboard.html index 6806e8e..121344d 100644 --- a/templates/admin/social_audit_dashboard.html +++ b/templates/admin/social_audit_dashboard.html @@ -524,12 +524,6 @@ Uruchom audyt - - - - - Szczegóły - diff --git a/templates/admin/social_media.html b/templates/admin/social_media.html deleted file mode 100755 index 45211cc..0000000 --- a/templates/admin/social_media.html +++ /dev/null @@ -1,537 +0,0 @@ -{% extends "base.html" %} - -{% block title %}Social Media Analytics - Norda Biznes Partner{% endblock %} - -{% block extra_css %} - -{% endblock %} - -{% block content %} -
-

Social Media Analytics

-

Pelny przeglad kont social media firm czlonkowskich

-
- - -
-
-
{{ companies_with_sm }}
-
Firm z Social Media
-
-
-
{{ companies_without_sm|length }}
-
Firm BEZ Social Media
-
- {% for stat in platform_stats %} -
-
{{ stat.companies }}
-
{{ stat.platform|title }}
-
- {% endfor %} -
- - -
-
-
{{ fresh_30d }}
-
Zweryfikowane < 30 dni
-
-
-
{{ stale_90d }}
-
Nieaktualne > 90 dni
-
-
- - -
-
- - - -
- - -
-

Kombinacje platform Social Media

-
- {% for combo, companies in platform_combos.items() %} -
-

- {% for platform in combo.split(', ') %} - {{ platform|upper }} - {% endfor %} - {{ companies|length }} -

-
- {% for company in companies %} - {{ company.name }} - {% endfor %} -
-
- {% endfor %} -
- - -

Analiza szczegolowa

-
-
-

Tylko Facebook {{ only_facebook|length }}

-
- {% for c in only_facebook %} - {{ c.name }} - {% endfor %} -
-
-
-

Tylko LinkedIn {{ only_linkedin|length }}

-
- {% for c in only_linkedin %} - {{ c.name }} - {% endfor %} -
-
-
-

Tylko Instagram {{ only_instagram|length }}

-
- {% for c in only_instagram %} - {{ c.name }} - {% endfor %} -
-
-
-

Wszystkie glowne (FB+LI+IG) {{ has_all_major|length }}

-
- {% for c in has_all_major %} - {{ c.name }} - {% endfor %} -
-
-
-
- - -
-

Firmy bez danych Social Media ({{ companies_without_sm|length }})

-

Te firmy wymagaja uzupelnienia danych o kontach social media.

-
- {% for c in companies_without_sm|sort(attribute='name') %} - {{ c.name }} - {% endfor %} -
-
- - -
-

Wszystkie wpisy Social Media

- - -
- Filtruj platformy: - - - - - - - - -
- -
- - - - - - - - - - - - - {% for entry in all_entries %} - {% set sm = entry[0] %} - - - - - - - - - {% endfor %} - -
FirmaPlatformaURLZrodloZweryfikowanoStatus
{{ entry.company_name }}{{ sm.platform|upper }}{{ sm.url[:50] }}{% if sm.url|length > 50 %}...{% endif %}{{ sm.source or '-' }} - {% set days_ago = (now - sm.verified_at).days if sm.verified_at else 999 %} - - {{ sm.verified_at.strftime('%Y-%m-%d') if sm.verified_at else '-' }} - - {% if sm.check_status == 'needs_verification' %} - Do weryfikacji - {% elif not sm.is_valid %} - Nieaktywny - {% else %} - OK - {% endif %} -
-
-
-
-{% endblock %} - -{% block extra_js %} -const now = new Date(); - -// Active platform filters (empty = all) -let activeFilters = new Set(); - -function showTab(tabName, clickedBtn) { - // Hide all tabs - document.querySelectorAll('.tab-content').forEach(el => el.classList.remove('active')); - document.querySelectorAll('.tab').forEach(el => el.classList.remove('active')); - - // Show selected tab - document.getElementById('tab-' + tabName).classList.add('active'); - if (clickedBtn) clickedBtn.classList.add('active'); -} - -function toggleFilter(platform, btn) { - const allBtn = document.querySelector('.filter-btn[data-platform="all"]'); - - if (platform === 'all') { - // Clear all filters, show everything - activeFilters.clear(); - document.querySelectorAll('.filter-btn').forEach(b => b.classList.remove('active')); - allBtn.classList.add('active'); - } else { - // Toggle specific platform - allBtn.classList.remove('active'); - - if (activeFilters.has(platform)) { - activeFilters.delete(platform); - btn.classList.remove('active'); - } else { - activeFilters.add(platform); - btn.classList.add('active'); - } - - // If no filters active, activate "all" - if (activeFilters.size === 0) { - allBtn.classList.add('active'); - } - } - - applyFilters(); -} - -function applyFilters() { - const table = document.getElementById('sm-table'); - if (!table) return; - - const rows = table.querySelectorAll('tbody tr'); - let visibleCount = 0; - - rows.forEach(row => { - const platform = row.dataset.platform; - - if (activeFilters.size === 0 || activeFilters.has(platform)) { - row.classList.remove('hidden-row'); - visibleCount++; - } else { - row.classList.add('hidden-row'); - } - }); - - // Update count display - const countEl = document.getElementById('filter-count'); - if (countEl) { - if (activeFilters.size === 0) { - countEl.textContent = ''; - } else { - countEl.textContent = `Pokazano: ${visibleCount} z ${rows.length}`; - } - } -} -{% endblock %} diff --git a/templates/base.html b/templates/base.html index f7a2495..ee398df 100755 --- a/templates/base.html +++ b/templates/base.html @@ -1654,45 +1654,45 @@ - Deklaracje + Zarządzanie deklaracjami - Składki + Zarządzanie składkami {% if current_user.has_role(SystemRole.ADMIN) %} - Korzyści + Zarządzanie korzyściami {% endif %} - Rekomendacje + Moderacja rekomendacji - Kalendarz + Zarządzanie kalendarzem - Forum + Moderacja forum - Ogłoszenia + Moderacja ogłoszeń @@ -1700,17 +1700,17 @@ Insights AI - + - Social Media + Audyt social media - Social Dashboard beta + Publikacja social media beta diff --git a/templates/dashboard.html b/templates/dashboard.html index 523ea06..9bfe6a8 100755 --- a/templates/dashboard.html +++ b/templates/dashboard.html @@ -932,12 +932,12 @@ Zarządzaj - + -
Social Media
- Edytuj +
Audyt social media
+ Otwórz